]> granicus.if.org Git - clang/commitdiff
[modules] Handle merged fields in designated initializers.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 8 Apr 2016 19:57:40 +0000 (19:57 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 8 Apr 2016 19:57:40 +0000 (19:57 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@265838 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaInit.cpp
test/Modules/Inputs/merge-decl-context/a.h
test/Modules/merge-decl-context.cpp

index bd8522d597717be452f9bed111564272a2506512..81b5312d87aa334577f0eaa3d0c7e7f4d2470dec 100644 (file)
@@ -2227,8 +2227,10 @@ InitListChecker::CheckDesignatedInitializer(const InitializedEntity &Entity,
     for (auto *FI : RT->getDecl()->fields()) {
       if (FI->isUnnamedBitfield())
         continue;
-      if (KnownField == FI)
+      if (declaresSameEntity(KnownField, FI)) {
+        KnownField = FI;
         break;
+      }
       ++FieldIndex;
     }
 
@@ -2241,11 +2243,11 @@ InitListChecker::CheckDesignatedInitializer(const InitializedEntity &Entity,
       FieldIndex = 0;
       if (!VerifyOnly) {
         FieldDecl *CurrentField = StructuredList->getInitializedFieldInUnion();
-        if (CurrentField && CurrentField != *Field) {
+        if (CurrentField && !declaresSameEntity(CurrentField, *Field)) {
           assert(StructuredList->getNumInits() == 1
                  && "A union should never have more than one initializer!");
 
-          // we're about to throw away an initializer, emit warning
+          // We're about to throw away an initializer, emit warning.
           SemaRef.Diag(D->getFieldLoc(),
                        diag::warn_initializer_overrides)
             << D->getSourceRange();
index 89cc7120fd17128ad30940c4f0167b4167fa3c39..7be90b1535de2442b9c74ce345079a3fbc8cad09 100644 (file)
@@ -21,4 +21,8 @@ inline A<int> ff(int i) {
   return fff<A<int>>(&i);
 }
 
+struct Aggregate {
+  int member;
+};
+
 #endif
index 55219ed587b0d4c7059d7457539036adbf6fea87..5dbf3d1bd95f604986083fedcd930ce25f2c7088 100644 (file)
 // RUN:     -fmodule-map-file=%S/Inputs/merge-decl-context/merge-decl-context.modulemap -I%S/Inputs \
 // RUN:     -emit-llvm -o %t/test.o %s
 
+// RUN: %clang_cc1 -x c++ -std=c++11 -fmodules -fmodules-cache-path=%t \
+// RUN:     -fmodule-map-file=%S/Inputs/merge-decl-context/merge-decl-context.modulemap -I%S/Inputs \
+// RUN:     -emit-llvm -o %t/test.o -DNO_TEXTUAL_INCLUSION %s
+
+#ifndef NO_TEXTUAL_INCLUSION
 #include "Inputs/merge-decl-context/a.h"
+#endif
 #include "Inputs/merge-decl-context/b.h"
 #include "Inputs/merge-decl-context/c.h"
 #include "Inputs/merge-decl-context/d.h"
@@ -26,3 +32,5 @@
 void t() {
   ff(42);
 }
+
+static_assert(Aggregate{.member = 1}.member == 1, "");