https://gcc.gnu.org/g:180625ae72b3f733813a360fae4f0d6ce79eccdc
commit r15-2756-g180625ae72b3f733813a360fae4f0d6ce79eccdc Author: Patrick Palka <ppa...@redhat.com> Date: Tue Aug 6 11:51:45 2024 -0400 c++: fold calls to std::forward_like [PR96780] This extends our folding of cast-like standard library functions to also include C++23's std::forward_like. PR c++/96780 gcc/cp/ChangeLog: * cp-gimplify.cc (cp_fold) <case CALL_EXPR>: Fold calls to std::forward_like as well. gcc/testsuite/ChangeLog: * g++.dg/opt/pr96780.C: Also test std::forward_like folding. Reviewed-by: Marek Polacek <mpola...@redhat.com> Reviewed-by: Jason Merrill <ja...@redhat.com> Diff: --- gcc/cp/cp-gimplify.cc | 1 + gcc/testsuite/g++.dg/opt/pr96780.C | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/gcc/cp/cp-gimplify.cc b/gcc/cp/cp-gimplify.cc index b88c3b7f370b..0c589eeaaec4 100644 --- a/gcc/cp/cp-gimplify.cc +++ b/gcc/cp/cp-gimplify.cc @@ -3313,6 +3313,7 @@ cp_fold (tree x, fold_flags_t flags) && DECL_NAME (callee) != NULL_TREE && (id_equal (DECL_NAME (callee), "move") || id_equal (DECL_NAME (callee), "forward") + || id_equal (DECL_NAME (callee), "forward_like") || id_equal (DECL_NAME (callee), "addressof") /* This addressof equivalent is used heavily in libstdc++. */ || id_equal (DECL_NAME (callee), "__addressof") diff --git a/gcc/testsuite/g++.dg/opt/pr96780.C b/gcc/testsuite/g++.dg/opt/pr96780.C index 61e11855eeb3..a29cda8b836e 100644 --- a/gcc/testsuite/g++.dg/opt/pr96780.C +++ b/gcc/testsuite/g++.dg/opt/pr96780.C @@ -29,6 +29,10 @@ void f() { auto&& x11 = std::as_const(a); auto&& x12 = std::as_const(ca); #endif +#if __cpp_lib_forward_like + auto&& x13 = std::forward_like<int&&>(a); + auto&& x14 = std::forward_like<int&&>(ca); +#endif } // { dg-final { scan-tree-dump-not "= std::move" "gimple" } } @@ -36,3 +40,4 @@ void f() { // { dg-final { scan-tree-dump-not "= std::addressof" "gimple" } } // { dg-final { scan-tree-dump-not "= std::__addressof" "gimple" } } // { dg-final { scan-tree-dump-not "= std::as_const" "gimple" } } +// { dg-final { scan-tree-dump-not "= std::forward_like" "gimple" } }