Bug 23715 – ImportC: No rejection of _Thread_local variables declared at function scope without 'static' as per C11 6.2.4-5

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
Linux
Creation time
2023-02-15T16:52:15Z
Last change time
2023-04-10T23:53:46Z
Keywords
accepts-invalid, ImportC, pull
Assigned to
No Owner
Creator
Iain Buclaw
Depends on
23689
See also
https://issues.dlang.org/show_bug.cgi?id=23689

Comments

Comment #0 by ibuclaw — 2023-02-15T16:52:15Z
When compiling the test with `gcc -std=c11 -fsyntax-only` compilable/testcstuff1.c:273:23: error: function-scope ‘tli’ implicitly auto and declared ‘_Thread_local’ 273 | _Thread_local int tli; | Original test ``` void test2() { _Thread_local int tli; } ```
Comment #1 by bugzilla — 2023-02-20T07:18:43Z
Shouldn't _Thread_local override the auto default?
Comment #2 by ibuclaw — 2023-02-20T12:27:47Z
(In reply to Walter Bright from comment #1) > Shouldn't _Thread_local override the auto default? It does not, and the C11 spec makes this clear: This paragraph under C11 6.2.4 - Storage durations of objects """ C11 6.2.4-5: An object whose identifier is declared with no linkage and without the storage-class specifier `static` has *automatic storage duration*, as do some compound literals. The result of attempting to indirectly access an object with automatic storage duration from a thread other than the one with which the object is associated is implementation-defined. """ So, top-level `_Thread_local` variables of course get either external or internal linkage (depending on `static`). Local variables *always* have no linkage unless declared `static`. The correct test (that is also accepted by gcc/clang) would be: ``` void test2() { static _Thread_local int tli; } ``` ImportC parser still needs fixing to reject invalid uses of `_Thread_local`.
Comment #3 by dlang-bot — 2023-04-10T18:54:28Z
@WalterBright created dlang/dmd pull request #15094 "fix Issue 23715 - ImportC: No rejection of _Thread_local variables de…" fixing this issue: - fix Issue 23715 - ImportC: No rejection of _Thread_local variables declared at function scope without 'static' as per C11 6.2.4-5 https://github.com/dlang/dmd/pull/15094
Comment #4 by dlang-bot — 2023-04-10T23:53:46Z
dlang/dmd pull request #15094 "fix Issue 23715 - ImportC: No rejection of _Thread_local variables de…" was merged into master: - 281407b919869f1b7184b8f645fb55bdae8af4c7 by Walter Bright: fix Issue 23715 - ImportC: No rejection of _Thread_local variables declared at function scope without 'static' as per C11 6.2.4-5 https://github.com/dlang/dmd/pull/15094