[Issue 23088] New: spurious case of "`expression`" has no effect
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed May 4 13:34:11 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=23088
Issue ID: 23088
Summary: spurious case of "`expression`" has no effect
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Keywords: diagnostic, rejects-valid
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: b2.temp at gmx.com
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.
--
More information about the Digitalmars-d-bugs
mailing list