Allow subtraction of function pointer types in C, as a GNU extension. Fixes rdar://problem/6520707
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62859 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index ab5bd6b..6ec4d4a 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -2746,6 +2746,17 @@
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();