[gcc r14-6511] c++: TARGET_EXPR location in default arg [PR96997]

Jason Merrill jason@gcc.gnu.org
Wed Dec 13 20:06:32 GMT 2023


https://gcc.gnu.org/g:063564ecbfc618cd019f86216a0224e144effae1

commit r14-6511-g063564ecbfc618cd019f86216a0224e144effae1
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Dec 13 14:15:44 2023 -0500

    c++: TARGET_EXPR location in default arg [PR96997]
    
    My r14-6505-g52b4b7d7f5c7c0 change to copy the location in
    build_aggr_init_expr reopened PR96997; let's fix it properly this time, by
    clearing the location like we do for other trees.
    
            PR c++/96997
    
    gcc/cp/ChangeLog:
    
            * tree.cc (bot_manip): Check data.clear_location for TARGET_EXPR.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/debug/cleanup2.C: New test.

Diff:
---
 gcc/cp/tree.cc                        |  3 +++
 gcc/testsuite/g++.dg/debug/cleanup2.C | 10 ++++++++++
 2 files changed, 13 insertions(+)

diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc
index c4e41fd7b5c..d26e73aaf95 100644
--- a/gcc/cp/tree.cc
+++ b/gcc/cp/tree.cc
@@ -3170,6 +3170,9 @@ bot_manip (tree* tp, int* walk_subtrees, void* data_)
       if (TREE_OPERAND (u, 1) == error_mark_node)
 	return error_mark_node;
 
+      if (data.clear_location)
+	SET_EXPR_LOCATION (u, input_location);
+
       /* Replace the old expression with the new version.  */
       *tp = u;
       /* We don't have to go below this point; the recursive call to
diff --git a/gcc/testsuite/g++.dg/debug/cleanup2.C b/gcc/testsuite/g++.dg/debug/cleanup2.C
new file mode 100644
index 00000000000..03bf92c8424
--- /dev/null
+++ b/gcc/testsuite/g++.dg/debug/cleanup2.C
@@ -0,0 +1,10 @@
+// PR c++/96997
+// { dg-additional-options "-g -fdump-tree-gimple-lineno" }
+
+struct A { A(); ~A(); };
+void f(const A& = A());
+int main() { f(); }
+
+// The destructor call for the A temporary should not have the location of the
+// f declaration.
+// { dg-final { scan-tree-dump-not ".C:5" "gimple" } }


More information about the Gcc-cvs mailing list