]> granicus.if.org Git - clang/commitdiff
Implement comparisons between nullptr and Objective-C object
authorDouglas Gregor <dgregor@apple.com>
Wed, 1 Jun 2011 15:12:24 +0000 (15:12 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 1 Jun 2011 15:12:24 +0000 (15:12 +0000)
pointers. Fixes PR10052.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@132397 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/SemaObjCXX/nullptr.mm [new file with mode: 0644]

index e75af910bdaa11be62179fd56a734c9594b6d001..9afd5f8ccd8f370e62539d236ceb12daf857dba3 100644 (file)
@@ -7536,7 +7536,7 @@ QualType Sema::CheckCompareOperands(ExprResult &lex, ExprResult &rex, SourceLoca
     // Comparison of pointers with null pointer constants and equality
     // comparisons of member pointers to null pointer constants.
     if (RHSIsNull &&
-        ((lType->isPointerType() || lType->isNullPtrType()) ||
+        ((lType->isAnyPointerType() || lType->isNullPtrType()) ||
          (!isRelational && lType->isMemberPointerType()))) {
       rex = ImpCastExprToType(rex.take(), lType, 
                         lType->isMemberPointerType()
@@ -7545,7 +7545,7 @@ QualType Sema::CheckCompareOperands(ExprResult &lex, ExprResult &rex, SourceLoca
       return ResultTy;
     }
     if (LHSIsNull &&
-        ((rType->isPointerType() || rType->isNullPtrType()) ||
+        ((rType->isAnyPointerType() || rType->isNullPtrType()) ||
          (!isRelational && rType->isMemberPointerType()))) {
       lex = ImpCastExprToType(lex.take(), rType, 
                         rType->isMemberPointerType()
diff --git a/test/SemaObjCXX/nullptr.mm b/test/SemaObjCXX/nullptr.mm
new file mode 100644 (file)
index 0000000..4cd5669
--- /dev/null
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s
+
+@interface A
+@end
+
+void comparisons(A *a) {
+  (void)(a == nullptr);
+  (void)(nullptr == a);
+}
+
+void assignment(A *a) {
+  a = nullptr;
+}