[libcxx-commits] [libcxx] 8426b51 - [libcxx][test][NFC] Fix std::pair convertible tests in light of CWG2137 (#97403)

via libcxx-commits libcxx-commits at lists.llvm.org
Sat Jul 6 12:34:16 PDT 2024


Author: Mital Ashok
Date: 2024-07-06T15:34:12-04:00
New Revision: 8426b51e0e942b27af8a50b9cee53c1b68d139c2

URL: https://github.com/llvm/llvm-project/commit/8426b51e0e942b27af8a50b9cee53c1b68d139c2
DIFF: https://github.com/llvm/llvm-project/commit/8426b51e0e942b27af8a50b9cee53c1b68d139c2.diff

LOG: [libcxx][test][NFC] Fix std::pair convertible tests in light of CWG2137 (#97403)

https://cplusplus.github.io/CWG/issues/2137.html

This change was previously made as part of
924701311aa79180e86ad8ce43d253f27d25ec7d (#77768) and later reverted in
6e4930c67508a90bdfd756f6e45417b5253cd741

This change is still needed because the comment is still true: A
standards-conformant compiler is currently supposed to fail this test.

This also means that any future work on CWG2137 with Clang would not
need to modify the libc++ test suite

Added: 
    

Modified: 
    libcxx/test/std/utilities/utility/pairs/pairs.pair/ctor.pair_U_V_move.pass.cpp

Removed: 
    


################################################################################
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<CopyOnly, CopyOnly&>();
         test_pair_rv<CopyOnly, CopyOnly&&>();
 
-        test_pair_rv<ExplicitTypes::CopyOnly, ExplicitTypes::CopyOnly>();
+        /* For ExplicitTypes::CopyOnly, two of the viable candidates for initializing from a non-const xvalue are:
+         *   pair(const pair&);  // (defaulted copy constructor)
+         *   template<class U1, class U2> explicit pair(const pair<U1, U2>&&); [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<ExplicitTypes::CopyOnly, int>;
+          using P2  = std::pair<int, ExplicitTypes::CopyOnly>;
+          using UP1 = std::pair<ExplicitTypes::CopyOnly, int>&&;
+          using UP2 = std::pair<int, ExplicitTypes::CopyOnly>&&;
+          static_assert(std::is_constructible<P1, UP1>::value, "");
+          static_assert(std::is_convertible<P1, UP1>::value, "");
+          static_assert(std::is_constructible<P2, UP2>::value, "");
+          static_assert(std::is_convertible<P2, UP2>::value, "");
+        }
         test_pair_rv<ExplicitTypes::CopyOnly, ExplicitTypes::CopyOnly&, true, false>();
         test_pair_rv<ExplicitTypes::CopyOnly, ExplicitTypes::CopyOnly&&, true, false>();
 


        


More information about the libcxx-commits mailing list