[clang] [Clang] Avoid assertion failure for initialized extern aliases (PR #223124)

via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 23 05:49:22 PDT 2026


================
@@ -14127,6 +14093,15 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) {
     return;
   }
 
+  // handleAliasAttr() runs before the initializer is attached to the VarDecl,
+  // so it cannot determine that an extern declaration with an initializer is a
+  // definition. Diagnose the conflict now that an initializer is present and
----------------
keepyixiao wrote:

Thanks, I reproduced this and confirmed that the current patch does not handle it. AddInitializerToDecl() receives the out-of-line definition, which has no AliasAttr; the attribute is on the earlier in-class declaration returned by
getFirstDecl().

Although we could find it through the redeclaration chain, directly removing the AliasAttr from the earlier declaration does not seem like the right recovery. It may be better to preserve the existing alias declaration and
diagnose the initialized out-of-line declaration as a conflicting definition. Would handling this during redeclaration merging be more appropriate?

https://github.com/llvm/llvm-project/pull/223124


More information about the cfe-commits mailing list