Bug 17703 – __traits(compiles, a[] = b[]) generates errors without surrounding parentheses

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-07-29T18:52:20Z
Last change time
2024-12-13T18:53:45Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
Mike Franklin
Moved to GitHub: dmd#19293 →

Comments

Comment #0 by slavo5150 — 2017-07-29T18:52:20Z
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
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19293 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB