[clang] [clang] Fix ASTWriter crash after merging named enums (PR #114240)
Michael Jabbour via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 21 00:58:29 PST 2025
================
@@ -2551,18 +2551,7 @@ void Sema::MergeTypedefNameDecl(Scope *S, TypedefNameDecl *New,
// Make the old tag definition visible.
makeMergedDefinitionVisible(Hidden);
- // If this was an unscoped enumeration, yank all of its enumerators
- // out of the scope.
- if (isa<EnumDecl>(NewTag)) {
- Scope *EnumScope = getNonFieldDeclScope(S);
- for (auto *D : NewTag->decls()) {
- auto *ED = cast<EnumConstantDecl>(D);
- assert(EnumScope->isDeclScope(ED));
- EnumScope->RemoveDecl(ED);
- IdResolver.RemoveDecl(ED);
- ED->getLexicalDeclContext()->removeDecl(ED);
----------------
michael-jabbour-sonarsource wrote:
Additionally, as far as I can see, for `EnumDeclConstant`s created by the parser, the DeclContext is always the containing `Enum` itself:
https://github.com/llvm/llvm-project/blob/79231a86846b7dff09497fc58ea1e82e892052bd/clang/lib/Sema/SemaDecl.cpp#L19739-L19740
Therefore, after the refactoring I did, I think that the call can be simplified to:
```
ED->removeDecl(ECD);
```
https://github.com/llvm/llvm-project/pull/114240
More information about the cfe-commits
mailing list