PR16540: ASTVector::insert(Context, Iter, Element) doesn't compile
Fix some uninstantiable code in ASTVector::insert. I've added a
cheap-and-dirty compile test for this, because I don't have the time to
figure out a nice way to get a real ASTContext to implement executable
tests - but we probably should have them for this ADT.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186253 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/AST/ASTVector.h b/include/clang/AST/ASTVector.h
index 669e50d..0d4b3c4 100644
--- a/include/clang/AST/ASTVector.h
+++ b/include/clang/AST/ASTVector.h
@@ -216,11 +216,11 @@
iterator insert(ASTContext &C, iterator I, const T &Elt) {
if (I == this->end()) { // Important special case for empty vector.
- push_back(Elt);
+ push_back(Elt, C);
return this->end()-1;
}
- if (this->EndX < this->CapacityX) {
+ if (this->End < this->Capacity) {
Retry:
new (this->end()) T(this->back());
this->setEnd(this->end()+1);
diff --git a/unittests/AST/ASTVectorTest.cpp b/unittests/AST/ASTVectorTest.cpp
new file mode 100644
index 0000000..f852743
--- /dev/null
+++ b/unittests/AST/ASTVectorTest.cpp
@@ -0,0 +1,26 @@
+//===- unittests/AST/DeclTest.cpp --- Declaration tests -------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Unit tests for the ASTVector container.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Support/Compiler.h"
+#include "clang/AST/ASTVector.h"
+#include "clang/Basic/TargetInfo.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+
+LLVM_ATTRIBUTE_UNUSED void CompileTest() {
+ ASTContext *C = 0;
+ ASTVector<int> V;
+ V.insert(*C, V.begin(), 0);
+}
diff --git a/unittests/AST/CMakeLists.txt b/unittests/AST/CMakeLists.txt
index c414ae3..70f86d3 100644
--- a/unittests/AST/CMakeLists.txt
+++ b/unittests/AST/CMakeLists.txt
@@ -1,6 +1,7 @@
add_clang_unittest(ASTTests
ASTContextParentMapTest.cpp
ASTTypeTraitsTest.cpp
+ ASTVectorTest.cpp
CommentLexer.cpp
CommentParser.cpp
DeclPrinterTest.cpp