[C++ PATCH] Fix -Wunused-but-set-* with some static_casts (PR c++/44682)
Jakub Jelinek
jakub@redhat.com
Mon Jun 28 16:50:00 GMT 2010
Hi!
When using build_base_path, mark_exp_read isn't called on the original
expression if want_pointer, because build_base_path builds POINTER_PLUS_EXPR
of that with some offset directly, not using FE functions that end up
calling mark_exp_read on the arguments. For !want_pointer it is called by
cp_build_unary_op.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
2010-06-28 Jakub Jelinek <jakub@redhat.com>
PR c++/44682
* class.c (build_base_path): If want_pointer, call mark_rvalue_use
on expr.
* g++.dg/warn/Wunused-var-14.C: New test.
--- gcc/cp/class.c.jj 2010-06-17 08:17:04.000000000 +0200
+++ gcc/cp/class.c 2010-06-28 10:44:33.000000000 +0200
@@ -283,6 +283,8 @@ build_base_path (enum tree_code code,
if (!want_pointer)
/* This must happen before the call to save_expr. */
expr = cp_build_unary_op (ADDR_EXPR, expr, 0, tf_warning_or_error);
+ else
+ mark_rvalue_use (expr);
offset = BINFO_OFFSET (binfo);
fixed_type_p = resolves_to_fixed_type_p (expr, &nonnull);
--- gcc/testsuite/g++.dg/warn/Wunused-var-14.C.jj 2010-06-28 10:50:59.000000000 +0200
+++ gcc/testsuite/g++.dg/warn/Wunused-var-14.C 2010-06-28 10:51:20.000000000 +0200
@@ -0,0 +1,17 @@
+// PR c++/44682
+// { dg-do compile }
+// { dg-options "-Wunused" }
+
+struct S { virtual ~S () {} };
+struct T { virtual ~T () {} };
+struct U : S, T {};
+
+void f (U &);
+
+void
+g (void *v)
+{
+ T *t = static_cast <T *> (v);
+ U *u = static_cast <U *> (t);
+ f (*u);
+}
Jakub
More information about the Gcc-patches
mailing list