This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C++ PATCH] Fix attribute parsing for bitfields
- From: Nathan Sidwell <nathan at acm dot org>
- To: Jakub Jelinek <jakub at redhat dot com>, Jason Merrill <jason at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Thu, 28 Sep 2017 16:37:14 -0700
- Subject: Re: [C++ PATCH] Fix attribute parsing for bitfields
- Authentication-results: sourceware.org; auth=none
- References: <20170919125426.GK1701@tucnak> <56458ce2-1a72-7852-13ac-a1e71f5131ea@acm.org> <20170928184745.GE1701@tucnak>
On 09/28/2017 11:47 AM, Jakub Jelinek wrote:
I don't see the first half of 1) related to second half thereof, the
DECL_BIT_FIELD_REPRESENTATIVE is unrelated to the parsing bug, and a needed
precondition of 2).
That's very conscientious of you.
As I said on IRC, I hope [[/__attribute__/alignas early is rare enough that
the tentative parsing shouldn't be a big deal, if it is, we could add some
cheaper function that allows us to skip over attributes (return a peek
offset after the attributes given a starting peek offset).
I agree.
--- gcc/cp/parser.c.jj 2017-09-22 20:51:48.181537880 +0200
+++ gcc/cp/parser.c 2017-09-27 17:50:15.082792676 +0200
@@ -23443,35 +23443,64 @@ cp_parser_member_declaration (cp_parser*
/* Peek at the next token. */
token = cp_lexer_peek_token (parser->lexer);
+ if (cp_next_tokens_can_be_attribute_p (parser)
+ || (token->type == CPP_NAME
+ && cp_nth_tokens_can_be_attribute_p (parser, 2)
+ && (named_bitfld = true)))
+ {
Please insert a comment describing why we're doing the lookahead and our
supposition that it is rare, so the simplicity of a tentative parse is
worth the expense. Also, as I mentioned before, the other alternative
is to let the non-bitfield declarator parsing get an unnamed decl and
then look for the ':'. But that's a more complicated change we decided
not to do.
the mid-condition assignment is ugly, but probably the least ugly.
ok for trunk.
nathan
--
Nathan Sidwell