Bug 2139 – Compiler rejects delegate of a static struct instance as non-constant

Status
RESOLVED
Resolution
WORKSFORME
Severity
minor
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2008-06-02T16:26:15Z
Last change time
2019-10-03T08:57:35Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
Jarrett Billingsley

Comments

Comment #0 by jarrett.billingsley — 2008-06-02T16:26:15Z
The following works. ---------------------------- struct S { static S s; } const foo = &S.s; ---------------------------- The following also works. ---------------------------- void f() {} const bar = &f; ---------------------------- The following, however, does not: ---------------------------- struct S { static S s; void f() {} } // error, non-constant expression S.s.f const baz = &S.s.f; ---------------------------- The compiler should be able to initialize baz at compile time, since baz is composed of the address of a statically-allocated struct and the address of a non-virtual function.
Comment #1 by razvan.nitu1305 — 2019-09-09T13:50:20Z
The compiler now errors in the first case: Error: cannot take address of thread-local variable s at compile time And in the third case: Error: static variable s cannot be read at compile time The second case compiles.