From patchwork Mon Jun 28 16:00:27 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 57157 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 48312B6EEE for ; Tue, 29 Jun 2010 01:59:45 +1000 (EST) Received: (qmail 10029 invoked by alias); 28 Jun 2010 15:59:44 -0000 Received: (qmail 9941 invoked by uid 22791); 28 Jun 2010 15:59:43 -0000 X-SWARE-Spam-Status: No, hits=-6.0 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 28 Jun 2010 15:59:38 +0000 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o5SFxanh010193 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 28 Jun 2010 11:59:37 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o5SFxZNT018110 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 28 Jun 2010 11:59:36 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id o5SG0Rot005775; Mon, 28 Jun 2010 18:00:27 +0200 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id o5SG0R5t005773; Mon, 28 Jun 2010 18:00:27 +0200 Date: Mon, 28 Jun 2010 18:00:27 +0200 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] Fix -Wunused-but-set-* with some static_casts (PR c++/44682) Message-ID: <20100628160027.GK25077@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-12-10) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list 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); +}