]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: fold calls to std::forward_like [PR96780]
authorPatrick Palka <ppalka@redhat.com>
Tue, 6 Aug 2024 15:51:45 +0000 (11:51 -0400)
committerPatrick Palka <ppalka@redhat.com>
Tue, 6 Aug 2024 15:51:45 +0000 (11:51 -0400)
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 <mpolacek@redhat.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/cp-gimplify.cc
gcc/testsuite/g++.dg/opt/pr96780.C

index b88c3b7f370b5b9c2e848158b0962263fc4404e9..0c589eeaaec4e062b63fa54343fd6b9b265a4b28 100644 (file)
@@ -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")
index 61e11855eeb3a809392e55e1403870d787e80bf7..a29cda8b836ee5f816b88179aec5b3a8b5ad4d2e 100644 (file)
@@ -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" } }