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.
Tested x86_64-pc-linux-gnu, applying to trunk. gcc/cp/ChangeLog 2020-04-07 Jason Merrill <ja...@redhat.com> PR c++/94480 * parser.c (cp_parser_requires_expression): Use tentative_firewall. --- gcc/cp/parser.c | 3 +++ gcc/testsuite/g++.dg/cpp2a/concepts-requires21.C | 7 +++++++ 2 files changed, 10 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-requires21.C 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<typename T, typename U> +constexpr bool is_same_v = __is_same (T, U); + +static_assert(is_same_v<bool, decltype(requires { requires false; })>); base-commit: 31449cf8e119bbe172a68689068591827472da5c -- 2.18.1