From patchwork Thu Mar 1 17:51:56 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 144094 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 3AB14B6F9F for ; Fri, 2 Mar 2012 06:08:31 +1100 (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=1331233712; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: References:In-Reply-To:Content-Type:Mailing-List:Precedence: List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=D129+AQy2mcvMCBW4L5TdjmTEG4=; b=htsgSRCGTY82T9f 8UDrx6854n4q/8o6s4n2S/a4tlr8Dwks1GjqjP55nhWKgsrzrqcIq6aZIyi9MGrs 7RkNcYu35BEHVTcoSXLvD54d+/flymMsysQoAFSmGSHlPf7kleJy3Uu763wg7T+7 cHLVPRTGPAfMtTESVba6miw0sX7I= 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:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:References:In-Reply-To:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=G6SjDJBA8rQOf9JQrK2WDVFmi1om9NGGNCcKoZPo4FNpOoyc+ZvoKpbUVJZuzE LOtoGAVBVJefPGUSUWvYAZ+XjSyfHAFwqThMzmsKuniE97m4K1B9vLsAyGidVHGF vKevtr2hF05rU4mLOya/01Lk70cD1Zv/QJPsig6abvNWM=; Received: (qmail 15076 invoked by alias); 1 Mar 2012 19:08:24 -0000 Received: (qmail 15058 invoked by uid 22791); 1 Mar 2012 19:08:23 -0000 X-SWARE-Spam-Status: No, hits=-6.6 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; Thu, 01 Mar 2012 19:08:09 +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 q21J7p2D015184 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 1 Mar 2012 14:08:09 -0500 Received: from [10.3.113.22] (ovpn-113-22.phx2.redhat.com [10.3.113.22]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q21HpuET024930 for ; Thu, 1 Mar 2012 12:51:56 -0500 Message-ID: <4F4FB73C.9090704@redhat.com> Date: Thu, 01 Mar 2012 12:51:56 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:10.0.1) Gecko/20120216 Thunderbird/10.0.1 MIME-Version: 1.0 To: gcc-patches List Subject: Re: C++ PATCH to warn about ignored attributes References: <4F3B0F81.5040402@redhat.com> In-Reply-To: <4F3B0F81.5040402@redhat.com> 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 On 02/14/2012 08:50 PM, Jason Merrill wrote: > While looking at PR 51930, I discovered that we were silently ignoring > attributes on explicit instantiations; this patch warns about this. This > isn't exactly a regression, but the submitter ran into it as a result of > a behavior change in 4.7, and the patch is extremely safe, so I think it > should go in. It turns out that we already had a warning for this situation that also gives a suggestion for how to deal with it, so I'm going to make that warning apply to this case as well. Tested x86_64-pc-linux-gnu, applying to trunk. commit fc93bb109ba5d22a5c08ee026d572436a999bdef Author: Jason Merrill Date: Wed Feb 29 21:51:33 2012 -0500 PR c++/51930 * decl.c (check_tag_decl): Move warning for misplaced attributes here. (shadow_tag): From here. * parser.c (cp_parser_explicit_instantiation): Don't warn here. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 2a6a516..c47f87c 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -4216,6 +4216,19 @@ check_tag_decl (cp_decl_specifier_seq *declspecs) error ("% cannot be used for type declarations"); } + if (declspecs->attributes) + { + location_t loc = input_location; + if (!CLASSTYPE_TEMPLATE_INSTANTIATION (declared_type)) + /* For a non-template class, use the name location; for a template + class (an explicit instantiation), use the current location. */ + input_location = location_of (declared_type); + warning (0, "attribute ignored in declaration of %q#T", declared_type); + warning (0, "attribute for %q#T must follow the %qs keyword", + declared_type, class_key_or_enum_as_string (declared_type)); + input_location = loc; + } + return declared_type; } @@ -4240,14 +4253,6 @@ shadow_tag (cp_decl_specifier_seq *declspecs) if (!t) return NULL_TREE; - if (declspecs->attributes) - { - warning (0, "attribute ignored in declaration of %q+#T", t); - warning (0, "attribute for %q+#T must follow the %qs keyword", - t, class_key_or_enum_as_string (t)); - - } - if (maybe_process_partial_specialization (t) == error_mark_node) return NULL_TREE; diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 3e2be97..491f48e 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -13122,9 +13122,6 @@ cp_parser_explicit_instantiation (cp_parser* parser) tree type; type = check_tag_decl (&decl_specifiers); - if (decl_specifiers.attributes) - warning (OPT_Wattributes, - "attributes ignored on explicit type instantiation"); /* Turn access control back on for names used during template instantiation. */ pop_deferring_access_checks (); diff --git a/gcc/testsuite/g++.dg/ext/attrib43.C b/gcc/testsuite/g++.dg/ext/attrib43.C index fe9f072..acae3f2 100644 --- a/gcc/testsuite/g++.dg/ext/attrib43.C +++ b/gcc/testsuite/g++.dg/ext/attrib43.C @@ -2,4 +2,4 @@ template struct A { }; template __attribute__ ((packed)) -struct A; // { dg-warning "attributes ignored" } +struct A; // { dg-warning "attribute" }