public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [pushed] c++: requires-expression and tentative parse [PR94480]
@ 2020-04-08  5:12 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2020-04-08  5:12 UTC (permalink / raw)
  To: gcc-patches

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  <jason@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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-04-08  5:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-08  5:12 [pushed] c++: requires-expression and tentative parse [PR94480] Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).