Comment #0 by bearophile_hugs — 2011-06-29T17:03:56Z
In the following four cases of "if" I think it's better to receive warnings from the compiler, because the code probably contains mistakes (this compiles with no errors on DMD 2.053):
struct Foo {
int x;
bool foo() { return true; }
}
void main() {
Foo* p;
int* arr = (new int[5]).ptr;
if (p != null || p.x) {}
if (p == null && p.foo()) {}
if (!p && p.foo()) {}
if (arr == null && arr[3]) {}
}
Comment #1 by razvan.nitu1305 — 2022-08-15T14:38:32Z
This is more suited for a third party library. Also, the compiler will need to do dataflow analysis to understand these cases.