(Hopefully) instantiate dependent array types correctly.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67032 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp
index 38a6919..3afa4ee 100644
--- a/lib/Lex/Preprocessor.cpp
+++ b/lib/Lex/Preprocessor.cpp
@@ -488,6 +488,9 @@
else if (0) // STDC94 ?
DefineBuiltinMacro(Buf, "__STDC_VERSION__=199409L");
+ if (PP.getLangOptions().CPlusPlus0x)
+ DefineBuiltinMacro(Buf, "__GXX_EXPERIMENTAL_CXX0X__");
+
if (PP.getLangOptions().Freestanding)
DefineBuiltinMacro(Buf, "__STDC_HOSTED__=0");
else
diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp
index b7f0bbc..dbdc5a8 100644
--- a/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/lib/Sema/SemaTemplateInstantiate.cpp
@@ -283,9 +283,27 @@
TemplateTypeInstantiator::
InstantiateDependentSizedArrayType(const DependentSizedArrayType *T,
unsigned Quals) const {
- // FIXME: Implement this
- assert(false && "Cannot instantiate DependentSizedArrayType yet");
- return QualType();
+ Expr *ArraySize = T->getSizeExpr();
+ assert(ArraySize->isValueDependent() &&
+ "dependent sized array types must have value dependent size expr");
+
+ // Instantiate the element type if needed
+ QualType ElementType = T->getElementType();
+ if (ElementType->isDependentType()) {
+ ElementType = Instantiate(ElementType);
+ if (ElementType.isNull())
+ return QualType();
+ }
+
+ // Instantiate the size expression
+ Sema::OwningExprResult InstantiatedArraySize =
+ SemaRef.InstantiateExpr(ArraySize, TemplateArgs, NumTemplateArgs);
+ if (InstantiatedArraySize.isInvalid())
+ return QualType();
+
+ return SemaRef.BuildArrayType(ElementType, T->getSizeModifier(),
+ (Expr *)InstantiatedArraySize.release(),
+ T->getIndexTypeQualifier(), Loc, Entity);
}
QualType
diff --git a/test/SemaTemplate/instantiate-array.cpp b/test/SemaTemplate/instantiate-array.cpp
new file mode 100644
index 0000000..d67645e
--- /dev/null
+++ b/test/SemaTemplate/instantiate-array.cpp
@@ -0,0 +1,28 @@
+// RUN: clang -fsyntax-only -verify %s -std=c++0x
+
+#ifndef __GXX_EXPERIMENTAL_CXX0X__
+#define __CONCAT(__X, __Y) __CONCAT1(__X, __Y)
+#define __CONCAT1(__X, __Y) __X ## __Y
+
+#define static_assert(__b, __m) \
+ typedef int __CONCAT(__sa, __LINE__)[__b ? 1 : -1]
+#endif
+
+template <int N> class IntArray {
+ int elems[N];
+};
+
+static_assert(sizeof(IntArray<10>) == sizeof(int) * 10, "Array size mismatch");
+static_assert(sizeof(IntArray<1>) == sizeof(int) * 1, "Array size mismatch");
+
+template <typename T> class TenElementArray {
+ int elems[10];
+};
+
+static_assert(sizeof(TenElementArray<int>) == sizeof(int) * 10, "Array size mismatch");
+
+template<typename T, int N> class Array {
+ T elems[N];
+};
+
+static_assert(sizeof(Array<int, 10>) == sizeof(int) * 10, "Array size mismatch");