Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading