]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: Fix up attribute rollbacks in cp_parser_statement
authorJakub Jelinek <jakub@redhat.com>
Fri, 30 Jul 2021 15:44:38 +0000 (17:44 +0200)
committerJakub Jelinek <jakub@redhat.com>
Fri, 30 Jul 2021 15:44:38 +0000 (17:44 +0200)
commit0ba2003cf306aa98b6ec91c9d849ab9bafcf17c2
tree41ff2dc33aad41fbda41722670e552777510dd80
parent59ffdb9849be033540ad680836cd4cc592098ca4
c++: Fix up attribute rollbacks in cp_parser_statement

During the OpenMP directives using C++ attribute syntax work, I've noticed
that cp_parser_statement when parsing various block declarations that do
not allow attribute-specifier-seq at the start rolls back the attributes
only if std_attrs is non-NULL (i.e. some attributes have been parsed),
but doesn't roll back if some tokens were parsed as attribute-specifier-seq,
but didn't yield any attributes (e.g. [[]][[]][[]][[]]), which means
we accept those empty attributes even in places where they don't appear
in the grammar.

The following patch fixes that by instead checking if there are any
tokens to roll back.  This makes the parsing handle the first
function the same as the second one (where some attribute appears).

The testcase contains two xfails, using namespace ... apparently
allows attributes at the start and the attributes shall appeartain to
using in that case.  To be fixed incrementally.

2021-07-30  Jakub Jelinek  <jakub@redhat.com>

* parser.c (cp_parser_statement): Rollback attributes not just
when std_attrs is non-NULL, but whenever
cp_parser_std_attribute_spec_seq parsed any tokens.

* g++.dg/cpp0x/gen-attrs-76.C: New test.
gcc/cp/parser.c
gcc/testsuite/g++.dg/cpp0x/gen-attrs-76.C [new file with mode: 0644]