From patchwork Mon Mar 18 19:34:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1058060 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-498053-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="hcQkNDuP"; 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 44NRGY6QXhz9s70 for ; Tue, 19 Mar 2019 06:34:54 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version :content-transfer-encoding; q=dns; s=default; b=nGLEVXa3uWp3Cutf V3K1J3sqrRk9jS4Yr/bAAlaLpXbTv5ph9tCjRoBMc7Tg22zs7UdxVcKfbuRb5bLq rgk+g8JfSDCjAK/ETFaGq1tnGT+Wbig5p14lMRLERCDbMGTZmv+C0/oVRIJqXeOH YVbxvWBtFamp2qnn0dWOw6nTGEQ= 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:from :to:subject:date:message-id:mime-version :content-transfer-encoding; s=default; bh=0DcU7J92rCVsYeF7XpPu+l pOCnc=; b=hcQkNDuPz0MAg+AqXHmVjQ58BF9IoR2FzehuHwsrsIqZn4kdM8j0F9 6SWR7nrFTIraaihzrFgiqUIxhOVXs7UWFjFZLg7oIoVo3R6MMMLIapWhQ3VuRxK8 xaoLFbaIw0kJFlaquHU1A6Au7I2n35hTrPf2SoOA7qB0wLjzyi2K0= Received: (qmail 100836 invoked by alias); 18 Mar 2019 19:34:46 -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 100826 invoked by uid 89); 18 Mar 2019 19:34:46 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-20.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy= X-HELO: mail-qt1-f193.google.com Received: from mail-qt1-f193.google.com (HELO mail-qt1-f193.google.com) (209.85.160.193) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 18 Mar 2019 19:34:45 +0000 Received: by mail-qt1-f193.google.com with SMTP id x12so3265133qts.7 for ; Mon, 18 Mar 2019 12:34:44 -0700 (PDT) Received: from orpheus.redhat.com (209-6-216-142.s141.c3-0.smr-cbr1.sbo-smr.ma.cable.rcncustomer.com. [209.6.216.142]) by smtp.gmail.com with ESMTPSA id 50sm6306803qtr.96.2019.03.18.12.34.42 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Mar 2019 12:34:42 -0700 (PDT) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] PR c++/89640 - GNU attributes on lambda. Date: Mon, 18 Mar 2019 15:34:40 -0400 Message-Id: <20190318193440.22190-1-jason@redhat.com> MIME-Version: 1.0 X-IsSubscribed: yes My patch for PR 60503 to fix C++11 attribute parsing on lambdas accidentally removed support for GNU attributes. Tested x86_64-pc-linux-gnu, applying to trunk. * parser.c (cp_parser_lambda_declarator_opt): Allow GNU attributes. --- gcc/cp/parser.c | 15 ++++++++++----- gcc/testsuite/g++.dg/ext/attr-lambda1.C | 9 +++++++++ gcc/cp/ChangeLog | 3 +++ 3 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/attr-lambda1.C base-commit: 956a881aa78d012361dcca529c0e09c972ef1215 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index b8a0245ce57..81aff35cad9 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -10790,7 +10790,8 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr) This means an empty parameter list, no attributes, and no exception specification. */ tree param_list = void_list_node; - tree attributes = NULL_TREE; + tree std_attrs = NULL_TREE; + tree gnu_attrs = NULL_TREE; tree exception_spec = NULL_TREE; tree template_param_list = NULL_TREE; tree tx_qual = NULL_TREE; @@ -10849,7 +10850,8 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr) /* In the decl-specifier-seq of the lambda-declarator, each decl-specifier shall either be mutable or constexpr. */ int declares_class_or_enum; - if (cp_lexer_next_token_is_decl_specifier_keyword (parser->lexer)) + if (cp_lexer_next_token_is_decl_specifier_keyword (parser->lexer) + && !cp_next_tokens_can_be_gnu_attribute_p (parser)) cp_parser_decl_specifier_seq (parser, CP_PARSER_FLAGS_ONLY_MUTABLE_OR_CONSTEXPR, &lambda_specs, &declares_class_or_enum); @@ -10866,7 +10868,7 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr) /* Parse optional exception specification. */ exception_spec = cp_parser_exception_specification_opt (parser); - attributes = cp_parser_std_attribute_spec_seq (parser); + std_attrs = cp_parser_std_attribute_spec_seq (parser); /* Parse optional trailing return type. */ if (cp_lexer_next_token_is (parser->lexer, CPP_DEREF)) @@ -10875,6 +10877,9 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr) return_type = cp_parser_trailing_type_id (parser); } + if (cp_next_tokens_can_be_gnu_attribute_p (parser)) + gnu_attrs = cp_parser_gnu_attributes_opt (parser); + /* The function parameters must be in scope all the way until after the trailing-return-type in case of decltype. */ pop_bindings_and_leave_scope (); @@ -10922,11 +10927,11 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr) exception_spec, return_type, /*requires_clause*/NULL_TREE); - declarator->std_attributes = attributes; + declarator->std_attributes = std_attrs; fco = grokmethod (&return_type_specs, declarator, - NULL_TREE); + gnu_attrs); if (fco != error_mark_node) { DECL_INITIALIZED_IN_CLASS_P (fco) = 1; diff --git a/gcc/testsuite/g++.dg/ext/attr-lambda1.C b/gcc/testsuite/g++.dg/ext/attr-lambda1.C new file mode 100644 index 00000000000..01470c32233 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/attr-lambda1.C @@ -0,0 +1,9 @@ +// PR c++/89640 +// { dg-options "" } +// { dg-do compile { target c++11 } } + +void test() { + []() __attribute__((noinline,cold)) { + asm volatile(""); + }(); +} diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index bc3850d3aff..a3341bd9672 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 2019-03-18 Jason Merrill + PR c++/89640 - GNU attributes on lambda. + * parser.c (cp_parser_lambda_declarator_opt): Allow GNU attributes. + PR c++/89682 - wrong access error in default argument. * pt.c (tsubst_default_argument): Don't defer access checks.