Bug 9345 – CTFE fails when using std.string.format with imported string enum
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-01-18T03:43:00Z
Last change time
2015-06-09T05:15:21Z
Assigned to
nobody
Creator
yazan.dabain
Comments
Comment #0 by yazan.dabain — 2013-01-18T03:43:42Z
File enumfile.d
---------------
module enumfile;
enum Foo : string {
a = "Please print me",
}
File main.d
-----------
import enumfile;
import std.stdio; //without importing std.stdio or any other package, the CTFE error disappears
import std.string;
void main() {
pragma(msg, "%s".format(Foo.a));
}
Compiler output:
format.d(7): Error: cannot cast a read-only string literal to mutable in CTFE
format.d(7): called from here: format("%s", "Please print me")
format("%s", "Please print me")
The code compiles correctly when either the import for the unrelated package is commented out, or when the enum is moved to the same file.
Comment #1 by yazan.dabain — 2013-01-19T07:02:18Z
I was looking into this again today. This problem only exists when using rdmd. Compiling using DMD v2.061 or HEAD is successful.
Comment #2 by yazan.dabain — 2013-01-19T07:10:10Z
Okay, it is the include flag.
dmd -I. main.d
Fails with the same output as above.
BTW, the compiler output shows correctly the filename main.d and not format.d as in the first comment. I was testing locally using a file named format.d.