Bug 23086 – spurious case of `expression has no effect` message

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-05-04T12:50:51Z
Last change time
2022-05-04T13:41:41Z
Keywords
diagnostic, rejects-valid
Assigned to
No Owner
Creator
Basile-z

Comments

Comment #0 by b2.temp — 2022-05-04T12:50:51Z
For the following code ``` static int v; ref int a() { a++; return a; } int main() { a == 0; return v ? 0 : 1; } ``` we get, with -de, the output > /tmp/temp_7F3C12CCD670.d:15:5: Error: `a() == 0` has no effect but the effect of the call directly influences the return code of the program.
Comment #1 by b2.temp — 2022-05-04T12:52:14Z
also `ref int a()` is not `pure`
Comment #2 by b2.temp — 2022-05-04T13:05:42Z
the check should dig in the sub expressions and take in account if they contain impure calls, in which case the message should not be emitted.
Comment #3 by b2.temp — 2022-05-04T13:41:41Z
`a` was supposed to return a global, closed an opened https://issues.dlang.org/show_bug.cgi?id=23088 for less confusion.