[cfe-commits] r62859 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/Sema/pointer-subtract-compat.c
Douglas Gregor
dgregor at apple.com
Fri Jan 23 11:03:35 PST 2009
Author: dgregor
Date: Fri Jan 23 13:03:35 2009
New Revision: 62859
URL: http://llvm.org/viewvc/llvm-project?rev=62859&view=rev
Log:
Allow subtraction of function pointer types in C, as a GNU extension. Fixes rdar://problem/6520707
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/Sema/pointer-subtract-compat.c
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=62859&r1=62858&r2=62859&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Jan 23 13:03:35 2009
@@ -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();
Modified: cfe/trunk/test/Sema/pointer-subtract-compat.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/pointer-subtract-compat.c?rev=62859&r1=62858&r2=62859&view=diff
==============================================================================
--- cfe/trunk/test/Sema/pointer-subtract-compat.c (original)
+++ cfe/trunk/test/Sema/pointer-subtract-compat.c Fri Jan 23 13:03:35 2009
@@ -4,3 +4,8 @@
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}}
+}
More information about the cfe-commits
mailing list