c++: requires-expression and tentative parse [PR94480]
authorJason Merrill <jason@redhat.com>
Tue, 7 Apr 2020 04:45:26 +0000 (00:45 -0400)
committerJason Merrill <jason@redhat.com>
Wed, 8 Apr 2020 05:12:12 +0000 (01:12 -0400)
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  <jason@redhat.com>

PR c++/94480
* parser.c (cp_parser_requires_expression): Use tentative_firewall.

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/g++.dg/cpp2a/concepts-requires21.C [new file with mode: 0644]

index 8227f28e1bf807143af9c95611594c51163a693e..31f1fc433fdf08ba5093295a21c511e9e912b8b5 100644 (file)
@@ -1,5 +1,8 @@
 2020-04-07  Jason Merrill  <jason@redhat.com>
 
+       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.
index 2c33ca4dd168dc37d836ca520694c5eae6fa026f..a95d43127d72b5d57a802df6bb17e44f1b48633e 100644 (file)
@@ -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 (file)
index 0000000..1d21cce
--- /dev/null
@@ -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; })>);