c++: source position of lambda captures [PR84471]
authorJason Merrill <jason@redhat.com>
Fri, 2 Dec 2022 03:58:28 +0000 (22:58 -0500)
committerJason Merrill <jason@redhat.com>
Wed, 21 Dec 2022 02:01:44 +0000 (21:01 -0500)
commit302485a70a33f3a86e85ad9051de2b51c5dc0bc0
tree534f842bc26f4d4d286508c401f22d56b97abdab
parenta996888327c2248b59db7244333740c2b51578c9
c++: source position of lambda captures [PR84471]

If the DECL_VALUE_EXPR of a VAR_DECL has EXPR_LOCATION set, then any use of
that variable looks like it has that location, which leads to the debugger
jumping back and forth for both lambdas and structured bindings.

Rather than fix all the uses, it seems simplest to remove any EXPR_LOCATION
when setting DECL_VALUE_EXPR.  So the cp/ hunks aren't necessary, but they
avoid the need to unshare to remove the location.

PR c++/84471
PR c++/107504

gcc/cp/ChangeLog:

* coroutines.cc (transform_local_var_uses): Don't
specify a location for DECL_VALUE_EXPR.
* decl.cc (cp_finish_decomp): Likewise.

gcc/ChangeLog:

* fold-const.cc (protected_set_expr_location_unshare): Not static.
* tree.h: Declare it.
* tree.cc (decl_value_expr_insert): Use it.

include/ChangeLog:

* ansidecl.h (ATTRIBUTE_WARN_UNUSED_RESULT): Add __.

gcc/testsuite/ChangeLog:

* g++.dg/tree-ssa/value-expr1.C: New test.
* g++.dg/tree-ssa/value-expr2.C: New test.
* g++.dg/analyzer/pr93212.C: Move warning.
gcc/cp/coroutines.cc
gcc/cp/decl.cc
gcc/fold-const.cc
gcc/testsuite/g++.dg/analyzer/pr93212.C
gcc/testsuite/g++.dg/tree-ssa/value-expr1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/tree-ssa/value-expr2.C [new file with mode: 0644]
gcc/tree.cc
gcc/tree.h
include/ansidecl.h