On 6/19/19 8:18 PM, Marek Polacek wrote:
We are wrongly accepting invalid code like:

   struct alignas(16 S2 { }; // missing )

The reason is that cp_parser_type_specifier uses tentative parsing to see if
we're dealing with a class-specifier, and if that doesn't work, it looks for
an elaborated-type-specifier.  When trying to parse it as a class-specifier,
we use cp_parser_class_head which parses any attributes after the class-key
via cp_parser_attributes_opt, and that includes an alignment-specifier.

So we're parsing the alignment-specifier, find the missing ')', but since we
are parsing tentatively, no error is issued.  Then we get back to
cp_parser_class_head, and that commits:

23862   /* At this point, we're going ahead with the class-specifier, even
23863      if some other problem occurs.  */
23864   cp_parser_commit_to_tentative_parse (parser);

so we lose the error.  Fixed as below.  Other approach would be to use
a tentative_firewall, but that would be a much bigger hammer.

...and here you only commit when you know there's going to be an error, so if follow-on errors make less sense it isn't a big deal. OK.

Jason

Reply via email to