Skip to content

Commit a7d789a

Browse files
committed
Move field initialized and add constinit test
1 parent 7a65205 commit a7d789a

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

libcxx/include/__utility/no_destroy.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct __uninitialized_tag {};
3030
// initialization using __emplace.
3131
template <class _Tp>
3232
struct __no_destroy {
33-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __no_destroy(__uninitialized_tag) {}
33+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __no_destroy(__uninitialized_tag) : __obj_() {}
3434

3535
template <class... _Args>
3636
_LIBCPP_HIDE_FROM_ABI explicit __no_destroy(_Args&&... __args) {
@@ -46,7 +46,7 @@ struct __no_destroy {
4646
_LIBCPP_HIDE_FROM_ABI _Tp const& __get() const { return *reinterpret_cast<const _Tp*>(__obj_); }
4747

4848
private:
49-
_ALIGNAS_TYPE(_Tp) char __obj_[sizeof(_Tp)] = {};
49+
_ALIGNAS_TYPE(_Tp) char __obj_[sizeof(_Tp)];
5050
};
5151

5252
_LIBCPP_END_NAMESPACE_STD

libcxx/test/libcxx/utilities/no_destroy.pass.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,8 @@ int main(int, char**) {
2626

2727
return 0;
2828
}
29+
#if TEST_STD_VER > 17
30+
// Test constexpr-constructibility.
31+
constinit std::__no_destroy<int> nd_int_const(std::__uninitialized_tag{});
32+
#endif
33+

0 commit comments

Comments
 (0)