https://issues.dlang.org/show_bug.cgi?id=18945

Jonathan M Davis <[email protected]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |[email protected]
                   |                            |m

--- Comment #1 from Jonathan M Davis <[email protected]> ---
Yeah. And bizarrely, this code actually results in an error about not being
able to call stuff during CTFE:

int foo()
{
    import std.datetime;
    return cast(int)Clock.currTime().stdTime;
}

void main()
{
    immutable i = foo();
    int[i] arr;
}

Getting rid of the declaration for arr fixes the problem. So, clearly, the
compiler is currently deciding whether it should do CTFE on an immutable, local
variable based on whether it's then used in a context where its value must be
known at compile time instead of forcing enum to be used instead. It also seems
to do the same with const.

The fact that the static array's size can use a local variable is completely
inconsistent with how CTFE normally works and makes the whole situation that
much more confusing. CTFE should only be kicking in based on whether the value
is actually needed at compile time and not based on whether the variable that
it's assigned to is then used at compile time.

--

Reply via email to