In constructors, don't generate implicit initializers for members of anonymous structs contained within anonymous unions.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140015 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index b3ec382..ecbff96 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -2262,6 +2262,19 @@
 };
 }
 
+/// \brief Determine whether the given indirect field declaration is somewhere
+/// within an anonymous union.
+static bool isWithinAnonymousUnion(IndirectFieldDecl *F) {
+  for (IndirectFieldDecl::chain_iterator C = F->chain_begin(), 
+                                      CEnd = F->chain_end();
+       C != CEnd; ++C)
+    if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>((*C)->getDeclContext()))
+      if (Record->isUnion())
+        return true;
+        
+  return false;
+}
+
 static bool CollectFieldInitializer(Sema &SemaRef, BaseAndFieldInfo &Info,
                                     FieldDecl *Field, 
                                     IndirectFieldDecl *Indirect = 0) {
@@ -2293,7 +2306,8 @@
 
   // Don't build an implicit initializer for union members if none was
   // explicitly specified.
-  if (Field->getParent()->isUnion())
+  if (Field->getParent()->isUnion() ||
+      (Indirect && isWithinAnonymousUnion(Indirect)))
     return false;
 
   // Don't try to build an implicit initializer if there were semantic
diff --git a/test/CXX/special/class.init/class.base.init/p8-0x.cpp b/test/CXX/special/class.init/class.base.init/p8-0x.cpp
index 81ed9c2..f857e3d 100644
--- a/test/CXX/special/class.init/class.base.init/p8-0x.cpp
+++ b/test/CXX/special/class.init/class.base.init/p8-0x.cpp
@@ -48,4 +48,12 @@
     K(int n) : n(n) {}
     K(int n, bool) : ndc(n) {}
   };
+  struct Nested {
+    Nested() {}
+    union {
+      struct {
+        NoDefaultCtor ndc;
+      };
+    };
+  };
 }