digitalmars.D.bugs - [Issue 6225] New: Some common null test mistakes
- d-bugmail puremagic.com (32/32) Jun 29 2011 http://d.puremagic.com/issues/show_bug.cgi?id=6225
http://d.puremagic.com/issues/show_bug.cgi?id=6225
Summary: Some common null test mistakes
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Keywords: diagnostic
Severity: enhancement
Priority: P2
Component: DMD
AssignedTo: nobody puremagic.com
ReportedBy: bearophile_hugs eml.cc
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]) {}
}
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 29 2011








d-bugmail puremagic.com