From: Richard Smith Date: Fri, 8 Apr 2016 19:57:40 +0000 (+0000) Subject: [modules] Handle merged fields in designated initializers. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1a7db1ee8291541058b2b19d0ed87b41f56cd13d;p=clang [modules] Handle merged fields in designated initializers. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@265838 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index bd8522d597..81b5312d87 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -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(); diff --git a/test/Modules/Inputs/merge-decl-context/a.h b/test/Modules/Inputs/merge-decl-context/a.h index 89cc7120fd..7be90b1535 100644 --- a/test/Modules/Inputs/merge-decl-context/a.h +++ b/test/Modules/Inputs/merge-decl-context/a.h @@ -21,4 +21,8 @@ inline A ff(int i) { return fff>(&i); } +struct Aggregate { + int member; +}; + #endif diff --git a/test/Modules/merge-decl-context.cpp b/test/Modules/merge-decl-context.cpp index 55219ed587..5dbf3d1bd9 100644 --- a/test/Modules/merge-decl-context.cpp +++ b/test/Modules/merge-decl-context.cpp @@ -18,7 +18,13 @@ // 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, "");