]> granicus.if.org Git - clang/commitdiff
Fix initialization for members of anonymous struct in a union.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 16 Aug 2010 17:27:13 +0000 (17:27 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 16 Aug 2010 17:27:13 +0000 (17:27 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@111159 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclCXX.cpp
test/CodeGenCXX/anonymous-union-member-initializer.cpp

index a1a84667595f799da3070817a16af184b9973d96..1d0b4a9450f89e8887b50ae408e74595720998cf 100644 (file)
@@ -1798,6 +1798,9 @@ static bool CollectFieldInitializer(BaseAndFieldInfo &Info,
           // Once we've initialized a field of an anonymous union, the union
           // field in the class is also initialized, so exit immediately.
           return false;
+        } else if ((*FA)->isAnonymousStructOrUnion()) {
+          if (CollectFieldInitializer(Info, Top, *FA))
+            return true;
         }
       }
 
index a4da2c04fd7b708273fa41ce2f5763f6cd435980..9ba38052e1720c0a24078d8f1de972842abfb2be 100644 (file)
@@ -78,3 +78,15 @@ namespace test3 {
   // CHECK-NEXT: [[CVALUE:%.*]] = getelementptr inbounds {{.*}} [[STRUCT]], i32 0, i32 0
   // CHECK-NEXT: store i8* null, void i8** [[CVALUE]]
 }
+
+struct S {
+  // CHECK: store i32 42
+  // CHECK: store i32 55
+  S() : x(42), y(55) {}
+  union {
+    struct {
+      int x;
+      union { int y; };
+    };
+  };
+} s;