[gcc r10-9469] c++: Fix endless errors on invalid requirement seq [PR97742]
Jakub Jelinek
jakub@gcc.gnu.org
Fri Mar 19 23:29:11 GMT 2021
https://gcc.gnu.org/g:a7237df0aa26f74cc52103f5c8dba5f0efbb198f
commit r10-9469-ga7237df0aa26f74cc52103f5c8dba5f0efbb198f
Author: Jakub Jelinek <jakub@redhat.com>
Date: Fri Feb 12 09:55:46 2021 +0100
c++: Fix endless errors on invalid requirement seq [PR97742]
As the testcase shows, if we reach CPP_EOF during parsing of requirement
sequence, we end up with endless loop where we always report invalid
requirement expression, don't consume any token (as we are at eof) and
repeat.
This patch stops the loop when we reach CPP_EOF.
2021-02-12 Jakub Jelinek <jakub@redhat.com>
PR c++/97742
* parser.c (cp_parser_requirement_seq): Stop iterating after reaching
CPP_EOF.
* g++.dg/cpp2a/concepts-requires24.C: New test.
(cherry picked from commit cf059e1c099ed45c97f740c030dcb8e146ac7d4a)
Diff:
---
gcc/cp/parser.c | 4 +++-
gcc/testsuite/g++.dg/cpp2a/concepts-requires24.C | 4 ++++
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index ba75c4797e4..40af0de95e4 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -27895,7 +27895,9 @@ cp_parser_requirement_seq (cp_parser *parser)
tree req = cp_parser_requirement (parser);
if (req != error_mark_node)
result = tree_cons (NULL_TREE, req, result);
- } while (cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_BRACE));
+ }
+ while (cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_BRACE)
+ && cp_lexer_next_token_is_not (parser->lexer, CPP_EOF));
/* If there are no valid requirements, this is not a valid expression. */
if (!result)
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-requires24.C b/gcc/testsuite/g++.dg/cpp2a/concepts-requires24.C
new file mode 100644
index 00000000000..597528b49f8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-requires24.C
@@ -0,0 +1,4 @@
+// PR c++/97742
+// { dg-do compile { target c++20 } }
+
+template <int = requires { true // { dg-error "expected" }
More information about the Gcc-cvs
mailing list