[clang] Allow weak/selectany external definitions in header units. (PR #162713)
Michael Spencer via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 15 13:15:36 PDT 2025
================
@@ -13822,7 +13822,10 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) {
!VDecl->isInvalidDecl() && VDecl->isThisDeclarationADefinition() &&
VDecl->getFormalLinkage() == Linkage::External && !VDecl->isInline() &&
!VDecl->isTemplated() && !isa<VarTemplateSpecializationDecl>(VDecl) &&
- !VDecl->getInstantiatedFromStaticDataMember()) {
+ !VDecl->getInstantiatedFromStaticDataMember() &&
+ // The intent of the above section seems to be to prevent ODR issues.
+ // Weak symbols do the same but are not part of the c++ spec.
----------------
Bigcheese wrote:
Really they are the same thing. It's not that they are common, they just have approximately the same semantics as inline.
I don't like the wording of "The intent of the above section seems to be" because it makes it sound like we don't actually know what the compiler is doing. We know it's disallowing multiple definitions of entities that are not allowed to have multiple definitions, and weak/selectany are just another way to allow multiple definitions.
https://github.com/llvm/llvm-project/pull/162713
More information about the cfe-commits
mailing list