diff options
author | Jason Merrill <jason@redhat.com> | 2020-04-07 00:45:26 -0400 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2020-04-08 01:12:12 -0400 |
commit | 845d451e1f73d8a9a84382c3c6d4fca9c8220403 (patch) | |
tree | 72b481f86d22f55976656952389f782a7316d498 | |
parent | f1a6150ecb7b17f068150e98bc107d730604f5b6 (diff) | |
download | gcc-845d451e1f73d8a9a84382c3c6d4fca9c8220403.zip gcc-845d451e1f73d8a9a84382c3c6d4fca9c8220403.tar.gz gcc-845d451e1f73d8a9a84382c3c6d4fca9c8220403.tar.bz2 |
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 <jason@redhat.com>
PR c++/94480
* parser.c (cp_parser_requires_expression): Use tentative_firewall.
-rw-r--r-- | gcc/cp/ChangeLog | 3 | ||||
-rw-r--r-- | gcc/cp/parser.c | 3 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp2a/concepts-requires21.C | 7 |
3 files changed, 13 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 8227f28..31f1fc4 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -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. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 2c33ca4..a95d431 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 0000000..1d21cce7 --- /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; })>); |