[clang] [Clang] disallow selectany on non-global-variable declarations (PR #189641)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Wed May 6 05:33:06 PDT 2026
================
@@ -7146,15 +7148,16 @@ static void checkAliasAttr(Sema &S, NamedDecl &ND) {
}
static void checkSelectAnyAttr(Sema &S, NamedDecl &ND) {
- // 'selectany' only applies to externally visible variable declarations.
- // It does not apply to functions.
- if (SelectAnyAttr *Attr = ND.getAttr<SelectAnyAttr>()) {
- if (isa<FunctionDecl>(ND) || !ND.isExternallyVisible()) {
- S.Diag(Attr->getLocation(),
- diag::err_attribute_selectany_non_extern_data);
- ND.dropAttr<SelectAnyAttr>();
- }
- }
+ SelectAnyAttr *Attr = ND.getAttr<SelectAnyAttr>();
+ if (!Attr)
+ return;
+
+ if (auto *VD = dyn_cast<VarDecl>(&ND))
+ if (!VD->isStaticDataMember() && VD->isExternallyVisible())
+ return;
----------------
AaronBallman wrote:
```suggestion
if (const auto *VD = dyn_cast<VarDecl>(&ND); VD &&!VD->isStaticDataMember() && VD->isExternallyVisible())
return;
```
Needs to be reformatted though.
https://github.com/llvm/llvm-project/pull/189641
More information about the cfe-commits
mailing list