www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17351] New: Static const array can't be evaluated at compile

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

          Issue ID: 17351
           Summary: Static const array can't be evaluated at compile time
                    when passed as ref argument
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: lucia.mcojocaru gmail.com

Static const arrays can't be evaluated at compile time when they are passed as
__ref__ arguments to a function. 

bool fun(S)(ref S[3] a) { return true; }     // (1)
void main()
{
    static const int[3] sa2 = 1;
    static assert(fun(sa2));
}

staticcomp.d(8): Error: static variable sa2 cannot be read at compile time
staticcomp.d(8):        called from here: fun(sa2)
staticcomp.d(8):        while evaluating: static assert(fun(sa2))

Non-ref param implementation compiles without errors.
bool fun(S)(S[3] a) { return true; }       // (2)

Defining both (1) and (2) overloads in the same program fails to pick the
non-ref overload and gives the same compilation error.

--
Apr 26 2017