Re: [C++ Patch] PR 14710 (add -Wuseless-cast)

2012-03-19 Thread Paolo Carlini
On 03/19/2012 03:59 PM, Jason Merrill wrote: OK. Thanks. I committed the patch. I'm going to add, as obvious, the following few additional tests, which my previous iteration got wrong. Paolo. // 2012-03-19 Paolo Carlini * g++.dg/warn/Wuseless-cast.C: Extend. Ind

Re: [C++ Patch] PR 14710 (add -Wuseless-cast)

2012-03-19 Thread Jason Merrill
OK. Jason

Re: [C++ Patch] PR 14710 (add -Wuseless-cast)

2012-03-19 Thread Paolo Carlini
On 03/19/2012 02:17 PM, Jason Merrill wrote: On 03/18/2012 11:32 AM, Paolo Carlini wrote: + if ((TREE_CODE (type) == REFERENCE_TYPE + && lvalue_p (expr) + && same_type_p (TREE_TYPE (expr), TREE_TYPE (type))) + || same_type_p (TREE_TYPE (expr), type)) +warning (OPT_Wuseless_cast,

Re: [C++ Patch] PR 14710 (add -Wuseless-cast)

2012-03-19 Thread Jason Merrill
On 03/18/2012 11:32 AM, Paolo Carlini wrote: + if ((TREE_CODE (type) == REFERENCE_TYPE + && lvalue_p (expr) + && same_type_p (TREE_TYPE (expr), TREE_TYPE (type))) + || same_type_p (TREE_TYPE (expr), type)) + warning (OPT_Wuseless_cast, "useless cast to type %qT",

Re: [C++ Patch] PR 14710 (add -Wuseless-cast)

2012-03-18 Thread Paolo Carlini
Hi, That won't catch something like int i; static_cast(i); which is also a useless cast, because i is already an int lvalue; not all lvalues are derived from references. Note that something like static_cast(42); is not a useless cast, because it turns a prvalue into an xvalue. Agreed. In o

Re: [C++ Patch] PR 14710 (add -Wuseless-cast)

2012-03-17 Thread Jason Merrill
On 03/16/2012 05:42 PM, Paolo Carlini wrote: 3- References can be easily missed because wrapped in INDIRECT_REF: as explained at the beginning of tree.c and already used in many places, a REFERENCE_REF_P check (and in case a TREE_OPERAND (expr, 0)) takes care of that. I'm not 100% sure the soluti