Bug 10858 – CTFE wrong code for comparison of array of pointers
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-08-20T03:45:00Z
Last change time
2015-06-09T05:10:45Z
Assigned to
nobody
Creator
monarchdodra
Comments
Comment #0 by monarchdodra — 2013-08-20T03:45:53Z
Apparently, CTFE cannot interpret "new int*" at compile time. However, it can (!?) interpret new int*[](1)?
However, depending on the context, it may actually no correctly evaluate it:
//----
auto foo1(T)()
{
return new T;
}
auto foo2(T)()
{
return new T[](1);
}
void main()
{
//foo1 tests.
version (none) {
bool dg1()
{
auto a = foo1!(int*)(); //Fails here.
assert(a == null);
return true;
}
enum a = foo1!(int*)(); //Fails
static assert(dg1()); //Also fails.
}
//foo2 tests
{
bool dg2()
{
auto a = foo2!(int*)(); //OK?
assert(a[0] == null); //Fails here ???
return true;
}
enum a = foo2!(int*)(); //OK
static assert(a[0] == null); //OK
static assert(dg2()); //FAILS.
}
}
//----
In this example (the "foo2" tests), we can see that "enum a = foo2!(int*)()" is perfectly evaluated. The "static assert" afterwards proves it.
However, if these two instructions are instead evaluated with CTFE "static assert(dg2())", then "something" will fail...
Comment #1 by clugdbug — 2013-09-05T23:24:28Z
This is a horrible wrong-code bug, nothing to do with 'new'. The bug is in ==.
The pointer doesn't need to be null.
Reduced test case:
bool bug10858()
{
int *[4] x;
x[0] = null;
assert(x[0] == null);
return true;
}
static assert(bug10858());
Comment #2 by github-bugzilla — 2013-09-09T23:46:40Z