Improve exception safety in dynamic_format_arg_store

This commit is contained in:
Victor Zverovich
2020-03-21 08:51:48 -07:00
parent 2951169481
commit dd97f4920c
2 changed files with 33 additions and 8 deletions

View File

@@ -284,7 +284,7 @@ FMT_NORETURN FMT_API void assert_fail(const char* file, int line,
#ifndef FMT_ASSERT
# ifdef NDEBUG
// FMT_ASSERT is not empty to avoid -Werror=empty-body.
// FMT_ASSERT is not empty to avoid -Werror=empty-body.
# define FMT_ASSERT(condition, message) ((void)0)
# else
# define FMT_ASSERT(condition, message) \
@@ -1236,11 +1236,11 @@ class dynamic_arg_list {
public:
template <typename T, typename Arg> const T& push(const Arg& arg) {
auto next = std::move(head_);
auto node = new typed_node<T>(arg);
head_.reset(node);
head_->next = std::move(next);
return node->value;
auto node = std::unique_ptr<typed_node<T>>(new typed_node<T>(arg));
auto& value = node->value;
node->next = std::move(head_);
head_ = std::move(node);
return value;
}
};
} // namespace internal