From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id C23C139A3C39 for ; Wed, 28 Jul 2021 20:32:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C23C139A3C39 Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-583-IU44zofKM76AlhP6PIGP9A-1; Wed, 28 Jul 2021 16:32:11 -0400 X-MC-Unique: IU44zofKM76AlhP6PIGP9A-1 Received: by mail-qk1-f199.google.com with SMTP id q9-20020a05620a0c89b02903ba3e0f08d7so2381083qki.3 for ; Wed, 28 Jul 2021 13:32:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=qbUSV2PhjWUlav0FZH9198D+zOSSwBWLJMMeFoyfU/Q=; b=rTcH7t2iGTt3o2qyqFv5Y6lKP9XB6KKR1BJBd1KcD63CeSp3fk3EZo48qhzH7V4X9E COGolLC1eHIvvsh8reGF1qo2PPe92ubPA2W0HtgCBi29dxYm0imWnSM/qJt1CUgcknhW 7GyHvFmuNrp8ny8n0CjMkiYd2S1xNpnPieilrXSH5tVLPbZKnb7va8BKtKM6RpuIMIs/ vi4xO0WAGcmHuDgiou251RJfnttNscHM/0zZH4BLQ0d3k7dqK2iTLaUvfnCLJ+HyG6gr 5Sjh4nGnpXWMITY3fDoK4nkWgqG/WPx2ewesCHVxWa5zNYK1Bcowg8oVWucjZoBESrtU VU9A== X-Gm-Message-State: AOAM530KjETlOXxNYXP9npyE9IR3DITNVKuzQ4YB+xcjFtv4Ajl9H8AE YlyKbVAPXMKelSZz0k7EnHJH6fOQsjoAMORLywMEOH5tXZw781It/FDD8iU4BN+A71zxvmQkPzZ nO4LyYEpUMOjodOvsV7HijhrVW3iWLqcaiyzvlqz+p4GuSHuap2gFFIlM3zGpuJry8Q== X-Received: by 2002:ac8:44a8:: with SMTP id a8mr1302912qto.238.1627504330596; Wed, 28 Jul 2021 13:32:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxunhxOrWfjqo8mo48B8x2jvvJtsQaSpot4YBKUshk8wqhS1t+YINhbR1xHjyHbsZzSWL6tNg== X-Received: by 2002:ac8:44a8:: with SMTP id a8mr1302893qto.238.1627504330277; Wed, 28 Jul 2021 13:32:10 -0700 (PDT) Received: from [192.168.1.148] (130-44-159-43.s11817.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id t6sm561691qkg.75.2021.07.28.13.32.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 28 Jul 2021 13:32:09 -0700 (PDT) Subject: Re: [PATCH] c++: Accept C++11 attribute-definition [PR101582] To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org References: <20210723080325.GY2380545@tucnak> From: Jason Merrill Message-ID: <69567a30-abda-eda2-0595-9dccb9816934@redhat.com> Date: Wed, 28 Jul 2021 16:32:08 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210723080325.GY2380545@tucnak> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 Jul 2021 20:32:16 -0000 On 7/23/21 4:03 AM, Jakub Jelinek wrote: > Hi! > > As the following testcase shows, we don't parse properly > C++11 attribute-declaration: > https://eel.is/c++draft/dcl.dcl#nt:attribute-declaration > > cp_parser_toplevel_declaration just handles empty-declaration parsing > (with diagnostics for C++98) This seems to be a bug: from the comments, cp_parser_toplevel_declaration is intended to only handle #pragma parsing, everything else should be in cp_parser_declaration. As a result, we wrongly reject extern "C" ; So please move empty-declaration and attribute-declaration handling into cp_parser_declaration. > and otherwise calls cp_parser_declaration > which on it calls cp_parser_simple_declaration and rejects it with > "does not declare anything" permerror. > > The following patch instead handles it in cp_parser_toplevel_declaration > by parsing the attributes (standard ones only, we've never supported > __attribute__((...)); at namespace scope, so I'm not sure we need to > introduce that), which for C++98 emits the needed diagnostics, and then > warning if there are any attributes that we throw away on the floor. > > I'll need this later for OpenMP directives at namespace scope, e.g. > [[omp::directive (requires, atomic_default_mem_order(seq_cst))]]; > should be valid at namespace scope (and many other directives). > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? > > 2021-07-23 Jakub Jelinek > > PR c++/101582 > * parser.c (cp_parser_skip_std_attribute_spec_seq): Add a forward > declaration. > (cp_parser_toplevel_declaration): Parse attribute-declaration. > > * g++.dg/cpp0x/gen-attrs-45.C: Expect a warning about ignored > attributes instead of error. > * g++.dg/cpp0x/gen-attrs-75.C: New test. > > --- gcc/cp/parser.c.jj 2021-07-22 17:47:26.025761491 +0200 > +++ gcc/cp/parser.c 2021-07-22 19:09:28.487513184 +0200 > @@ -2507,6 +2507,8 @@ static tree cp_parser_std_attribute_spec > (cp_parser *); > static tree cp_parser_std_attribute_spec_seq > (cp_parser *); > +static size_t cp_parser_skip_std_attribute_spec_seq > + (cp_parser *, size_t); > static size_t cp_parser_skip_attributes_opt > (cp_parser *, size_t); > static bool cp_parser_extension_opt > @@ -14547,6 +14549,20 @@ cp_parser_toplevel_declaration (cp_parse > if (cxx_dialect < cxx11) > pedwarn (input_location, OPT_Wpedantic, "extra %<;%>"); > } > + else if (cp_lexer_nth_token_is (parser->lexer, > + cp_parser_skip_std_attribute_spec_seq (parser, > + 1), > + CPP_SEMICOLON)) > + { > + location_t attrs_loc = token->location; > + tree std_attrs = cp_parser_std_attribute_spec_seq (parser); > + if (std_attrs != NULL_TREE) > + warning_at (make_location (attrs_loc, attrs_loc, parser->lexer), > + OPT_Wattributes, > + "attributes in attribute declaration are ignored"); > + if (cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON)) > + cp_lexer_consume_token (parser->lexer); > + } > else > /* Parse the declaration itself. */ > cp_parser_declaration (parser, NULL_TREE); > --- gcc/testsuite/g++.dg/cpp0x/gen-attrs-45.C.jj 2020-01-12 11:54:37.072403466 +0100 > +++ gcc/testsuite/g++.dg/cpp0x/gen-attrs-45.C 2021-07-22 19:14:38.250222344 +0200 > @@ -1,4 +1,4 @@ > // PR c++/52906 > // { dg-do compile { target c++11 } } > > -[[gnu::deprecated]]; // { dg-error "does not declare anything" } > +[[gnu::deprecated]]; // { dg-warning "attributes in attribute declaration are ignored" } > --- gcc/testsuite/g++.dg/cpp0x/gen-attrs-75.C.jj 2021-07-22 19:14:58.438942693 +0200 > +++ gcc/testsuite/g++.dg/cpp0x/gen-attrs-75.C 2021-07-22 19:12:18.442158972 +0200 > @@ -0,0 +1,8 @@ > +// PR c++/101582 > +// { dg-do compile } > +// { dg-options "" } > + > +; > +[[]] [[]] [[]]; // { dg-warning "attributes only available with" "" { target c++98_only } } > +[[foobar]]; // { dg-warning "attributes in attribute declaration are ignored" } > +// { dg-warning "attributes only available with" "" { target c++98_only } .-1 } > > Jakub >