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)();
}
Comment #1 by code — 2017-08-03T19:02:30Z
Looks like the assignment expression parsing isn't fully working, below example works.
void works(int a, int b)
{
static assert(__traits(compiles, a = b));
}
Also the specs support the case
http://dlang.org/spec/grammar.html#TraitsArgument
I went back until 2.050 and it still wouldn't accept the code, downgrading to a normal bug.
Simple workaround:
__traits(compiles, { exp; })
Comment #2 by schveiguy — 2018-11-30T03:53:22Z
Just ran into this too.
Comment #3 by robert.schadek — 2024-12-13T18:53:45Z