diff options
author | Jason Merrill <jason@redhat.com> | 2021-11-19 17:01:10 -0500 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2021-11-22 17:42:53 -0500 |
commit | 5440c88e61f5c624eb87e19801eef6eedf27e8ab (patch) | |
tree | c5ede3ce9a981ca2934d5a24df4b7102c8ef5e42 /gcc/cp | |
parent | a6e0d593707ae44dec0bdf2bcdc4f539050b46db (diff) | |
download | gcc-5440c88e61f5c624eb87e19801eef6eedf27e8ab.zip gcc-5440c88e61f5c624eb87e19801eef6eedf27e8ab.tar.gz gcc-5440c88e61f5c624eb87e19801eef6eedf27e8ab.tar.bz2 |
c++: improved return expression location
Stripping the location wrapper from retval meant we didn't have the
necessary location information for any conversion diagnostics. We only need
the stripping for the named return value optimization, let's use the
unstripped expression for everything else.
gcc/cp/ChangeLog:
* typeck.c (check_return_expr): Only strip location wrapper during
NRV handling.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/pr65327.C: Adjust location.
* g++.dg/cpp23/constexpr-nonlit4.C: Likewise.
* g++.dg/cpp23/constexpr-nonlit5.C: Likewise.
* g++.dg/cpp2a/constexpr-init1.C: Likewise.
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/typeck.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 58919aa..63a0eae 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -10545,19 +10545,20 @@ check_return_expr (tree retval, bool *no_warning) this restriction, anyway. (jason 2000-11-19) See finish_function and finalize_nrv for the rest of this optimization. */ + tree bare_retval = NULL_TREE; if (retval) { retval = maybe_undo_parenthesized_ref (retval); - STRIP_ANY_LOCATION_WRAPPER (retval); + bare_retval = tree_strip_any_location_wrapper (retval); } - bool named_return_value_okay_p = can_do_nrvo_p (retval, functype); + bool named_return_value_okay_p = can_do_nrvo_p (bare_retval, functype); if (fn_returns_value_p && flag_elide_constructors) { if (named_return_value_okay_p && (current_function_return_value == NULL_TREE - || current_function_return_value == retval)) - current_function_return_value = retval; + || current_function_return_value == bare_retval)) + current_function_return_value = bare_retval; else current_function_return_value = error_mark_node; } @@ -10571,7 +10572,7 @@ check_return_expr (tree retval, bool *no_warning) maybe_warn_pessimizing_move (retval, functype); /* Do any required conversions. */ - if (retval == result || DECL_CONSTRUCTOR_P (current_function_decl)) + if (bare_retval == result || DECL_CONSTRUCTOR_P (current_function_decl)) /* No conversions are required. */ ; else |