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] Avoid bogus -Wunused-value warnings (PR c++/39875)


Hi!

For PR c++/39551 g++ started warning about INDIRECT_REFs in
convert_to_void, but we shouldn't be warning when the cast to (void)
is explicit in the program, only when convert_to_void is called
implicitly.  I believe we can use the IMPLICIT argument of convert_to_void
for this.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2009-04-26  Jakub Jelinek  <jakub@redhat.com>

	PR c++/39875
	* cvt.c (convert_to_void) <case INDIRECT_REF>: Only warn about
	-Wunused-value if implicit.

--- gcc/cp/cvt.c.jj	2009-04-16 10:11:00.000000000 +0200
+++ gcc/cp/cvt.c	2009-04-26 21:27:22.000000000 +0200
@@ -878,6 +878,7 @@ convert_to_void (tree expr, const char *
                - automatic dereferencing of references, since the user cannot
                  control it. (See also warn_if_unused_value() in stmt.c.)  */
             if (warn_unused_value
+		&& implicit
                 && (complain & tf_warning)
                 && !TREE_NO_WARNING (expr)
                 && !is_reference)
--- gcc/testsuite/g++.dg/warn/Wunused-15.C.jj	2009-04-26 21:30:28.000000000 +0200
+++ gcc/testsuite/g++.dg/warn/Wunused-15.C	2009-04-26 21:29:11.000000000 +0200
@@ -0,0 +1,11 @@
+// PR c++/39875
+// { dg-do compile }
+// { dg-options "-Wunused-value" }
+
+int *i;
+void
+foo ()
+{
+  *i++;		// { dg-warning "value computed is not used" }
+  (void) *i++;	// { dg-bogus "value computed is not used" }
+}

	Jakub


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