* [PATCH] c++: Accept C++11 attribute-definition [PR101582]
@ 2021-07-23 8:03 Jakub Jelinek
2021-07-28 20:32 ` Jason Merrill
0 siblings, 1 reply; 5+ messages in thread
From: Jakub Jelinek @ 2021-07-23 8:03 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches
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) 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 <jakub@redhat.com>
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] c++: Accept C++11 attribute-definition [PR101582]
2021-07-23 8:03 [PATCH] c++: Accept C++11 attribute-definition [PR101582] Jakub Jelinek
@ 2021-07-28 20:32 ` Jason Merrill
2021-07-29 9:28 ` [PATCH v2] " Jakub Jelinek
0 siblings, 1 reply; 5+ messages in thread
From: Jason Merrill @ 2021-07-28 20:32 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: gcc-patches
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 <jakub@redhat.com>
>
> 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
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2] c++: Accept C++11 attribute-definition [PR101582]
2021-07-28 20:32 ` Jason Merrill
@ 2021-07-29 9:28 ` Jakub Jelinek
2021-07-29 19:03 ` Jason Merrill
0 siblings, 1 reply; 5+ messages in thread
From: Jakub Jelinek @ 2021-07-29 9:28 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches
On Wed, Jul 28, 2021 at 04:32:08PM -0400, Jason Merrill wrote:
> > 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.
So like this?
It means we allow for modules
export ;
or
export [[]];
where we previously rejected those, which is allowed by the grammar and
invalid because of
https://eel.is/c++draft/module.interface#3
but we allowed already before
export {}
which suffers from the same problem - the export-declaration doesn't declare
at least one name. So I think there just should be something that tracks if
the module exported at least one name and if not, diagnose it at the end of
cp_parser_module_export (and adjust the new modules testcase).
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
2021-07-29 Jakub Jelinek <jakub@redhat.com>
PR c++/101582
* parser.c (cp_parser_skip_std_attribute_spec_seq): Add a forward
declaration.
(cp_parser_declaration): Parse empty-declaration and
attribute-declaration.
(cp_parser_toplevel_declaration): Don't parse empty-declaration here.
* 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.
* g++.dg/modules/pr101582-1.C: New test.
--- gcc/cp/parser.c.jj 2021-07-28 23:06:38.658443554 +0200
+++ gcc/cp/parser.c 2021-07-28 23:12:10.955941089 +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
@@ -14410,6 +14412,31 @@ cp_parser_declaration (cp_parser* parser
cp_token *token2 = (token1->type == CPP_EOF
? token1 : cp_lexer_peek_nth_token (parser->lexer, 2));
+ if (token1->type == CPP_SEMICOLON)
+ {
+ cp_lexer_consume_token (parser->lexer);
+ /* A declaration consisting of a single semicolon is invalid
+ * before C++11. Allow it unless we're being pedantic. */
+ if (cxx_dialect < cxx11)
+ pedwarn (input_location, OPT_Wpedantic, "extra %<;%>");
+ return;
+ }
+ else if (cp_lexer_nth_token_is (parser->lexer,
+ cp_parser_skip_std_attribute_spec_seq (parser,
+ 1),
+ CPP_SEMICOLON))
+ {
+ location_t attrs_loc = token1->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);
+ return;
+ }
+
/* Get the high-water mark for the DECLARATOR_OBSTACK. */
void *p = obstack_alloc (&declarator_obstack, 0);
@@ -14560,14 +14587,6 @@ cp_parser_toplevel_declaration (cp_parse
cp_parser_declaration. (A #pragma at block scope is
handled in cp_parser_statement.) */
cp_parser_pragma (parser, pragma_external, NULL);
- else if (token->type == CPP_SEMICOLON)
- {
- cp_lexer_consume_token (parser->lexer);
- /* A declaration consisting of a single semicolon is invalid
- * before C++11. Allow it unless we're being pedantic. */
- if (cxx_dialect < cxx11)
- pedwarn (input_location, OPT_Wpedantic, "extra %<;%>");
- }
else
/* Parse the declaration itself. */
cp_parser_declaration (parser, NULL_TREE);
--- gcc/testsuite/g++.dg/cpp0x/gen-attrs-45.C.jj 2021-07-26 09:13:08.504121494 +0200
+++ gcc/testsuite/g++.dg/cpp0x/gen-attrs-45.C 2021-07-28 23:07:05.095085351 +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-28 23:07:05.095085351 +0200
+++ gcc/testsuite/g++.dg/cpp0x/gen-attrs-75.C 2021-07-29 10:59:09.630326797 +0200
@@ -0,0 +1,35 @@
+// 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 }
+
+extern "C" ;
+extern "C" [[]]; // { dg-warning "attributes only available with" "" { target c++98_only } }
+extern "C" extern "C" ;
+extern "C" extern "C" [[]][[]][[]]; // { dg-warning "attributes only available with" "" { target c++98_only } }
+__extension__ ;
+__extension__ [[]]; // { dg-warning "attributes only available with" "" { target c++98_only } }
+__extension__ __extension__ ;
+__extension__ __extension__ [[]][[]]; // { dg-warning "attributes only available with" "" { target c++98_only } }
+
+namespace N {
+
+;
+[[]] [[]] [[]]; // { 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 }
+
+extern "C" ;
+extern "C" [[]]; // { dg-warning "attributes only available with" "" { target c++98_only } }
+extern "C" extern "C" ;
+extern "C" extern "C" [[]][[]][[]]; // { dg-warning "attributes only available with" "" { target c++98_only } }
+__extension__ ;
+__extension__ [[]]; // { dg-warning "attributes only available with" "" { target c++98_only } }
+__extension__ __extension__ ;
+__extension__ __extension__ [[]][[]]; // { dg-warning "attributes only available with" "" { target c++98_only } }
+
+}
--- gcc/testsuite/g++.dg/modules/pr101582-1.C.jj 2021-07-29 11:07:17.567662550 +0200
+++ gcc/testsuite/g++.dg/modules/pr101582-1.C 2021-07-29 11:08:02.297051638 +0200
@@ -0,0 +1,9 @@
+// PR c++/101582
+// { dg-additional-options "-fmodules-ts" }
+export module pr101582;
+// { dg-module-cmi "pr101582" }
+export ;
+export [[]];
+export
+{
+}
Jakub
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] c++: Accept C++11 attribute-definition [PR101582]
2021-07-29 9:28 ` [PATCH v2] " Jakub Jelinek
@ 2021-07-29 19:03 ` Jason Merrill
2021-07-30 8:56 ` Jakub Jelinek
0 siblings, 1 reply; 5+ messages in thread
From: Jason Merrill @ 2021-07-29 19:03 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: gcc-patches
On 7/29/21 5:28 AM, Jakub Jelinek wrote:
> On Wed, Jul 28, 2021 at 04:32:08PM -0400, Jason Merrill wrote:
>>> 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.
>
> So like this?
> It means we allow for modules
> export ;
> or
> export [[]];
> where we previously rejected those, which is allowed by the grammar and
> invalid because of
> https://eel.is/c++draft/module.interface#3
> but we allowed already before
> export {}
> which suffers from the same problem - the export-declaration doesn't declare
> at least one name. So I think there just should be something that tracks if
> the module exported at least one name and if not, diagnose it at the end of
> cp_parser_module_export (and adjust the new modules testcase).
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>
> 2021-07-29 Jakub Jelinek <jakub@redhat.com>
>
> PR c++/101582
> * parser.c (cp_parser_skip_std_attribute_spec_seq): Add a forward
> declaration.
> (cp_parser_declaration): Parse empty-declaration and
> attribute-declaration.
> (cp_parser_toplevel_declaration): Don't parse empty-declaration here.
>
> * 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.
> * g++.dg/modules/pr101582-1.C: New test.
>
> --- gcc/cp/parser.c.jj 2021-07-28 23:06:38.658443554 +0200
> +++ gcc/cp/parser.c 2021-07-28 23:12:10.955941089 +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
> @@ -14410,6 +14412,31 @@ cp_parser_declaration (cp_parser* parser
> cp_token *token2 = (token1->type == CPP_EOF
> ? token1 : cp_lexer_peek_nth_token (parser->lexer, 2));
>
> + if (token1->type == CPP_SEMICOLON)
> + {
> + cp_lexer_consume_token (parser->lexer);
> + /* A declaration consisting of a single semicolon is invalid
> + * before C++11. Allow it unless we're being pedantic. */
> + if (cxx_dialect < cxx11)
> + pedwarn (input_location, OPT_Wpedantic, "extra %<;%>");
> + return;
> + }
> + else if (cp_lexer_nth_token_is (parser->lexer,
> + cp_parser_skip_std_attribute_spec_seq (parser,
> + 1),
> + CPP_SEMICOLON))
> + {
> + location_t attrs_loc = token1->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");
Let's not mention the obscure attribute-declaration grammar nonterminal,
"attribute ignored" seems sufficient.
> + if (cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON))
> + cp_lexer_consume_token (parser->lexer);
> + return;
> + }
> +
> /* Get the high-water mark for the DECLARATOR_OBSTACK. */
> void *p = obstack_alloc (&declarator_obstack, 0);
>
> @@ -14560,14 +14587,6 @@ cp_parser_toplevel_declaration (cp_parse
> cp_parser_declaration. (A #pragma at block scope is
> handled in cp_parser_statement.) */
> cp_parser_pragma (parser, pragma_external, NULL);
> - else if (token->type == CPP_SEMICOLON)
> - {
> - cp_lexer_consume_token (parser->lexer);
> - /* A declaration consisting of a single semicolon is invalid
> - * before C++11. Allow it unless we're being pedantic. */
> - if (cxx_dialect < cxx11)
> - pedwarn (input_location, OPT_Wpedantic, "extra %<;%>");
> - }
> else
> /* Parse the declaration itself. */
> cp_parser_declaration (parser, NULL_TREE);
> --- gcc/testsuite/g++.dg/cpp0x/gen-attrs-45.C.jj 2021-07-26 09:13:08.504121494 +0200
> +++ gcc/testsuite/g++.dg/cpp0x/gen-attrs-45.C 2021-07-28 23:07:05.095085351 +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-28 23:07:05.095085351 +0200
> +++ gcc/testsuite/g++.dg/cpp0x/gen-attrs-75.C 2021-07-29 10:59:09.630326797 +0200
> @@ -0,0 +1,35 @@
> +// 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 }
> +
> +extern "C" ;
> +extern "C" [[]]; // { dg-warning "attributes only available with" "" { target c++98_only } }
> +extern "C" extern "C" ;
> +extern "C" extern "C" [[]][[]][[]]; // { dg-warning "attributes only available with" "" { target c++98_only } }
> +__extension__ ;
> +__extension__ [[]]; // { dg-warning "attributes only available with" "" { target c++98_only } }
> +__extension__ __extension__ ;
> +__extension__ __extension__ [[]][[]]; // { dg-warning "attributes only available with" "" { target c++98_only } }
> +
> +namespace N {
> +
> +;
> +[[]] [[]] [[]]; // { 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 }
> +
> +extern "C" ;
> +extern "C" [[]]; // { dg-warning "attributes only available with" "" { target c++98_only } }
> +extern "C" extern "C" ;
> +extern "C" extern "C" [[]][[]][[]]; // { dg-warning "attributes only available with" "" { target c++98_only } }
> +__extension__ ;
> +__extension__ [[]]; // { dg-warning "attributes only available with" "" { target c++98_only } }
> +__extension__ __extension__ ;
> +__extension__ __extension__ [[]][[]]; // { dg-warning "attributes only available with" "" { target c++98_only } }
> +
> +}
> --- gcc/testsuite/g++.dg/modules/pr101582-1.C.jj 2021-07-29 11:07:17.567662550 +0200
> +++ gcc/testsuite/g++.dg/modules/pr101582-1.C 2021-07-29 11:08:02.297051638 +0200
> @@ -0,0 +1,9 @@
> +// PR c++/101582
> +// { dg-additional-options "-fmodules-ts" }
> +export module pr101582;
> +// { dg-module-cmi "pr101582" }
> +export ;
> +export [[]];
> +export
> +{
> +}
These should have xfailed dg-errors.
OK with those changes.
Jason
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] c++: Accept C++11 attribute-definition [PR101582]
2021-07-29 19:03 ` Jason Merrill
@ 2021-07-30 8:56 ` Jakub Jelinek
0 siblings, 0 replies; 5+ messages in thread
From: Jakub Jelinek @ 2021-07-30 8:56 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches
On Thu, Jul 29, 2021 at 03:03:50PM -0400, Jason Merrill wrote:
> Let's not mention the obscure attribute-declaration grammar nonterminal,
> "attribute ignored" seems sufficient.
Ok, thanks. Here is what I've committed and I have also filed
PR101686 for the module related xfails.
2021-07-30 Jakub Jelinek <jakub@redhat.com>
PR c++/101582
* parser.c (cp_parser_skip_std_attribute_spec_seq): Add a forward
declaration.
(cp_parser_declaration): Parse empty-declaration and
attribute-declaration.
(cp_parser_toplevel_declaration): Don't parse empty-declaration here.
* 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.
* g++.dg/modules/pr101582-1.C: New test.
--- gcc/cp/parser.c.jj 2021-07-28 23:06:38.658443554 +0200
+++ gcc/cp/parser.c 2021-07-28 23:12:10.955941089 +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
@@ -14410,6 +14412,30 @@ cp_parser_declaration (cp_parser* parser
cp_token *token2 = (token1->type == CPP_EOF
? token1 : cp_lexer_peek_nth_token (parser->lexer, 2));
+ if (token1->type == CPP_SEMICOLON)
+ {
+ cp_lexer_consume_token (parser->lexer);
+ /* A declaration consisting of a single semicolon is invalid
+ * before C++11. Allow it unless we're being pedantic. */
+ if (cxx_dialect < cxx11)
+ pedwarn (input_location, OPT_Wpedantic, "extra %<;%>");
+ return;
+ }
+ else if (cp_lexer_nth_token_is (parser->lexer,
+ cp_parser_skip_std_attribute_spec_seq (parser,
+ 1),
+ CPP_SEMICOLON))
+ {
+ location_t attrs_loc = token1->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, "attribute ignored");
+ if (cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON))
+ cp_lexer_consume_token (parser->lexer);
+ return;
+ }
+
/* Get the high-water mark for the DECLARATOR_OBSTACK. */
void *p = obstack_alloc (&declarator_obstack, 0);
@@ -14560,14 +14587,6 @@ cp_parser_toplevel_declaration (cp_parse
cp_parser_declaration. (A #pragma at block scope is
handled in cp_parser_statement.) */
cp_parser_pragma (parser, pragma_external, NULL);
- else if (token->type == CPP_SEMICOLON)
- {
- cp_lexer_consume_token (parser->lexer);
- /* A declaration consisting of a single semicolon is invalid
- * before C++11. Allow it unless we're being pedantic. */
- if (cxx_dialect < cxx11)
- pedwarn (input_location, OPT_Wpedantic, "extra %<;%>");
- }
else
/* Parse the declaration itself. */
cp_parser_declaration (parser, NULL_TREE);
--- gcc/testsuite/g++.dg/cpp0x/gen-attrs-45.C.jj 2021-07-26 09:13:08.504121494 +0200
+++ gcc/testsuite/g++.dg/cpp0x/gen-attrs-45.C 2021-07-28 23:07:05.095085351 +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 "attribute ignored" }
--- gcc/testsuite/g++.dg/cpp0x/gen-attrs-75.C.jj 2021-07-28 23:07:05.095085351 +0200
+++ gcc/testsuite/g++.dg/cpp0x/gen-attrs-75.C 2021-07-29 10:59:09.630326797 +0200
@@ -0,0 +1,35 @@
+// PR c++/101582
+// { dg-do compile }
+// { dg-options "" }
+
+;
+[[]] [[]] [[]]; // { dg-warning "attributes only available with" "" { target c++98_only } }
+[[foobar]]; // { dg-warning "attribute ignored" }
+// { dg-warning "attributes only available with" "" { target c++98_only } .-1 }
+
+extern "C" ;
+extern "C" [[]]; // { dg-warning "attributes only available with" "" { target c++98_only } }
+extern "C" extern "C" ;
+extern "C" extern "C" [[]][[]][[]]; // { dg-warning "attributes only available with" "" { target c++98_only } }
+__extension__ ;
+__extension__ [[]]; // { dg-warning "attributes only available with" "" { target c++98_only } }
+__extension__ __extension__ ;
+__extension__ __extension__ [[]][[]]; // { dg-warning "attributes only available with" "" { target c++98_only } }
+
+namespace N {
+
+;
+[[]] [[]] [[]]; // { dg-warning "attributes only available with" "" { target c++98_only } }
+[[foobar]]; // { dg-warning "attribute ignored" }
+// { dg-warning "attributes only available with" "" { target c++98_only } .-1 }
+
+extern "C" ;
+extern "C" [[]]; // { dg-warning "attributes only available with" "" { target c++98_only } }
+extern "C" extern "C" ;
+extern "C" extern "C" [[]][[]][[]]; // { dg-warning "attributes only available with" "" { target c++98_only } }
+__extension__ ;
+__extension__ [[]]; // { dg-warning "attributes only available with" "" { target c++98_only } }
+__extension__ __extension__ ;
+__extension__ __extension__ [[]][[]]; // { dg-warning "attributes only available with" "" { target c++98_only } }
+
+}
--- gcc/testsuite/g++.dg/modules/pr101582-1.C.jj 2021-07-29 11:07:17.567662550 +0200
+++ gcc/testsuite/g++.dg/modules/pr101582-1.C 2021-07-29 11:08:02.297051638 +0200
@@ -0,0 +1,9 @@
+// PR c++/101582
+// { dg-additional-options "-fmodules-ts" }
+export module pr101582;
+// { dg-module-cmi "pr101582" }
+export ; // { dg-error "export declaration does not declare anything" "" { xfail *-*-* } }
+export [[]]; // { dg-error "export declaration does not declare anything" "" { xfail *-*-* } }
+export // { dg-error "export declaration does not declare anything" "" { xfail *-*-* } }
+{
+}
Jakub
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-07-30 8:56 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-23 8:03 [PATCH] c++: Accept C++11 attribute-definition [PR101582] Jakub Jelinek
2021-07-28 20:32 ` Jason Merrill
2021-07-29 9:28 ` [PATCH v2] " Jakub Jelinek
2021-07-29 19:03 ` Jason Merrill
2021-07-30 8:56 ` Jakub Jelinek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).