[cfe-dev] Q. on pointer/integer comparison
Robinson, Paul
Paul_Robinson at playstation.sony.com
Thu Apr 3 12:00:28 PDT 2014
Cool. Although I have to wonder if there's a consolidated 2011-as-amended document,
or do I have to cruise the defects page every time I'm trying to look something up?
Thanks,
--paulr
From: metafoo at gmail.com [mailto:metafoo at gmail.com] On Behalf Of Richard Smith
Sent: Wednesday, April 02, 2014 6:58 PM
To: Robinson, Paul
Cc: cfe-dev at cs.uiuc.edu
Subject: Re: [cfe-dev] Q. on pointer/integer comparison
On Wed, Apr 2, 2014 at 5:47 PM, Robinson, Paul <Paul_Robinson at playstation.sony.com<mailto:Paul_Robinson at playstation.sony.com>> wrote:
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.)
This was changed by DR 903:
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#903
We implement this DR in C++11 onwards, since the C++98 rules are *really* broken when combined with C++11's generalized constant expressions. Without this change, ridiculous things like
struct S { int n; };
int *p = S().n;
... would compile, because S().n is an integral constant expression with value 0.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140403/0d91e8c7/attachment.html>
More information about the cfe-dev
mailing list