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 3 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 @@ -129,8 +129,13 @@ _NODISCARD constexpr void* _Voidify_iter(_Iter _It) noexcept {
}

#if _HAS_CXX20
#ifdef __EDG__ // TRANSITION, DevCom-10000405
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-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)...);
Expand Down
1 change: 1 addition & 0 deletions tests/std/test.lst
Original file line number Diff line number Diff line change
Expand Up @@ -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
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;
S(int v) : v(v) {}
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
S(const S&) = delete;
};

union U {
char c;
S s;
U() : c{} {}
~U() noexcept {}
};

struct copy_elider {
operator S() const {
return S(42);
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
}
};

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
}