diff --git a/stl/inc/xutility b/stl/inc/xutility index 6a198cd193..ced00e52e7 100644 --- a/stl/inc/xutility +++ b/stl/inc/xutility @@ -218,8 +218,13 @@ _NODISCARD constexpr void* _Voidify_iter(_Iter _It) noexcept { } #if _HAS_CXX20 +#ifdef __EDG__ // TRANSITION, DevCom-1691516 template ()) _Ty(_STD declval<_Types>()...))>> +#else // ^^^ no workaround // workaround vvv +template ()) _Ty(_STD declval<_Types>()...))>* = nullptr> +#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 */ { _MSVC_CONSTEXPR return ::new (_Voidify_iter(_Location)) _Ty(_STD forward<_Types>(_Args)...); diff --git a/tests/std/test.lst b/tests/std/test.lst index 6b3827e715..ee79137274 100644 --- a/tests/std/test.lst +++ b/tests/std/test.lst @@ -202,6 +202,7 @@ tests\GH_002431_byte_range_find_with_unreachable_sentinel tests\GH_002488_promise_not_default_constructible_types tests\GH_002558_format_presetPadding tests\GH_002581_common_reference_workaround +tests\GH_002620_construct_at_workaround tests\GH_002655_alternate_name_broke_linker tests\GH_002711_Zc_alignedNew- tests\GH_002760_syncstream_memory_leak 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..2b90c2d13b --- /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; + explicit 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-10000388 + construct_at(&u.s, copy_elider{}); +#endif // TRANSITION, DevCom-10000388 +}