Skip to content

Commit

Permalink
[libcxx][test][NFC] Fix std::pair convertible tests in light of CWG21…
Browse files Browse the repository at this point in the history
…37 (llvm#97403)

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

This change was previously made as part of
9247013 (llvm#77768) and later reverted in
6e4930c

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
  • Loading branch information
MitalAshok committed Jul 6, 2024
1 parent 6e4bb60 commit 8426b51
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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>();

Expand Down

0 comments on commit 8426b51

Please sign in to comment.