Bug 11126 – Link failure when instancing anonymous class to a static variable
Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-09-26T06:07:00Z
Last change time
2013-11-20T04:01:22Z
Keywords
link-failure
Assigned to
nobody
Creator
andrej.mitrovich
Comments
Comment #0 by andrej.mitrovich — 2013-09-26T06:07:16Z
-----
class C {}
void main()
{
static C c = new class C {};
}
-----
$ dmd test.d
Error 42: Symbol Undefined _Dmain12__anonclass16__vtblZ
However I'm not sure I understand why the above is allowed to compile (nevermind the link failure), since the following fails to compile:
-----
class C {}
void main()
{
static /*C*/ c = new class C {};
}
-----
test.d(5): Error: variable test.main.c is mutable. Only const or immutable class thread local variable are allowed, not test.main.__anonclass1
Comment #1 by yebblies — 2013-11-20T03:40:33Z
Now gives
testx.d(325): Error: variable testx.main.c is mutable. Only const or immutable class thread local variable are allowed, not testx.main.__anonclass1
And with:
class C {}
void main()
{
static immutable C c = cast(immutable)new class C {};
}
it appears to work. Can't get a link failure, on win32.
Comment #2 by andrej.mitrovich — 2013-11-20T04:01:22Z