thread_local cannot create tentative definitions
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
The following program demonstrates the issue:
```c
thread_local int x,x;
int main(){}
```
Clang incorrectly allows this, it should be rejected which GCC correctly does:
> If the declaration of an identifier for an object has file scope and an initializer, or has file scope and storage-class specifier thread_local, the declaration is an external definition for the identifier.
Section 6.9.3 "External object definitions" Paragraph 1 ISO/IEC 9899:2024
This wording has been adjusted by [Issue 1009](https://www.open-std.org/jtc1/sc22/wg14/issues/c23/issue1009.html) but that does not matter for this case.
Contributor guide
Research direction
Start by compiling the provided C reproducer with Clang and GCC, confirming that Clang accepts the duplicate file-scope thread_local definition while GCC rejects it. Locate the Clang semantic handling for file-scope thread_local declarations and add a regression test; done means Clang rejects the reproducer with an appropriate diagnostic.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 58/100