summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-03-15 20:12:13 +0000
committerAnders Carlsson <andersca@mac.com>2009-03-15 20:12:13 +0000
commit5bd30395b96ce7ab3e5495a2af5639c3b29669ea (patch)
treeb9c498f9379c40dfa47b3ad7434f971ee6a6fde2 /clang
parent27de6a5e9148f3090fdf4e70c50a9238e60d11d0 (diff)
downloadbcm5719-llvm-5bd30395b96ce7ab3e5495a2af5639c3b29669ea.tar.gz
bcm5719-llvm-5bd30395b96ce7ab3e5495a2af5639c3b29669ea.zip
(Hopefully) instantiate dependent array types correctly.
llvm-svn: 67032
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Lex/Preprocessor.cpp3
-rw-r--r--clang/lib/Sema/SemaTemplateInstantiate.cpp24
-rw-r--r--clang/test/SemaTemplate/instantiate-array.cpp28
3 files changed, 52 insertions, 3 deletions
diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp
index 38a6919be37..3afa4ee6b23 100644
--- a/clang/lib/Lex/Preprocessor.cpp
+++ b/clang/lib/Lex/Preprocessor.cpp
@@ -488,6 +488,9 @@ static void InitializePredefinedMacros(Preprocessor &PP,
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/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index b7f0bbc923a..dbdc5a8a716 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -283,9 +283,27 @@ QualType
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/clang/test/SemaTemplate/instantiate-array.cpp b/clang/test/SemaTemplate/instantiate-array.cpp
new file mode 100644
index 00000000000..d67645e0417
--- /dev/null
+++ b/clang/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");
OpenPOWER on IntegriCloud