Bug 1461 – Local variable as template alias parameter breaks CTFE
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2007-08-31T09:25:00Z
Last change time
2014-02-16T15:25:30Z
Keywords
rejects-valid
Assigned to
nobody
Creator
reiner.pope
Comments
Comment #0 by reiner.pope — 2007-08-31T09:25:03Z
The following code fails to compile with error, "cannot evaluate generate() at compile time." This error is stopped by declaring x in global scope.
void main()
{
int x;
const string text = Gen!(x).generate();
}
template Gen(alias A)
{
string generate()
{
return null;
}
}
Comment #1 by clugdbug — 2008-06-30T03:50:52Z
Changed version, since this applied to D1.x as well. Still not fixed in D1.031.
For phobos2, the code now needs to use 'enum' instead of const to trigger the behaviour:
---
void main()
{
int x;
enum string text = Gen!(x).generate();
}
template Gen(alias A)
{
string generate()
{
return null;
}
}