Message ID | Zr5qzQhcLH9LWiP/@tucnak |
---|---|
State | New |
Headers | show |
Series | c++: Parse and ignore attributes on base specifiers [PR110345] | expand |
On 8/15/24 4:53 PM, Jakub Jelinek wrote: > Hi! > > For C++ 26 P2552R3 I went through all the spots (except modules) where > attribute-specifier-seq appears in the grammar and tried to construct > a testcase in all those spots, for now for [[deprecated]] attribute. > > This is the third issue I found. > > https://eel.is/c++draft/class.derived#general-1 has attribute-specifier-seq > at the start of base-specifier. The following patch parses it there and > warns about those. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? OK. > 2024-08-15 Jakub Jelinek <jakub@redhat.com> > > PR c++/110345 > * parser.cc (cp_parser_base_specifier): Parse standard attributes > at the start and emit a warning if there are any non-ignored ones. > > * g++.dg/cpp0x/gen-attrs-83.C: New test. > > --- gcc/cp/parser.cc.jj 2024-08-15 17:41:44.554159692 +0200 > +++ gcc/cp/parser.cc 2024-08-15 18:00:33.202211372 +0200 > @@ -28987,11 +28987,12 @@ cp_parser_base_clause (cp_parser* parser > /* Parse a base-specifier. > > base-specifier: > - :: [opt] nested-name-specifier [opt] class-name > - virtual access-specifier [opt] :: [opt] nested-name-specifier > - [opt] class-name > - access-specifier virtual [opt] :: [opt] nested-name-specifier > - [opt] class-name > + attribute-specifier-seq [opt] :: [opt] nested-name-specifier [opt] > + class-name > + attribute-specifier-seq [opt] virtual access-specifier [opt] :: [opt] > + nested-name-specifier [opt] class-name > + attribute-specifier-seq [opt] access-specifier virtual [opt] :: [opt] > + nested-name-specifier [opt] class-name > > Returns a TREE_LIST. The TREE_PURPOSE will be one of > ACCESS_{DEFAULT,PUBLIC,PROTECTED,PRIVATE}_[VIRTUAL]_NODE to > @@ -29009,6 +29010,12 @@ cp_parser_base_specifier (cp_parser* par > bool class_scope_p, template_p; > tree access = access_default_node; > tree type; > + location_t attrs_loc = cp_lexer_peek_token (parser->lexer)->location; > + tree std_attrs = cp_parser_std_attribute_spec_seq (parser); > + > + if (std_attrs != NULL_TREE && any_nonignored_attribute_p (std_attrs)) > + warning_at (attrs_loc, OPT_Wattributes, > + "attributes on base specifiers are ignored"); > > /* Process the optional `virtual' and `access-specifier'. */ > while (!done) > --- gcc/testsuite/g++.dg/cpp0x/gen-attrs-83.C.jj 2024-08-15 17:58:52.093456428 +0200 > +++ gcc/testsuite/g++.dg/cpp0x/gen-attrs-83.C 2024-08-15 18:27:23.864431390 +0200 > @@ -0,0 +1,10 @@ > +// { dg-do compile { target c++11 } } > + > +struct A {}; > +struct B {}; > +struct C {}; > +struct D : [[]] [[]] A, > + [[]] virtual public B, [[]] [[]] [[]] public virtual C {}; > +struct E : [[gnu::deprecated]] A, // { dg-warning "attributes on base specifiers are ignored" } > + [[gnu::deprecated]] virtual public B, // { dg-warning "attributes on base specifiers are ignored" } > + [[gnu::deprecated]] public virtual C {}; // { dg-warning "attributes on base specifiers are ignored" } > > Jakub >
--- gcc/cp/parser.cc.jj 2024-08-15 17:41:44.554159692 +0200 +++ gcc/cp/parser.cc 2024-08-15 18:00:33.202211372 +0200 @@ -28987,11 +28987,12 @@ cp_parser_base_clause (cp_parser* parser /* Parse a base-specifier. base-specifier: - :: [opt] nested-name-specifier [opt] class-name - virtual access-specifier [opt] :: [opt] nested-name-specifier - [opt] class-name - access-specifier virtual [opt] :: [opt] nested-name-specifier - [opt] class-name + attribute-specifier-seq [opt] :: [opt] nested-name-specifier [opt] + class-name + attribute-specifier-seq [opt] virtual access-specifier [opt] :: [opt] + nested-name-specifier [opt] class-name + attribute-specifier-seq [opt] access-specifier virtual [opt] :: [opt] + nested-name-specifier [opt] class-name Returns a TREE_LIST. The TREE_PURPOSE will be one of ACCESS_{DEFAULT,PUBLIC,PROTECTED,PRIVATE}_[VIRTUAL]_NODE to @@ -29009,6 +29010,12 @@ cp_parser_base_specifier (cp_parser* par bool class_scope_p, template_p; tree access = access_default_node; tree type; + location_t attrs_loc = cp_lexer_peek_token (parser->lexer)->location; + tree std_attrs = cp_parser_std_attribute_spec_seq (parser); + + if (std_attrs != NULL_TREE && any_nonignored_attribute_p (std_attrs)) + warning_at (attrs_loc, OPT_Wattributes, + "attributes on base specifiers are ignored"); /* Process the optional `virtual' and `access-specifier'. */ while (!done) --- gcc/testsuite/g++.dg/cpp0x/gen-attrs-83.C.jj 2024-08-15 17:58:52.093456428 +0200 +++ gcc/testsuite/g++.dg/cpp0x/gen-attrs-83.C 2024-08-15 18:27:23.864431390 +0200 @@ -0,0 +1,10 @@ +// { dg-do compile { target c++11 } } + +struct A {}; +struct B {}; +struct C {}; +struct D : [[]] [[]] A, + [[]] virtual public B, [[]] [[]] [[]] public virtual C {}; +struct E : [[gnu::deprecated]] A, // { dg-warning "attributes on base specifiers are ignored" } + [[gnu::deprecated]] virtual public B, // { dg-warning "attributes on base specifiers are ignored" } + [[gnu::deprecated]] public virtual C {}; // { dg-warning "attributes on base specifiers are ignored" }