From 577b39349e20a5ca39bd4aa04793aa1bdfd6216a Mon Sep 17 00:00:00 2001 From: Ben Langmuir Date: Mon, 26 Jan 2015 19:04:10 +0000 Subject: [PATCH] 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. llvm-svn: 227115 --- clang/lib/Sema/SemaInit.cpp | 6 +++--- clang/test/SemaTemplate/instantiate-static-var.cpp | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index 9aca373..e354869 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/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/clang/test/SemaTemplate/instantiate-static-var.cpp b/clang/test/SemaTemplate/instantiate-static-var.cpp index f309f29..a7b3433 100644 --- a/clang/test/SemaTemplate/instantiate-static-var.cpp +++ b/clang/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; +} -- 2.7.4