Hi,
a while ago Martin noticed that an unintended consequence of an old
tweak of mine - which avoided redundant error messages emitted from
cp_parser_init_declarator - is that, in some cases, we started accepting
ill-formed typeofs. Luckily, decltype isn't affected and that points to
the real issue: by the time that place in cp_parser_init_declarator is
reached, for a decltype version we already emitted a correct error
message. Thus I think the right way to fix the problem is simply
committing to tentative parse when, toward the end of
cp_parser_sizeof_operand we know that we must be looking at a (possibly
ill-formed) expression. Tested x86_64-linux.
Thanks, Paolo.
///////////////////////////
/cp
2019-05-10 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/89875
* parser.c (cp_parser_sizeof_operand): When the type-id production
did not work out commit to the tentative parse.
/testsuite
2019-05-10 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/89875
* g++.dg/cpp0x/decltype-pr66548.C: Remove xfail.
* g++.dg/template/sizeof-template-argument.C: Adjust expected error.
Index: cp/parser.c
===================================================================
--- cp/parser.c (revision 271059)
+++ cp/parser.c (working copy)
@@ -28998,7 +28998,11 @@ cp_parser_sizeof_operand (cp_parser* parser, enum
/* If the type-id production did not work out, then we must be
looking at the unary-expression production. */
if (!expr)
- expr = cp_parser_unary_expression (parser);
+ {
+ cp_parser_commit_to_tentative_parse (parser);
+
+ expr = cp_parser_unary_expression (parser);
+ }
/* Go back to evaluating expressions. */
--cp_unevaluated_operand;
Index: testsuite/g++.dg/cpp0x/decltype-pr66548.C
===================================================================
--- testsuite/g++.dg/cpp0x/decltype-pr66548.C (revision 271059)
+++ testsuite/g++.dg/cpp0x/decltype-pr66548.C (working copy)
@@ -11,7 +11,7 @@ struct Meow {};
void f ()
{
- decltype (Meow.purr ()) d; // { dg-error "expected primary-expression"
"pr89875" { xfail c++98_only } }
+ decltype (Meow.purr ()) d; // { dg-error "expected primary-expression" }
(void)&d;
}
Index: testsuite/g++.dg/template/sizeof-template-argument.C
===================================================================
--- testsuite/g++.dg/template/sizeof-template-argument.C (revision
271059)
+++ testsuite/g++.dg/template/sizeof-template-argument.C (working copy)
@@ -3,9 +3,9 @@
template<int> struct A {};
-template<typename> struct B : A <sizeof(=)> {}; /* { dg-error "template
argument" } */
+template<typename> struct B : A <sizeof(=)> {}; /* { dg-error "expected
primary-expression" } */
-template<typename> struct C : A <sizeof(=)> {}; /* { dg-error "template
argument" } */
+template<typename> struct C : A <sizeof(=)> {}; /* { dg-error "expected
primary-expression" } */
int a;