[clang] Allow weak/selectany external definitions in header units. (PR #162713)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 14 20:24:17 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.
----------------
akrieger wrote:
https://eel.is/c++draft/module.import#6
I could import the exact phrasing `A header unit shall not contain a definition of a non-inline function or variable whose name has external linkage.` I guess? I will iterate on it and see if I find something I like.
https://github.com/llvm/llvm-project/pull/162713
More information about the cfe-commits
mailing list