[Issue 23715] compilable/testcstuff1.c:273:23: error: function-scope 'tli' implicitly auto and declared '_Thread_local'
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Feb 20 12:27:47 UTC 2023
https://issues.dlang.org/show_bug.cgi?id=23715
Iain Buclaw <ibuclaw at gdcproject.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |ibuclaw at gdcproject.org
--- Comment #2 from Iain Buclaw <ibuclaw at gdcproject.org> ---
(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`.
--
More information about the Digitalmars-d-bugs
mailing list