This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C++ PATCH] Fix -Wunused-but-set-parameter bug with references (PR c++/47783)


Hi!

On the following testcase we incorrectly warn that r argument
is set but not used.  For normal references (instead of
references inside of aggregates) we don't warn because we never
consider REFERENCE_TYPE parameters or variables for these warnings.

The following patch fixes it, but am not sure if you want to call there
mark_exp_read, mark_rvalue_use or something else or if you prefer to
do it somewhere else.

Bootstrapped/regtested on x86_64-linux and i686-linux.

2011-02-17  Jakub Jelinek  <jakub@redhat.com>

	PR c++/47783
	* cvt.c (convert_from_reference): Call mark_exp_read.

	* g++.dg/warn/Wunused-parm-4.C: New test.

--- gcc/cp/cvt.c.jj	2011-02-15 15:42:18.000000000 +0100
+++ gcc/cp/cvt.c	2011-02-17 18:01:50.000000000 +0100
@@ -512,6 +512,7 @@ convert_from_reference (tree val)
       tree t = TREE_TYPE (TREE_TYPE (val));
       tree ref = build1 (INDIRECT_REF, t, val);
 
+      mark_exp_read (val);
        /* We *must* set TREE_READONLY when dereferencing a pointer to const,
 	  so that we get the proper error message if the result is used
 	  to assign to.  Also, &* is supposed to be a no-op.  */
--- gcc/testsuite/g++.dg/warn/Wunused-parm-4.C.jj	2011-02-17 18:11:28.000000000 +0100
+++ gcc/testsuite/g++.dg/warn/Wunused-parm-4.C	2011-02-17 18:11:09.000000000 +0100
@@ -0,0 +1,24 @@
+// PR c++/47783
+// { dg-do compile }
+// { dg-options "-Wunused -W" }
+
+struct R
+{
+  int &i;
+};
+
+void
+foo (R r, int &s)
+{
+  r.i = 7;
+  s = 8;
+}
+
+int
+bar ()
+{
+  int x = 1, y = 1;
+  R r = { x };
+  foo (r, y);
+  return x + y;
+}

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]