From patchwork Thu Sep 20 14:01:18 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 185395 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 3DBFE2C0085 for ; Fri, 21 Sep 2012 00:01:51 +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=1348754512; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:From:To:Cc:Subject:Date: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=Z2d1crCIaYKfhn34ZteUktT76Es=; b=WSaWq55/gY8Jt/S LsWG9WVK11MrKbr3EycUNr3+osyqkQMnvwtRyyK8wWkriM8GkjcBF+UIx00mBEGf Yo/lR6k0aynULnCBEWS4we6UrHYir3NdxBoTk2p+AMG8GLSxiL+Qd9/cEreYZ3Jo Qs2FfhPtVH5hySF/AcIPi+32hfLM= 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:X-URL:Date: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=d2JM4ayRkImLUAhZoF9Gwvn0cttg7gEpRUhq5H+zgrmk0ZrQ0swwipmIol9UOu URzia4GG++l9ntf50LO5EeGNZyVbDSqYS4YaRPnGF0JQrct8NwyiR56yqegH5xyv uqRPotPAWxaUublEsTXlGrREyt1yAfqvbfJ1mMpiizh6A=; Received: (qmail 3858 invoked by alias); 20 Sep 2012 14:01:42 -0000 Received: (qmail 3841 invoked by uid 22791); 20 Sep 2012 14:01:39 -0000 X-SWARE-Spam-Status: No, hits=-6.2 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; Thu, 20 Sep 2012 14:01:22 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q8KE1L6T030938 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 20 Sep 2012 10:01:21 -0400 Received: from localhost (ovpn-116-41.ams2.redhat.com [10.36.116.41]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q8KE1KLY031562 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 20 Sep 2012 10:01:21 -0400 Received: by localhost (Postfix, from userid 500) id F337A29C051; Thu, 20 Sep 2012 16:01:18 +0200 (CEST) From: Dodji Seketeli To: GCC Patches Cc: Jason Merrill Subject: [PATCH] PR c++/54372 - unused attribute inactive on dependant entities X-URL: http://www.redhat.com Date: Thu, 20 Sep 2012 16:01:18 +0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (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 Hello, In the example of this patch, gcc/g++ invoked with -Wunused-local-typedefs warns on dependant entities even when those are decorated with the 'unused' attribute. 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. This patch makes maybe_warn_unused_local_typedefs check for the syntactic presence of the 'unused' attribute. Tested on x86_64-unknown-linux-gnu against trunk. gcc/c-family/ * c-common.c (maybe_warn_unused_local_typedefs): Check for the presence of the attribute 'unused'. gcc/testsuite/ * g++.dg/warn/Wunused-local-typedefs-2.C: New test. --- gcc/c-family/c-common.c | 3 +- .../g++.dg/warn/Wunused-local-typedefs-2.C | 35 ++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletions(-) create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-local-typedefs-2.C diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 6de2f1c..cf8b1e1 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -10899,7 +10899,8 @@ maybe_warn_unused_local_typedefs (void) && errorcount == unused_local_typedefs_warn_count) { FOR_EACH_VEC_ELT (tree, l->local_typedefs, i, decl) - if (!TREE_USED (decl)) + if (!TREE_USED (decl) + && !lookup_attribute ("unused", DECL_ATTRIBUTES (decl))) warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wunused_local_typedefs, "typedef %qD locally defined but not used", decl); diff --git a/gcc/testsuite/g++.dg/warn/Wunused-local-typedefs-2.C b/gcc/testsuite/g++.dg/warn/Wunused-local-typedefs-2.C new file mode 100644 index 0000000..77bacd7 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/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)); + } +};