www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17703] New: __traits(compiles, AssignmentExpression) no

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

          Issue ID: 17703
           Summary: __traits(compiles, AssignmentExpression) no longer
                    compiles without surrounding parens
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: regression
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: slavo5150 yahoo.com

void Test(T...)()
{
    static assert(__traits(compiles, T[0] = T[1]), "Doesn't compile");
}

void main()
{
    int x;
    int y;
    Test!(x, y)();    
}

This code fails to compile with:
(3): Error: found '=' when expecting ')' following template argument list
(3): Error: found 'T' when expecting ')' 
(3): Error: found '[' when expecting ';' 
(3): Error: found ']' when expecting ';' following statement 
(3): Error: found ')' instead of statement

It used to compile a few years ago. 

Enclosing `T[0] = T[1]` in parentheses will allow it to compile.

void Test(T...)()
{
    static assert(__traits(compiles, (T[0] = T[1])), "Doesn't compile");
}

void main()
{
    int x;
    int y;
    Test!(x, y)();    
}

--
Jul 29 2017