From 824e57cbf4115db5dfe90ed49ff9828cbcc14b02 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Wed, 29 May 2019 17:30:36 +0000 Subject: [PATCH] re PR c++/89875 (invalid typeof reference to a member of an incomplete struct accepted at function scope) /cp 2019-05-29 Paolo Carlini 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-29 Paolo Carlini PR c++/89875 * g++.dg/cpp0x/decltype-pr66548.C: Remove xfail. * g++.dg/template/sizeof-template-argument.C: Adjust expected error. From-SVN: r271746 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/parser.c | 14 ++++++++++---- gcc/testsuite/ChangeLog | 10 ++++++++-- gcc/testsuite/g++.dg/cpp0x/decltype-pr66548.C | 2 +- .../g++.dg/template/sizeof-template-argument.C | 4 ++-- 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index d0122c7b024..ee7eab080cb 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2019-05-29 Paolo Carlini + + PR c++/89875 + * parser.c (cp_parser_sizeof_operand): When the type-id production + did not work out commit to the tentative parse. + 2019-05-29 Jakub Jelinek P1091R3 - Extending structured bindings to be more like var decls diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 08b4105c97f..1de35da83ec 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -28942,6 +28942,8 @@ cp_parser_sizeof_operand (cp_parser* parser, enum rid keyword) { tree type = NULL_TREE; + tentative_firewall firewall (parser); + /* We can't be sure yet whether we're looking at a type-id or an expression. */ cp_parser_parse_tentatively (parser); @@ -28969,11 +28971,15 @@ cp_parser_sizeof_operand (cp_parser* parser, enum rid keyword) /* If all went well, then we're done. */ if (cp_parser_parse_definitely (parser)) expr = type; - } + else + { + /* Commit to the tentative_firewall so we get syntax errors. */ + cp_parser_commit_to_tentative_parse (parser); - /* 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); + } + } + else expr = cp_parser_unary_expression (parser); /* Go back to evaluating expressions. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a2d46357e39..19971c9a1ba 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,7 +1,13 @@ +2019-05-29 Paolo Carlini + + PR c++/89875 + * g++.dg/cpp0x/decltype-pr66548.C: Remove xfail. + * g++.dg/template/sizeof-template-argument.C: Adjust expected error. + 2019-05-29 Alejandro Martinez - * gcc.target/aarch64/sve2/aarch64-sve2.exp: New file, regression driver - for AArch64 SVE2. + * gcc.target/aarch64/sve2/aarch64-sve2.exp: New file, regression + driver for AArch64 SVE2. * gcc.target/aarch64/sve2/average_1.c: New test. * lib/target-supports.exp (check_effective_target_aarch64_sve2): New helper. diff --git a/gcc/testsuite/g++.dg/cpp0x/decltype-pr66548.C b/gcc/testsuite/g++.dg/cpp0x/decltype-pr66548.C index 93a7d490f2f..3757b671fdd 100644 --- a/gcc/testsuite/g++.dg/cpp0x/decltype-pr66548.C +++ b/gcc/testsuite/g++.dg/cpp0x/decltype-pr66548.C @@ -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; } diff --git a/gcc/testsuite/g++.dg/template/sizeof-template-argument.C b/gcc/testsuite/g++.dg/template/sizeof-template-argument.C index 31aeeec9bfc..2bfff6d9a18 100644 --- a/gcc/testsuite/g++.dg/template/sizeof-template-argument.C +++ b/gcc/testsuite/g++.dg/template/sizeof-template-argument.C @@ -3,9 +3,9 @@ template struct A {}; -template struct B : A {}; /* { dg-error "template argument" } */ +template struct B : A {}; /* { dg-error "expected primary-expression" } */ -template struct C : A {}; /* { dg-error "template argument" } */ +template struct C : A {}; /* { dg-error "expected primary-expression" } */ int a;