www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Is D2.0 CTFE broken?

reply "Koroskin Denis" <2korden+dmd gmail.com> writes:
CTFE doesn't work for a few releases for me. Consider the following  
example:

int func()
{
     return 0;
}

template copy(int i)
{
     const int copy = i;
}

void main()
{
     const int f = func(); // Error: non-constant expression f = func()
     const int t = copy!(f);
}

Compiles well with DMD1.033 and DMD2.007 and fails with DMD2.013, 2.015,  
2.017. Other versions not tested.
Is it by design or a bug? It's a blocker issue for me.
Jul 17 2008
parent Max Samukha <samukha voliacable.com.removethis> writes:
On Thu, 17 Jul 2008 12:22:00 +0400, "Koroskin Denis"
<2korden+dmd gmail.com> wrote:

CTFE doesn't work for a few releases for me. Consider the following  
example:

int func()
{
     return 0;
}

template copy(int i)
{
     const int copy = i;
}

void main()
{
     const int f = func(); // Error: non-constant expression f = func()
     const int t = copy!(f);
}

Compiles well with DMD1.033 and DMD2.007 and fails with DMD2.013, 2.015,  
2.017. Other versions not tested.
Is it by design or a bug? It's a blocker issue for me.
I think dmd 2.017 does it right but the error message is misleading. const int f is a run time entity and func will be called at run time. So f's value cannot be used as template argument. Add 'static' to the declaration of f to fix your example. Or use enum.
Jul 17 2008