From 3e85c9c561186746af97640d66ecbe67b5afe46c Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Thu, 16 Jun 2011 18:52:05 +0000 Subject: [PATCH] Allow comparison between block pointers and NULL pointer constants. Fixes PR10145. llvm-svn: 133179 --- clang/lib/Sema/SemaExpr.cpp | 6 ++++-- clang/test/SemaObjCXX/nullptr.mm | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 5e30e7179c6c..76612cd6d878 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -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 diff --git a/clang/test/SemaObjCXX/nullptr.mm b/clang/test/SemaObjCXX/nullptr.mm index 4cd5669ef5ae..4a9d1a07de9d 100644 --- a/clang/test/SemaObjCXX/nullptr.mm +++ b/clang/test/SemaObjCXX/nullptr.mm @@ -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;