diff options
Diffstat (limited to 'clang/lib/Sema/SemaExpr.cpp')
-rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 063e0ec314d..d2e84c10e22 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -3811,6 +3811,20 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc, 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; + } // Handle block pointer types. if (!isRelational && lType->isBlockPointerType() && rType->isBlockPointerType()) { QualType lpointee = lType->getAsBlockPointerType()->getPointeeType(); |