From patchwork Mon Jun 28 16:00:27 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [C++] Fix -Wunused-but-set-* with some static_casts (PR c++/44682) Date: Mon, 28 Jun 2010 06:00:27 -0000 From: Jakub Jelinek X-Patchwork-Id: 57157 Message-Id: <20100628160027.GK25077@tyan-ft48-01.lab.bos.redhat.com> To: Jason Merrill Cc: gcc-patches@gcc.gnu.org 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 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. Jakub --- 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 (v); + U *u = static_cast (t); + f (*u); +}