From: Anders Carlsson Date: Wed, 2 Sep 2009 19:17:55 +0000 (+0000) Subject: Fix a codegen crash when a class template has a constructor that does member initiali... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f4b5f5c6a1487317aab9aa30d97bccfd57c82c98;p=clang Fix a codegen crash when a class template has a constructor that does member initialization of an anonymous union. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80826 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index 285cc62012..807115eb67 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -242,17 +242,19 @@ Decl *TemplateDeclInstantiator::VisitFieldDecl(FieldDecl *D) { D->getTypeSpecStartLoc(), D->getAccess(), 0); - if (Field) { - if (Invalid) - Field->setInvalidDecl(); - - if (!Field->getDeclName()) { - // Keep track of where this decl came from. - SemaRef.Context.setInstantiatedFromUnnamedFieldDecl(Field, D); - } + if (!Field) + return 0; + + if (Invalid) + Field->setInvalidDecl(); - Owner->addDecl(Field); + if (!Field->getDeclName()) { + // Keep track of where this decl came from. + SemaRef.Context.setInstantiatedFromUnnamedFieldDecl(Field, D); } + + Field->setImplicit(D->isImplicit()); + Owner->addDecl(Field); return Field; } diff --git a/test/CodeGenCXX/template-anonymous-union-member-initializer.cpp b/test/CodeGenCXX/template-anonymous-union-member-initializer.cpp new file mode 100644 index 0000000000..f8454282ba --- /dev/null +++ b/test/CodeGenCXX/template-anonymous-union-member-initializer.cpp @@ -0,0 +1,10 @@ +// RUN: clang-cc -emit-llvm -o %t %s +template +class A +{ + union { void *d; }; + + A() : d(0) { } +}; + +A a0;