Title
Relational pointer comparisons against the null pointer constant
Status
cd3
Section
7.6.9 [expr.rel]
Submitter
James Widman

Created on 2006-05-24.00:00:00 last changed 123 months ago

Messages

Date: 2013-04-15.00:00:00

[Moved to DR status at the April, 2013 meeting as paper N3624.]

Date: 2013-04-15.00:00:00

Proposed resolution (April, 2013):

This issue is resolved by the resolution of issue 1512.

Date: 2006-05-24.00:00:00

In C, this is ill-formed (cf C99 6.5.8):

    void f(char* s) {
        if (s < 0) { }
    }

...but in C++, it's not. Why? Who would ever need to write (s > 0) when they could just as well write (s != 0)?

This has been in the language since the ARM (and possibly earlier); apparently it's because the pointer conversions (7.3.12 [conv.ptr]) need to be performed on both operands whenever one of the operands is of pointer type. So it looks like the "null-ptr-to-real-pointer-type" conversion is hitching a ride with the other pointer conversions.

History
Date User Action Args
2014-03-03 00:00:00adminsetstatus: drwp -> cd3
2013-10-14 00:00:00adminsetstatus: dr -> drwp
2013-09-03 00:00:00adminsetmessages: + msg4561
2013-09-03 00:00:00adminsetmessages: + msg4560
2013-09-03 00:00:00adminsetstatus: open -> dr
2006-05-24 00:00:00admincreate