Bug 4910 – [CTFE] Cannot evaluate a function that has failed at once
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-09-21T15:33:00Z
Last change time
2011-06-07T01:23:06Z
Keywords
rejects-valid
Assigned to
nobody
Creator
rsinfu
Comments
Comment #0 by rsinfu — 2010-09-21T15:33:40Z
If the interpretor failed to evaluate a function with an invalid argument at once, then it fails to evaluate the same function with a valid argument.
The following code fails (it should succeed):
-------------------- test1.d
int echo(int a)
{
return a;
}
template ctfe(int v) { }
static int var;
static assert(!__traits(compiles, ctfe!(echo(var)) ));
enum c = echo(123); // (10)
--------------------
% dmd -o- -c test1.d
test1.d(10): Error: cannot evaluate echo(123) at compile time
test1.d(10): Error: cannot evaluate echo(123) at compile time
--------------------
But it succeeds if echo(123) is evaluated before the failure.
-------------------- test2.d
int echo(int a)
{
return a;
}
enum c = echo(123);
template ctfe(int v) { }
static int var;
static assert(!__traits(compiles, ctfe!(echo(var)) ));
--------------------
% dmd -o- -c test2.d
% _
--------------------