Fix assert instantiating string init of static variable
authorBen Langmuir <blangmuir@apple.com>
Mon, 26 Jan 2015 19:04:10 +0000 (19:04 +0000)
committerBen Langmuir <blangmuir@apple.com>
Mon, 26 Jan 2015 19:04:10 +0000 (19:04 +0000)
... when the variable's type is a typedef of a ConstantArrayType. Just
look through the typedef (and any other sugar).  We only use the
constant array type here to get the element count.

llvm-svn: 227115

clang/lib/Sema/SemaInit.cpp
clang/test/SemaTemplate/instantiate-static-var.cpp

index 9aca373..e354869 100644 (file)
@@ -149,9 +149,9 @@ static void updateStringLiteralType(Expr *E, QualType Ty) {
 static void CheckStringInit(Expr *Str, QualType &DeclT, const ArrayType *AT,
                             Sema &S) {
   // Get the length of the string as parsed.
-  uint64_t StrLength =
-    cast<ConstantArrayType>(Str->getType())->getSize().getZExtValue();
-
+  auto *ConstantArrayTy =
+      cast<ConstantArrayType>(Str->getType()->getUnqualifiedDesugaredType());
+  uint64_t StrLength = ConstantArrayTy->getSize().getZExtValue();
 
   if (const IncompleteArrayType *IAT = dyn_cast<IncompleteArrayType>(AT)) {
     // C99 6.7.8p14. We have an array of character type with unknown size
index f309f29..a7b3433 100644 (file)
@@ -114,3 +114,15 @@ namespace PR6449 {
   template class X1<char>;
 
 }
+
+typedef char MyString[100];
+template <typename T>
+struct StaticVarWithTypedefString {
+  static MyString str;
+};
+template <typename T>
+MyString StaticVarWithTypedefString<T>::str = "";
+
+void testStaticVarWithTypedefString() {
+  (void)StaticVarWithTypedefString<int>::str;
+}