On Tue, Aug 06, 2024 at 10:01:22AM -0400, Patrick Palka wrote:
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this
> look OK  for trunk?

Looks simple & good.

Reviewed-by: Marek Polacek <pola...@redhat.com>
 
> -- >8 --
> 
> 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: Test std::forward_like folding.
> ---
>  gcc/cp/cp-gimplify.cc              | 3 ++-
>  gcc/testsuite/g++.dg/opt/pr96780.C | 5 +++++
>  2 files changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/gcc/cp/cp-gimplify.cc b/gcc/cp/cp-gimplify.cc
> index b88c3b7f370..3db9657ae93 100644
> --- a/gcc/cp/cp-gimplify.cc
> +++ b/gcc/cp/cp-gimplify.cc
> @@ -3316,7 +3316,8 @@ cp_fold (tree x, fold_flags_t flags)
>               || id_equal (DECL_NAME (callee), "addressof")
>               /* This addressof equivalent is used heavily in libstdc++.  */
>               || id_equal (DECL_NAME (callee), "__addressof")
> -             || id_equal (DECL_NAME (callee), "as_const")))
> +             || id_equal (DECL_NAME (callee), "as_const")
> +             || id_equal (DECL_NAME (callee), "forward_like")))
>         {
>           r = CALL_EXPR_ARG (x, 0);
>           /* Check that the return and argument types are sane before
> diff --git a/gcc/testsuite/g++.dg/opt/pr96780.C 
> b/gcc/testsuite/g++.dg/opt/pr96780.C
> index 61e11855eeb..a29cda8b836 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" } }
> -- 
> 2.46.0.39.g891ee3b9db
> 

Marek

Reply via email to