From cbdca06e25caeb8eb65d0e04425eca463a16c860 Mon Sep 17 00:00:00 2001 From: frederick-vs-ja Date: Thu, 26 Aug 2021 10:53:34 +0800 Subject: [PATCH 1/2] Adopt LWG-3528 Use static_assert as std::make_from_tuple is unconstrained. --- stl/inc/tuple | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stl/inc/tuple b/stl/inc/tuple index 8fae9205b56..27529447934 100644 --- a/stl/inc/tuple +++ b/stl/inc/tuple @@ -983,6 +983,8 @@ constexpr decltype(auto) apply(_Callable&& _Obj, _Tuple&& _Tpl) { // invoke _Obj template constexpr _Ty _Make_from_tuple_impl( _Tuple&& _Tpl, index_sequence<_Indices...>) { // construct _Ty from the elements of _Tpl + static_assert(is_constructible_v<_Ty, decltype(_STD get<_Indices>(_STD declval<_Tuple>()))...>, + "C-style cast is forbidden (N4892 [tuple.apply]/2)."); return _Ty(_STD get<_Indices>(_STD forward<_Tuple>(_Tpl))...); } From 733b44a2c0574a9dfe2d7fe386b65545dae5cf4c Mon Sep 17 00:00:00 2001 From: frederick-vs-ja Date: Thu, 26 Aug 2021 12:25:51 +0800 Subject: [PATCH 2/2] Adopt CaseyCarter's suggestions --- stl/inc/tuple | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stl/inc/tuple b/stl/inc/tuple index 27529447934..7d368bdd308 100644 --- a/stl/inc/tuple +++ b/stl/inc/tuple @@ -981,10 +981,10 @@ constexpr decltype(auto) apply(_Callable&& _Obj, _Tuple&& _Tpl) { // invoke _Obj } template -constexpr _Ty _Make_from_tuple_impl( - _Tuple&& _Tpl, index_sequence<_Indices...>) { // construct _Ty from the elements of _Tpl - static_assert(is_constructible_v<_Ty, decltype(_STD get<_Indices>(_STD declval<_Tuple>()))...>, - "C-style cast is forbidden (N4892 [tuple.apply]/2)."); +constexpr _Ty _Make_from_tuple_impl(_Tuple&& _Tpl, index_sequence<_Indices...>) { + // construct _Ty from the elements of _Tpl + static_assert(is_constructible_v<_Ty, decltype(_STD get<_Indices>(_STD forward<_Tuple>(_Tpl)))...>, + "the target type must be constructible from the fields of the argument tuple (N4892 [tuple.apply]/2)."); return _Ty(_STD get<_Indices>(_STD forward<_Tuple>(_Tpl))...); }