Skip to content

Commit cd9829c

Browse files
authored
[libc++][NFC] Use __construct_at and __destroy_at instead of using preprocessor conditionals (#70866)
1 parent 2c54513 commit cd9829c

File tree

4 files changed

+5
-17
lines changed

4 files changed

+5
-17
lines changed

libcxx/include/__memory/allocator_traits.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -300,11 +300,7 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits
300300
__enable_if_t<!__has_construct<allocator_type, _Tp*, _Args...>::value> >
301301
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
302302
static void construct(allocator_type&, _Tp* __p, _Args&&... __args) {
303-
#if _LIBCPP_STD_VER >= 20
304-
_VSTD::construct_at(__p, _VSTD::forward<_Args>(__args)...);
305-
#else
306-
::new ((void*)__p) _Tp(_VSTD::forward<_Args>(__args)...);
307-
#endif
303+
std::__construct_at(__p, std::forward<_Args>(__args)...);
308304
}
309305

310306
template <class _Tp, class =
@@ -319,11 +315,7 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits
319315
__enable_if_t<!__has_destroy<allocator_type, _Tp*>::value> >
320316
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
321317
static void destroy(allocator_type&, _Tp* __p) {
322-
#if _LIBCPP_STD_VER >= 20
323-
_VSTD::destroy_at(__p);
324-
#else
325-
__p->~_Tp();
326-
#endif
318+
std::__destroy_at(__p);
327319
}
328320

329321
template <class _Ap = _Alloc, class =

libcxx/include/optional

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -416,11 +416,7 @@ struct __optional_storage_base : __optional_destruct_base<_Tp>
416416
_LIBCPP_CONSTEXPR_SINCE_CXX20 void __construct(_Args&&... __args)
417417
{
418418
_LIBCPP_ASSERT_INTERNAL(!has_value(), "__construct called for engaged __optional_storage");
419-
#if _LIBCPP_STD_VER >= 20
420-
_VSTD::construct_at(_VSTD::addressof(this->__val_), _VSTD::forward<_Args>(__args)...);
421-
#else
422-
::new ((void*)_VSTD::addressof(this->__val_)) value_type(_VSTD::forward<_Args>(__args)...);
423-
#endif
419+
std::__construct_at(std::addressof(this->__val_), std::forward<_Args>(__args)...);
424420
this->__engaged_ = true;
425421
}
426422

libcxx/test/std/containers/sequences/vector/vector.cons/copy.move_only.verify.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616

1717
void f() {
1818
std::vector<MoveOnly> v;
19-
std::vector<MoveOnly> copy = v; // expected-error-re@* {{{{(no matching function for call to 'construct_at')|(call to implicitly-deleted copy constructor of 'MoveOnly')|(call to deleted constructor of 'MoveOnly')}}}}
19+
std::vector<MoveOnly> copy = v; // expected-error-re@* {{{{(no matching function for call to '__construct_at')|(call to deleted constructor of 'MoveOnly')}}}}
2020
}

libcxx/test/std/containers/sequences/vector/vector.modifiers/resize_not_move_insertable.verify.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ int main(int, char**) {
3333

3434
// Other diagnostics that might be seen as Clang tries to continue compiling:
3535
// expected-error@* 0-2 {{call to deleted constructor}}
36-
// expected-error@* 0-2 {{no matching function for call to 'construct_at'}}
36+
// expected-error@* 0-2 {{no matching function for call to '__construct_at'}}
3737
{
3838

3939
std::vector<BadUserNoCookie<1> > x;

0 commit comments

Comments
 (0)