From bfbbee350dae7eae8c16551afd5fcedc035d3685 Mon Sep 17 00:00:00 2001 From: Mital Ashok Date: Tue, 2 Jul 2024 10:51:43 +0100 Subject: [PATCH] [libcxx][test][NFC] Fix std::pair convertible tests in light of CWG2137 --- .../pairs.pair/ctor.pair_U_V_move.pass.cpp | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/libcxx/test/std/utilities/utility/pairs/pairs.pair/ctor.pair_U_V_move.pass.cpp b/libcxx/test/std/utilities/utility/pairs/pairs.pair/ctor.pair_U_V_move.pass.cpp index 3b2d093eb34d4..8ba9b5696eff1 100644 --- a/libcxx/test/std/utilities/utility/pairs/pairs.pair/ctor.pair_U_V_move.pass.cpp +++ b/libcxx/test/std/utilities/utility/pairs/pairs.pair/ctor.pair_U_V_move.pass.cpp @@ -121,7 +121,28 @@ int main(int, char**) test_pair_rv(); test_pair_rv(); - test_pair_rv(); + /* For ExplicitTypes::CopyOnly, two of the viable candidates for initializing from a non-const xvalue are: + * pair(const pair&); // (defaulted copy constructor) + * template explicit pair(const pair&&); [U1 = ExplicitTypes::CopyOnly, U2 = int] + * + * This results in diverging behavior for test_convertible which uses copy-list-initialization. + * Prior to CWG2137, this would have selected the first (non-explicit) ctor as explicit ctors + * would not be considered. Afterwards, it should select the second since it is a better match, + * and then failed because it is explicit. + * + * This may change with future defect reports, and some compilers only have partial support + * for CWG2137, so use std::is_convertible directly to avoid a copy-list-initialization + */ + { + using P1 = std::pair; + using P2 = std::pair; + using UP1 = std::pair&&; + using UP2 = std::pair&&; + static_assert(std::is_constructible::value, ""); + static_assert(std::is_convertible::value, ""); + static_assert(std::is_constructible::value, ""); + static_assert(std::is_convertible::value, ""); + } test_pair_rv(); test_pair_rv();