]> granicus.if.org Git - clang/commitdiff
Allow subtraction of function pointer types in C, as a GNU extension. Fixes rdar...
authorDouglas Gregor <dgregor@apple.com>
Fri, 23 Jan 2009 19:03:35 +0000 (19:03 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 23 Jan 2009 19:03:35 +0000 (19:03 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62859 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/Sema/pointer-subtract-compat.c

index ab5bd6bd11942fa3142845d77e5f9ee3d40aa17a..6ec4d4a61f348fc7d067c075e48441414a3e92d4 100644 (file)
@@ -2746,6 +2746,17 @@ QualType Sema::CheckSubtractionOperands(Expr *&lex, Expr *&rex,
           if (!lpointee->isVoidType())
             Diag(Loc, diag::ext_gnu_void_ptr)
               << lex->getSourceRange() << rex->getSourceRange();
+        } else if (rpointee->isFunctionType()) {
+          if (getLangOptions().CPlusPlus) {
+            Diag(Loc, diag::err_typecheck_pointer_arith_function_type)
+              << rex->getType() << rex->getSourceRange();
+            return QualType();
+          }
+          
+          // GNU extension: arithmetic on pointer to function
+          if (!lpointee->isFunctionType())
+            Diag(Loc, diag::ext_gnu_ptr_func_arith)
+              << lex->getType() << lex->getSourceRange();
         } else {
           Diag(Loc, diag::err_typecheck_sub_ptr_object)
             << rex->getType() << rex->getSourceRange();
index 4ed6abf8af7181a22737b867a7e18c3a212bbc27..9aebe9cdcebb8248136435cc17081ce0849bcd89 100644 (file)
@@ -4,3 +4,8 @@ typedef const char rchar;
 int a(char* a, rchar* b) {
   return a-b;
 }
+
+// <rdar://problem/6520707> 
+void f0(void (*fp)(void)) {
+  int x = fp - fp; // expected-warning{{arithmetic on pointer to function type 'void (*)(void)' is a GNU extension}}
+}