]> granicus.if.org Git - clang/commitdiff
Fix a problem with the diagnostics of invalid arithmetic with function
authorChandler Carruth <chandlerc@gmail.com>
Mon, 20 Jun 2011 07:52:11 +0000 (07:52 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Mon, 20 Jun 2011 07:52:11 +0000 (07:52 +0000)
pointers I found while working on the NULL arithmetic warning. We here
always assuming the LHS was the pointer, instead of using the selected
pointer expression.

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

lib/Sema/SemaExpr.cpp
test/Sema/pointer-addition.c
test/SemaCXX/null_in_arithmetic_ops.cpp

index 5d6291006899596395d90748818e15ef9007b803..a00877622de5b48b2a79cb5652e9abce404af66a 100644 (file)
@@ -7218,13 +7218,13 @@ QualType Sema::CheckAdditionOperands( // C99 6.5.6
       } else if (PointeeTy->isFunctionType()) {
         if (getLangOptions().CPlusPlus) {
           Diag(Loc, diag::err_typecheck_pointer_arith_function_type)
-            << lex.get()->getType() << lex.get()->getSourceRange();
+            << PExp->getType() << PExp->getSourceRange();
           return QualType();
         }
 
         // GNU extension: arithmetic on pointer to function
         Diag(Loc, diag::ext_gnu_ptr_func_arith)
-          << lex.get()->getType() << lex.get()->getSourceRange();
+          << PExp->getType() << PExp->getSourceRange();
       } else {
         // Check if we require a complete type.
         if (((PExp->getType()->isPointerType() &&
index aa425a7fd9d9810a0215a8ae926367d5ac659078..01047a068490ba83c7af1dee41ff855b216ea430 100644 (file)
@@ -14,7 +14,8 @@ void a(S* b, void* c) {
   /* The next couple tests are only pedantic warnings in gcc */
   void (*d)(S*,void*) = a;
   d += 1;    // expected-warning {{arithmetic on pointer to function type 'void (*)(S *, void *)' is a GNU extension}}
-  d++;       // expected-warning {{arithmetic on pointer to function type 'void (*)(S *, void *)' is a GNU extension}}}
+  d++;       // expected-warning {{arithmetic on pointer to function type 'void (*)(S *, void *)' is a GNU extension}}
   d--;       // expected-warning {{arithmetic on pointer to function type 'void (*)(S *, void *)' is a GNU extension}}
   d -= 1;    // expected-warning {{arithmetic on pointer to function type 'void (*)(S *, void *)' is a GNU extension}}
+  (void)(1 + d); // expected-warning {{arithmetic on pointer to function type 'void (*)(S *, void *)' is a GNU extension}}
 }
index 9665c3959e7c0403a39ae164387a4f844522ff41..d9cfc5f89a8d1c609523aac607b8c8b47ccbf8e0 100644 (file)
@@ -33,7 +33,7 @@ void f() {
   v = 0 ? NULL + d : d + NULL; // \
     expected-error {{invalid operands to binary expression ('long' and 'void (X::*)()')}} \
     expected-error {{invalid operands to binary expression ('void (X::*)()' and 'long')}}
-  v = 0 ? NULL + e : e + NULL; // expected-error 2{{arithmetic on pointer to function type}}
+  v = 0 ? NULL + e : e + NULL; // expected-error 2{{arithmetic on pointer to function type 'void (*)()'}}
   v = 0 ? NULL + f : f + NULL; // expected-warning 2{{use of NULL in arithmetic operation}}
   v = 0 ? NULL + "f" : "f" + NULL; // expected-warning 2{{use of NULL in arithmetic operation}}