[clang] [C++20] [Modules] merge the type for anony enum from import and #include (PR #214121)
Vassil Vassilev via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 7 02:29:53 PDT 2026
================
@@ -2667,6 +2667,33 @@ void Sema::MergeTypedefNameDecl(Scope *S, TypedefNameDecl *New,
else
New->setTypeSourceInfo(OldTD->getTypeSourceInfo());
+ // See https://github.com/llvm/llvm-project/issues/213299 for the case.
+ //
+ // Ideally, we shall merge the new enum with the old enum when we
+ // creating the new enum. But the enum is anonymous and the typedef's name
+ // come after the enum body, it is too late to merge them. This is the
+ // choice 10 years ago: a523022b5384d7a0901beea7a5f36ee9c09ba339. Actually
+ // what we're merging here is the typedef decls.
+ //
+ // Then https://github.com/llvm/llvm-project/pull/114240 removes the logic
+ // to remove the new ED. This the direct trigger for the above issue of
+ // ambiguous look ups.
+ //
+ // We choose to fix the problem by setting the type of new enum to the
+ // type of old enums. This is consistent with the above call to
+ // setTypeSourceInfo.
+ //
+ // The check `M && M->isGlobalModule()` is not necessary but we hopt to
+ // limit the impact of this change. We can relax the check when we find
+ // similar issue later in other cases.
----------------
vgvassilev wrote:
I don't think a person reading the code needs this and if we apply this rule elsewhere the codebase will look more like prose than code. I think the causality of these changes should be in the commit log.
https://github.com/llvm/llvm-project/pull/214121
More information about the cfe-commits
mailing list