================ @@ -5494,55 +5494,62 @@ InjectAnonymousStructOrUnionMembers(Sema &SemaRef, Scope *S, DeclContext *Owner, RecordDecl *AnonRecord, AccessSpecifier AS, StorageClass SC, SmallVectorImpl<NamedDecl *> &Chaining) { + bool Invalid = false; // Look every FieldDecl and IndirectFieldDecl with a name. for (auto *D : AnonRecord->decls()) { if ((isa<FieldDecl>(D) || isa<IndirectFieldDecl>(D)) && cast<NamedDecl>(D)->getDeclName()) { ValueDecl *VD = cast<ValueDecl>(D); - if (CheckAnonMemberRedeclaration(SemaRef, S, Owner, VD->getDeclName(), - VD->getLocation(), AnonRecord->isUnion(), - SC)) { - // C++ [class.union]p2: - // The names of the members of an anonymous union shall be - // distinct from the names of any other entity in the - // scope in which the anonymous union is declared. + // C++ [class.union]p2: + // The names of the members of an anonymous union shall be + // distinct from the names of any other entity in the + // scope in which the anonymous union is declared. + + const bool FieldInvalid = CheckAnonMemberRedeclaration( + SemaRef, S, Owner, VD->getDeclName(), VD->getLocation(), + AnonRecord->isUnion(), SC); + if (FieldInvalid) Invalid = true; - } else { - // C++ [class.union]p2: - // For the purpose of name lookup, after the anonymous union - // definition, the members of the anonymous union are - // considered to have been defined in the scope in which the - // anonymous union is declared. - unsigned OldChainingSize = Chaining.size(); - if (IndirectFieldDecl *IF = dyn_cast<IndirectFieldDecl>(VD)) - Chaining.append(IF->chain_begin(), IF->chain_end()); - else - Chaining.push_back(VD); - assert(Chaining.size() >= 2); - NamedDecl **NamedChain = - new (SemaRef.Context)NamedDecl*[Chaining.size()]; - for (unsigned i = 0; i < Chaining.size(); i++) - NamedChain[i] = Chaining[i]; + // Inject the IndirectFieldDecl even if invalid, because later + // diagnostics may depend on it being present, see findDefaultInitializer. + + // C++ [class.union]p2: + // For the purpose of name lookup, after the anonymous union + // definition, the members of the anonymous union are + // considered to have been defined in the scope in which the + // anonymous union is declared. + unsigned OldChainingSize = Chaining.size(); + if (IndirectFieldDecl *IF = dyn_cast<IndirectFieldDecl>(VD)) + Chaining.append(IF->chain_begin(), IF->chain_end()); + else + Chaining.push_back(VD); + + assert(Chaining.size() >= 2); + NamedDecl **NamedChain = ---------------- erichkeane wrote:
Thanks, I hate it. https://github.com/llvm/llvm-project/pull/153140 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits