Bug 3730 – Struct's explicit constructor can't initialize global variables

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2010-01-20T12:20:00Z
Last change time
2015-06-09T01:27:22Z
Assigned to
nobody
Creator
tomeksowi

Comments

Comment #0 by tomeksowi — 2010-01-20T12:20:09Z
Test case: struct S { int a; this(int a) { this.a = a; } static immutable S es = S(3); } Compiler output (message printed twice in original): test.d|9|Error: cannot evaluate ((S __ctmp516; test.d|9|Error: cannot evaluate ((S __ctmp516; Don't know if that should compile but surely the message could be more appealing. static this() may be used as a workaround for this bug.
Comment #1 by clugdbug — 2010-01-20T12:55:03Z
This works for me in DMD2.039 Windows svn 342. (Are you sure you're not using 2.038?)
Comment #2 by tomeksowi — 2010-01-21T10:56:04Z
(In reply to comment #1) > This works for me in DMD2.039 Windows svn 342. (Are you sure you're not using > 2.038?) Yes, I even compiled from command line to make sure. C:\Projekty\Witajki\Witaj Phobosie>dmd Digital Mars D Compiler v2.039 Copyright (c) 1999-2009 by Digital Mars written by Walter Bright Documentation: http://www.digitalmars.com/d/2.0/index.html [snip] C:\Projekty\Witajki\Witaj Phobosie>dmd test.d test.d(8): Error: cannot evaluate ((S __ctmp1; ) , __ctmp1).this(3) at compile time test.d(8): Error: cannot evaluate ((S __ctmp1; ) , __ctmp1).this(3) at compile time There's more output after newline which CodeBlocks didn't pick up. I don't know the SVN rev. of my DMD, though. Maybe sb fixed that after the release?
Comment #3 by yebblies — 2011-06-12T22:46:24Z
This compiles without error in dmd2.053