Issue |
131679
|
Summary |
[clang-tidy] misc-use-internal-linkage false positive with thread_local block-level variable
|
Labels |
clang-tidy,
false-positive
|
Assignees |
|
Reporter |
kiwixz
|
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.
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs