diff options
| author | Anders Carlsson <andersca@mac.com> | 2010-11-04 03:17:43 +0000 |
|---|---|---|
| committer | Anders Carlsson <andersca@mac.com> | 2010-11-04 03:17:43 +0000 |
| commit | a95069c52fb4a4e7492252b8cbb8765e621d485c (patch) | |
| tree | 585cf3db34012d7556dde96fb32fd407e8775304 /clang/lib/Sema/SemaExpr.cpp | |
| parent | 4efe13d8d4d87d4a9e6bf3723492a372c6767d31 (diff) | |
| download | bcm5719-llvm-a95069c52fb4a4e7492252b8cbb8765e621d485c.tar.gz bcm5719-llvm-a95069c52fb4a4e7492252b8cbb8765e621d485c.zip | |
It's OK to use nullptr in relational operators if the other side is a null pointer constant.
llvm-svn: 118234
Diffstat (limited to 'clang/lib/Sema/SemaExpr.cpp')
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 51bb6315e16..6df818cd7a5 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -5735,6 +5735,7 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc, return ResultTy; } } + // C++ [expr.rel]p2: // [...] Pointer conversions (4.10) and qualification // conversions (4.4) are performed on pointer operands (or on @@ -5788,10 +5789,14 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc, } if (getLangOptions().CPlusPlus) { + // Comparison of nullptr_t with itself. + if (lType->isNullPtrType() && rType->isNullPtrType()) + return ResultTy; + // Comparison of pointers with null pointer constants and equality // comparisons of member pointers to null pointer constants. if (RHSIsNull && - (lType->isPointerType() || + ((lType->isPointerType() || lType->isNullPtrType()) || (!isRelational && lType->isMemberPointerType()))) { ImpCastExprToType(rex, lType, lType->isMemberPointerType() @@ -5800,7 +5805,7 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc, return ResultTy; } if (LHSIsNull && - (rType->isPointerType() || + ((rType->isPointerType() || rType->isNullPtrType()) || (!isRelational && rType->isMemberPointerType()))) { ImpCastExprToType(lex, rType, rType->isMemberPointerType() @@ -5840,10 +5845,6 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc, ImpCastExprToType(rex, T, CK_BitCast); return ResultTy; } - - // Comparison of nullptr_t with itself. - if (lType->isNullPtrType() && rType->isNullPtrType()) - return ResultTy; } // Handle block pointer types. |

