No warning for bogus comparison.
Hyman Rosen
hymie@prolifics.com
Mon Jan 26 16:00:00 GMT 1998
Paul Koning <pkoning@xedia.com> writes:
> >>>>> "Hyman" == Hyman Rosen <hymie@prolifics.com> writes:
> Hyman> The following code is silently compiled, with no warnings:
> Hyman> int f() { if (0 > f) return 1; return 0; }
>
> So what's the problem? It's comparing 0 with the address of
> function f... And since 0 is the null pointer, which is compatible
> with all pointers, you don't get a type mismatch.
Well, here's what the C++ draft standard says (5.9):
If two pointers p and q of the same type point to different objects
that are not members of the same object or elements of the same
array or to different functions, or if only one of them is null, the
results of p<q, p>q, p<=q, and p>=q are unspecified.
So I have a construct in my code whose behavior is explicitly unspecified.
I think this merits a warning.
More information about the Gcc-bugs
mailing list