forked from OSchip/llvm-project
[modules] Handle merged fields in designated initializers.
llvm-svn: 265838
This commit is contained in:
parent
fec5c64b63
commit
fe1bc708b5
|
@ -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();
|
||||
|
|
|
@ -21,4 +21,8 @@ inline A<int> ff(int i) {
|
|||
return fff<A<int>>(&i);
|
||||
}
|
||||
|
||||
struct Aggregate {
|
||||
int member;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -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, "");
|
||||
|
|
Loading…
Reference in New Issue