From fda4ef854552a492bbcfd0380fe121def1a706e3 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Tue, 29 Mar 2022 22:55:29 +0700 Subject: [PATCH 1/6] MSVC workaround of construct_at constraint Co-authored-by: A. Jiang --- stl/inc/xutility | 8 +++-- tests/std/test.lst | 1 + .../GH_002620_construct_at_workaround/env.lst | 4 +++ .../test.cpp | 33 +++++++++++++++++++ 4 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 tests/std/tests/GH_002620_construct_at_workaround/env.lst create mode 100644 tests/std/tests/GH_002620_construct_at_workaround/test.cpp diff --git a/stl/inc/xutility b/stl/inc/xutility index 07cc76c0e1..31a185e552 100644 --- a/stl/inc/xutility +++ b/stl/inc/xutility @@ -130,9 +130,13 @@ _NODISCARD constexpr void* _Voidify_iter(_Iter _It) noexcept { #if _HAS_CXX20 template ()) _Ty(_STD declval<_Types>()...))>> -constexpr _Ty* construct_at(_Ty* const _Location, _Types&&... _Args) noexcept( - noexcept(::new (_Voidify_iter(_Location)) _Ty(_STD forward<_Types>(_Args)...))) /* strengthened */ { +#else // ^^^ no workaround // workaround vvv + void_t()) _Ty(_STD declval<_Types>()...))>* = nullptr> +#endif // TRANSITION, DevCom-XXXX, DevCom-XXXX + constexpr _Ty* construct_at(_Ty* const _Location, _Types&&... _Args) noexcept( + noexcept(::new (_Voidify_iter(_Location)) _Ty(_STD forward<_Types>(_Args)...))) /* strengthened */ { return ::new (_Voidify_iter(_Location)) _Ty(_STD forward<_Types>(_Args)...); } #endif // _HAS_CXX20 diff --git a/tests/std/test.lst b/tests/std/test.lst index 2cc70b68f8..49976bc3cd 100644 --- a/tests/std/test.lst +++ b/tests/std/test.lst @@ -195,6 +195,7 @@ tests\GH_002299_implicit_sfinae_constraints tests\GH_002307_usual_scope_guard tests\GH_002488_promise_not_default_constructible_types tests\GH_002581_common_reference_workaround +tests\GH_002620_construct_at_workaround tests\LWG2597_complex_branch_cut tests\LWG3018_shared_ptr_function tests\LWG3146_excessive_unwrapping_ref_cref diff --git a/tests/std/tests/GH_002620_construct_at_workaround/env.lst b/tests/std/tests/GH_002620_construct_at_workaround/env.lst new file mode 100644 index 0000000000..351a8293d9 --- /dev/null +++ b/tests/std/tests/GH_002620_construct_at_workaround/env.lst @@ -0,0 +1,4 @@ +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +RUNALL_INCLUDE ..\usual_20_matrix.lst diff --git a/tests/std/tests/GH_002620_construct_at_workaround/test.cpp b/tests/std/tests/GH_002620_construct_at_workaround/test.cpp new file mode 100644 index 0000000000..fac0ea1e02 --- /dev/null +++ b/tests/std/tests/GH_002620_construct_at_workaround/test.cpp @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft Corporation. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +#include + +using namespace std; + +struct S { + int v; + S(int v) : v(v) {} + S(const S&) = delete; +}; + +union U { + char c; + S s; + U() : c{} {} + ~U() noexcept {} +}; + +struct copy_elider { + operator S() const { + return S(42); + } +}; + +int main() { + U u; + // GH-2620: : SFINAE constraint on construct_at prevents emplacing immovable objects with copy elision +#ifndef __EDG__ // TRANSITION, DevCom-XXXX + construct_at(&u.s, copy_elider{}); +#endif // TRANSITION, DevCom-XXXX +} From 2c70e9c6aae023c64bb2d020fbefc0a99762e73b Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Wed, 30 Mar 2022 15:47:50 +0700 Subject: [PATCH 2/6] add DevCom issues numbers and better formatting --- stl/inc/xutility | 9 +++++---- .../std/tests/GH_002620_construct_at_workaround/test.cpp | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/stl/inc/xutility b/stl/inc/xutility index 31a185e552..85586552ef 100644 --- a/stl/inc/xutility +++ b/stl/inc/xutility @@ -129,14 +129,15 @@ _NODISCARD constexpr void* _Voidify_iter(_Iter _It) noexcept { } #if _HAS_CXX20 +#if __EDG__ // TRANSITION, DevCom-10000405 template ()) _Ty(_STD declval<_Types>()...))>> #else // ^^^ no workaround // workaround vvv +template ()) _Ty(_STD declval<_Types>()...))>* = nullptr> -#endif // TRANSITION, DevCom-XXXX, DevCom-XXXX - constexpr _Ty* construct_at(_Ty* const _Location, _Types&&... _Args) noexcept( - noexcept(::new (_Voidify_iter(_Location)) _Ty(_STD forward<_Types>(_Args)...))) /* strengthened */ { +#endif // TRANSITION, DevCom-10000405 +constexpr _Ty* construct_at(_Ty* const _Location, _Types&&... _Args) noexcept( + noexcept(::new (_Voidify_iter(_Location)) _Ty(_STD forward<_Types>(_Args)...))) /* strengthened */ { return ::new (_Voidify_iter(_Location)) _Ty(_STD forward<_Types>(_Args)...); } #endif // _HAS_CXX20 diff --git a/tests/std/tests/GH_002620_construct_at_workaround/test.cpp b/tests/std/tests/GH_002620_construct_at_workaround/test.cpp index fac0ea1e02..32e5a4960a 100644 --- a/tests/std/tests/GH_002620_construct_at_workaround/test.cpp +++ b/tests/std/tests/GH_002620_construct_at_workaround/test.cpp @@ -27,7 +27,7 @@ struct copy_elider { int main() { U u; // GH-2620: : SFINAE constraint on construct_at prevents emplacing immovable objects with copy elision -#ifndef __EDG__ // TRANSITION, DevCom-XXXX +#ifndef __EDG__ // TRANSITION, DevCom-10000388 construct_at(&u.s, copy_elider{}); -#endif // TRANSITION, DevCom-XXXX +#endif // TRANSITION, DevCom-10000388 } From f6a075c91d908c87812a6466dad977af893c2ac5 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Wed, 30 Mar 2022 15:51:18 +0700 Subject: [PATCH 3/6] typo --- stl/inc/xutility | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/inc/xutility b/stl/inc/xutility index 85586552ef..b3f163c1c1 100644 --- a/stl/inc/xutility +++ b/stl/inc/xutility @@ -129,7 +129,7 @@ _NODISCARD constexpr void* _Voidify_iter(_Iter _It) noexcept { } #if _HAS_CXX20 -#if __EDG__ // TRANSITION, DevCom-10000405 +#ifdef __EDG__ // TRANSITION, DevCom-10000405 template ()) _Ty(_STD declval<_Types>()...))>> #else // ^^^ no workaround // workaround vvv From 8f5953ca1160cb2187b66445114894475932d7f8 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Wed, 30 Mar 2022 13:00:26 -0700 Subject: [PATCH 4/6] Code review nitpicks. --- tests/std/tests/GH_002620_construct_at_workaround/test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/std/tests/GH_002620_construct_at_workaround/test.cpp b/tests/std/tests/GH_002620_construct_at_workaround/test.cpp index 32e5a4960a..9fd1f0f386 100644 --- a/tests/std/tests/GH_002620_construct_at_workaround/test.cpp +++ b/tests/std/tests/GH_002620_construct_at_workaround/test.cpp @@ -7,7 +7,7 @@ using namespace std; struct S { int v; - S(int v) : v(v) {} + S(int v_) : v(v_) {} S(const S&) = delete; }; @@ -20,7 +20,7 @@ union U { struct copy_elider { operator S() const { - return S(42); + return S{42}; } }; From 02822f5ff52a39b7df7756094313fae31fa0a877 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Thu, 31 Mar 2022 14:37:59 +0700 Subject: [PATCH 5/6] update DevCom bug number --- stl/inc/xutility | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stl/inc/xutility b/stl/inc/xutility index b3f163c1c1..717148361c 100644 --- a/stl/inc/xutility +++ b/stl/inc/xutility @@ -129,13 +129,13 @@ _NODISCARD constexpr void* _Voidify_iter(_Iter _It) noexcept { } #if _HAS_CXX20 -#ifdef __EDG__ // TRANSITION, DevCom-10000405 +#ifdef __EDG__ // TRANSITION, DevCom-1691516 template ()) _Ty(_STD declval<_Types>()...))>> #else // ^^^ no workaround // workaround vvv template ()) _Ty(_STD declval<_Types>()...))>* = nullptr> -#endif // TRANSITION, DevCom-10000405 +#endif // TRANSITION, DevCom-1691516 constexpr _Ty* construct_at(_Ty* const _Location, _Types&&... _Args) noexcept( noexcept(::new (_Voidify_iter(_Location)) _Ty(_STD forward<_Types>(_Args)...))) /* strengthened */ { return ::new (_Voidify_iter(_Location)) _Ty(_STD forward<_Types>(_Args)...); From 8247c4c354c57b2350c5bb5b5b75c08bdd433532 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Thu, 31 Mar 2022 14:40:23 +0700 Subject: [PATCH 6/6] explicit --- tests/std/tests/GH_002620_construct_at_workaround/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/std/tests/GH_002620_construct_at_workaround/test.cpp b/tests/std/tests/GH_002620_construct_at_workaround/test.cpp index 9fd1f0f386..2b90c2d13b 100644 --- a/tests/std/tests/GH_002620_construct_at_workaround/test.cpp +++ b/tests/std/tests/GH_002620_construct_at_workaround/test.cpp @@ -7,7 +7,7 @@ using namespace std; struct S { int v; - S(int v_) : v(v_) {} + explicit S(int v_) : v(v_) {} S(const S&) = delete; };