]> granicus.if.org Git - clang/commitdiff
Allow comparison of 'void *' with function pointer
authorFariborz Jahanian <fjahanian@apple.com>
Mon, 21 Dec 2009 18:19:17 +0000 (18:19 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Mon, 21 Dec 2009 18:19:17 +0000 (18:19 +0000)
as a g++ extension (fixes radar 7481987).

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

lib/Sema/SemaExpr.cpp
test/SemaObjCXX/function-pointer-void-star.mm [new file with mode: 0644]

index 791948fb2b286158f5e8b3d5bfebd69df6e3a340..f67a7a6bb9d9dc7cc6569014f16b709d1f439877 100644 (file)
@@ -5170,7 +5170,18 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc,
     if (getLangOptions().CPlusPlus) {
       if (LCanPointeeTy == RCanPointeeTy)
         return ResultTy;
-
+      if (!isRelational &&
+          (LCanPointeeTy->isVoidType() || RCanPointeeTy->isVoidType())) {
+        // Valid unless comparison between non-null pointer and function pointer
+        // This is a gcc extension compatibility comparison.
+        if ((LCanPointeeTy->isFunctionType() || RCanPointeeTy->isFunctionType())
+            && !LHSIsNull && !RHSIsNull) {
+          Diag(Loc, diag::ext_typecheck_comparison_of_fptr_to_void)
+            << lType << rType << lex->getSourceRange() << rex->getSourceRange();
+          ImpCastExprToType(rex, lType, CastExpr::CK_BitCast);
+          return ResultTy;
+        }
+      }
       // C++ [expr.rel]p2:
       //   [...] Pointer conversions (4.10) and qualification
       //   conversions (4.4) are performed on pointer operands (or on
diff --git a/test/SemaObjCXX/function-pointer-void-star.mm b/test/SemaObjCXX/function-pointer-void-star.mm
new file mode 100644 (file)
index 0000000..8d3d625
--- /dev/null
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+extern "C" id (*_dealloc)(id) ;
+
+void foo() {
+        extern void *_original_dealloc;
+        if (_dealloc == _original_dealloc) { }
+        if (_dealloc != _original_dealloc) { }
+}