From patchwork Wed Aug 21 14:24:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 1150882 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-507454-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="LEflsBob"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46D90K2Bs7z9sN1 for ; Thu, 22 Aug 2019 00:24:31 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=LpWb22iP/B7TUR4FvFI+3e5a4NuqqUPaTD8V8nhmV6GtwVdiISLDg HRkwIV7Jxdj9aBsBy/I4eWR4+woyLjtlJB1MKi4Dng8a2zOKKGmJ5NzLrsJhmNtI Gs5IoCp80HGO+z4qM2aMXOfbvw2UrQfl4uU9N9pWW7KJgsep2y9RZE= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=s9vcaf/bYuzSQlGJMambwkQZZLE=; b=LEflsBobZr/bOqo44oYh z5Bqd4V3fgTnXXX+l96lYvRTsf2tf37Fv7n61gxOl2Vis1OyoVBbQQ5MmHubgml+ QA17S9MurY6xGMD69NJAMr3KKwKNKFE/b8L+F36DsITw3HqsulXw4je1unuAtS/8 8HmIjrcYmOPmsLseQcnUpgA= Received: (qmail 58143 invoked by alias); 21 Aug 2019 14:24:23 -0000 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 Received: (qmail 58067 invoked by uid 89); 21 Aug 2019 14:24:15 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=HX-Languages-Length:1997 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 21 Aug 2019 14:24:13 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6A96AC056808 for ; Wed, 21 Aug 2019 14:24:11 +0000 (UTC) Received: from redhat.com (unknown [10.20.4.51]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DA23C6B49C; Wed, 21 Aug 2019 14:24:10 +0000 (UTC) Date: Wed, 21 Aug 2019 10:24:09 -0400 From: Marek Polacek To: GCC Patches , Jason Merrill Subject: C++ PATCH for c++/91304 - prefix attributes ignored in condition Message-ID: <20190821142409.GD14737@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.12.1 (2019-06-15) Currently, we disregard prefix attributes in conditions, e.g.: if ([[maybe_unused]] int i = f()) { } The problem here is that although we've parsed the attribute, it was never passed down to start_decl, so the effects were lost. Bootstrapped/regtested on x86_64-linux, ok for trunk? 2019-08-21 Marek Polacek PR c++/91304 - prefix attributes ignored in condition. * parser.c (cp_parser_condition): Handle prefix attributes. * g++.dg/cpp0x/gen-attrs-70.C: New test. diff --git gcc/cp/parser.c gcc/cp/parser.c index dbbfe1dbc2f..b410a6c030f 100644 --- gcc/cp/parser.c +++ gcc/cp/parser.c @@ -12066,6 +12066,10 @@ cp_parser_condition (cp_parser* parser) /* Restore the saved message. */ parser->type_definition_forbidden_message = saved_message; + /* Gather the attributes that were provided with the + decl-specifiers. */ + tree prefix_attributes = type_specifiers.attributes; + cp_parser_maybe_commit_to_declaration (parser, type_specifiers.any_specifiers_p); @@ -12116,7 +12120,7 @@ cp_parser_condition (cp_parser* parser) /* Create the declaration. */ decl = start_decl (declarator, &type_specifiers, /*initialized_p=*/true, - attributes, /*prefix_attributes=*/NULL_TREE, + attributes, prefix_attributes, &pushed_scope); /* Parse the initializer. */ diff --git gcc/testsuite/g++.dg/cpp0x/gen-attrs-70.C gcc/testsuite/g++.dg/cpp0x/gen-attrs-70.C new file mode 100644 index 00000000000..90a2e97a3f6 --- /dev/null +++ gcc/testsuite/g++.dg/cpp0x/gen-attrs-70.C @@ -0,0 +1,13 @@ +// PR c++/91304 - prefix attributes ignored in condition. +// { dg-do compile { target c++11 } } +// { dg-additional-options "-Wall -Wextra" } + +int f(); + +void g() +{ + if ([[maybe_unused]] int i = f()) { } + if ([[deprecated]] int i = f()) { i = 10; } // { dg-warning ".i. is deprecated" } + if (int i [[maybe_unused]] = f()) { } + if (int i [[deprecated]] = f()) { i = 10; } // { dg-warning ".i. is deprecated" } +}