<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/131679>131679</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-tidy] misc-use-internal-linkage false positive with thread_local block-level variable
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy,
false-positive
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
kiwixz
</td>
</tr>
</table>
<pre>
As I understand from the C++ standard ([dcl.stc.3](https://eel.is/c++draft/dcl.stc#3)), `thread_local` block-level variables are implicitly `static`.
> The thread_local specifier indicates that the named entity has thread storage duration ([[basic.stc.thread]](https://eel.is/c++draft/basic.stc.thread))[.](https://eel.is/c++draft/dcl.stc#3.sentence-1)
It shall be applied only to the declaration of a variable of namespace or block scope, to a structured binding declaration ([[dcl.struct.bind]](https://eel.is/c++draft/dcl.struct.bind)), or to the declaration of a static data member[.](https://eel.is/c++draft/dcl.stc#3.sentence-2)
When thread_local is applied to a variable of block scope the [storage-class-specifier](https://eel.is/c++draft/dcl.stc#nt:storage-class-specifier) static is implied if no other [storage-class-specifier](https://eel.is/c++draft/dcl.stc#nt:storage-class-specifier) appears in the [decl-specifier-seq](https://eel.is/c++draft/dcl.spec.general#nt:decl-specifier-seq)[.](https://eel.is/c++draft/dcl.stc#3.sentence-3)
But I get a warning with the following code ([godbolt](https://gcc.godbolt.org/z/Gna6Ef7dK)):
```cpp
static void f() {
thread_local int a;
}
```
```
<source>:2:22: warning: variable 'a' can be made static or moved into an anonymous namespace to enforce internal linkage [misc-use-internal-linkage]
2 | thread_local int a;
| ^
| static
1 warning generated.
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy8VluPozgT_TWVlxIITEiaBx5Id-fT6HtdaR9Xxi6Cd4zN2ia9mV-_MpBMpi8r9Wi0EbnZdTunThm49-pkiGooD1A-bfgUeuvqr-pF_f1t01p5qRuPX3AykpwP3EjsnB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