[clang] clang: Improve block-scope thread-local diagnostic (PR #234704)

Chen Miao via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 29 03:38:24 PDT 2026


================
@@ -8217,11 +8217,18 @@ NamedDecl *Sema::ActOnVariableDeclarator(
     if (NewVD->hasLocalStorage() &&
         (SCSpec != DeclSpec::SCS_unspecified ||
          TSCS != DeclSpec::TSCS_thread_local ||
-         !DC->isFunctionOrMethod()))
-      Diag(D.getDeclSpec().getThreadStorageClassSpecLoc(),
-           diag::err_thread_non_global)
-        << DeclSpec::getSpecifierName(TSCS);
-    else if (!Context.getTargetInfo().isTLSSupported()) {
+         !DC->isFunctionOrMethod())) {
+      if (TSCS == DeclSpec::TSCS__Thread_local &&
----------------
ChenMiaoi wrote:

Would it be better to write it this way?

``` cc
unsigned DiagID =
    TSCS == DeclSpec::TSCS__Thread_local && DC->isFunctionOrMethod()
        ? diag::err_thread_local_block_scope
        : diag::err_thread_non_global;
Diag(D.getDeclSpec().getThreadStorageClassSpecLoc(), DiagID)
    << DeclSpec::getSpecifierName(TSCS);
```

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


More information about the cfe-commits mailing list