[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
Fri Apr 28 17:09:46 PDT 2017


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

Andrei Alexandrescu <andrei at erdani.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |---

--- Comment #3 from Andrei Alexandrescu <andrei at erdani.com> ---
Please let's keep this opened until we get to a resolution, thanks.

There are several issues here. First, consider this variation:

bool fun(const int a) { return true; }
bool gun(const int[3] a) { return true; }

void main()
{
    static const int x1 = 1;
    static assert(fun(x1));
    static const int[3] x;
    static assert(gun(x));
}

The int goes through, the int[3] does not although the pass by value protocol
is the same for both. Apparently float is also handled the same as int. At a
minimum we should include in the specification what types enjoy such special
treatment.

The second experiment:

bool fun(const int a) { return true; }
bool fun(ref const int a) { return true; }

void main()
{
    static const int x1 = 1;
    static assert(fun(x1));
}

Here, the code attempts to avoid the problem by overloading on ref. However,
the call is resolved to the ref version even though it does not go through.
This should definitely be fixed, otherwise we're in the position of making a
workaround impossible.

The third experiment:

bool fun(T)(auto ref const T a) { return true; }

void main()
{
    static const int x1 = 1;
    static assert(fun(x1));
}

Here, the code gives complete leeway to the compiler as to what version should
be called. Again, the compiler chooses the ref version to then refuse to let it
go through.

--


More information about the Digitalmars-d-bugs mailing list