Bug 6344 – [CTFE] Assertion Failure in interpret.c when create an empty slice from null pointer

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2011-07-18T12:07:00Z
Last change time
2011-07-21T20:33:57Z
Keywords
ice-on-valid-code
Assigned to
nobody
Creator
andrej.mitrovich

Comments

Comment #0 by andrej.mitrovich — 2011-07-18T12:07:58Z
DMD 2.054, XP32: import std.array; import std.stdio; import std.conv; import std.traits; enum Foo { pre_x, pre_y, pre_z, } mixin(wrapEnum!(Foo)("NewEnum", "pre_")); // fails private string wrapEnum(Type)(string newName, string prefix) { string result = "enum " ~ newName ~ " {"; foreach (member; EnumMembers!Type) { result ~= to!string(member).replace(prefix, "") ~ ","; } return result ~ "}"; } void main() { // writeln(wrapEnum!(Foo)("NewEnum", "pre_")); // writes: enum NewEnum {x,y,z,} } Output: Assertion failure: 'se->e1->op == TOKarrayliteral || se->e1->op == TOKstring' on line 4957 in file 'interpret.c' abnormal program termination
Comment #1 by kennytm — 2011-07-18T13:01:40Z
First reduction: -------------------------------- import std.array; string rp(string subject) { auto app = appender!string(); app.put(subject[0 .. 0]); auto m = app.data; return m; } enum e = rp("pre_x"); --------------------------------
Comment #2 by kennytm — 2011-07-18T13:16:45Z
Ultimate cause: create an empty slice from a 'null' pointer. ---------------------- static assert({ char* c = null; auto m = c[0..0]; return true; }()); ----------------------
Comment #3 by bugzilla — 2011-07-21T20:33:57Z