]> granicus.if.org Git - clang/commitdiff
Fix a codegen crash when a class template has a constructor that does member initiali...
authorAnders Carlsson <andersca@mac.com>
Wed, 2 Sep 2009 19:17:55 +0000 (19:17 +0000)
committerAnders Carlsson <andersca@mac.com>
Wed, 2 Sep 2009 19:17:55 +0000 (19:17 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80826 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaTemplateInstantiateDecl.cpp
test/CodeGenCXX/template-anonymous-union-member-initializer.cpp [new file with mode: 0644]

index 285cc620121786e0e1d5229d31bdd7e69bf4b5e1..807115eb67017b188e887d55df5785af31044d1d 100644 (file)
@@ -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 (file)
index 0000000..f845428
--- /dev/null
@@ -0,0 +1,10 @@
+// RUN: clang-cc -emit-llvm -o %t %s
+template <typename T>
+class A
+{
+    union { void *d; };
+
+    A() : d(0) { }
+};
+
+A<int> a0;