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

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6344 - [CTFE] Assertion Failure in interpret.c when create an empty slice from null pointer
Summary: [CTFE] Assertion Failure in interpret.c when create an empty slice from null ...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Windows
: P2 major
Assignee: No Owner
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
Reported: 2011年07月18日 12:07 UTC by Andrej Mitrovic
Modified: 2011年07月21日 20:33 UTC (History)
2 users (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Andrej Mitrovic 2011年07月18日 12:07:58 UTC
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 kennytm 2011年07月18日 13:01:40 UTC
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 kennytm 2011年07月18日 13:16:45 UTC
Ultimate cause: create an empty slice from a 'null' pointer.
----------------------
static assert({
 char* c = null;
 auto m = c[0..0];
 return true;
}());
----------------------


AltStyle によって変換されたページ (->オリジナル) /