From b7b5d4bb222aba58d472b90ea7266aa988a20ec8 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Wed, 12 Oct 2022 10:41:24 +0800 Subject: [PATCH 1/2] Additional test coverage for `common_type_t` Ensuring that common_type specializations are not doing evil. --- .../tests/P1522R1_difference_type/test.cpp | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/std/tests/P1522R1_difference_type/test.cpp b/tests/std/tests/P1522R1_difference_type/test.cpp index 3a0cb740e2..01ce691973 100644 --- a/tests/std/tests/P1522R1_difference_type/test.cpp +++ b/tests/std/tests/P1522R1_difference_type/test.cpp @@ -125,6 +125,18 @@ constexpr bool test_unsigned() { STATIC_ASSERT(SAME_AS, _Unsigned128>); STATIC_ASSERT(SAME_AS, _Unsigned128>); + struct ConversionSource { + constexpr operator _Unsigned128() const { + return _Unsigned128{}; + } + }; + STATIC_ASSERT(SAME_AS, _Unsigned128>); + + struct ConversionTarget { + constexpr ConversionTarget(_Unsigned128) {} + }; + STATIC_ASSERT(SAME_AS, ConversionTarget>); + #ifdef __cpp_lib_concepts // TRANSITION, GH-395 STATIC_ASSERT(std::_Integer_class<_Unsigned128>); STATIC_ASSERT(std::_Integer_like<_Unsigned128>); @@ -446,6 +458,18 @@ constexpr bool test_signed() { STATIC_ASSERT(SAME_AS, _Signed128>); STATIC_ASSERT(SAME_AS, _Signed128>); + struct ConversionSource { + constexpr operator _Signed128() const { + return _Signed128{}; + } + }; + STATIC_ASSERT(SAME_AS, _Signed128>); + + struct ConversionTarget { + constexpr ConversionTarget(_Signed128) {} + }; + STATIC_ASSERT(SAME_AS, ConversionTarget>); + #ifdef __cpp_lib_concepts // TRANSITION, GH-395 STATIC_ASSERT(std::_Integer_class<_Signed128>); STATIC_ASSERT(std::_Integer_like<_Signed128>); From 52b96676a574f8c28261ae44ba0f2442cec3d500 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Wed, 12 Oct 2022 10:44:36 +0800 Subject: [PATCH 2/2] Remove unnecessary `common_type` specializations And evil ones! --- stl/inc/__msvc_int128.hpp | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/stl/inc/__msvc_int128.hpp b/stl/inc/__msvc_int128.hpp index 8740686ae2..c1abd2979a 100644 --- a/stl/inc/__msvc_int128.hpp +++ b/stl/inc/__msvc_int128.hpp @@ -1026,22 +1026,6 @@ class numeric_limits<_Unsigned128> : public _Num_int_base { static constexpr int digits10 = 38; }; -#ifdef __cpp_lib_concepts -template -struct common_type<_Ty, _Unsigned128> { - using type = _Unsigned128; -}; -template -struct common_type<_Unsigned128, _Ty> { - using type = _Unsigned128; -}; -#else // ^^^ defined(__cpp_lib_concepts) / !defined(__cpp_lib_concepts) vvv -template -struct common_type<_Ty, _Unsigned128> : enable_if, _Unsigned128> {}; -template -struct common_type<_Unsigned128, _Ty> : enable_if, _Unsigned128> {}; -#endif // ^^^ !defined(__cpp_lib_concepts) ^^^ - struct _Signed128 : _Base128 { using _Signed_type = _Signed128; using _Unsigned_type = _Unsigned128; @@ -1427,22 +1411,6 @@ class numeric_limits<_Signed128> : public _Num_int_base { static constexpr int digits10 = 38; }; -#ifdef __cpp_lib_concepts -template -struct common_type<_Ty, _Signed128> { - using type = _Signed128; -}; -template -struct common_type<_Signed128, _Ty> { - using type = _Signed128; -}; -#else // ^^^ defined(__cpp_lib_concepts) / !defined(__cpp_lib_concepts) vvv -template -struct common_type<_Ty, _Signed128> : enable_if, _Signed128> {}; -template -struct common_type<_Signed128, _Ty> : enable_if, _Signed128> {}; -#endif // ^^^ !defined(__cpp_lib_concepts) ^^^ - template <> struct common_type<_Signed128, _Unsigned128> { using type = _Unsigned128;