This fixes 92370. cp_lexer_peek_token never returned NULL, so the check for
that was always irrelevant. However, prior to my r277514 patch, eof caused us
to point at the unique eof token, which had an UNKNOWN_LOCATION and hence we
fell out of the loop.
The lexer doesn't give the EOF token it returns a location corresponding to the
beginning of the line at EOF (which seems wrong), but if it did, it wouldn't
work if the VC marker occurred on the last line of a deferred parse buffer.
thus we must check explicitly.
Whilst there I realized this'd also break if we'd run out of locations and every
token was UNKNOWN_LOCATION.
Applying to trunk.
nathan
--
Nathan Sidwell
2019-11-05 Nathan Sidwell <nat...@acm.org>
cp/
PR c++/92370
* parser.c (cp_parser_error_1): Check EOF and UNKNOWN_LOCATION
when skipping over version control marker.
testsuite/
PR c++/92370
* g++.dg/pr92370.C: New.
Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c (revision 277833)
+++ gcc/cp/parser.c (working copy)
@@ -2890,12 +2890,16 @@ cp_parser_error_1 (cp_parser* parser, co
error_at (loc, "version control conflict marker in file");
expanded_location token_exploc = expand_location (token->location);
/* Consume tokens until the end of the source line. */
- while (1)
+ for (;;)
{
cp_lexer_consume_token (parser->lexer);
cp_token *next = cp_lexer_peek_token (parser->lexer);
- if (next == NULL)
+ if (next->type == CPP_EOF)
break;
+ if (next->location == UNKNOWN_LOCATION
+ || loc == UNKNOWN_LOCATION)
+ break;
+
expanded_location next_exploc = expand_location (next->location);
if (next_exploc.file != token_exploc.file)
break;
Index: gcc/testsuite/g++.dg/pr92370.C
===================================================================
--- gcc/testsuite/g++.dg/pr92370.C (nonexistent)
+++ gcc/testsuite/g++.dg/pr92370.C (working copy)
@@ -0,0 +1,3 @@
+// PR 92370 ICE with conlict marker
+
+<<<<<<<>>>>>>> // { dg-error "conflict marker" }