From patchwork Tue Jun 22 13:52:34 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 56500 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 C41F1B6EFE for ; Tue, 22 Jun 2010 23:52:16 +1000 (EST) Received: (qmail 3914 invoked by alias); 22 Jun 2010 13:52:13 -0000 Received: (qmail 3855 invoked by uid 22791); 22 Jun 2010 13:52:11 -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; Tue, 22 Jun 2010 13:52:05 +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 o5MDq3rQ013756 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 22 Jun 2010 09:52:03 -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 o5MDq2AZ021631 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 22 Jun 2010 09:52:03 -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 o5MDqZKD016719; Tue, 22 Jun 2010 15:52:35 +0200 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id o5MDqZUt016718; Tue, 22 Jun 2010 15:52:35 +0200 Date: Tue, 22 Jun 2010 15:52:34 +0200 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] Fix -Wunused-but-set-variable warnings on .*/->* operands (PR c++/44619) Message-ID: <20100622135234.GS7811@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! .* and ->* operands aren't marked as read, the following patch fixes it. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? Or should that be mark_rvalue_use (or something else)? 2010-06-22 Jakub Jelinek PR c++/44619 * typeck2.c (build_m_component_ref): Call mark_exp_read on datum and component. * g++.dg/warn/Wunused-var-13.C: New test. Jakub --- gcc/cp/typeck2.c.jj 2010-06-20 16:36:49.000000000 +0200 +++ gcc/cp/typeck2.c 2010-06-22 12:28:34.000000000 +0200 @@ -1478,6 +1478,9 @@ build_m_component_ref (tree datum, tree if (error_operand_p (datum) || error_operand_p (component)) return error_mark_node; + mark_exp_read (datum); + mark_exp_read (component); + ptrmem_type = TREE_TYPE (component); if (!TYPE_PTR_TO_MEMBER_P (ptrmem_type)) { --- gcc/testsuite/g++.dg/warn/Wunused-var-13.C.jj 2010-06-22 12:30:04.000000000 +0200 +++ gcc/testsuite/g++.dg/warn/Wunused-var-13.C 2010-06-22 08:20:23.000000000 +0200 @@ -0,0 +1,22 @@ +// PR c++/44619 +// { dg-do compile } +// { dg-options "-Wunused -W" } + +struct S { int x, y; }; + +int +f1 () +{ + struct S p; + int S::*q = &S::x; + p.*q = 5; + return p.*q; +} + +int +f2 (struct S *p, int S::*q) +{ + struct S *r = p; + int S::*s = q; + return r->*s; +}