Skip to content

Commit a12ad78

Browse files
Fix ctors
1 parent f059be5 commit a12ad78

File tree

2 files changed

+55
-36
lines changed

2 files changed

+55
-36
lines changed

libcxx/include/__stacktrace/basic.h

Lines changed: 54 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,11 @@ class _LIBCPP_EXPORTED_FROM_ABI basic_stacktrace : private __stacktrace::base {
4848
friend struct hash<basic_stacktrace<_Allocator>>;
4949
friend struct __stacktrace::__to_string;
5050

51-
using _ATraits _LIBCPP_NODEBUG = allocator_traits<_Allocator>;
52-
constexpr static bool __kPropOnCopyAssign = _ATraits::propagate_on_container_copy_assignment::value;
53-
constexpr static bool __kPropOnMoveAssign = _ATraits::propagate_on_container_move_assignment::value;
54-
constexpr static bool __kPropOnSwap = _ATraits::propagate_on_container_swap::value;
55-
constexpr static bool __kAlwaysEqual = _ATraits::is_always_equal::value;
56-
constexpr static bool __kNoThrowDflConstruct = is_nothrow_default_constructible_v<_Allocator>;
51+
using _ATraits _LIBCPP_NODEBUG = allocator_traits<_Allocator>;
52+
constexpr static bool __kPropOnCopyAssign = _ATraits::propagate_on_container_copy_assignment::value;
53+
constexpr static bool __kPropOnMoveAssign = _ATraits::propagate_on_container_move_assignment::value;
54+
constexpr static bool __kPropOnSwap = _ATraits::propagate_on_container_swap::value;
55+
constexpr static bool __kAlwaysEqual = _ATraits::is_always_equal::value;
5756
constexpr static bool __kNoThrowAlloc =
5857
noexcept(noexcept(_Allocator().allocate(1)) && noexcept(_Allocator().allocate_at_least(1)));
5958

@@ -115,42 +114,63 @@ class _LIBCPP_EXPORTED_FROM_ABI basic_stacktrace : private __stacktrace::base {
115114

116115
_LIBCPP_EXPORTED_FROM_ABI constexpr ~basic_stacktrace() = default;
117116

118-
_LIBCPP_EXPORTED_FROM_ABI basic_stacktrace() noexcept(__kNoThrowDflConstruct) : basic_stacktrace(allocator_type()) {}
119-
120-
_LIBCPP_EXPORTED_FROM_ABI explicit basic_stacktrace(const allocator_type& __alloc) noexcept
121-
: base(__alloc), __entries_(__alloc_) {}
122-
123-
_LIBCPP_EXPORTED_FROM_ABI basic_stacktrace(basic_stacktrace const& __other)
124-
: basic_stacktrace(__other, _ATraits::select_on_container_copy_construction(__other.__alloc_)) {}
125-
126-
_LIBCPP_EXPORTED_FROM_ABI basic_stacktrace(basic_stacktrace&& __other) noexcept
127-
: __alloc_(std::move(__other.__alloc_)), __entries_(std::move(__other.__entries_)) {}
128-
129-
_LIBCPP_EXPORTED_FROM_ABI basic_stacktrace(basic_stacktrace const& __other, allocator_type const& __alloc)
130-
: base(__alloc), __alloc_(__alloc), __entries_(__other.__entries_, __alloc) {}
131-
132-
_LIBCPP_EXPORTED_FROM_ABI basic_stacktrace(basic_stacktrace&& __other, allocator_type const& __alloc)
133-
: base(__alloc) {
134-
__entries_ = {std::move(__other.__entries_), __alloc_};
135-
}
136-
137-
_LIBCPP_EXPORTED_FROM_ABI basic_stacktrace& operator=(const basic_stacktrace& __other) {
138-
if (this != std::addressof(__other)) {
117+
// clang-format off
118+
119+
_LIBCPP_EXPORTED_FROM_ABI explicit
120+
basic_stacktrace(const allocator_type& __alloc) /* not noexcept */
121+
: base(__alloc)
122+
, __alloc_(__alloc)
123+
, __entries_(__alloc_) {}
124+
125+
_LIBCPP_EXPORTED_FROM_ABI
126+
basic_stacktrace(basic_stacktrace const& __other,
127+
allocator_type const& __alloc) /* not noexcept */
128+
: base(__alloc)
129+
, __alloc_(__alloc)
130+
, __entries_(__other.__entries_, __alloc) {}
131+
132+
_LIBCPP_EXPORTED_FROM_ABI
133+
basic_stacktrace(basic_stacktrace&& __other,
134+
allocator_type const& __alloc) /* not noexcept */
135+
: base(__alloc)
136+
, __alloc_(__alloc)
137+
, __entries_{std::move(__other.__entries_), __alloc_} {}
138+
139+
_LIBCPP_EXPORTED_FROM_ABI
140+
basic_stacktrace() noexcept(is_nothrow_default_constructible_v<allocator_type>)
141+
: basic_stacktrace(allocator_type()) {}
142+
143+
_LIBCPP_EXPORTED_FROM_ABI
144+
basic_stacktrace(basic_stacktrace const& __other) noexcept
145+
: basic_stacktrace(__other,
146+
_ATraits::select_on_container_copy_construction(__other.__alloc_)) {}
147+
148+
_LIBCPP_EXPORTED_FROM_ABI
149+
basic_stacktrace(basic_stacktrace&& __other) noexcept
150+
: basic_stacktrace(std::move(__other),
151+
__other.__alloc_) {}
152+
153+
_LIBCPP_EXPORTED_FROM_ABI
154+
basic_stacktrace& operator=(const basic_stacktrace& __other) /* not noexcept */ {
155+
if (std::addressof(__other) != this) {
139156
if (__kPropOnCopyAssign) {
140-
__alloc_ = __other.__alloc_;
157+
new (this) basic_stacktrace(__other, __other.__alloc_);
158+
} else {
159+
new (this) basic_stacktrace(__other);
141160
}
142-
__entries_ = {__other.__entries_, __alloc_};
143161
}
144162
return *this;
145163
}
146164

147-
_LIBCPP_EXPORTED_FROM_ABI basic_stacktrace&
148-
operator=(basic_stacktrace&& __other) noexcept(__kPropOnMoveAssign || __kAlwaysEqual) {
149-
if (this != std::addressof(__other)) {
165+
_LIBCPP_EXPORTED_FROM_ABI
166+
basic_stacktrace& operator=(basic_stacktrace&& __other)
167+
noexcept(__kPropOnMoveAssign || __kAlwaysEqual) {
168+
if (std::addressof(__other) != this) {
150169
if (__kPropOnMoveAssign) {
151-
__alloc_ = std::move(__other.__alloc_);
170+
new (this) basic_stacktrace(std::move(__other), __other.__alloc_);
171+
} else {
172+
new (this) basic_stacktrace(std::move(__other));
152173
}
153-
__entries_ = {std::move(__other.__entries_), __alloc_};
154174
}
155175
return *this;
156176
}

libcxx/test/std/diagnostics/stacktrace/basic.cons/ctor_with_alloc.pass.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ void test_construct_with_alloc_noexcept() {
3232

3333
using A1 = std::allocator<std::stacktrace_entry>;
3434
static_assert(std::is_nothrow_constructible_v<A1>);
35-
static_assert(noexcept(std::basic_stacktrace<A1>(A1())));
36-
3735
using A2 = TestAlloc<std::stacktrace_entry, false, true, true, true>;
3836
static_assert(!std::is_nothrow_constructible_v<A2>);
37+
3938
static_assert(!noexcept(std::basic_stacktrace<A2>(A2())));
4039
}
4140

0 commit comments

Comments
 (0)