[cfe-commits] r71405 - in /cfe/trunk: include/clang/AST/ include/clang/Frontend/ include/clang/Parse/ lib/AST/ lib/CodeGen/ lib/Frontend/ lib/Parse/ lib/Sema/ test/SemaCXX/ www/
Sebastian Redl
sebastian.redl at getdesigned.at
Mon May 11 13:49:19 PDT 2009
Chris Lattner wrote:
> On May 10, 2009, at 11:38 AM, Sebastian Redl wrote:
> Implement C++0x nullptr.
>
>> //===----------------------------------------------------------------------===//
>>
>> @@ -431,6 +434,9 @@
>> Width = Target.getLongDoubleWidth();
>> Align = Target.getLongDoubleAlign();
>> break;
>> + case BuiltinType::NullPtr:
>> + Width = Target.getPointerWidth(0); // C++ 3.9.1p11:
>> sizeof(nullptr_t)
>> + Align = Target.getPointerAlign(0); // == sizeof(void*)
>> }
>> break;
>
> Hi Sebastian,
>
> Though not strictly needed, please do add an explicit break to this case.
>
Sure, was only an oversight.
> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Sun May 10 13:38:11 2009
> @@ -3811,6 +3811,20 @@
> ImpCastExprToType(rex, lType); // promote the pointer to pointer
> return ResultTy;
> }
> + // C++ allows comparison of pointers with null pointer constants.
> + if (getLangOptions().CPlusPlus) {
> + if (lType->isPointerType() && RHSIsNull) {
> + ImpCastExprToType(rex, lType);
> + return ResultTy;
> + }
> + if (rType->isPointerType() && LHSIsNull) {
> + ImpCastExprToType(lex, rType);
> + return ResultTy;
> + }
> + // And comparison of nullptr_t with itself.
> + if (lType->isNullPtrType() && rType->isNullPtrType())
> + return ResultTy;
> + }
>
> Can't this be handled by making isNullPointerConstant handle this? If
> so, LHSIsNull/RHSIsNull are already computed.
As Eli pointed out, that would allow the illegal nullptr == 0.
Sebastian
More information about the cfe-commits
mailing list