aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2021-02-12 09:55:46 +0100
committerJakub Jelinek <jakub@redhat.com>2021-02-12 09:58:25 +0100
commitcf059e1c099ed45c97f740c030dcb8e146ac7d4a (patch)
tree861d014b76691ea6e3ddd8abe054cb4be344d195 /gcc
parent95d94b52ea8478334fb92cca545f0bd904bd0034 (diff)
downloadgcc-cf059e1c099ed45c97f740c030dcb8e146ac7d4a.zip
gcc-cf059e1c099ed45c97f740c030dcb8e146ac7d4a.tar.gz
gcc-cf059e1c099ed45c97f740c030dcb8e146ac7d4a.tar.bz2
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/parser.c4
-rw-r--r--gcc/testsuite/g++.dg/cpp2a/concepts-requires24.C4
2 files changed, 7 insertions, 1 deletions
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index d68dcb7..7077579 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -28807,7 +28807,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 0000000..597528b
--- /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" }