<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/128201>128201</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-tidy] Check request: bugprone-thread-local-synchronization-primitive
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
denzor200
</td>
</tr>
</table>
<pre>
Needs a check that will find definitions of synchronization primitives(like `std::mutex`, `std::condition_variable`, etc) with `thread_local` attribute and suggest removing that attribute.
BEFORE
```
thread_local std::mutex m;
```
AFTER
```
std::mutex m;
```
https://godbolt.org/z/W9E4jWMKW
You might be surprised seeing that code snippet and you may doubt the usefulness of the diagnostics I propose talking "How can you even make such a mistake in your code? It's impossible to allow `thread_local` to be used with `std::mutex` without explicit intent! It's a nonsense!". I completely understand you - I never seen the code like this in real code bases written by humans. But it possible to find in the code written by ChatGPT... The bot wished us happy debugging:)
So, the things are changing - we are living in 2025 and we review the code not only written by humans. And our review tool(I mean Clang Tidy) must also begin adapting to new reality.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyMVE1v4zgP_jXKhYghy0mTHHxIO837Fov9wGyBYk8D2WJsTmXJK1HJpL9-IfVjOt05LGDANkVSz0M-pI6RBofYivW1WH9a6MSjD61B9-SDknLReXNpf0M0ETT0I_aPwKNmOJO1cCRnwOCRHDF5F8EfIV5cPwbv6ElnG8yBJmI6YRRqa-kRQVzJyEY0e9Hsp8T4TVxJoW5-sPfemZLzy0kH0p3FFyfkXqgdnInHHMBjQG2-WN9rK64kaOZAXWIE7QzENAwYGQJO_kRueIb-5lMJuRdyf317-P3zbf6-ki-P3L9PDD_ChUk01x_chdzvD_e3nz-Y_1PgyDzH7KYOQh0GbzpvufJhEOrwJNThYXe7-vrw6y8Pz-5_-QQTDSNDhxBTmANFNBAR3xj23iBER_OMXApxyTH6AsanjoFHhBTxmKz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