On 1/18/22 18:20, Jakub Jelinek wrote:
On Tue, Jan 18, 2022 at 05:56:47PM -0500, Jason Merrill wrote:
Debug information was getting confused because input_location was different
depending on whether we had looked ahead to see if the next tokens look like
a template argument list.

I tried resetting input_location in cp_lexer_rollback_tokens itself, but
that caused regressions, so let's just do it here for now.

Tested x86_64-pc-linux-gnu, applying to trunk.

        PR c++/104025

gcc/cp/ChangeLog:

        * parser.cc (saved_token_sentinel::rollback): Call
        cp_lexer_set_source_position.
        (~saved_token_sentinel): Call rollback.

gcc/testsuite/ChangeLog:

        * g++.dg/warn/pr104025.C: New test.

The testcase fails for me with this change.

Oops, thanks.  Fixed thus:

From bd0ef3534816a1b8ffad544d9ed720690a97d7cc Mon Sep 17 00:00:00 2001
From: Jason Merrill <ja...@redhat.com>
Date: Tue, 18 Jan 2022 22:11:56 -0500
Subject: [PATCH] c++: fix PR104025 change
To: gcc-patches@gcc.gnu.org

Somehow I pushed my earlier patch without it actually fixing the test; we
need input_location to be for the last consumed token, not the next one.

gcc/cp/ChangeLog:

	* parser.cc (saved_token_sentinel::rollback): Use
	cp_lexer_previous_token.
---
 gcc/cp/parser.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 60d9f7bb723..00279c43404 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -1308,7 +1308,8 @@ struct saved_token_sentinel
   void rollback ()
   {
     cp_lexer_rollback_tokens (lexer);
-    cp_lexer_set_source_position (lexer);
+    cp_lexer_set_source_position_from_token
+      (cp_lexer_previous_token (lexer));
     mode = STS_DONOTHING;
   }
   ~saved_token_sentinel ()
-- 
2.27.0

Reply via email to