Bug 23088 – spurious case of "`expression` has no effect"

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-05-04T13:34:11Z
Last change time
2022-05-27T11:46:54Z
Keywords
diagnostic, pull, rejects-valid
Assigned to
No Owner
Creator
Basile-z

Comments

Comment #0 by b2.temp — 2022-05-04T13:34:11Z
For the following code ``` static int v; extern(C) int rand(); ref int a() { return v = rand(); } int main() { a == 0; return v ? 1 : 0; } ``` we get, with -de, the output > /tmp/temp_7F3C12CCD670.d:12:5: Error: `a() == 0` has no effect but the effect of the call directly influences the return code of the program. The compiler, by digging in the nested expressions could determine that it contains one call to an impure function and consequently allow (or not warn) about the comparison.
Comment #1 by b2.temp — 2022-05-04T16:28:19Z
-we
Comment #2 by dlang-bot — 2022-05-08T02:11:14Z
@maxhaton created dlang/dmd pull request #14091 "Fix Issue 23088 - This bug is a symptom of a bad error message." fixing this issue: - Fix Issue 23088 - This bug is a symptom of a bad error message. The expression (or rather it's context is still worthy of being illegal) https://github.com/dlang/dmd/pull/14091
Comment #3 by dlang-bot — 2022-05-27T11:46:54Z
dlang/dmd pull request #14091 "Fix Issue 23088 - This bug is a symptom of a bad error message." was merged into master: - 3eedace3346b6245695f4c00ce6bae760cf7df57 by mhh: Fix Issue 23088 - This bug is a symptom of a bad error message. The expression (or rather it's context is still worthy of being illegal) https://github.com/dlang/dmd/pull/14091