From 34a9c14e787ef602479fe6ff3780594ebe762c37 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Mon, 15 Jan 2024 09:52:13 +0800 Subject: [PATCH 1/3] Make `is_nothrow_convertible` a class template and ADL-proof --- stl/inc/type_traits | 4 +-- .../test.compile.pass.cpp | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/stl/inc/type_traits b/stl/inc/type_traits index 3071d59197..d1a88f9c28 100644 --- a/stl/inc/type_traits +++ b/stl/inc/type_traits @@ -1764,7 +1764,7 @@ constexpr auto invoke(_Callable&& _Obj, _Ty1&& _Arg1, _Types2&&... _Args2) noexc #pragma warning(disable : 4365) // '%s': conversion from '%s' to '%s', signed/unsigned mismatch (/Wall) template , bool = is_void_v<_To>> -_INLINE_VAR constexpr bool _Is_nothrow_convertible_v = noexcept(_Fake_copy_init<_To>(_STD declval<_From>())); +_INLINE_VAR constexpr bool _Is_nothrow_convertible_v = noexcept(_STD _Fake_copy_init<_To>(_STD declval<_From>())); #pragma warning(pop) @@ -1784,7 +1784,7 @@ _EXPORT_STD template inline constexpr bool is_nothrow_convertible_v = _Is_nothrow_convertible_v<_From, _To>; _EXPORT_STD template -using is_nothrow_convertible = _Is_nothrow_convertible<_From, _To>; +struct is_nothrow_convertible : bool_constant<_Is_nothrow_convertible_v<_From, _To>> {}; #endif // _HAS_CXX20 template diff --git a/tests/std/tests/P0758R1_is_nothrow_convertible/test.compile.pass.cpp b/tests/std/tests/P0758R1_is_nothrow_convertible/test.compile.pass.cpp index 041abc2d4a..15f6eaca21 100644 --- a/tests/std/tests/P0758R1_is_nothrow_convertible/test.compile.pass.cpp +++ b/tests/std/tests/P0758R1_is_nothrow_convertible/test.compile.pass.cpp @@ -105,5 +105,30 @@ STATIC_ASSERT(is_nothrow_convertible_v); STATIC_ASSERT(!is_nothrow_convertible_v); STATIC_ASSERT(!is_nothrow_convertible_v); +// Also test GH-4317 : some traits are an aliases and fail when used with parameter pack + +template +using aliased_is_nothrow_convertible = is_nothrow_convertible; + +template class Tmpl> +constexpr bool is_specialization_of_v = false; +template class Tmpl> +constexpr bool is_specialization_of_v, Tmpl> = true; + +STATIC_ASSERT(is_specialization_of_v, is_nothrow_convertible>); +STATIC_ASSERT(!is_specialization_of_v, aliased_is_nothrow_convertible>); + +// Also test that is_nothrow_convertible/is_nothrow_convertible_v are ADL-proof + +template +struct holder { + T t; +}; + +struct incomplete; + +STATIC_ASSERT(is_nothrow_convertible*, holder*>::value); +STATIC_ASSERT(is_nothrow_convertible_v*, holder*>); + // VSO_0105317_expression_sfinae and VSO_0000000_type_traits provide // additional coverage of this machinery From 4b2cbb55e4063a1155b819ec64e4348e0ea5ca0c Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Mon, 15 Jan 2024 10:32:52 +0800 Subject: [PATCH 2/3] Skip `_M_CEE` for tests for incomplete types --- .../tests/P0758R1_is_nothrow_convertible/test.compile.pass.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/std/tests/P0758R1_is_nothrow_convertible/test.compile.pass.cpp b/tests/std/tests/P0758R1_is_nothrow_convertible/test.compile.pass.cpp index 15f6eaca21..a86418ae4d 100644 --- a/tests/std/tests/P0758R1_is_nothrow_convertible/test.compile.pass.cpp +++ b/tests/std/tests/P0758R1_is_nothrow_convertible/test.compile.pass.cpp @@ -118,6 +118,7 @@ constexpr bool is_specialization_of_v, Tmpl> = true; STATIC_ASSERT(is_specialization_of_v, is_nothrow_convertible>); STATIC_ASSERT(!is_specialization_of_v, aliased_is_nothrow_convertible>); +#ifndef _M_CEE // TRANSITION, VSO-1659496 // Also test that is_nothrow_convertible/is_nothrow_convertible_v are ADL-proof template @@ -129,6 +130,7 @@ struct incomplete; STATIC_ASSERT(is_nothrow_convertible*, holder*>::value); STATIC_ASSERT(is_nothrow_convertible_v*, holder*>); +#endif // _M_CEE // VSO_0105317_expression_sfinae and VSO_0000000_type_traits provide // additional coverage of this machinery From e50a400846a443ec4c98a54647c251757567274c Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Tue, 16 Jan 2024 12:02:59 -0800 Subject: [PATCH 3/3] Fix grammar mistake in bug title. --- .../tests/P0758R1_is_nothrow_convertible/test.compile.pass.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/std/tests/P0758R1_is_nothrow_convertible/test.compile.pass.cpp b/tests/std/tests/P0758R1_is_nothrow_convertible/test.compile.pass.cpp index a86418ae4d..06dfe28844 100644 --- a/tests/std/tests/P0758R1_is_nothrow_convertible/test.compile.pass.cpp +++ b/tests/std/tests/P0758R1_is_nothrow_convertible/test.compile.pass.cpp @@ -105,7 +105,7 @@ STATIC_ASSERT(is_nothrow_convertible_v); STATIC_ASSERT(!is_nothrow_convertible_v); STATIC_ASSERT(!is_nothrow_convertible_v); -// Also test GH-4317 : some traits are an aliases and fail when used with parameter pack +// Also test GH-4317 : some traits are aliases and fail when used with parameter packs template using aliased_is_nothrow_convertible = is_nothrow_convertible;