6161#include "llvm/ADT/STLForwardCompat.h"
6262#include "llvm/ADT/SmallString.h"
6363#include "llvm/ADT/StringExtras.h"
64+ #include "llvm/Support/SaveAndRestore.h"
6465#include "llvm/TargetParser/Triple.h"
6566#include <algorithm>
6667#include <cstring>
@@ -2563,18 +2564,7 @@ void Sema::MergeTypedefNameDecl(Scope *S, TypedefNameDecl *New,
25632564 // Make the old tag definition visible.
25642565 makeMergedDefinitionVisible(Hidden);
25652566
2566- // If this was an unscoped enumeration, yank all of its enumerators
2567- // out of the scope.
2568- if (isa<EnumDecl>(NewTag)) {
2569- Scope *EnumScope = getNonFieldDeclScope(S);
2570- for (auto *D : NewTag->decls()) {
2571- auto *ED = cast<EnumConstantDecl>(D);
2572- assert(EnumScope->isDeclScope(ED));
2573- EnumScope->RemoveDecl(ED);
2574- IdResolver.RemoveDecl(ED);
2575- ED->getLexicalDeclContext()->removeDecl(ED);
2576- }
2577- }
2567+ CleanupMergedEnum(S, NewTag);
25782568 }
25792569 }
25802570
@@ -2651,6 +2641,19 @@ void Sema::MergeTypedefNameDecl(Scope *S, TypedefNameDecl *New,
26512641 notePreviousDefinition(Old, New->getLocation());
26522642}
26532643
2644+ void Sema::CleanupMergedEnum(Scope *S, Decl *New) {
2645+ // If this was an unscoped enumeration, yank all of its enumerators
2646+ // out of the scope.
2647+ if (auto *ED = dyn_cast<EnumDecl>(New); ED && !ED->isScoped()) {
2648+ Scope *EnumScope = getNonFieldDeclScope(S);
2649+ for (auto *ECD : ED->enumerators()) {
2650+ assert(EnumScope->isDeclScope(ECD));
2651+ EnumScope->RemoveDecl(ECD);
2652+ IdResolver.RemoveDecl(ECD);
2653+ }
2654+ }
2655+ }
2656+
26542657/// DeclhasAttr - returns true if decl Declaration already has the target
26552658/// attribute.
26562659static bool DeclHasAttr(const Decl *D, const Attr *A) {
@@ -12611,6 +12614,7 @@ namespace {
1261112614 bool isRecordType;
1261212615 bool isPODType;
1261312616 bool isReferenceType;
12617+ bool isInCXXOperatorCall;
1261412618
1261512619 bool isInitList;
1261612620 llvm::SmallVector<unsigned, 4> InitFieldIndex;
@@ -12623,6 +12627,7 @@ namespace {
1262312627 isPODType = false;
1262412628 isRecordType = false;
1262512629 isReferenceType = false;
12630+ isInCXXOperatorCall = false;
1262612631 isInitList = false;
1262712632 if (ValueDecl *VD = dyn_cast<ValueDecl>(OrigDecl)) {
1262812633 isPODType = VD->getType().isPODType(S.Context);
@@ -12810,6 +12815,7 @@ namespace {
1281012815 }
1281112816
1281212817 void VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
12818+ llvm::SaveAndRestore CxxOpCallScope(isInCXXOperatorCall, true);
1281312819 Expr *Callee = E->getCallee();
1281412820
1281512821 if (isa<UnresolvedLookupExpr>(Callee))
@@ -12820,6 +12826,19 @@ namespace {
1282012826 HandleValue(Arg->IgnoreParenImpCasts());
1282112827 }
1282212828
12829+ void VisitLambdaExpr(LambdaExpr *E) {
12830+ if (!isInCXXOperatorCall) {
12831+ Inherited::VisitLambdaExpr(E);
12832+ return;
12833+ }
12834+
12835+ for (Expr *Init : E->capture_inits())
12836+ if (DeclRefExpr *DRE = dyn_cast_if_present<DeclRefExpr>(Init))
12837+ HandleDeclRefExpr(DRE);
12838+ else if (Init)
12839+ Visit(Init);
12840+ }
12841+
1282312842 void VisitUnaryOperator(UnaryOperator *E) {
1282412843 // For POD record types, addresses of its own members are well-defined.
1282512844 if (E->getOpcode() == UO_AddrOf && isRecordType &&
@@ -18330,12 +18349,14 @@ void Sema::ActOnTagStartDefinition(Scope *S, Decl *TagD) {
1833018349 AddPushedVisibilityAttribute(Tag);
1833118350}
1833218351
18333- bool Sema::ActOnDuplicateDefinition(Decl *Prev, SkipBodyInfo &SkipBody) {
18352+ bool Sema::ActOnDuplicateDefinition(Scope *S, Decl *Prev,
18353+ SkipBodyInfo &SkipBody) {
1833418354 if (!hasStructuralCompatLayout(Prev, SkipBody.New))
1833518355 return false;
1833618356
1833718357 // Make the previous decl visible.
1833818358 makeMergedDefinitionVisible(SkipBody.Previous);
18359+ CleanupMergedEnum(S, SkipBody.New);
1833918360 return true;
1834018361}
1834118362
0 commit comments