Is D2.0 CTFE broken?

Max Samukha samukha at voliacable.com.removethis
Thu Jul 17 02:58:18 PDT 2008


On Thu, 17 Jul 2008 12:22:00 +0400, "Koroskin Denis"
<2korden+dmd at 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.



More information about the Digitalmars-d mailing list