aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-09-02 19:17:55 +0000
committerAnders Carlsson <andersca@mac.com>2009-09-02 19:17:55 +0000
commitf4b5f5c6a1487317aab9aa30d97bccfd57c82c98 (patch)
tree52a3c305b7b4068e2da51801d3f0abc97b078354
parent1164d859c7828d3856f17e43da323332a5e3920e (diff)
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
-rw-r--r--lib/Sema/SemaTemplateInstantiateDecl.cpp20
-rw-r--r--test/CodeGenCXX/template-anonymous-union-member-initializer.cpp10
2 files changed, 21 insertions, 9 deletions
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 <typename T>
+class A
+{
+ union { void *d; };
+
+ A() : d(0) { }
+};
+
+A<int> a0;