From bbe8b6b2affb81b12a945d070a79b3e709a5922f Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Sun, 29 Sep 2024 04:22:45 +0800 Subject: [PATCH] ``: Privatize `pair`'s internal non-Standard constructor (#4979) --- stl/inc/utility | 11 ++++++----- .../tests/VSO_0000000_more_pair_tuple_sfinae/test.cpp | 7 +++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/stl/inc/utility b/stl/inc/utility index c5f9265dcfa..549d8cccd95 100644 --- a/stl/inc/utility +++ b/stl/inc/utility @@ -315,11 +315,6 @@ struct pair { // store a pair of values } #endif // _HAS_CXX23 - template - constexpr pair(_Tuple1& _Val1, _Tuple2& _Val2, index_sequence<_Indices1...>, index_sequence<_Indices2...>) - : first(_STD _Tuple_get<_Indices1>(_STD move(_Val1))...), - second(_STD _Tuple_get<_Indices2>(_STD move(_Val2))...) {} - template _CONSTEXPR20 pair(piecewise_construct_t, tuple<_Types1...> _Val1, tuple<_Types2...> _Val2) : pair(_Val1, _Val2, index_sequence_for<_Types1...>{}, index_sequence_for<_Types2...>{}) {} @@ -466,6 +461,12 @@ struct pair { // store a pair of values _Ty1 first; // the first stored value _Ty2 second; // the second stored value + +private: + template + constexpr pair(_Tuple1& _Val1, _Tuple2& _Val2, index_sequence<_Indices1...>, index_sequence<_Indices2...>) + : first(_STD _Tuple_get<_Indices1>(_STD move(_Val1))...), + second(_STD _Tuple_get<_Indices2>(_STD move(_Val2))...) {} }; #if _HAS_CXX17 diff --git a/tests/std/tests/VSO_0000000_more_pair_tuple_sfinae/test.cpp b/tests/std/tests/VSO_0000000_more_pair_tuple_sfinae/test.cpp index c1f45849030..7fc2e4102a7 100644 --- a/tests/std/tests/VSO_0000000_more_pair_tuple_sfinae/test.cpp +++ b/tests/std/tests/VSO_0000000_more_pair_tuple_sfinae/test.cpp @@ -558,6 +558,13 @@ STATIC_ASSERT(!is_constructible_v, allocator_arg_t, allocator, pai STATIC_ASSERT(is_constructible_v, allocator_arg_t, allocator, pair>); STATIC_ASSERT(!is_constructible_v, allocator_arg_t, allocator, pair>); +// Also test that the internal constructor used for the piecewise_construct_t constructor of pair is not public. +STATIC_ASSERT(!is_constructible_v, tuple<>&, tuple<>&, make_index_sequence<0>, make_index_sequence<0>>); +STATIC_ASSERT( + !is_constructible_v, tuple&, tuple<>&, make_index_sequence<1>, make_index_sequence<0>>); +STATIC_ASSERT( + !is_constructible_v, tuple&, tuple&, make_index_sequence<1>, make_index_sequence<1>>); + pair func1() { const int x = 17;