From 77a962ef10234fe6598cc6287500056a442d7228 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Tue, 5 Apr 2022 21:24:22 +0800 Subject: [PATCH 1/9] Implement LWG-3121 The original issue reported in LWG-3121 has been resolved. The addition part resolves LWG-3155. --- stl/inc/tuple | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/stl/inc/tuple b/stl/inc/tuple index ab3952ad1d..5fa45d6e82 100644 --- a/stl/inc/tuple +++ b/stl/inc/tuple @@ -135,6 +135,16 @@ template struct _Tuple_perfect_val<_Myself, _This2> : bool_constant>>> {}; +template +struct _Tuple_perfect_val, _Uty0, _Uty1> + : disjunction, allocator_arg_t>>, + is_same<_Remove_cvref_t<_Ty0>, allocator_arg_t>> {}; + +template +struct _Tuple_perfect_val, _Uty0, _Uty1, _Uty2> + : disjunction, allocator_arg_t>>, + is_same<_Remove_cvref_t<_Ty0>, allocator_arg_t>> {}; + struct _Ignore { // struct that ignores assignments template constexpr const _Ignore& operator=(const _Ty&) const noexcept /* strengthened */ { From 274983ff4bcc737717f078fecc269b8ad1a49957 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Tue, 5 Apr 2022 21:27:47 +0800 Subject: [PATCH 2/9] Add test files for LWG-3121 --- .../env.lst | 4 ++ .../test.cpp | 53 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 tests/std/tests/LWG3121_constrained_tuple_forwarding_ctor/env.lst create mode 100644 tests/std/tests/LWG3121_constrained_tuple_forwarding_ctor/test.cpp diff --git a/tests/std/tests/LWG3121_constrained_tuple_forwarding_ctor/env.lst b/tests/std/tests/LWG3121_constrained_tuple_forwarding_ctor/env.lst new file mode 100644 index 0000000000..19f025bd0e --- /dev/null +++ b/tests/std/tests/LWG3121_constrained_tuple_forwarding_ctor/env.lst @@ -0,0 +1,4 @@ +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +RUNALL_INCLUDE ..\usual_matrix.lst diff --git a/tests/std/tests/LWG3121_constrained_tuple_forwarding_ctor/test.cpp b/tests/std/tests/LWG3121_constrained_tuple_forwarding_ctor/test.cpp new file mode 100644 index 0000000000..6965298f9c --- /dev/null +++ b/tests/std/tests/LWG3121_constrained_tuple_forwarding_ctor/test.cpp @@ -0,0 +1,53 @@ +// Copyright (c) Microsoft Corporation. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +#include +#include +#include + +#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) + +#if _HAS_CXX20 +#define CONSTEXPR_VAR_20 constexpr +#else +#define CONSTEXPR_VAR_20 const +#endif + +using namespace std; + +class pseudo_any { + bool has_value_ = false; + +public: + pseudo_any() = default; + template , pseudo_any>>, + is_copy_constructible>>, + int> = 0> + constexpr pseudo_any(ValT&&) noexcept : has_value_{true} {} + + constexpr bool has_value() const noexcept { return has_value_; } +}; + +STATIC_ASSERT(is_copy_constructible_v>); + +using TA2 = tuple; +using TA3 = tuple; + +CONSTEXPR_VAR_20 TA2 t2{allocator_arg, allocator{}}; +CONSTEXPR_VAR_20 TA3 t3{allocator_arg, allocator{}, tuple{}}; + +#if _HAS_CXX20 +static_assert(!get<0>(t2).has_value()); +static_assert(!get<1>(t2).has_value()); +static_assert(!get<0>(t3).has_value()); +static_assert(!get<1>(t3).has_value()); +static_assert(get<2>(t3).has_value()); +#endif + +int main() { + assert(!get<0>(t2).has_value()); + assert(!get<1>(t2).has_value()); + assert(!get<0>(t3).has_value()); + assert(!get<1>(t3).has_value()); + assert(get<2>(t3).has_value()); +} From 5088f7ffea322d6763c651edb367c5ae00b389d7 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Tue, 5 Apr 2022 21:30:15 +0800 Subject: [PATCH 3/9] Add test for LWG-3121 to test.lst --- tests/std/test.lst | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/std/test.lst b/tests/std/test.lst index 2a8cf5e9ac..217244f3f9 100644 --- a/tests/std/test.lst +++ b/tests/std/test.lst @@ -198,6 +198,7 @@ tests\GH_002488_promise_not_default_constructible_types tests\GH_002581_common_reference_workaround tests\LWG2597_complex_branch_cut tests\LWG3018_shared_ptr_function +tests\LWG3121_constrained_tuple_forwarding_ctor tests\LWG3146_excessive_unwrapping_ref_cref tests\LWG3422_seed_seq_ctors tests\LWG3480_directory_iterator_range From 8bd4dfdb574d459c1e1b20a8c52ce05a64c8732a Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Tue, 5 Apr 2022 21:37:42 +0800 Subject: [PATCH 4/9] Add --- .../std/tests/LWG3121_constrained_tuple_forwarding_ctor/test.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/std/tests/LWG3121_constrained_tuple_forwarding_ctor/test.cpp b/tests/std/tests/LWG3121_constrained_tuple_forwarding_ctor/test.cpp index 6965298f9c..badd19bbdb 100644 --- a/tests/std/tests/LWG3121_constrained_tuple_forwarding_ctor/test.cpp +++ b/tests/std/tests/LWG3121_constrained_tuple_forwarding_ctor/test.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) From 48a8eadd99f779956e609230bd96b1fa6b4891ed Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Tue, 5 Apr 2022 21:45:51 +0800 Subject: [PATCH 5/9] clang-format --- .../test.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/std/tests/LWG3121_constrained_tuple_forwarding_ctor/test.cpp b/tests/std/tests/LWG3121_constrained_tuple_forwarding_ctor/test.cpp index badd19bbdb..970c4f25e5 100644 --- a/tests/std/tests/LWG3121_constrained_tuple_forwarding_ctor/test.cpp +++ b/tests/std/tests/LWG3121_constrained_tuple_forwarding_ctor/test.cpp @@ -1,10 +1,10 @@ // Copyright (c) Microsoft Corporation. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -#include -#include -#include #include +#include +#include +#include #define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) @@ -21,12 +21,14 @@ class pseudo_any { public: pseudo_any() = default; - template , pseudo_any>>, - is_copy_constructible>>, - int> = 0> + template , pseudo_any>>, is_copy_constructible>>, + int> = 0> constexpr pseudo_any(ValT&&) noexcept : has_value_{true} {} - constexpr bool has_value() const noexcept { return has_value_; } + constexpr bool has_value() const noexcept { + return has_value_; + } }; STATIC_ASSERT(is_copy_constructible_v>); From cfa545551757cf9a857defb24513288875a44564 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Tue, 5 Apr 2022 21:45:58 +0800 Subject: [PATCH 6/9] clang-format --- stl/inc/tuple | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stl/inc/tuple b/stl/inc/tuple index 5fa45d6e82..1b678d7b95 100644 --- a/stl/inc/tuple +++ b/stl/inc/tuple @@ -138,12 +138,12 @@ struct _Tuple_perfect_val<_Myself, _This2> template struct _Tuple_perfect_val, _Uty0, _Uty1> : disjunction, allocator_arg_t>>, - is_same<_Remove_cvref_t<_Ty0>, allocator_arg_t>> {}; + is_same<_Remove_cvref_t<_Ty0>, allocator_arg_t>> {}; template struct _Tuple_perfect_val, _Uty0, _Uty1, _Uty2> : disjunction, allocator_arg_t>>, - is_same<_Remove_cvref_t<_Ty0>, allocator_arg_t>> {}; + is_same<_Remove_cvref_t<_Ty0>, allocator_arg_t>> {}; struct _Ignore { // struct that ignores assignments template From 5a89c2ffa30f83f8fdc5c42a9a4d1491e6deeff5 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Thu, 7 Apr 2022 09:11:52 +0800 Subject: [PATCH 7/9] Use _Remove_cvref_t to reject volatile versions Co-authored-by: S. B. Tam --- stl/inc/tuple | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/inc/tuple b/stl/inc/tuple index 1b678d7b95..d31a28a930 100644 --- a/stl/inc/tuple +++ b/stl/inc/tuple @@ -133,7 +133,7 @@ struct _Tuple_perfect_val : true_type {}; template struct _Tuple_perfect_val<_Myself, _This2> - : bool_constant>>> {}; + : bool_constant>> {}; template struct _Tuple_perfect_val, _Uty0, _Uty1> From 43165df04ecd17eeb3005bab86134dd05fcd7a01 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Thu, 7 Apr 2022 10:24:26 +0800 Subject: [PATCH 8/9] clang-format Unbreak line. --- stl/inc/tuple | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/stl/inc/tuple b/stl/inc/tuple index d31a28a930..bd93d6b174 100644 --- a/stl/inc/tuple +++ b/stl/inc/tuple @@ -132,8 +132,7 @@ template struct _Tuple_perfect_val : true_type {}; template -struct _Tuple_perfect_val<_Myself, _This2> - : bool_constant>> {}; +struct _Tuple_perfect_val<_Myself, _This2> : bool_constant>> {}; template struct _Tuple_perfect_val, _Uty0, _Uty1> From 698053e2dc32f42285ff980163509ff1c62f193a Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Wed, 13 Apr 2022 21:07:05 -0700 Subject: [PATCH 9/9] Code review feedback. --- stl/inc/tuple | 8 ++++---- .../LWG3121_constrained_tuple_forwarding_ctor/test.cpp | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/stl/inc/tuple b/stl/inc/tuple index bd93d6b174..49492bda9c 100644 --- a/stl/inc/tuple +++ b/stl/inc/tuple @@ -136,13 +136,13 @@ struct _Tuple_perfect_val<_Myself, _This2> : bool_constant struct _Tuple_perfect_val, _Uty0, _Uty1> - : disjunction, allocator_arg_t>>, - is_same<_Remove_cvref_t<_Ty0>, allocator_arg_t>> {}; + : bool_constant, allocator_arg_t>>, + is_same<_Remove_cvref_t<_Ty0>, allocator_arg_t>>> {}; template struct _Tuple_perfect_val, _Uty0, _Uty1, _Uty2> - : disjunction, allocator_arg_t>>, - is_same<_Remove_cvref_t<_Ty0>, allocator_arg_t>> {}; + : bool_constant, allocator_arg_t>>, + is_same<_Remove_cvref_t<_Ty0>, allocator_arg_t>>> {}; struct _Ignore { // struct that ignores assignments template diff --git a/tests/std/tests/LWG3121_constrained_tuple_forwarding_ctor/test.cpp b/tests/std/tests/LWG3121_constrained_tuple_forwarding_ctor/test.cpp index 970c4f25e5..f421d2e583 100644 --- a/tests/std/tests/LWG3121_constrained_tuple_forwarding_ctor/test.cpp +++ b/tests/std/tests/LWG3121_constrained_tuple_forwarding_ctor/test.cpp @@ -17,6 +17,7 @@ using namespace std; class pseudo_any { +private: bool has_value_ = false; public: @@ -45,7 +46,7 @@ static_assert(!get<1>(t2).has_value()); static_assert(!get<0>(t3).has_value()); static_assert(!get<1>(t3).has_value()); static_assert(get<2>(t3).has_value()); -#endif +#endif // _HAS_CXX20 int main() { assert(!get<0>(t2).has_value());