From e39bb62faf6579cc299d8a9eee6f9d1817d49ca7 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Tue, 11 Apr 2023 00:57:34 +0800 Subject: [PATCH 1/2] Workaround for `operator<=>` for `shared_ptr` --- stl/inc/memory | 5 +++++ tests/std/tests/P1614R2_spaceship/test.cpp | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/stl/inc/memory b/stl/inc/memory index 9ba2b098c14..658f3e78cdc 100644 --- a/stl/inc/memory +++ b/stl/inc/memory @@ -1883,7 +1883,12 @@ _NODISCARD bool operator==(const shared_ptr<_Ty1>& _Left, const shared_ptr<_Ty2> #if _HAS_CXX20 _EXPORT_STD template _NODISCARD strong_ordering operator<=>(const shared_ptr<_Ty1>& _Left, const shared_ptr<_Ty2>& _Right) noexcept { +#if !defined(__EDG__) && !defined(__clang__) // TRANSITION, DevCom-10334808 + using _Common_ptr_t = decltype(false ? _Left.get() : _Right.get()); + return static_cast<_Common_ptr_t>(_Left.get()) <=> static_cast<_Common_ptr_t>(_Right.get()); +#else // ^^^ workaround / no workaround vvv return _Left.get() <=> _Right.get(); +#endif // ^^^ no workaround ^^^ } #else // ^^^ _HAS_CXX20 / !_HAS_CXX20 vvv template diff --git a/tests/std/tests/P1614R2_spaceship/test.cpp b/tests/std/tests/P1614R2_spaceship/test.cpp index 46303176e35..b54788afa0b 100644 --- a/tests/std/tests/P1614R2_spaceship/test.cpp +++ b/tests/std/tests/P1614R2_spaceship/test.cpp @@ -1021,6 +1021,18 @@ void ordering_test_cases() { spaceship_test(p1, p3, p5); spaceship_test(p1, nullptr, p4); } + { // shared_ptr, heterogeneous + std::shared_ptr p1{}; + std::shared_ptr p2{} + std::shared_ptr p3{}; + + std::shared_ptr p4{new int}; + + spaceship_test(p1, p2, p4); + spaceship_test(p1, p3, p4); + spaceship_test(p2, p3, p4); + spaceship_test(p1, nullptr, p4); + } { // slice std::slice a1(2, 3, 4); std::slice a2(2, 3, 4); From 49362f304cd1103378b3c9d1995545485a1c1742 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Tue, 11 Apr 2023 01:10:06 +0800 Subject: [PATCH 2/2] Missing `;` I must have been too tired to correctly write anything... --- tests/std/tests/P1614R2_spaceship/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/std/tests/P1614R2_spaceship/test.cpp b/tests/std/tests/P1614R2_spaceship/test.cpp index b54788afa0b..aee2e256ee3 100644 --- a/tests/std/tests/P1614R2_spaceship/test.cpp +++ b/tests/std/tests/P1614R2_spaceship/test.cpp @@ -1023,7 +1023,7 @@ void ordering_test_cases() { } { // shared_ptr, heterogeneous std::shared_ptr p1{}; - std::shared_ptr p2{} + std::shared_ptr p2{}; std::shared_ptr p3{}; std::shared_ptr p4{new int};