[gcc r14-11259] libstdc++: Fix views::transform(move_only_fn{}) forwarding [PR118413]
Patrick Palka
ppalka@gcc.gnu.org
Wed Jan 29 15:29:46 GMT 2025
https://gcc.gnu.org/g:f0420cc224db64efe87cbe2f45d4d7ba8deb9eb0
commit r14-11259-gf0420cc224db64efe87cbe2f45d4d7ba8deb9eb0
Author: Patrick Palka <ppalka@redhat.com>
Date: Wed Jan 29 10:02:28 2025 -0500
libstdc++: Fix views::transform(move_only_fn{}) forwarding [PR118413]
The range adaptor perfect forwarding simplification mechanism is currently
only enabled for trivially copyable bound arguments, to prevent undesirable
copies of complex objects. But "trivially copyable" is the wrong property
to check for here, since a move-only type with a trivial move constructor
is considered trivially copyable, and after P2492R2 we can't assume copy
constructibility of the bound arguments. This patch makes the mechanism
more specifically check for trivial copy constructibility instead so
that it's properly disabled for move-only bound arguments.
PR libstdc++/118413
libstdc++-v3/ChangeLog:
* include/std/ranges (views::__adaptor::_Partial): Adjust
constraints on the "simple" partial specializations to require
is_trivially_copy_constructible_v instead of
is_trivially_copyable_v.
* testsuite/std/ranges/adaptors/adjacent_transform/1.cc (test04):
Extend P2494R2 test.
* testsuite/std/ranges/adaptors/transform.cc (test09): Likewise.
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
(cherry picked from commit 09d1cbee10b8c51aed48f047f30717f622d6f811)
Diff:
---
libstdc++-v3/include/std/ranges | 4 ++--
libstdc++-v3/testsuite/std/ranges/adaptors/adjacent_transform/1.cc | 1 +
libstdc++-v3/testsuite/std/ranges/adaptors/transform.cc | 2 ++
3 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
index eba539176848..a966699479bb 100644
--- a/libstdc++-v3/include/std/ranges
+++ b/libstdc++-v3/include/std/ranges
@@ -1122,7 +1122,7 @@ namespace views::__adaptor
// which makes overload resolution failure diagnostics more concise.
template<typename _Adaptor, typename... _Args>
requires __adaptor_has_simple_extra_args<_Adaptor, _Args...>
- && (is_trivially_copyable_v<_Args> && ...)
+ && (is_trivially_copy_constructible_v<_Args> && ...)
struct _Partial<_Adaptor, _Args...> : _RangeAdaptorClosure<_Partial<_Adaptor, _Args...>>
{
tuple<_Args...> _M_args;
@@ -1153,7 +1153,7 @@ namespace views::__adaptor
// where _Adaptor accepts a single extra argument.
template<typename _Adaptor, typename _Arg>
requires __adaptor_has_simple_extra_args<_Adaptor, _Arg>
- && is_trivially_copyable_v<_Arg>
+ && is_trivially_copy_constructible_v<_Arg>
struct _Partial<_Adaptor, _Arg> : _RangeAdaptorClosure<_Partial<_Adaptor, _Arg>>
{
_Arg _M_arg;
diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/adjacent_transform/1.cc b/libstdc++-v3/testsuite/std/ranges/adaptors/adjacent_transform/1.cc
index a5791b3da702..772e4b3b6a0d 100644
--- a/libstdc++-v3/testsuite/std/ranges/adaptors/adjacent_transform/1.cc
+++ b/libstdc++-v3/testsuite/std/ranges/adaptors/adjacent_transform/1.cc
@@ -110,6 +110,7 @@ test04()
};
// P2494R2 Relaxing range adaptors to allow for move only types
static_assert( requires { views::pairwise_transform(x, move_only{}); } );
+ static_assert( requires { x | views::pairwise_transform(move_only{}); } );
}
int
diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/transform.cc b/libstdc++-v3/testsuite/std/ranges/adaptors/transform.cc
index e1b74353e632..783b0fba7e1e 100644
--- a/libstdc++-v3/testsuite/std/ranges/adaptors/transform.cc
+++ b/libstdc++-v3/testsuite/std/ranges/adaptors/transform.cc
@@ -191,8 +191,10 @@ test09()
#if __cpp_lib_ranges >= 202207L
// P2494R2 Relaxing range adaptors to allow for move only types
static_assert( requires { transform(x, move_only{}); } );
+ static_assert( requires { x | transform(move_only{}); } ); // PR libstdc++/118413
#else
static_assert( ! requires { transform(x, move_only{}); } );
+ static_assert( ! requires { x | transform(move_only{}); } );
#endif
}
More information about the Libstdc++-cvs
mailing list