Bug 18508 – Using statement without effect should error

Status
RESOLVED
Resolution
INVALID
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-02-23T17:57:26Z
Last change time
2018-02-27T08:49:33Z
Assigned to
No Owner
Creator
Seb

Comments

Comment #0 by greensunny12 — 2018-02-23T17:57:26Z
cat << EOF | dmd -c -o- - int f(int a){ return a; } void main() { int a; a=f(0),f(1); assert(a==1); } EOF It already errors for cat << EOF | dmd -c -o- - int f(int a){ return a; } void main() { int a; a=0,1; assert(a==1); } EOF
Comment #1 by issues.dlang — 2018-02-23T22:48:00Z
I'm not sure what is and isn't supposed to be legal with the comma operator now, but if the issue is that the statement has no effect, then there isn't necessarily a bug here, because f isn't pure. Yes, _we_ can see that f has no effect, but the compiler doesn't look past the signature. Now, I slapped pure on f to see what would happen, and that still doesn't produce an error, so there probably is a bug if your example has pure on f, but as-is, I'm not sure that it actually shows a bug.
Comment #2 by schveiguy — 2018-02-24T01:05:00Z
It is supposed to be illegal to use the result of a comma expression. See here: https://dlang.org/spec/expression.html#expression
Comment #3 by dfj1esp02 — 2018-02-27T08:49:33Z
Yep, no statement without effect in the example. Even pure function can still throw exception, which is effect too.