From eacb16dc798d06acfb9741a2496584ab0728257a Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Thu, 28 Jun 2018 20:24:49 +0000 Subject: [PATCH] C++: less verbose error-recovery for version conflict markers gcc/cp/ChangeLog: * parser.c (cp_parser_error_1): After issuing a conflict marker error, consume tokens until the end of the source line. gcc/testsuite/ChangeLog: * g++.dg/conflict-markers-2.C: New test. From-SVN: r262232 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/parser.c | 14 ++++++++++++++ gcc/testsuite/g++.dg/conflict-markers-2.C | 17 +++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 gcc/testsuite/g++.dg/conflict-markers-2.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 862b7370b7e..906f0b41678 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2018-06-28 David Malcolm + + * parser.c (cp_parser_error_1): After issuing a conflict marker + error, consume tokens until the end of the source line. + 2018-06-28 Jason Merrill PR c++/86342 - -Wdeprecated-copy and system headers. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index a02091e0a5d..a076de146e6 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -2862,6 +2862,20 @@ cp_parser_error_1 (cp_parser* parser, const char* gmsgid, if (cp_lexer_peek_conflict_marker (parser->lexer, token->type, &loc)) { 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) + { + cp_lexer_consume_token (parser->lexer); + cp_token *next = cp_lexer_peek_token (parser->lexer); + if (next == NULL) + break; + expanded_location next_exploc = expand_location (next->location); + if (next_exploc.file != token_exploc.file) + break; + if (next_exploc.line != token_exploc.line) + break; + } return; } } diff --git a/gcc/testsuite/g++.dg/conflict-markers-2.C b/gcc/testsuite/g++.dg/conflict-markers-2.C new file mode 100644 index 00000000000..4fc38207184 --- /dev/null +++ b/gcc/testsuite/g++.dg/conflict-markers-2.C @@ -0,0 +1,17 @@ +// { dg-do compile { target c++11 } } + +extern void f1 (void); +extern void f2 (void); +extern void f3 (void); +extern void f4 (void); + +void test () +{ + f1 (); +<<<<<<< HEAD // { dg-error "conflict marker" } + f2 (); +======= // { dg-error "conflict marker" } + f3 (); +>>>>>>> 252be53... Some commit message // { dg-error "conflict marker" } + f4 (); +} -- 2.30.2