From patchwork Tue Sep 25 11:57:11 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 186794 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 B92812C0089 for ; Tue, 25 Sep 2012 21:57:44 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1349179065; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:From:To:Cc:Subject:References:Date:In-Reply-To: Message-ID:User-Agent:MIME-Version:Content-Type:Mailing-List: Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:Sender:Delivered-To; bh=/NPqaJv0l3FDwqloBSAb7z1otiU=; b=x4ZTwLSFGY/TWOyqQCwUhPegQBQ0Uh0kV8mMsgRbkzs0TdMVjC+QTFTbiTAm+c wYujDqGWym4SQq9qkM4/QGLfin6yzgvKQ2ooyhxmg7WMbbPv7GKCn3IQ+Zt+rZdB bX2yPa/HwrELZMEp6AH6UQ8NsCFdUYP24ycxZLfzg4hCM= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:From:To:Cc:Subject:References:X-URL:Date:In-Reply-To:Message-ID:User-Agent:MIME-Version:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=OYjZK7QR2W2ve5DfWmGNPuGSyhsP+CChn818QPddcJMQEbvDLeZhW0QKwLb/w6 1i/Wh4iYfox6tzlq0g0SkYVyXczKozdypByfyLf6H6h8nzTCcmVDaupBL45wn3j/ asn00h0OAYRpZxaAA5PJiBnAO7il30yaX4vZUAiOgLJFY=; Received: (qmail 17200 invoked by alias); 25 Sep 2012 11:57:34 -0000 Received: (qmail 17183 invoked by uid 22791); 25 Sep 2012 11:57:32 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS 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, 25 Sep 2012 11:57:14 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q8PBvDGk020047 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 25 Sep 2012 07:57:13 -0400 Received: from localhost (dhcp-193-189.cdg.redhat.com [10.32.193.189]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q8PBvCW0007991 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 25 Sep 2012 07:57:13 -0400 Received: by localhost (Postfix, from userid 1000) id A19E42C007C; Tue, 25 Sep 2012 13:57:11 +0200 (CEST) From: Dodji Seketeli To: Jason Merrill Cc: GCC Patches Subject: Re: [PATCH] PR c++/54372 - unused attribute inactive on dependant entities References: <5060B64B.70808@redhat.com> X-URL: http://www.redhat.com Date: Tue, 25 Sep 2012 13:57:11 +0200 In-Reply-To: <5060B64B.70808@redhat.com> (Jason Merrill's message of "Mon, 24 Sep 2012 15:36:43 -0400") Message-ID: <87d31ab9ig.fsf@redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1 (gnu/linux) MIME-Version: 1.0 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 Jason Merrill writes: > On 09/20/2012 10:01 AM, Dodji Seketeli wrote: >> This is because in cplus_decl_attributes, save_template_attributes >> makes so that the 'unused' attribute is applied to its appertaining >> entity only at instantiation time. But then at parsing time >> maybe_warn_unused_local_typedefs checks for TREE_USED before warning. > > I guess we should propagate TREE_USED when instantiating a typedef. As we discussed on IRC, this will not really help, as what we want is to be able to take advantage of the attribute at compile time. Rather, the patch below makes is_late_template_attribute the "unused" attribute be applied directly, as you suggested. Tested on x86_64-unknown-linux-gnu against trunk. --- gcc/cp/decl2.c | 5 ++++ .../c-c++-common/Wunused-local-typedefs-2.c | 35 ++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 gcc/testsuite/c-c++-common/Wunused-local-typedefs-2.c diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 0df4613..a590d17 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -1104,6 +1104,11 @@ is_late_template_attribute (tree attr, tree decl) if (is_attribute_p ("weak", name)) return true; + /* Attribute unused is applied directly, as it appertains to + decls. */ + if (is_attribute_p ("unused", name)) + return false; + /* If any of the arguments are dependent expressions, we can't evaluate the attribute until instantiation time. */ for (arg = args; arg; arg = TREE_CHAIN (arg)) diff --git a/gcc/testsuite/c-c++-common/Wunused-local-typedefs-2.c b/gcc/testsuite/c-c++-common/Wunused-local-typedefs-2.c new file mode 100644 index 0000000..77bacd7 --- /dev/null +++ b/gcc/testsuite/c-c++-common/Wunused-local-typedefs-2.c @@ -0,0 +1,35 @@ +/* Origin PR c++/54372 + { dg-options "-Wunused-local-typedefs" } + { dg-do compile } +*/ + +template +void f2() +{ + typedef T t __attribute__((unused)); +} + +class S +{ + template + void f4() + { + typedef T t __attribute__((unused)); + } +}; + +template +class tS +{ + void f() + { + typedef T t2 __attribute__((unused)); + } + + template + void f2() + { + typedef T t1 __attribute__((unused)); + typedef U t2 __attribute__((unused)); + } +};