diff mbox

[C++,/,RFC] Tidy c-common.c:pointer_int_sum?

Message ID 515C68EC.9030902@oracle.com
State New
Headers show

Commit Message

Paolo Carlini April 3, 2013, 5:37 p.m. UTC
Hi,

earlier today I noticed that I wasn't able to construct a testcase 
tirggering this warning and decided to replace the body with a 
gcc_unreachable () and boot & test C/OBJC/C++/OBJC++. No regressions. 
Its this some sort of legacy case which can go away?

Thanks!
Paolo.

//////////////////////

Comments

Paolo Carlini April 3, 2013, 8:39 p.m. UTC | #1
.. I analyzed a bit what is happening and this is what I see: the only 
interesting case is that of C++, where pointer_int_sum is called via 
cp_pointer_int_sum. The latter is only called by cp_build_binary_op but 
that happens for MINUS_EXPR and PLUS_EXPR as operator. In such cases 
however, only operands with POINTER_TYPE as TREE_TYPE are passed to 
cp_pointer_int_sum. AFAICS this never happens for actual pointers to 
(non-static) member function, eg, for:

struct A { void f(); };

auto p = &A::f + 1;

the TREE_TYPE of the first operand is RECORD_TYPE (the TREE_CODE is 
PTRMEM_CST).

On the other hand, for static member functions the representation uses 
as TREE_TYPE a POINTER_TYPE to FUNCTION_TYPE, which is correctly handled 
by pointer_int_sum.

Paolo.
Jason Merrill April 3, 2013, 8:51 p.m. UTC | #2
Ok.

Jason
diff mbox

Patch

Index: c-common.c
===================================================================
--- c-common.c	(revision 197432)
+++ c-common.c	(working copy)
@@ -4290,12 +4290,6 @@  pointer_int_sum (location_t loc, enum tree_code re
 	       "pointer to a function used in arithmetic");
       size_exp = integer_one_node;
     }
-  else if (TREE_CODE (TREE_TYPE (result_type)) == METHOD_TYPE)
-    {
-      pedwarn (loc, pedantic ? OPT_Wpedantic : OPT_Wpointer_arith,
-	       "pointer to member function used in arithmetic");
-      size_exp = integer_one_node;
-    }
   else
     size_exp = size_in_bytes (TREE_TYPE (result_type));