r227115 - Fix assert instantiating string init of static variable

Ben Langmuir blangmuir at apple.com
Mon Jan 26 11:04:10 PST 2015


Author: benlangmuir
Date: Mon Jan 26 13:04:10 2015
New Revision: 227115

URL: http://llvm.org/viewvc/llvm-project?rev=227115&view=rev
Log:
Fix assert instantiating string init of static variable

... 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.

Modified:
    cfe/trunk/lib/Sema/SemaInit.cpp
    cfe/trunk/test/SemaTemplate/instantiate-static-var.cpp

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=227115&r1=227114&r2=227115&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Mon Jan 26 13:04:10 2015
@@ -149,9 +149,9 @@ static void updateStringLiteralType(Expr
 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

Modified: cfe/trunk/test/SemaTemplate/instantiate-static-var.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-static-var.cpp?rev=227115&r1=227114&r2=227115&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-static-var.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-static-var.cpp Mon Jan 26 13:04:10 2015
@@ -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;
+}





More information about the cfe-commits mailing list