16
16
#include "clang/AST/ASTConsumer.h"
17
17
#include "clang/AST/ASTContext.h"
18
18
#include "clang/AST/ASTLambda.h"
19
- #include "clang/AST/ASTMutationListener.h"
20
19
#include "clang/AST/CXXInheritance.h"
21
20
#include "clang/AST/CharUnits.h"
22
21
#include "clang/AST/CommentDiagnostic.h"
@@ -1974,9 +1973,7 @@ void Sema::MergeTypedefNameDecl(TypedefNameDecl *New, LookupResult &OldDecls) {
1974
1973
New->setTypeSourceInfo(OldTD->getTypeSourceInfo());
1975
1974
1976
1975
// Make the old tag definition visible.
1977
- if (auto *Listener = getASTMutationListener())
1978
- Listener->RedefinedHiddenDefinition(Hidden, NewTag->getLocation());
1979
- Hidden->setHidden(false);
1976
+ makeMergedDefinitionVisible(Hidden, NewTag->getLocation());
1980
1977
}
1981
1978
}
1982
1979
@@ -11311,8 +11308,8 @@ static FixItHint createFriendTagNNSFixIt(Sema &SemaRef, NamedDecl *ND, Scope *S,
11311
11308
/// \param IsTypeSpecifier \c true if this is a type-specifier (or
11312
11309
/// trailing-type-specifier) other than one in an alias-declaration.
11313
11310
///
11314
- /// \param SkipBody If non-null, will be set to true if the caller should skip
11315
- /// the definition of this tag, and treat it as if it were a declaration.
11311
+ /// \param SkipBody If non-null, will be set to indicate if the caller should
11312
+ /// skip the definition of this tag and treat it as if it were a declaration.
11316
11313
Decl *Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK,
11317
11314
SourceLocation KWLoc, CXXScopeSpec &SS,
11318
11315
IdentifierInfo *Name, SourceLocation NameLoc,
@@ -11323,7 +11320,7 @@ Decl *Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK,
11323
11320
SourceLocation ScopedEnumKWLoc,
11324
11321
bool ScopedEnumUsesClassTag,
11325
11322
TypeResult UnderlyingType,
11326
- bool IsTypeSpecifier, bool *SkipBody) {
11323
+ bool IsTypeSpecifier, SkipBodyInfo *SkipBody) {
11327
11324
// If this is not a definition, it must have a name.
11328
11325
IdentifierInfo *OrigName = Name;
11329
11326
assert((Name != nullptr || TUK == TUK_Definition) &&
@@ -11633,6 +11630,10 @@ Decl *Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK,
11633
11630
}
11634
11631
}
11635
11632
11633
+ // If we have a known previous declaration to use, then use it.
11634
+ if (Previous.empty() && SkipBody && SkipBody->Previous)
11635
+ Previous.addDecl(SkipBody->Previous);
11636
+
11636
11637
if (!Previous.empty()) {
11637
11638
NamedDecl *PrevDecl = Previous.getFoundDecl();
11638
11639
NamedDecl *DirectPrevDecl =
@@ -11774,10 +11775,8 @@ Decl *Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK,
11774
11775
// assume that this definition is identical to the hidden one
11775
11776
// we already have. Make the existing definition visible and
11776
11777
// use it in place of this one.
11777
- *SkipBody = true;
11778
- if (auto *Listener = getASTMutationListener())
11779
- Listener->RedefinedHiddenDefinition(Hidden, KWLoc);
11780
- Hidden->setHidden(false);
11778
+ SkipBody->ShouldSkip = true;
11779
+ makeMergedDefinitionVisible(Hidden, KWLoc);
11781
11780
return Def;
11782
11781
} else if (!IsExplicitSpecializationAfterInstantiation) {
11783
11782
// A redeclaration in function prototype scope in C isn't
@@ -13465,6 +13464,29 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl *Enum,
13465
13464
Val, EnumVal);
13466
13465
}
13467
13466
13467
+ Sema::SkipBodyInfo Sema::shouldSkipAnonEnumBody(Scope *S, IdentifierInfo *II,
13468
+ SourceLocation IILoc) {
13469
+ if (!getLangOpts().Modules || !getLangOpts().CPlusPlus)
13470
+ return SkipBodyInfo();
13471
+
13472
+ // We have an anonymous enum definition. Look up the first enumerator to
13473
+ // determine if we should merge the definition with an existing one and
13474
+ // skip the body.
13475
+ NamedDecl *PrevDecl = LookupSingleName(S, II, IILoc, LookupOrdinaryName,
13476
+ ForRedeclaration);
13477
+ auto *PrevECD = dyn_cast_or_null<EnumConstantDecl>(PrevDecl);
13478
+ NamedDecl *Hidden;
13479
+ if (PrevECD &&
13480
+ !hasVisibleDefinition(cast<NamedDecl>(PrevECD->getDeclContext()),
13481
+ &Hidden)) {
13482
+ SkipBodyInfo Skip;
13483
+ Skip.ShouldSkip = true;
13484
+ Skip.Previous = Hidden;
13485
+ return Skip;
13486
+ }
13487
+
13488
+ return SkipBodyInfo();
13489
+ }
13468
13490
13469
13491
Decl *Sema::ActOnEnumConstant(Scope *S, Decl *theEnumDecl, Decl *lastEnumConst,
13470
13492
SourceLocation IdLoc, IdentifierInfo *Id,
0 commit comments