On 2/11/21 11:35 AM, Marek Polacek wrote:
On Thu, Feb 11, 2021 at 05:30:24PM +0100, Jakub Jelinek via Gcc-patches wrote:
Hi!

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.

Ok for trunk if it passes bootstrap/regtest?

LGTM.

OK.

2021-02-11  Jakub Jelinek  <ja...@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.

--- gcc/cp/parser.c.jj  2021-02-03 17:14:01.000000000 +0100
+++ gcc/cp/parser.c     2021-02-11 14:44:05.877357556 +0100
@@ -28816,7 +28816,9 @@ cp_parser_requirement_seq (cp_parser *pa
        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)
--- gcc/testsuite/g++.dg/cpp2a/concepts-requires24.C.jj 2021-02-11 
14:40:28.548815748 +0100
+++ gcc/testsuite/g++.dg/cpp2a/concepts-requires24.C    2021-02-11 
14:39:40.209362526 +0100
@@ -0,0 +1,4 @@
+// PR c++/97742
+// { dg-do compile { target c++20 } }
+
+template <int = requires { true     // { dg-error "expected" }

        Jakub


Marek


Reply via email to