Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change SFINAE constraint on construct_at (MSVC workaround) #2624

Merged
merged 8 commits into from
Jun 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions stl/inc/xutility
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,13 @@ _NODISCARD constexpr void* _Voidify_iter(_Iter _It) noexcept {
}

#if _HAS_CXX20
#ifdef __EDG__ // TRANSITION, DevCom-1691516
template <class _Ty, class... _Types,
class = void_t<decltype(::new (_STD declval<void*>()) _Ty(_STD declval<_Types>()...))>>
#else // ^^^ no workaround // workaround vvv
template <class _Ty, class... _Types,
void_t<decltype(::new (_STD declval<void*>()) _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)...);
Expand Down
1 change: 1 addition & 0 deletions tests/std/test.lst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions tests/std/tests/GH_002620_construct_at_workaround/env.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

RUNALL_INCLUDE ..\usual_20_matrix.lst
33 changes: 33 additions & 0 deletions tests/std/tests/GH_002620_construct_at_workaround/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <memory>

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: <xutility>: SFINAE constraint on construct_at prevents emplacing immovable objects with copy elision
#ifndef __EDG__ // TRANSITION, DevCom-10000388
fsb4000 marked this conversation as resolved.
Show resolved Hide resolved
construct_at(&u.s, copy_elider{});
#endif // TRANSITION, DevCom-10000388
}