From: Ben Langmuir Date: Mon, 26 Jan 2015 19:04:10 +0000 (+0000) Subject: Fix assert instantiating string init of static variable X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=28dfa35addb4a4fcd35c9e3b656f919e456e4021;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@227115 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index 9aca373d97..e354869484 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -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(Str->getType())->getSize().getZExtValue(); - + auto *ConstantArrayTy = + cast(Str->getType()->getUnqualifiedDesugaredType()); + uint64_t StrLength = ConstantArrayTy->getSize().getZExtValue(); if (const IncompleteArrayType *IAT = dyn_cast(AT)) { // C99 6.7.8p14. We have an array of character type with unknown size diff --git a/test/SemaTemplate/instantiate-static-var.cpp b/test/SemaTemplate/instantiate-static-var.cpp index f309f29eaf..a7b3433b35 100644 --- a/test/SemaTemplate/instantiate-static-var.cpp +++ b/test/SemaTemplate/instantiate-static-var.cpp @@ -114,3 +114,15 @@ namespace PR6449 { template class X1; } + +typedef char MyString[100]; +template +struct StaticVarWithTypedefString { + static MyString str; +}; +template +MyString StaticVarWithTypedefString::str = ""; + +void testStaticVarWithTypedefString() { + (void)StaticVarWithTypedefString::str; +}