[Issue 17351] Static const array can't be evaluated at compile time when passed as ref argument

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sat Apr 29 08:01:38 PDT 2017


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

--- Comment #8 from ag0aep6g at gmail.com ---
(In reply to Andrei Alexandrescu from comment #6)
> Now, Lucia (@somzzz) has gotten to the point where it all passes druntime
> and phobos unittests, but breaks in exactly one point in the compiler. It
> can be reduced to this:
> 
> static const int[3] x = [1, 2, 3];
> static assert(x == x);

Got it. You need the special overload behavior to keep that assert working with
the new implementation. I'm not particularly opposed to tweaking overload
resolution to that end.

However, as mentioned, another option could be to disallow that static assert
on the grounds that x being static const doesn't mean it's a compile-time
constant. I realize that this would be a relatively disruptive change, but it
would simplify the language instead of complicating it further.

It would also make this little gem impossible:

----
void main()
{
    const bool x = __ctfe;
    static const bool y = x;
    static assert(x == y); /* passes */
    assert(x == y); /* fails */
}
----

--


More information about the Digitalmars-d-bugs mailing list