]> granicus.if.org Git - clang/commitdiff
Allow comparison between block pointers and NULL pointer
authorDouglas Gregor <dgregor@apple.com>
Thu, 16 Jun 2011 18:52:05 +0000 (18:52 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 16 Jun 2011 18:52:05 +0000 (18:52 +0000)
constants. Fixes PR10145.

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

lib/Sema/SemaExpr.cpp
test/SemaObjCXX/nullptr.mm

index 5e30e7179c6c9aacdfedc9702abcf30e26fa494d..76612cd6d878f6b124fc93be2c62011f6d7c2fdd 100644 (file)
@@ -7772,7 +7772,8 @@ QualType Sema::CheckCompareOperands(ExprResult &lex, ExprResult &rex, SourceLoca
     // comparisons of member pointers to null pointer constants.
     if (RHSIsNull &&
         ((lType->isAnyPointerType() || lType->isNullPtrType()) ||
-         (!isRelational && lType->isMemberPointerType()))) {
+         (!isRelational && 
+          (lType->isMemberPointerType() || lType->isBlockPointerType())))) {
       rex = ImpCastExprToType(rex.take(), lType, 
                         lType->isMemberPointerType()
                           ? CK_NullToMemberPointer
@@ -7781,7 +7782,8 @@ QualType Sema::CheckCompareOperands(ExprResult &lex, ExprResult &rex, SourceLoca
     }
     if (LHSIsNull &&
         ((rType->isAnyPointerType() || rType->isNullPtrType()) ||
-         (!isRelational && rType->isMemberPointerType()))) {
+         (!isRelational && 
+          (rType->isMemberPointerType() || rType->isBlockPointerType())))) {
       lex = ImpCastExprToType(lex.take(), rType, 
                         rType->isMemberPointerType()
                           ? CK_NullToMemberPointer
index 4cd5669ef5ae2af326fb88f6defbffe49e919984..4a9d1a07de9de2e292f4843f30e5cf80ac79c890 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++0x -fblocks -fsyntax-only -verify %s
 
 @interface A
 @end
@@ -11,3 +11,6 @@ void comparisons(A *a) {
 void assignment(A *a) {
   a = nullptr;
 }
+
+int PR10145a = (void(^)())0 == nullptr;
+int PR10145b = nullptr == (void(^)())0;