================
@@ -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
+ // remove the attribute before the post-initialization checks.
+ if (const auto *Attr = VDecl->getAttr<AliasAttr>()) {
+ Diag(Attr->getLocation(), diag::err_alias_is_definition) << VDecl << 0;
+ VDecl->dropAttr<AliasAttr>();
----------------
keepyixiao wrote:
Thanks for the suggestion. I considered calling setInvalidDecl() here, but this
check is immediately followed by the invalid-declaration recovery path. Marking
the declaration invalid would therefore replace the initializer with a
RecoveryExpr, return early, and suppress normal initializer diagnostics such as
-Wextern-initializer. It may also affect subsequent redeclaration handling.
Since the existing alias checks diagnose and drop the attribute without
invalidating the declaration。I kept the same recovery behavior here. Currently,
I’ve followed your suggestion and added VDecl->setInvalidDecl(). Would you
still prefer that the declaration be marked invalid despite these recovery
differences?
https://github.com/llvm/llvm-project/pull/223124
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits