Hi all, hi Gaby,
thus a more sensible try at fixing this issue:
function.c:do_warn_unused_parameter uses "%q+D" for the error call. That
means that cp/error.c:cp_printer does:
if (set_locus && t != NULL)
*text->locus = location_of (t);
and it's important that location_of (t) is correct. However, for
PARM_DECLs, location_of (still) does:
if (TREE_CODE (t) == PARM_DECL && DECL_CONTEXT (t))
t = DECL_CONTEXT (t);
else if ...
...
which means that for those we end up with the location of a
FUNCTION_DECL or anyway not exactly the location of the PARM_DECL
itself. I went through the C++ front-end and currently there are very
few cases if any where location_of may be fed a PARM_DECL, and the very
few seem Ok to me. The testsuite passes on x86_64-linux of course, thus
I'm proposing the below. IMHO now that we are in Stage 1 the risk of
breaking locations somewhere else is low enough. By the way, as
discussed today elsewhere, the C front-end is already Ok.
Thanks!
Paolo.
//////////////////////////
/cp
2013-09-09 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/58362
* error.c (location_of): Don't handle PARM_DECLs specially.
/testsuite
2013-09-09 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/58362
* g++.dg/warn/Wunused-parm-5.C: New.
Index: cp/error.c
===================================================================
--- cp/error.c (revision 202384)
+++ cp/error.c (working copy)
@@ -2786,9 +2789,7 @@ lang_decl_name (tree decl, int v, bool translate)
location_t
location_of (tree t)
{
- if (TREE_CODE (t) == PARM_DECL && DECL_CONTEXT (t))
- t = DECL_CONTEXT (t);
- else if (TYPE_P (t))
+ if (TYPE_P (t))
{
t = TYPE_MAIN_DECL (t);
if (t == NULL_TREE)
Index: testsuite/g++.dg/warn/Wunused-parm-5.C
===================================================================
--- testsuite/g++.dg/warn/Wunused-parm-5.C (revision 0)
+++ testsuite/g++.dg/warn/Wunused-parm-5.C (working copy)
@@ -0,0 +1,14 @@
+// PR c++/58362
+// { dg-options "-Wunused-parameter" }
+
+void f1 (long s) { } // { dg-warning "15:unused parameter 's'" }
+
+void f2 (long s, int u) { } // { dg-warning "15:unused parameter 's'" }
+// { dg-warning "22:unused parameter 'u'" "" { target *-*-* } 6 }
+
+void f3 (long s);
+void f3 (long s) { } // { dg-warning "15:unused parameter 's'" }
+
+void f4 (long s, int u);
+void f4 (long s, int u) { } // { dg-warning "15:unused parameter 's'" }
+// { dg-warning "22:unused parameter 'u'" "" { target *-*-* } 13 }