Bug 9744 – Poor error message taking address of thread-local variable at compile time

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-03-18T02:58:00Z
Last change time
2013-03-30T21:52:15Z
Keywords
diagnostic
Assigned to
nobody
Creator
clugdbug

Comments

Comment #0 by clugdbug — 2013-03-18T02:58:09Z
Taking the address of a static variable is rejected, but not a __gshared variable: --- __gshared int x1; static int x2; static void *q1 = &x1; // Compiles static void *q2 = &x2; // Rejected --- bug.d(4): Error: non-constant expression & x2 This doesn't apply in CTFE, only in constant folding. There is a unittest in bitmanip which relies on this bug.
Comment #1 by clugdbug — 2013-03-18T03:09:01Z
Or perhaps the correct behaviour would be to allow shared and __gshared to have their address taken in all cases (including CTFE), and to generate an error "cannot take the address of a thread-local variable at compile time" for static variables. Currently, the error is generated in the glue layer, which is wrong.
Comment #2 by clugdbug — 2013-03-18T03:54:33Z
I'm splitting this bug report into two parts. This one becomes a diagnostic error message for the thread-local case. The second will be a CTFE enhancement, to allow taking the address of static variables inside CTFE.
Comment #3 by github-bugzilla — 2013-03-30T21:51:56Z
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/7aa4ef0974cc9ffe2267883c2e98bf00d5285cba Fix issue 9744 Poor error message taking address of thread-local variable at compile time Move the error message from the glue layer, into the interpreter. Also fix an incorrect entry point into the glue layer.