From 845d451e1f73d8a9a84382c3c6d4fca9c8220403 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Tue, 7 Apr 2020 00:45:26 -0400 Subject: [PATCH] c++: requires-expression and tentative parse [PR94480] The problem here was that cp_parser_requires_expression committing to a tentative parse confused cp_parser_decltype_expr, which needs to still be tentative. The only reason to commit here is to get syntax errors within the requires-expression, which we can still do when the commit is firewalled from the enclosing context. gcc/cp/ChangeLog 2020-04-07 Jason Merrill PR c++/94480 * parser.c (cp_parser_requires_expression): Use tentative_firewall. --- gcc/cp/ChangeLog | 3 +++ gcc/cp/parser.c | 3 +++ gcc/testsuite/g++.dg/cpp2a/concepts-requires21.C | 7 +++++++ 3 files changed, 13 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-requires21.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 8227f28e1bf..31f1fc433fd 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 2020-04-07 Jason Merrill + PR c++/94480 + * parser.c (cp_parser_requires_expression): Use tentative_firewall. + PR c++/94481 * parser.c (cp_parser_placeholder_type_specifier): Use matching_parens. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 2c33ca4dd16..a95d43127d7 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -27740,6 +27740,9 @@ cp_parser_requires_expression (cp_parser *parser) gcc_assert (cp_lexer_next_token_is_keyword (parser->lexer, RID_REQUIRES)); location_t loc = cp_lexer_consume_token (parser->lexer)->location; + /* Avoid committing to outer tentative parse. */ + tentative_firewall firewall (parser); + /* This is definitely a requires-expression. */ cp_parser_commit_to_tentative_parse (parser); diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-requires21.C b/gcc/testsuite/g++.dg/cpp2a/concepts-requires21.C new file mode 100644 index 00000000000..1d21cce7eee --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-requires21.C @@ -0,0 +1,7 @@ +// PR c++/94480 +// { dg-do compile { target c++2a } } + +template +constexpr bool is_same_v = __is_same (T, U); + +static_assert(is_same_v); -- 2.30.2