May 04, 2022 [Issue 23088] New: spurious case of "`expression`" has no effect | ||||
---|---|---|---|---|
| ||||
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@puremagic.com Reporter: b2.temp@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. -- |
Copyright © 1999-2021 by the D Language Foundation