[cfe-dev] Q. on pointer/integer comparison

Robinson, Paul Paul_Robinson at playstation.sony.com
Wed Apr 2 17:47:13 PDT 2014


With -std=c++11, clang will complain about the expression in 
bar() but not foo().

    bool foo(int *p) { return (p != 0); }
    bool bar(int* p) { return (p != (1 - 1)); }

With -std=c++03, clang accepts both.

[expr.const]p3 has a Note that says an integral constant expression
can be used as a null pointer constant.
So, I think Clang should accept both even in C++11 mode.

Bug, or my usual confusion about the standard?  (I can see issuing
a warning, because it would be hard to contrive a real-world case
where somebody would actually want to do this; but if it conforms,
Clang should not reject it.)

Thanks,
--paulr






More information about the cfe-dev mailing list