From 12850bbdb118878f924864cc4cc37f216958ae23 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Fri, 29 Jul 2022 15:54:00 +0800 Subject: [PATCH 01/12] Test deduction guides upate for Deducing this (LWG-3617) --- .../tests/P0433R2_deduction_guides/test.cpp | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/tests/std/tests/P0433R2_deduction_guides/test.cpp b/tests/std/tests/P0433R2_deduction_guides/test.cpp index db6aabc226c..9de698f4ac3 100644 --- a/tests/std/tests/P0433R2_deduction_guides/test.cpp +++ b/tests/std/tests/P0433R2_deduction_guides/test.cpp @@ -43,6 +43,11 @@ #include #endif // _M_CEE +#if _HAS_CXX23 && !defined(__EDG__) \ + && !defined(__clang__) // TRANSITION, DevCom-10107077, Clang and EDG has not implemented Deducing this +#define HAS_EXPLICIT_THIS_PARAMETER +#endif // _HAS_CXX23 && !defined(__EDG__) && !defined(__clang__) + using namespace std; template @@ -328,6 +333,82 @@ void test_function_wrapper() { static_assert(is_same_v>); static_assert(is_same_v>); + +#ifdef HAS_EXPLICIT_THIS_PARAMETER + struct ExplicitThisByVal { + void operator()(this ExplicitThisByVal, char) {} + }; + + ExplicitThisByVal explicit_this_by_val_functor{}; + + F f11(explicit_this_by_val_functor); + F f12(as_const(explicit_this_by_val_functor)); + F f13(move(explicit_this_by_val_functor)); + F f14(move(as_const(explicit_this_by_val_functor))); + + static_assert(is_same_v>); + static_assert(is_same_v>); + static_assert(is_same_v>); + static_assert(is_same_v>); + + struct ExplicitThisByRef { + void operator()(this ExplicitThisByRef&, short) {} + }; + + ExplicitThisByRef explicit_this_by_ref_functor{}; + + F f15(explicit_this_by_ref_functor); + + static_assert(is_same_v>); + + struct ExplicitThisByCRef { + void operator()(this const ExplicitThisByCRef&, int) {} + }; + + ExplicitThisByCRef explicit_this_by_cref_functor{}; + + F f16(explicit_this_by_cref_functor); + F f17(as_const(explicit_this_by_cref_functor)); + F f18(move(explicit_this_by_cref_functor)); + F f19(move(as_const(explicit_this_by_cref_functor))); + + static_assert(is_same_v>); + static_assert(is_same_v>); + static_assert(is_same_v>); + static_assert(is_same_v>); + + struct ExplicitThisByRRef { + void operator()(this const ExplicitThisByRRef&, long) {} + }; + + ExplicitThisByRRef explicit_this_by_rref_functor{}; + + F f20(move(explicit_this_by_rref_functor)); + + static_assert(is_same_v>); + + struct ExplicitThisByConv { + struct That {}; + + explicit operator That(this ExplicitThisByConv) { + return {}; + } + + void operator()(this That, long long) {} + }; + + ExplicitThisByConv explicit_this_by_conv_functor{}; + + F f21(explicit_this_by_conv_functor); + F f22(as_const(explicit_this_by_conv_functor)); + F f23(move(explicit_this_by_conv_functor)); + F f24(move(as_const(explicit_this_by_conv_functor))); + + static_assert(is_same_v>); + static_assert(is_same_v>); + static_assert(is_same_v>); + static_assert(is_same_v>); +#endif // HAS_EXPLICIT_THIS_PARAMETER } void test_searchers() { From 63d8a2d7a7a06aa6e25e0c0713da70906e59dee5 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Fri, 29 Jul 2022 15:56:32 +0800 Subject: [PATCH 02/12] Implement LWG-3617 --- stl/inc/type_traits | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/stl/inc/type_traits b/stl/inc/type_traits index f1c2d4acae0..bca3ddcc008 100644 --- a/stl/inc/type_traits +++ b/stl/inc/type_traits @@ -422,6 +422,23 @@ _MEMBER_CALL_CV_REF_NOEXCEPT(_IS_MEMFUNPTR) _CLASS_DEFINE_CV_REF_NOEXCEPT(_IS_MEMFUNPTR_ELLIPSIS) #undef _IS_MEMFUNPTR_ELLIPSIS +#if _HAS_CXX23 && !defined(__EDG__) \ + && !defined(__clang__) // TRANSITION, DevCom-10107077, Clang and EDG has not implemented Deducing this +#define _IS_MEMFUNPTR_EXPLICIT_THIS_GUIDES(CALL_OPT, CV_OPT, REF_OPT, NOEXCEPT_OPT) \ + template \ + struct _Is_memfunptr<_Ret(CALL_OPT*)(_Self, _Args...) NOEXCEPT_OPT> { \ + using _Bool_type = false_type; \ + using _Guide_type = type_identity<_Ret(_Args...)>; \ + }; + +_NON_MEMBER_CALL(_IS_MEMFUNPTR_EXPLICIT_THIS_GUIDES, , , ) +#ifdef __cpp_noexcept_function_type +_NON_MEMBER_CALL(_IS_MEMFUNPTR_EXPLICIT_THIS_GUIDES, , , noexcept) +#endif // __cpp_noexcept_function_type + +#undef _IS_MEMFUNPTR_EXPLICIT_THIS_GUIDES +#endif // _HAS_CXX23 && !defined(__EDG__) && !defined(__clang__) + #ifdef __clang__ template _INLINE_VAR constexpr bool is_member_function_pointer_v = __is_member_function_pointer(_Ty); From 9722f9d33fbd1a0decdf913b47f74ad747258d50 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Fri, 29 Jul 2022 16:23:49 +0800 Subject: [PATCH 03/12] It seems that EDG is ready. --- stl/inc/type_traits | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/stl/inc/type_traits b/stl/inc/type_traits index bca3ddcc008..8e2e48fdac7 100644 --- a/stl/inc/type_traits +++ b/stl/inc/type_traits @@ -422,8 +422,7 @@ _MEMBER_CALL_CV_REF_NOEXCEPT(_IS_MEMFUNPTR) _CLASS_DEFINE_CV_REF_NOEXCEPT(_IS_MEMFUNPTR_ELLIPSIS) #undef _IS_MEMFUNPTR_ELLIPSIS -#if _HAS_CXX23 && !defined(__EDG__) \ - && !defined(__clang__) // TRANSITION, DevCom-10107077, Clang and EDG has not implemented Deducing this +#if _HAS_CXX23 && !defined(__clang__) // TRANSITION, DevCom-10107077, Clang has not implemented Deducing this #define _IS_MEMFUNPTR_EXPLICIT_THIS_GUIDES(CALL_OPT, CV_OPT, REF_OPT, NOEXCEPT_OPT) \ template \ struct _Is_memfunptr<_Ret(CALL_OPT*)(_Self, _Args...) NOEXCEPT_OPT> { \ From 67dd06707c7fcfd033524f5d6d646fefb3836320 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Fri, 29 Jul 2022 16:24:23 +0800 Subject: [PATCH 04/12] It seems that EDG is ready --- tests/std/tests/P0433R2_deduction_guides/test.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/std/tests/P0433R2_deduction_guides/test.cpp b/tests/std/tests/P0433R2_deduction_guides/test.cpp index 9de698f4ac3..3ee79722b25 100644 --- a/tests/std/tests/P0433R2_deduction_guides/test.cpp +++ b/tests/std/tests/P0433R2_deduction_guides/test.cpp @@ -43,8 +43,7 @@ #include #endif // _M_CEE -#if _HAS_CXX23 && !defined(__EDG__) \ - && !defined(__clang__) // TRANSITION, DevCom-10107077, Clang and EDG has not implemented Deducing this +#if _HAS_CXX23 && !defined(__clang__) // TRANSITION, DevCom-10107077, Clang has not implemented Deducing this #define HAS_EXPLICIT_THIS_PARAMETER #endif // _HAS_CXX23 && !defined(__EDG__) && !defined(__clang__) From 8c57b34db2ec5284fd47c27f51e9ed89730a316c Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Fri, 29 Jul 2022 16:31:10 +0800 Subject: [PATCH 05/12] Move _Identity to front and use it --- stl/inc/type_traits | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/stl/inc/type_traits b/stl/inc/type_traits index 8e2e48fdac7..f954057b68b 100644 --- a/stl/inc/type_traits +++ b/stl/inc/type_traits @@ -78,6 +78,13 @@ struct is_void : bool_constant> {}; template using void_t = void; +template +struct _Identity { + using type = _Ty; +}; +template +using _Identity_t _MSVC_KNOWN_SEMANTICS = typename _Identity<_Ty>::type; + // Type modifiers template struct add_const { // add top-level const qualifier @@ -427,7 +434,7 @@ _CLASS_DEFINE_CV_REF_NOEXCEPT(_IS_MEMFUNPTR_ELLIPSIS) template \ struct _Is_memfunptr<_Ret(CALL_OPT*)(_Self, _Args...) NOEXCEPT_OPT> { \ using _Bool_type = false_type; \ - using _Guide_type = type_identity<_Ret(_Args...)>; \ + using _Guide_type = _Identity<_Ret(_Args...)>; \ }; _NON_MEMBER_CALL(_IS_MEMFUNPTR_EXPLICIT_THIS_GUIDES, , , ) @@ -1398,13 +1405,6 @@ template struct common_reference<_Ty1, _Ty2, _Ty3, _Rest...> : _Fold_common_reference {}; #endif // _HAS_CXX20 -template -struct _Identity { - using type = _Ty; -}; -template -using _Identity_t _MSVC_KNOWN_SEMANTICS = typename _Identity<_Ty>::type; - #if _HAS_CXX20 template struct type_identity { From ada7530b7d47061ad516f4768db662022e11cbc6 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Fri, 29 Jul 2022 16:58:07 +0800 Subject: [PATCH 06/12] WHY DID I MISTAKENLY USED explicit? Perhaps I was confused by the "explicit" in "explicit object parameter". --- tests/std/tests/P0433R2_deduction_guides/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/std/tests/P0433R2_deduction_guides/test.cpp b/tests/std/tests/P0433R2_deduction_guides/test.cpp index 3ee79722b25..1c48b85f614 100644 --- a/tests/std/tests/P0433R2_deduction_guides/test.cpp +++ b/tests/std/tests/P0433R2_deduction_guides/test.cpp @@ -389,7 +389,7 @@ void test_function_wrapper() { struct ExplicitThisByConv { struct That {}; - explicit operator That(this ExplicitThisByConv) { + operator That(this ExplicitThisByConv) { return {}; } From e9ac8b4323aef52c04d8722859ff87bead199aaa Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Fri, 29 Jul 2022 17:28:31 +0800 Subject: [PATCH 07/12] Cleanup wrong comments --- stl/inc/type_traits | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/inc/type_traits b/stl/inc/type_traits index f954057b68b..fb09ab24a45 100644 --- a/stl/inc/type_traits +++ b/stl/inc/type_traits @@ -443,7 +443,7 @@ _NON_MEMBER_CALL(_IS_MEMFUNPTR_EXPLICIT_THIS_GUIDES, , , noexcept) #endif // __cpp_noexcept_function_type #undef _IS_MEMFUNPTR_EXPLICIT_THIS_GUIDES -#endif // _HAS_CXX23 && !defined(__EDG__) && !defined(__clang__) +#endif // _HAS_CXX23 && !defined(__clang__) #ifdef __clang__ template From f89209f84d0396eeb412cbec04eed3f6900451df Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Fri, 29 Jul 2022 17:28:34 +0800 Subject: [PATCH 08/12] Cleanup wrong comments --- tests/std/tests/P0433R2_deduction_guides/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/std/tests/P0433R2_deduction_guides/test.cpp b/tests/std/tests/P0433R2_deduction_guides/test.cpp index 1c48b85f614..79532ba8e3b 100644 --- a/tests/std/tests/P0433R2_deduction_guides/test.cpp +++ b/tests/std/tests/P0433R2_deduction_guides/test.cpp @@ -45,7 +45,7 @@ #if _HAS_CXX23 && !defined(__clang__) // TRANSITION, DevCom-10107077, Clang has not implemented Deducing this #define HAS_EXPLICIT_THIS_PARAMETER -#endif // _HAS_CXX23 && !defined(__EDG__) && !defined(__clang__) +#endif // _HAS_CXX23 && !defined(__clang__) using namespace std; From d03b7ed585f2862f1d682e8f4c76ae12611f60d3 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Sat, 30 Jul 2022 07:10:15 +0800 Subject: [PATCH 09/12] Adopt strega-nil-ms's correction Co-authored-by: nicole mazzuca <83086508+strega-nil-ms@users.noreply.github.com> --- tests/std/tests/P0433R2_deduction_guides/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/std/tests/P0433R2_deduction_guides/test.cpp b/tests/std/tests/P0433R2_deduction_guides/test.cpp index 79532ba8e3b..4b077b2cf3b 100644 --- a/tests/std/tests/P0433R2_deduction_guides/test.cpp +++ b/tests/std/tests/P0433R2_deduction_guides/test.cpp @@ -377,7 +377,7 @@ void test_function_wrapper() { static_assert(is_same_v>); struct ExplicitThisByRRef { - void operator()(this const ExplicitThisByRRef&, long) {} + void operator()(this ExplicitThisByRRef&&, long) {} }; ExplicitThisByRRef explicit_this_by_rref_functor{}; From c6c892d255b2bc5af0cdcb10f6a41e7bf87671af Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Sat, 30 Jul 2022 07:58:58 +0800 Subject: [PATCH 10/12] Drop the non-lvalue-callable case --- .../tests/P0433R2_deduction_guides/test.cpp | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/tests/std/tests/P0433R2_deduction_guides/test.cpp b/tests/std/tests/P0433R2_deduction_guides/test.cpp index 4b077b2cf3b..a0f08d2f756 100644 --- a/tests/std/tests/P0433R2_deduction_guides/test.cpp +++ b/tests/std/tests/P0433R2_deduction_guides/test.cpp @@ -376,17 +376,7 @@ void test_function_wrapper() { static_assert(is_same_v>); static_assert(is_same_v>); - struct ExplicitThisByRRef { - void operator()(this ExplicitThisByRRef&&, long) {} - }; - - ExplicitThisByRRef explicit_this_by_rref_functor{}; - - F f20(move(explicit_this_by_rref_functor)); - - static_assert(is_same_v>); - - struct ExplicitThisByConv { + struct ExplicitThisByConv { struct That {}; operator That(this ExplicitThisByConv) { @@ -398,15 +388,15 @@ void test_function_wrapper() { ExplicitThisByConv explicit_this_by_conv_functor{}; - F f21(explicit_this_by_conv_functor); - F f22(as_const(explicit_this_by_conv_functor)); - F f23(move(explicit_this_by_conv_functor)); - F f24(move(as_const(explicit_this_by_conv_functor))); + F f20(explicit_this_by_conv_functor); + F f21(as_const(explicit_this_by_conv_functor)); + F f22(move(explicit_this_by_conv_functor)); + F f23(move(as_const(explicit_this_by_conv_functor))); + static_assert(is_same_v>); static_assert(is_same_v>); static_assert(is_same_v>); static_assert(is_same_v>); - static_assert(is_same_v>); #endif // HAS_EXPLICIT_THIS_PARAMETER } From f3a10944fad8c3ce1a57032384c2d3e6131f9d1b Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Sat, 30 Jul 2022 08:05:30 +0800 Subject: [PATCH 11/12] Why did I deleted one more space? --- tests/std/tests/P0433R2_deduction_guides/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/std/tests/P0433R2_deduction_guides/test.cpp b/tests/std/tests/P0433R2_deduction_guides/test.cpp index a0f08d2f756..bf511db7717 100644 --- a/tests/std/tests/P0433R2_deduction_guides/test.cpp +++ b/tests/std/tests/P0433R2_deduction_guides/test.cpp @@ -376,7 +376,7 @@ void test_function_wrapper() { static_assert(is_same_v>); static_assert(is_same_v>); - struct ExplicitThisByConv { + struct ExplicitThisByConv { struct That {}; operator That(this ExplicitThisByConv) { From 242c0cd0c8f9d3bf587b9c38fc913ccc567b21bf Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Thu, 4 Aug 2022 15:42:35 -0700 Subject: [PATCH 12/12] Extend test coverage. --- .../Dev11_0535636_functional_overhaul/test.cpp | 4 ++++ .../tests/P0433R2_deduction_guides/test.cpp | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/tests/std/tests/Dev11_0535636_functional_overhaul/test.cpp b/tests/std/tests/Dev11_0535636_functional_overhaul/test.cpp index 055718cc9ae..f5236ef8e63 100644 --- a/tests/std/tests/Dev11_0535636_functional_overhaul/test.cpp +++ b/tests/std/tests/Dev11_0535636_functional_overhaul/test.cpp @@ -151,6 +151,10 @@ STATIC_ASSERT(is_member_object_pointer_v); STATIC_ASSERT(!is_member_function_pointer_v); STATIC_ASSERT(!is_member_object_pointer_v); +// Verify that the machinery for LWG-3617 "function/packaged_task deduction guides and deducing this" +// doesn't cause such function pointers to be detected as PMFs. +STATIC_ASSERT(!is_member_function_pointer_v); + // N4594 20.13.7.6 [meta.trans.other]: // Template: diff --git a/tests/std/tests/P0433R2_deduction_guides/test.cpp b/tests/std/tests/P0433R2_deduction_guides/test.cpp index bf511db7717..3fb58b66819 100644 --- a/tests/std/tests/P0433R2_deduction_guides/test.cpp +++ b/tests/std/tests/P0433R2_deduction_guides/test.cpp @@ -397,6 +397,24 @@ void test_function_wrapper() { static_assert(is_same_v>); static_assert(is_same_v>); static_assert(is_same_v>); + + struct ExplicitThisNoexcept { + float operator()(this ExplicitThisNoexcept, double) noexcept { + return 3.14f; + } + }; + + ExplicitThisNoexcept explicit_this_noexcept_functor{}; + + F f24(explicit_this_noexcept_functor); + F f25(as_const(explicit_this_noexcept_functor)); + F f26(move(explicit_this_noexcept_functor)); + F f27(move(as_const(explicit_this_noexcept_functor))); + + static_assert(is_same_v>); + static_assert(is_same_v>); + static_assert(is_same_v>); + static_assert(is_same_v>); #endif // HAS_EXPLICIT_THIS_PARAMETER }