C++: less verbose error-recovery for version conflict markers
authorDavid Malcolm <dmalcolm@redhat.com>
Thu, 28 Jun 2018 20:24:49 +0000 (20:24 +0000)
committerDavid Malcolm <dmalcolm@gcc.gnu.org>
Thu, 28 Jun 2018 20:24:49 +0000 (20:24 +0000)
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
gcc/cp/parser.c
gcc/testsuite/g++.dg/conflict-markers-2.C [new file with mode: 0644]

index 862b737..906f0b4 100644 (file)
@@ -1,3 +1,8 @@
+2018-06-28  David Malcolm  <dmalcolm@redhat.com>
+
+       * 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  <jason@redhat.com>
 
        PR c++/86342 - -Wdeprecated-copy and system headers.
index a02091e..a076de1 100644 (file)
@@ -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 (file)
index 0000000..4fc3820
--- /dev/null
@@ -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 ();
+}