================
@@ -2667,6 +2667,22 @@ void Sema::MergeTypedefNameDecl(Scope *S,
TypedefNameDecl *New,
else
New->setTypeSourceInfo(OldTD->getTypeSourceInfo());
+ // An anonymous enum is recognized as a redeclaration only when its
typedef
+ // name gets merged, at which point two distinct enum types already
exist.
+ // Retype the new enumerators to the old enum type, matching the typedef
+ // merge above; otherwise the merged typedef and its enumerators disagree
+ // on the type (GH213299).
+ //
+ // FIXME: The global module restriction only limits the impact of this
+ // change; relax it if the issue shows up in other contexts.
+ if (Module *M = OldTag->getOwningModule(); M && M->isGlobalModule())
+ if (auto *NewEnum = dyn_cast<EnumDecl>(NewTag))
+ if (auto *OldEnum = dyn_cast<EnumDecl>(OldTag)) {
+ QualType OldEnumType = Context.getCanonicalTagType(OldEnum);
+ for (auto *ECD : NewEnum->enumerators())
+ ECD->setType(OldEnumType);
----------------
ChuanqiXu9 wrote:
If we set these as a 'redecl' chain **instead of** setting the type, it
doesn't work. As the definition of these **anony** enum are completed at this
point. I explained this in the old comment that this is too late to merge these
**anony** enums as when we see their name through the typedef, its type is
completed. Yeah, we can call setPreviousDecl here and call setType as well
here. But that is not covered by tests. I prefer to add them when needed.
https://github.com/llvm/llvm-project/pull/214121
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits