July 17, 2008
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.
July 17, 2008
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.