[clang] [Clang] disallow selectany on non-global-variable declarations (PR #189641)

Oleksandr Tarasiuk via cfe-commits cfe-commits at lists.llvm.org
Wed May 6 06:21:14 PDT 2026


================
@@ -3140,15 +3140,17 @@ static void checkNewAttributesAfterDef(Sema &S, Decl *New, const Decl *Old) {
         --E;
         continue;
       }
-    } else if (isa<SelectAnyAttr>(NewAttribute) &&
-               cast<VarDecl>(New)->isInline() &&
-               !cast<VarDecl>(New)->isInlineSpecified()) {
+    } else if (isa<SelectAnyAttr>(NewAttribute)) {
       // Don't warn about applying selectany to implicitly inline variables.
       // Older compilers and language modes would require the use of selectany
       // to make such variables inline, and it would have no effect if we
       // honored it.
-      ++I;
-      continue;
+      if (auto *VD = dyn_cast<VarDecl>(New)) {
+        if (VD->isInline() && !VD->isInlineSpecified()) {
+          ++I;
+          continue;
+        }
+      }
----------------
a-tarasyuk wrote:

@AaronBallman I've updated formatting for both cases.

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


More information about the cfe-commits mailing list