FMT_NOEXCEPT -> noexcept

This commit is contained in:
Victor Zverovich 2022-01-20 16:55:47 -08:00
parent 6240d02011
commit c28500556a
13 changed files with 149 additions and 170 deletions

View File

@ -214,17 +214,16 @@ FMT_BEGIN_DETAIL_NAMESPACE
// color is a struct of either a rgb color or a terminal color. // color is a struct of either a rgb color or a terminal color.
struct color_type { struct color_type {
FMT_CONSTEXPR color_type() FMT_NOEXCEPT : is_rgb(), value{} {} FMT_CONSTEXPR color_type() noexcept : is_rgb(), value{} {}
FMT_CONSTEXPR color_type(color rgb_color) FMT_NOEXCEPT : is_rgb(true), FMT_CONSTEXPR color_type(color rgb_color) noexcept : is_rgb(true), value{} {
value{} {
value.rgb_color = static_cast<uint32_t>(rgb_color); value.rgb_color = static_cast<uint32_t>(rgb_color);
} }
FMT_CONSTEXPR color_type(rgb rgb_color) FMT_NOEXCEPT : is_rgb(true), value{} { FMT_CONSTEXPR color_type(rgb rgb_color) noexcept : is_rgb(true), value{} {
value.rgb_color = (static_cast<uint32_t>(rgb_color.r) << 16) | value.rgb_color = (static_cast<uint32_t>(rgb_color.r) << 16) |
(static_cast<uint32_t>(rgb_color.g) << 8) | rgb_color.b; (static_cast<uint32_t>(rgb_color.g) << 8) | rgb_color.b;
} }
FMT_CONSTEXPR color_type(terminal_color term_color) FMT_NOEXCEPT : is_rgb(), FMT_CONSTEXPR color_type(terminal_color term_color) noexcept
value{} { : is_rgb(), value{} {
value.term_color = static_cast<uint8_t>(term_color); value.term_color = static_cast<uint8_t>(term_color);
} }
bool is_rgb; bool is_rgb;
@ -239,10 +238,8 @@ FMT_END_DETAIL_NAMESPACE
/** A text style consisting of foreground and background colors and emphasis. */ /** A text style consisting of foreground and background colors and emphasis. */
class text_style { class text_style {
public: public:
FMT_CONSTEXPR text_style(emphasis em = emphasis()) FMT_NOEXCEPT FMT_CONSTEXPR text_style(emphasis em = emphasis()) noexcept
: set_foreground_color(), : set_foreground_color(), set_background_color(), ems(em) {}
set_background_color(),
ems(em) {}
FMT_CONSTEXPR text_style& operator|=(const text_style& rhs) { FMT_CONSTEXPR text_style& operator|=(const text_style& rhs) {
if (!set_foreground_color) { if (!set_foreground_color) {
@ -283,34 +280,32 @@ class text_style {
return lhs.and_assign(rhs); return lhs.and_assign(rhs);
} }
FMT_CONSTEXPR bool has_foreground() const FMT_NOEXCEPT { FMT_CONSTEXPR bool has_foreground() const noexcept {
return set_foreground_color; return set_foreground_color;
} }
FMT_CONSTEXPR bool has_background() const FMT_NOEXCEPT { FMT_CONSTEXPR bool has_background() const noexcept {
return set_background_color; return set_background_color;
} }
FMT_CONSTEXPR bool has_emphasis() const FMT_NOEXCEPT { FMT_CONSTEXPR bool has_emphasis() const noexcept {
return static_cast<uint8_t>(ems) != 0; return static_cast<uint8_t>(ems) != 0;
} }
FMT_CONSTEXPR detail::color_type get_foreground() const FMT_NOEXCEPT { FMT_CONSTEXPR detail::color_type get_foreground() const noexcept {
FMT_ASSERT(has_foreground(), "no foreground specified for this style"); FMT_ASSERT(has_foreground(), "no foreground specified for this style");
return foreground_color; return foreground_color;
} }
FMT_CONSTEXPR detail::color_type get_background() const FMT_NOEXCEPT { FMT_CONSTEXPR detail::color_type get_background() const noexcept {
FMT_ASSERT(has_background(), "no background specified for this style"); FMT_ASSERT(has_background(), "no background specified for this style");
return background_color; return background_color;
} }
FMT_CONSTEXPR emphasis get_emphasis() const FMT_NOEXCEPT { FMT_CONSTEXPR emphasis get_emphasis() const noexcept {
FMT_ASSERT(has_emphasis(), "no emphasis specified for this style"); FMT_ASSERT(has_emphasis(), "no emphasis specified for this style");
return ems; return ems;
} }
private: private:
FMT_CONSTEXPR text_style(bool is_foreground, FMT_CONSTEXPR text_style(bool is_foreground,
detail::color_type text_color) FMT_NOEXCEPT detail::color_type text_color) noexcept
: set_foreground_color(), : set_foreground_color(), set_background_color(), ems() {
set_background_color(),
ems() {
if (is_foreground) { if (is_foreground) {
foreground_color = text_color; foreground_color = text_color;
set_foreground_color = true; set_foreground_color = true;
@ -345,11 +340,11 @@ class text_style {
return *this; return *this;
} }
friend FMT_CONSTEXPR_DECL text_style fg(detail::color_type foreground) friend FMT_CONSTEXPR_DECL text_style
FMT_NOEXCEPT; fg(detail::color_type foreground) noexcept;
friend FMT_CONSTEXPR_DECL text_style bg(detail::color_type background) friend FMT_CONSTEXPR_DECL text_style
FMT_NOEXCEPT; bg(detail::color_type background) noexcept;
detail::color_type foreground_color; detail::color_type foreground_color;
detail::color_type background_color; detail::color_type background_color;
@ -359,17 +354,16 @@ class text_style {
}; };
/** Creates a text style from the foreground (text) color. */ /** Creates a text style from the foreground (text) color. */
FMT_CONSTEXPR inline text_style fg(detail::color_type foreground) FMT_NOEXCEPT { FMT_CONSTEXPR inline text_style fg(detail::color_type foreground) noexcept {
return text_style(true, foreground); return text_style(true, foreground);
} }
/** Creates a text style from the background color. */ /** Creates a text style from the background color. */
FMT_CONSTEXPR inline text_style bg(detail::color_type background) FMT_NOEXCEPT { FMT_CONSTEXPR inline text_style bg(detail::color_type background) noexcept {
return text_style(false, background); return text_style(false, background);
} }
FMT_CONSTEXPR inline text_style operator|(emphasis lhs, FMT_CONSTEXPR inline text_style operator|(emphasis lhs, emphasis rhs) noexcept {
emphasis rhs) FMT_NOEXCEPT {
return text_style(lhs) | rhs; return text_style(lhs) | rhs;
} }
@ -377,7 +371,7 @@ FMT_BEGIN_DETAIL_NAMESPACE
template <typename Char> struct ansi_color_escape { template <typename Char> struct ansi_color_escape {
FMT_CONSTEXPR ansi_color_escape(detail::color_type text_color, FMT_CONSTEXPR ansi_color_escape(detail::color_type text_color,
const char* esc) FMT_NOEXCEPT { const char* esc) noexcept {
// If we have a terminal color, we need to output another escape code // If we have a terminal color, we need to output another escape code
// sequence. // sequence.
if (!text_color.is_rgb) { if (!text_color.is_rgb) {
@ -412,7 +406,7 @@ template <typename Char> struct ansi_color_escape {
to_esc(color.b, buffer + 15, 'm'); to_esc(color.b, buffer + 15, 'm');
buffer[19] = static_cast<Char>(0); buffer[19] = static_cast<Char>(0);
} }
FMT_CONSTEXPR ansi_color_escape(emphasis em) FMT_NOEXCEPT { FMT_CONSTEXPR ansi_color_escape(emphasis em) noexcept {
uint8_t em_codes[num_emphases] = {}; uint8_t em_codes[num_emphases] = {};
if (has_emphasis(em, emphasis::bold)) em_codes[0] = 1; if (has_emphasis(em, emphasis::bold)) em_codes[0] = 1;
if (has_emphasis(em, emphasis::faint)) em_codes[1] = 2; if (has_emphasis(em, emphasis::faint)) em_codes[1] = 2;
@ -433,10 +427,10 @@ template <typename Char> struct ansi_color_escape {
} }
buffer[index++] = static_cast<Char>(0); buffer[index++] = static_cast<Char>(0);
} }
FMT_CONSTEXPR operator const Char*() const FMT_NOEXCEPT { return buffer; } FMT_CONSTEXPR operator const Char*() const noexcept { return buffer; }
FMT_CONSTEXPR const Char* begin() const FMT_NOEXCEPT { return buffer; } FMT_CONSTEXPR const Char* begin() const noexcept { return buffer; }
FMT_CONSTEXPR_CHAR_TRAITS const Char* end() const FMT_NOEXCEPT { FMT_CONSTEXPR_CHAR_TRAITS const Char* end() const noexcept {
return buffer + std::char_traits<Char>::length(buffer); return buffer + std::char_traits<Char>::length(buffer);
} }
@ -445,32 +439,31 @@ template <typename Char> struct ansi_color_escape {
Char buffer[7u + 3u * num_emphases + 1u]; Char buffer[7u + 3u * num_emphases + 1u];
static FMT_CONSTEXPR void to_esc(uint8_t c, Char* out, static FMT_CONSTEXPR void to_esc(uint8_t c, Char* out,
char delimiter) FMT_NOEXCEPT { char delimiter) noexcept {
out[0] = static_cast<Char>('0' + c / 100); out[0] = static_cast<Char>('0' + c / 100);
out[1] = static_cast<Char>('0' + c / 10 % 10); out[1] = static_cast<Char>('0' + c / 10 % 10);
out[2] = static_cast<Char>('0' + c % 10); out[2] = static_cast<Char>('0' + c % 10);
out[3] = static_cast<Char>(delimiter); out[3] = static_cast<Char>(delimiter);
} }
static FMT_CONSTEXPR bool has_emphasis(emphasis em, static FMT_CONSTEXPR bool has_emphasis(emphasis em, emphasis mask) noexcept {
emphasis mask) FMT_NOEXCEPT {
return static_cast<uint8_t>(em) & static_cast<uint8_t>(mask); return static_cast<uint8_t>(em) & static_cast<uint8_t>(mask);
} }
}; };
template <typename Char> template <typename Char>
FMT_CONSTEXPR ansi_color_escape<Char> make_foreground_color( FMT_CONSTEXPR ansi_color_escape<Char> make_foreground_color(
detail::color_type foreground) FMT_NOEXCEPT { detail::color_type foreground) noexcept {
return ansi_color_escape<Char>(foreground, "\x1b[38;2;"); return ansi_color_escape<Char>(foreground, "\x1b[38;2;");
} }
template <typename Char> template <typename Char>
FMT_CONSTEXPR ansi_color_escape<Char> make_background_color( FMT_CONSTEXPR ansi_color_escape<Char> make_background_color(
detail::color_type background) FMT_NOEXCEPT { detail::color_type background) noexcept {
return ansi_color_escape<Char>(background, "\x1b[48;2;"); return ansi_color_escape<Char>(background, "\x1b[48;2;");
} }
template <typename Char> template <typename Char>
FMT_CONSTEXPR ansi_color_escape<Char> make_emphasis(emphasis em) FMT_NOEXCEPT { FMT_CONSTEXPR ansi_color_escape<Char> make_emphasis(emphasis em) noexcept {
return ansi_color_escape<Char>(em); return ansi_color_escape<Char>(em);
} }

View File

@ -144,9 +144,6 @@
# define FMT_EXCEPTIONS 1 # define FMT_EXCEPTIONS 1
# endif # endif
#endif #endif
#ifndef FMT_NOEXCEPT
# define FMT_NOEXCEPT noexcept
#endif
// [[noreturn]] is disabled on MSVC and NVCC because of bogus unreachable code // [[noreturn]] is disabled on MSVC and NVCC because of bogus unreachable code
// warnings. // warnings.
@ -333,7 +330,7 @@ FMT_BEGIN_DETAIL_NAMESPACE
template <typename... T> FMT_CONSTEXPR void ignore_unused(const T&...) {} template <typename... T> FMT_CONSTEXPR void ignore_unused(const T&...) {}
constexpr FMT_INLINE auto is_constant_evaluated(bool default_value = false) constexpr FMT_INLINE auto is_constant_evaluated(bool default_value = false)
FMT_NOEXCEPT -> bool { noexcept -> bool {
#ifdef __cpp_lib_is_constant_evaluated #ifdef __cpp_lib_is_constant_evaluated
ignore_unused(default_value); ignore_unused(default_value);
return std::is_constant_evaluated(); return std::is_constant_evaluated();
@ -435,10 +432,10 @@ template <typename Char> class basic_string_view {
using value_type = Char; using value_type = Char;
using iterator = const Char*; using iterator = const Char*;
constexpr basic_string_view() FMT_NOEXCEPT : data_(nullptr), size_(0) {} constexpr basic_string_view() noexcept : data_(nullptr), size_(0) {}
/** Constructs a string reference object from a C string and a size. */ /** Constructs a string reference object from a C string and a size. */
constexpr basic_string_view(const Char* s, size_t count) FMT_NOEXCEPT constexpr basic_string_view(const Char* s, size_t count) noexcept
: data_(s), : data_(s),
size_(count) {} size_(count) {}
@ -460,29 +457,29 @@ template <typename Char> class basic_string_view {
/** Constructs a string reference from a ``std::basic_string`` object. */ /** Constructs a string reference from a ``std::basic_string`` object. */
template <typename Traits, typename Alloc> template <typename Traits, typename Alloc>
FMT_CONSTEXPR basic_string_view( FMT_CONSTEXPR basic_string_view(
const std::basic_string<Char, Traits, Alloc>& s) FMT_NOEXCEPT const std::basic_string<Char, Traits, Alloc>& s) noexcept
: data_(s.data()), : data_(s.data()),
size_(s.size()) {} size_(s.size()) {}
template <typename S, FMT_ENABLE_IF(std::is_same< template <typename S, FMT_ENABLE_IF(std::is_same<
S, detail::std_string_view<Char>>::value)> S, detail::std_string_view<Char>>::value)>
FMT_CONSTEXPR basic_string_view(S s) FMT_NOEXCEPT : data_(s.data()), FMT_CONSTEXPR basic_string_view(S s) noexcept : data_(s.data()),
size_(s.size()) {} size_(s.size()) {}
/** Returns a pointer to the string data. */ /** Returns a pointer to the string data. */
constexpr auto data() const FMT_NOEXCEPT -> const Char* { return data_; } constexpr auto data() const noexcept -> const Char* { return data_; }
/** Returns the string size. */ /** Returns the string size. */
constexpr auto size() const FMT_NOEXCEPT -> size_t { return size_; } constexpr auto size() const noexcept -> size_t { return size_; }
constexpr auto begin() const FMT_NOEXCEPT -> iterator { return data_; } constexpr auto begin() const noexcept -> iterator { return data_; }
constexpr auto end() const FMT_NOEXCEPT -> iterator { return data_ + size_; } constexpr auto end() const noexcept -> iterator { return data_ + size_; }
constexpr auto operator[](size_t pos) const FMT_NOEXCEPT -> const Char& { constexpr auto operator[](size_t pos) const noexcept -> const Char& {
return data_[pos]; return data_[pos];
} }
FMT_CONSTEXPR void remove_prefix(size_t n) FMT_NOEXCEPT { FMT_CONSTEXPR void remove_prefix(size_t n) noexcept {
data_ += n; data_ += n;
size_ -= n; size_ -= n;
} }
@ -629,14 +626,14 @@ class basic_format_parse_context : private ErrorHandler {
Returns an iterator to the beginning of the format string range being Returns an iterator to the beginning of the format string range being
parsed. parsed.
*/ */
constexpr auto begin() const FMT_NOEXCEPT -> iterator { constexpr auto begin() const noexcept -> iterator {
return format_str_.begin(); return format_str_.begin();
} }
/** /**
Returns an iterator past the end of the format string range being parsed. Returns an iterator past the end of the format string range being parsed.
*/ */
constexpr auto end() const FMT_NOEXCEPT -> iterator { constexpr auto end() const noexcept -> iterator {
return format_str_.end(); return format_str_.end();
} }
@ -765,10 +762,10 @@ template <typename T> class buffer {
protected: protected:
// Don't initialize ptr_ since it is not accessed to save a few cycles. // Don't initialize ptr_ since it is not accessed to save a few cycles.
FMT_MSC_WARNING(suppress : 26495) FMT_MSC_WARNING(suppress : 26495)
buffer(size_t sz) FMT_NOEXCEPT : size_(sz), capacity_(sz) {} buffer(size_t sz) noexcept : size_(sz), capacity_(sz) {}
FMT_CONSTEXPR20 buffer(T* p = nullptr, size_t sz = 0, FMT_CONSTEXPR20 buffer(T* p = nullptr, size_t sz = 0,
size_t cap = 0) FMT_NOEXCEPT : ptr_(p), size_t cap = 0) noexcept : ptr_(p),
size_(sz), size_(sz),
capacity_(cap) {} capacity_(cap) {}
@ -776,7 +773,7 @@ template <typename T> class buffer {
buffer(buffer&&) = default; buffer(buffer&&) = default;
/** Sets the buffer data and capacity. */ /** Sets the buffer data and capacity. */
FMT_CONSTEXPR void set(T* buf_data, size_t buf_capacity) FMT_NOEXCEPT { FMT_CONSTEXPR void set(T* buf_data, size_t buf_capacity) noexcept {
ptr_ = buf_data; ptr_ = buf_data;
capacity_ = buf_capacity; capacity_ = buf_capacity;
} }
@ -791,23 +788,23 @@ template <typename T> class buffer {
buffer(const buffer&) = delete; buffer(const buffer&) = delete;
void operator=(const buffer&) = delete; void operator=(const buffer&) = delete;
auto begin() FMT_NOEXCEPT -> T* { return ptr_; } auto begin() noexcept -> T* { return ptr_; }
auto end() FMT_NOEXCEPT -> T* { return ptr_ + size_; } auto end() noexcept -> T* { return ptr_ + size_; }
auto begin() const FMT_NOEXCEPT -> const T* { return ptr_; } auto begin() const noexcept -> const T* { return ptr_; }
auto end() const FMT_NOEXCEPT -> const T* { return ptr_ + size_; } auto end() const noexcept -> const T* { return ptr_ + size_; }
/** Returns the size of this buffer. */ /** Returns the size of this buffer. */
constexpr auto size() const FMT_NOEXCEPT -> size_t { return size_; } constexpr auto size() const noexcept -> size_t { return size_; }
/** Returns the capacity of this buffer. */ /** Returns the capacity of this buffer. */
constexpr auto capacity() const FMT_NOEXCEPT -> size_t { return capacity_; } constexpr auto capacity() const noexcept -> size_t { return capacity_; }
/** Returns a pointer to the buffer data. */ /** Returns a pointer to the buffer data. */
FMT_CONSTEXPR auto data() FMT_NOEXCEPT -> T* { return ptr_; } FMT_CONSTEXPR auto data() noexcept -> T* { return ptr_; }
/** Returns a pointer to the buffer data. */ /** Returns a pointer to the buffer data. */
FMT_CONSTEXPR auto data() const FMT_NOEXCEPT -> const T* { return ptr_; } FMT_CONSTEXPR auto data() const noexcept -> const T* { return ptr_; }
/** Clears this buffer. */ /** Clears this buffer. */
void clear() { size_ = 0; } void clear() { size_ = 0; }
@ -1495,12 +1492,12 @@ class appender : public std::back_insert_iterator<detail::buffer<char>> {
public: public:
using std::back_insert_iterator<detail::buffer<char>>::back_insert_iterator; using std::back_insert_iterator<detail::buffer<char>>::back_insert_iterator;
appender(base it) FMT_NOEXCEPT : base(it) {} appender(base it) noexcept : base(it) {}
using _Unchecked_type = appender; // Mark iterator as checked. using _Unchecked_type = appender; // Mark iterator as checked.
auto operator++() FMT_NOEXCEPT -> appender& { return *this; } auto operator++() noexcept -> appender& { return *this; }
auto operator++(int) FMT_NOEXCEPT -> appender { return *this; } auto operator++(int) noexcept -> appender { return *this; }
}; };
// A formatting argument. It is a trivially copyable/constructible type to // A formatting argument. It is a trivially copyable/constructible type to
@ -1546,7 +1543,7 @@ template <typename Context> class basic_format_arg {
constexpr basic_format_arg() : type_(detail::type::none_type) {} constexpr basic_format_arg() : type_(detail::type::none_type) {}
constexpr explicit operator bool() const FMT_NOEXCEPT { constexpr explicit operator bool() const noexcept {
return type_ != detail::type::none_type; return type_ != detail::type::none_type;
} }
@ -1656,7 +1653,7 @@ class locale_ref {
constexpr locale_ref() : locale_(nullptr) {} constexpr locale_ref() : locale_(nullptr) {}
template <typename Locale> explicit locale_ref(const Locale& loc); template <typename Locale> explicit locale_ref(const Locale& loc);
explicit operator bool() const FMT_NOEXCEPT { return locale_ != nullptr; } explicit operator bool() const noexcept { return locale_ != nullptr; }
template <typename Locale> auto get() const -> Locale; template <typename Locale> auto get() const -> Locale;
}; };

View File

@ -58,7 +58,7 @@ inline int fmt_snprintf(char* buffer, size_t size, const char* format, ...) {
#endif // _MSC_VER #endif // _MSC_VER
FMT_FUNC void format_error_code(detail::buffer<char>& out, int error_code, FMT_FUNC void format_error_code(detail::buffer<char>& out, int error_code,
string_view message) FMT_NOEXCEPT { string_view message) noexcept {
// Report error code making sure that the output fits into // Report error code making sure that the output fits into
// inline_buffer_size to avoid dynamic memory allocation and potential // inline_buffer_size to avoid dynamic memory allocation and potential
// bad_alloc. // bad_alloc.
@ -81,7 +81,7 @@ FMT_FUNC void format_error_code(detail::buffer<char>& out, int error_code,
} }
FMT_FUNC void report_error(format_func func, int error_code, FMT_FUNC void report_error(format_func func, int error_code,
const char* message) FMT_NOEXCEPT { const char* message) noexcept {
memory_buffer full_message; memory_buffer full_message;
func(full_message, error_code, message); func(full_message, error_code, message);
// Don't use fwrite_fully because the latter may throw. // Don't use fwrite_fully because the latter may throw.
@ -130,7 +130,7 @@ template <typename Char> FMT_FUNC Char decimal_point_impl(locale_ref) {
} // namespace detail } // namespace detail
#if !FMT_MSC_VER #if !FMT_MSC_VER
FMT_API FMT_FUNC format_error::~format_error() FMT_NOEXCEPT = default; FMT_API FMT_FUNC format_error::~format_error() noexcept = default;
#endif #endif
FMT_FUNC std::system_error vsystem_error(int error_code, string_view format_str, FMT_FUNC std::system_error vsystem_error(int error_code, string_view format_str,
@ -792,14 +792,13 @@ struct uint128_wrapper {
uint64_t high_; uint64_t high_;
uint64_t low_; uint64_t low_;
constexpr uint128_wrapper(uint64_t high, uint64_t low) FMT_NOEXCEPT constexpr uint128_wrapper(uint64_t high, uint64_t low) noexcept
: high_{high}, : high_{high}, low_{low} {}
low_{low} {}
constexpr uint64_t high() const FMT_NOEXCEPT { return high_; } constexpr uint64_t high() const noexcept { return high_; }
constexpr uint64_t low() const FMT_NOEXCEPT { return low_; } constexpr uint64_t low() const noexcept { return low_; }
uint128_wrapper& operator+=(uint64_t n) FMT_NOEXCEPT { uint128_wrapper& operator+=(uint64_t n) noexcept {
#if FMT_HAS_BUILTIN(__builtin_addcll) #if FMT_HAS_BUILTIN(__builtin_addcll)
unsigned long long carry; unsigned long long carry;
low_ = __builtin_addcll(low_, n, 0, &carry); low_ = __builtin_addcll(low_, n, 0, &carry);
@ -823,7 +822,7 @@ struct uint128_wrapper {
// Implementation of Dragonbox algorithm: https://github.com/jk-jeon/dragonbox. // Implementation of Dragonbox algorithm: https://github.com/jk-jeon/dragonbox.
namespace dragonbox { namespace dragonbox {
// Computes 128-bit result of multiplication of two 64-bit unsigned integers. // Computes 128-bit result of multiplication of two 64-bit unsigned integers.
inline uint128_wrapper umul128(uint64_t x, uint64_t y) FMT_NOEXCEPT { inline uint128_wrapper umul128(uint64_t x, uint64_t y) noexcept {
#if FMT_USE_INT128 #if FMT_USE_INT128
auto p = static_cast<uint128_t>(x) * static_cast<uint128_t>(y); auto p = static_cast<uint128_t>(x) * static_cast<uint128_t>(y);
return {static_cast<uint64_t>(p >> 64), static_cast<uint64_t>(p)}; return {static_cast<uint64_t>(p >> 64), static_cast<uint64_t>(p)};
@ -852,7 +851,7 @@ inline uint128_wrapper umul128(uint64_t x, uint64_t y) FMT_NOEXCEPT {
} }
// Computes upper 64 bits of multiplication of two 64-bit unsigned integers. // Computes upper 64 bits of multiplication of two 64-bit unsigned integers.
inline uint64_t umul128_upper64(uint64_t x, uint64_t y) FMT_NOEXCEPT { inline uint64_t umul128_upper64(uint64_t x, uint64_t y) noexcept {
#if FMT_USE_INT128 #if FMT_USE_INT128
auto p = static_cast<uint128_t>(x) * static_cast<uint128_t>(y); auto p = static_cast<uint128_t>(x) * static_cast<uint128_t>(y);
return static_cast<uint64_t>(p >> 64); return static_cast<uint64_t>(p >> 64);
@ -866,7 +865,7 @@ inline uint64_t umul128_upper64(uint64_t x, uint64_t y) FMT_NOEXCEPT {
// Computes upper 128 bits of multiplication of a 64-bit unsigned integer and a // Computes upper 128 bits of multiplication of a 64-bit unsigned integer and a
// 128-bit unsigned integer. // 128-bit unsigned integer.
inline uint128_wrapper umul192_upper128(uint64_t x, inline uint128_wrapper umul192_upper128(uint64_t x,
uint128_wrapper y) FMT_NOEXCEPT { uint128_wrapper y) noexcept {
uint128_wrapper r = umul128(x, y.high()); uint128_wrapper r = umul128(x, y.high());
r += umul128_upper64(x, y.low()); r += umul128_upper64(x, y.low());
return r; return r;
@ -874,14 +873,14 @@ inline uint128_wrapper umul192_upper128(uint64_t x,
// Computes upper 64 bits of multiplication of a 32-bit unsigned integer and a // Computes upper 64 bits of multiplication of a 32-bit unsigned integer and a
// 64-bit unsigned integer. // 64-bit unsigned integer.
inline uint64_t umul96_upper64(uint32_t x, uint64_t y) FMT_NOEXCEPT { inline uint64_t umul96_upper64(uint32_t x, uint64_t y) noexcept {
return umul128_upper64(uint64_t(x) << 32, y); return umul128_upper64(uint64_t(x) << 32, y);
} }
// Computes lower 128 bits of multiplication of a 64-bit unsigned integer and a // Computes lower 128 bits of multiplication of a 64-bit unsigned integer and a
// 128-bit unsigned integer. // 128-bit unsigned integer.
inline uint128_wrapper umul192_lower128(uint64_t x, inline uint128_wrapper umul192_lower128(uint64_t x,
uint128_wrapper y) FMT_NOEXCEPT { uint128_wrapper y) noexcept {
uint64_t high = x * y.high(); uint64_t high = x * y.high();
uint128_wrapper high_low = umul128(x, y.low()); uint128_wrapper high_low = umul128(x, y.low());
return {high + high_low.high(), high_low.low()}; return {high + high_low.high(), high_low.low()};
@ -889,13 +888,13 @@ inline uint128_wrapper umul192_lower128(uint64_t x,
// Computes lower 64 bits of multiplication of a 32-bit unsigned integer and a // Computes lower 64 bits of multiplication of a 32-bit unsigned integer and a
// 64-bit unsigned integer. // 64-bit unsigned integer.
inline uint64_t umul96_lower64(uint32_t x, uint64_t y) FMT_NOEXCEPT { inline uint64_t umul96_lower64(uint32_t x, uint64_t y) noexcept {
return x * y; return x * y;
} }
// Computes floor(log10(pow(2, e))) for e in [-1700, 1700] using the method from // Computes floor(log10(pow(2, e))) for e in [-1700, 1700] using the method from
// https://fmt.dev/papers/Grisu-Exact.pdf#page=5, section 3.4. // https://fmt.dev/papers/Grisu-Exact.pdf#page=5, section 3.4.
inline int floor_log10_pow2(int e) FMT_NOEXCEPT { inline int floor_log10_pow2(int e) noexcept {
FMT_ASSERT(e <= 1700 && e >= -1700, "too large exponent"); FMT_ASSERT(e <= 1700 && e >= -1700, "too large exponent");
static_assert((-1 >> 1) == -1, "right shift is not arithmetic"); static_assert((-1 >> 1) == -1, "right shift is not arithmetic");
const int shift = 22; const int shift = 22;
@ -903,7 +902,7 @@ inline int floor_log10_pow2(int e) FMT_NOEXCEPT {
} }
// Various fast log computations. // Various fast log computations.
inline int floor_log2_pow10(int e) FMT_NOEXCEPT { inline int floor_log2_pow10(int e) noexcept {
FMT_ASSERT(e <= 1233 && e >= -1233, "too large exponent"); FMT_ASSERT(e <= 1233 && e >= -1233, "too large exponent");
const uint64_t log2_10_integer_part = 3; const uint64_t log2_10_integer_part = 3;
const uint64_t log2_10_fractional_digits = 0x5269e12f346e2bf9; const uint64_t log2_10_fractional_digits = 0x5269e12f346e2bf9;
@ -913,7 +912,7 @@ inline int floor_log2_pow10(int e) FMT_NOEXCEPT {
(log2_10_fractional_digits >> (64 - shift_amount)))) >> (log2_10_fractional_digits >> (64 - shift_amount)))) >>
shift_amount; shift_amount;
} }
inline int floor_log10_pow2_minus_log10_4_over_3(int e) FMT_NOEXCEPT { inline int floor_log10_pow2_minus_log10_4_over_3(int e) noexcept {
FMT_ASSERT(e <= 1700 && e >= -1700, "too large exponent"); FMT_ASSERT(e <= 1700 && e >= -1700, "too large exponent");
const uint64_t log10_4_over_3_fractional_digits = 0x1ffbfc2bbc780375; const uint64_t log10_4_over_3_fractional_digits = 0x1ffbfc2bbc780375;
const int shift_amount = 22; const int shift_amount = 22;
@ -927,7 +926,7 @@ inline int floor_log10_pow2_minus_log10_4_over_3(int e) FMT_NOEXCEPT {
// divisible by pow(10, N). // divisible by pow(10, N).
// Precondition: n <= pow(10, N + 1). // Precondition: n <= pow(10, N + 1).
template <int N> template <int N>
bool check_divisibility_and_divide_by_pow10(uint32_t& n) FMT_NOEXCEPT { bool check_divisibility_and_divide_by_pow10(uint32_t& n) noexcept {
static constexpr struct { static constexpr struct {
uint32_t magic_number; uint32_t magic_number;
int margin_bits; int margin_bits;
@ -944,7 +943,7 @@ bool check_divisibility_and_divide_by_pow10(uint32_t& n) FMT_NOEXCEPT {
// Computes floor(n / pow(10, N)) for small n and N. // Computes floor(n / pow(10, N)) for small n and N.
// Precondition: n <= pow(10, N + 1). // Precondition: n <= pow(10, N + 1).
template <int N> uint32_t small_division_by_pow10(uint32_t n) FMT_NOEXCEPT { template <int N> uint32_t small_division_by_pow10(uint32_t n) noexcept {
static constexpr struct { static constexpr struct {
uint32_t magic_number; uint32_t magic_number;
int shift_amount; int shift_amount;
@ -956,11 +955,11 @@ template <int N> uint32_t small_division_by_pow10(uint32_t n) FMT_NOEXCEPT {
} }
// Computes floor(n / 10^(kappa + 1)) (float) // Computes floor(n / 10^(kappa + 1)) (float)
inline uint32_t divide_by_10_to_kappa_plus_1(uint32_t n) FMT_NOEXCEPT { inline uint32_t divide_by_10_to_kappa_plus_1(uint32_t n) noexcept {
return n / float_info<float>::big_divisor; return n / float_info<float>::big_divisor;
} }
// Computes floor(n / 10^(kappa + 1)) (double) // Computes floor(n / 10^(kappa + 1)) (double)
inline uint64_t divide_by_10_to_kappa_plus_1(uint64_t n) FMT_NOEXCEPT { inline uint64_t divide_by_10_to_kappa_plus_1(uint64_t n) noexcept {
return umul128_upper64(n, 0x83126e978d4fdf3c) >> 9; return umul128_upper64(n, 0x83126e978d4fdf3c) >> 9;
} }
@ -971,7 +970,7 @@ template <> struct cache_accessor<float> {
using carrier_uint = float_info<float>::carrier_uint; using carrier_uint = float_info<float>::carrier_uint;
using cache_entry_type = uint64_t; using cache_entry_type = uint64_t;
static uint64_t get_cached_power(int k) FMT_NOEXCEPT { static uint64_t get_cached_power(int k) noexcept {
FMT_ASSERT(k >= float_info<float>::min_k && k <= float_info<float>::max_k, FMT_ASSERT(k >= float_info<float>::min_k && k <= float_info<float>::max_k,
"k is out of range"); "k is out of range");
static constexpr const uint64_t pow10_significands[] = { static constexpr const uint64_t pow10_significands[] = {
@ -1014,20 +1013,20 @@ template <> struct cache_accessor<float> {
}; };
static compute_mul_result compute_mul( static compute_mul_result compute_mul(
carrier_uint u, const cache_entry_type& cache) FMT_NOEXCEPT { carrier_uint u, const cache_entry_type& cache) noexcept {
auto r = umul96_upper64(u, cache); auto r = umul96_upper64(u, cache);
return {static_cast<carrier_uint>(r >> 32), return {static_cast<carrier_uint>(r >> 32),
static_cast<carrier_uint>(r) == 0}; static_cast<carrier_uint>(r) == 0};
} }
static uint32_t compute_delta(const cache_entry_type& cache, static uint32_t compute_delta(const cache_entry_type& cache,
int beta_minus_1) FMT_NOEXCEPT { int beta_minus_1) noexcept {
return static_cast<uint32_t>(cache >> (64 - 1 - beta_minus_1)); return static_cast<uint32_t>(cache >> (64 - 1 - beta_minus_1));
} }
static compute_mul_parity_result compute_mul_parity( static compute_mul_parity_result compute_mul_parity(
carrier_uint two_f, const cache_entry_type& cache, carrier_uint two_f, const cache_entry_type& cache,
int beta_minus_1) FMT_NOEXCEPT { int beta_minus_1) noexcept {
FMT_ASSERT(beta_minus_1 >= 1, ""); FMT_ASSERT(beta_minus_1 >= 1, "");
FMT_ASSERT(beta_minus_1 < 64, ""); FMT_ASSERT(beta_minus_1 < 64, "");
@ -1037,21 +1036,21 @@ template <> struct cache_accessor<float> {
} }
static carrier_uint compute_left_endpoint_for_shorter_interval_case( static carrier_uint compute_left_endpoint_for_shorter_interval_case(
const cache_entry_type& cache, int beta_minus_1) FMT_NOEXCEPT { const cache_entry_type& cache, int beta_minus_1) noexcept {
return static_cast<carrier_uint>( return static_cast<carrier_uint>(
(cache - (cache >> (float_info<float>::significand_bits + 2))) >> (cache - (cache >> (float_info<float>::significand_bits + 2))) >>
(64 - float_info<float>::significand_bits - 1 - beta_minus_1)); (64 - float_info<float>::significand_bits - 1 - beta_minus_1));
} }
static carrier_uint compute_right_endpoint_for_shorter_interval_case( static carrier_uint compute_right_endpoint_for_shorter_interval_case(
const cache_entry_type& cache, int beta_minus_1) FMT_NOEXCEPT { const cache_entry_type& cache, int beta_minus_1) noexcept {
return static_cast<carrier_uint>( return static_cast<carrier_uint>(
(cache + (cache >> (float_info<float>::significand_bits + 1))) >> (cache + (cache >> (float_info<float>::significand_bits + 1))) >>
(64 - float_info<float>::significand_bits - 1 - beta_minus_1)); (64 - float_info<float>::significand_bits - 1 - beta_minus_1));
} }
static carrier_uint compute_round_up_for_shorter_interval_case( static carrier_uint compute_round_up_for_shorter_interval_case(
const cache_entry_type& cache, int beta_minus_1) FMT_NOEXCEPT { const cache_entry_type& cache, int beta_minus_1) noexcept {
return (static_cast<carrier_uint>( return (static_cast<carrier_uint>(
cache >> cache >>
(64 - float_info<float>::significand_bits - 2 - beta_minus_1)) + (64 - float_info<float>::significand_bits - 2 - beta_minus_1)) +
@ -1064,7 +1063,7 @@ template <> struct cache_accessor<double> {
using carrier_uint = float_info<double>::carrier_uint; using carrier_uint = float_info<double>::carrier_uint;
using cache_entry_type = uint128_wrapper; using cache_entry_type = uint128_wrapper;
static uint128_wrapper get_cached_power(int k) FMT_NOEXCEPT { static uint128_wrapper get_cached_power(int k) noexcept {
FMT_ASSERT(k >= float_info<double>::min_k && k <= float_info<double>::max_k, FMT_ASSERT(k >= float_info<double>::min_k && k <= float_info<double>::max_k,
"k is out of range"); "k is out of range");
@ -1775,19 +1774,19 @@ template <> struct cache_accessor<double> {
}; };
static compute_mul_result compute_mul( static compute_mul_result compute_mul(
carrier_uint u, const cache_entry_type& cache) FMT_NOEXCEPT { carrier_uint u, const cache_entry_type& cache) noexcept {
auto r = umul192_upper128(u, cache); auto r = umul192_upper128(u, cache);
return {r.high(), r.low() == 0}; return {r.high(), r.low() == 0};
} }
static uint32_t compute_delta(cache_entry_type const& cache, static uint32_t compute_delta(cache_entry_type const& cache,
int beta_minus_1) FMT_NOEXCEPT { int beta_minus_1) noexcept {
return static_cast<uint32_t>(cache.high() >> (64 - 1 - beta_minus_1)); return static_cast<uint32_t>(cache.high() >> (64 - 1 - beta_minus_1));
} }
static compute_mul_parity_result compute_mul_parity( static compute_mul_parity_result compute_mul_parity(
carrier_uint two_f, const cache_entry_type& cache, carrier_uint two_f, const cache_entry_type& cache,
int beta_minus_1) FMT_NOEXCEPT { int beta_minus_1) noexcept {
FMT_ASSERT(beta_minus_1 >= 1, ""); FMT_ASSERT(beta_minus_1 >= 1, "");
FMT_ASSERT(beta_minus_1 < 64, ""); FMT_ASSERT(beta_minus_1 < 64, "");
@ -1798,21 +1797,21 @@ template <> struct cache_accessor<double> {
} }
static carrier_uint compute_left_endpoint_for_shorter_interval_case( static carrier_uint compute_left_endpoint_for_shorter_interval_case(
const cache_entry_type& cache, int beta_minus_1) FMT_NOEXCEPT { const cache_entry_type& cache, int beta_minus_1) noexcept {
return (cache.high() - return (cache.high() -
(cache.high() >> (float_info<double>::significand_bits + 2))) >> (cache.high() >> (float_info<double>::significand_bits + 2))) >>
(64 - float_info<double>::significand_bits - 1 - beta_minus_1); (64 - float_info<double>::significand_bits - 1 - beta_minus_1);
} }
static carrier_uint compute_right_endpoint_for_shorter_interval_case( static carrier_uint compute_right_endpoint_for_shorter_interval_case(
const cache_entry_type& cache, int beta_minus_1) FMT_NOEXCEPT { const cache_entry_type& cache, int beta_minus_1) noexcept {
return (cache.high() + return (cache.high() +
(cache.high() >> (float_info<double>::significand_bits + 1))) >> (cache.high() >> (float_info<double>::significand_bits + 1))) >>
(64 - float_info<double>::significand_bits - 1 - beta_minus_1); (64 - float_info<double>::significand_bits - 1 - beta_minus_1);
} }
static carrier_uint compute_round_up_for_shorter_interval_case( static carrier_uint compute_round_up_for_shorter_interval_case(
const cache_entry_type& cache, int beta_minus_1) FMT_NOEXCEPT { const cache_entry_type& cache, int beta_minus_1) noexcept {
return ((cache.high() >> return ((cache.high() >>
(64 - float_info<double>::significand_bits - 2 - beta_minus_1)) + (64 - float_info<double>::significand_bits - 2 - beta_minus_1)) +
1) / 1) /
@ -1822,7 +1821,7 @@ template <> struct cache_accessor<double> {
// Various integer checks // Various integer checks
template <class T> template <class T>
bool is_left_endpoint_integer_shorter_interval(int exponent) FMT_NOEXCEPT { bool is_left_endpoint_integer_shorter_interval(int exponent) noexcept {
return exponent >= return exponent >=
float_info< float_info<
T>::case_shorter_interval_left_endpoint_lower_threshold && T>::case_shorter_interval_left_endpoint_lower_threshold &&
@ -1831,7 +1830,7 @@ bool is_left_endpoint_integer_shorter_interval(int exponent) FMT_NOEXCEPT {
} }
// Remove trailing zeros from n and return the number of zeros removed (float) // Remove trailing zeros from n and return the number of zeros removed (float)
FMT_INLINE int remove_trailing_zeros(uint32_t& n) FMT_NOEXCEPT { FMT_INLINE int remove_trailing_zeros(uint32_t& n) noexcept {
#ifdef FMT_BUILTIN_CTZ #ifdef FMT_BUILTIN_CTZ
int t = FMT_BUILTIN_CTZ(n); int t = FMT_BUILTIN_CTZ(n);
#else #else
@ -1859,7 +1858,7 @@ FMT_INLINE int remove_trailing_zeros(uint32_t& n) FMT_NOEXCEPT {
} }
// Removes trailing zeros and returns the number of zeros removed (double) // Removes trailing zeros and returns the number of zeros removed (double)
FMT_INLINE int remove_trailing_zeros(uint64_t& n) FMT_NOEXCEPT { FMT_INLINE int remove_trailing_zeros(uint64_t& n) noexcept {
#ifdef FMT_BUILTIN_CTZLL #ifdef FMT_BUILTIN_CTZLL
int t = FMT_BUILTIN_CTZLL(n); int t = FMT_BUILTIN_CTZLL(n);
#else #else
@ -1945,7 +1944,7 @@ FMT_INLINE int remove_trailing_zeros(uint64_t& n) FMT_NOEXCEPT {
// The main algorithm for shorter interval case // The main algorithm for shorter interval case
template <class T> template <class T>
FMT_INLINE decimal_fp<T> shorter_interval_case(int exponent) FMT_NOEXCEPT { FMT_INLINE decimal_fp<T> shorter_interval_case(int exponent) noexcept {
decimal_fp<T> ret_value; decimal_fp<T> ret_value;
// Compute k and beta // Compute k and beta
const int minus_k = floor_log10_pow2_minus_log10_4_over_3(exponent); const int minus_k = floor_log10_pow2_minus_log10_4_over_3(exponent);
@ -1991,7 +1990,7 @@ FMT_INLINE decimal_fp<T> shorter_interval_case(int exponent) FMT_NOEXCEPT {
return ret_value; return ret_value;
} }
template <typename T> decimal_fp<T> to_decimal(T x) FMT_NOEXCEPT { template <typename T> decimal_fp<T> to_decimal(T x) noexcept {
// Step 1: integer promotion & Schubfach multiplier calculation. // Step 1: integer promotion & Schubfach multiplier calculation.
using carrier_uint = typename float_info<T>::carrier_uint; using carrier_uint = typename float_info<T>::carrier_uint;
@ -2479,7 +2478,7 @@ FMT_FUNC detail::utf8_to_utf16::utf8_to_utf16(string_view s) {
} }
FMT_FUNC void format_system_error(detail::buffer<char>& out, int error_code, FMT_FUNC void format_system_error(detail::buffer<char>& out, int error_code,
const char* message) FMT_NOEXCEPT { const char* message) noexcept {
FMT_TRY { FMT_TRY {
auto ec = std::error_code(error_code, std::generic_category()); auto ec = std::error_code(error_code, std::generic_category());
write(std::back_inserter(out), std::system_error(ec, message).what()); write(std::back_inserter(out), std::system_error(ec, message).what());
@ -2490,7 +2489,7 @@ FMT_FUNC void format_system_error(detail::buffer<char>& out, int error_code,
} }
FMT_FUNC void report_system_error(int error_code, FMT_FUNC void report_system_error(int error_code,
const char* message) FMT_NOEXCEPT { const char* message) noexcept {
report_error(format_system_error, error_code, message); report_error(format_system_error, error_code, message);
} }

View File

@ -735,8 +735,7 @@ class basic_memory_buffer final : public detail::buffer<T> {
of the other object to it. of the other object to it.
\endrst \endrst
*/ */
FMT_CONSTEXPR20 basic_memory_buffer(basic_memory_buffer&& other) FMT_CONSTEXPR20 basic_memory_buffer(basic_memory_buffer&& other) noexcept {
FMT_NOEXCEPT {
move(other); move(other);
} }
@ -745,8 +744,7 @@ class basic_memory_buffer final : public detail::buffer<T> {
Moves the content of the other ``basic_memory_buffer`` object to this one. Moves the content of the other ``basic_memory_buffer`` object to this one.
\endrst \endrst
*/ */
auto operator=(basic_memory_buffer&& other) FMT_NOEXCEPT auto operator=(basic_memory_buffer&& other) noexcept -> basic_memory_buffer& {
-> basic_memory_buffer& {
FMT_ASSERT(this != &other, ""); FMT_ASSERT(this != &other, "");
deallocate(); deallocate();
move(other); move(other);
@ -820,7 +818,7 @@ class FMT_API format_error : public std::runtime_error {
format_error& operator=(const format_error&) = default; format_error& operator=(const format_error&) = default;
format_error(format_error&&) = default; format_error(format_error&&) = default;
format_error& operator=(format_error&&) = default; format_error& operator=(format_error&&) = default;
~format_error() FMT_NOEXCEPT override FMT_MSC_DEFAULT; ~format_error() noexcept override FMT_MSC_DEFAULT;
}; };
/** /**
@ -1039,15 +1037,11 @@ FMT_CONSTEXPR20 inline auto count_digits(uint32_t n) -> int {
return count_digits_fallback(n); return count_digits_fallback(n);
} }
template <typename Int> constexpr auto digits10() FMT_NOEXCEPT -> int { template <typename Int> constexpr auto digits10() noexcept -> int {
return std::numeric_limits<Int>::digits10; return std::numeric_limits<Int>::digits10;
} }
template <> constexpr auto digits10<int128_t>() FMT_NOEXCEPT -> int { template <> constexpr auto digits10<int128_t>() noexcept -> int { return 38; }
return 38; template <> constexpr auto digits10<uint128_t>() noexcept -> int { return 38; }
}
template <> constexpr auto digits10<uint128_t>() FMT_NOEXCEPT -> int {
return 38;
}
template <typename Char> struct thousands_sep_result { template <typename Char> struct thousands_sep_result {
std::string grouping; std::string grouping;
@ -1254,8 +1248,7 @@ template <typename T> struct decimal_fp {
int exponent; int exponent;
}; };
template <typename T> template <typename T> FMT_API auto to_decimal(T x) noexcept -> decimal_fp<T>;
FMT_API auto to_decimal(T x) FMT_NOEXCEPT -> decimal_fp<T>;
} // namespace dragonbox } // namespace dragonbox
template <typename T> template <typename T>
@ -2435,10 +2428,10 @@ auto vformat(const Locale& loc, basic_string_view<Char> format_str,
using format_func = void (*)(detail::buffer<char>&, int, const char*); using format_func = void (*)(detail::buffer<char>&, int, const char*);
FMT_API void format_error_code(buffer<char>& out, int error_code, FMT_API void format_error_code(buffer<char>& out, int error_code,
string_view message) FMT_NOEXCEPT; string_view message) noexcept;
FMT_API void report_error(format_func func, int error_code, FMT_API void report_error(format_func func, int error_code,
const char* message) FMT_NOEXCEPT; const char* message) noexcept;
FMT_END_DETAIL_NAMESPACE FMT_END_DETAIL_NAMESPACE
FMT_API auto vsystem_error(int error_code, string_view format_str, FMT_API auto vsystem_error(int error_code, string_view format_str,
@ -2484,12 +2477,11 @@ auto system_error(int error_code, format_string<T...> fmt, T&&... args)
\endrst \endrst
*/ */
FMT_API void format_system_error(detail::buffer<char>& out, int error_code, FMT_API void format_system_error(detail::buffer<char>& out, int error_code,
const char* message) FMT_NOEXCEPT; const char* message) noexcept;
// Reports a system error without throwing an exception. // Reports a system error without throwing an exception.
// Can be used to report errors from destructors. // Can be used to report errors from destructors.
FMT_API void report_system_error(int error_code, FMT_API void report_system_error(int error_code, const char* message) noexcept;
const char* message) FMT_NOEXCEPT;
/** Fast integer formatter. */ /** Fast integer formatter. */
class format_int { class format_int {

View File

@ -141,7 +141,7 @@ template <typename Char> struct formatter<std::error_code, Char> {
}; };
#ifdef _WIN32 #ifdef _WIN32
FMT_API const std::error_category& system_category() FMT_NOEXCEPT; FMT_API const std::error_category& system_category() noexcept;
FMT_BEGIN_DETAIL_NAMESPACE FMT_BEGIN_DETAIL_NAMESPACE
// A converter from UTF-16 to UTF-8. // A converter from UTF-16 to UTF-8.
@ -165,7 +165,7 @@ class utf16_to_utf8 {
}; };
FMT_API void format_windows_error(buffer<char>& out, int error_code, FMT_API void format_windows_error(buffer<char>& out, int error_code,
const char* message) FMT_NOEXCEPT; const char* message) noexcept;
FMT_END_DETAIL_NAMESPACE FMT_END_DETAIL_NAMESPACE
FMT_API std::system_error vwindows_error(int error_code, string_view format_str, FMT_API std::system_error vwindows_error(int error_code, string_view format_str,
@ -207,10 +207,9 @@ std::system_error windows_error(int error_code, string_view message,
// Reports a Windows error without throwing an exception. // Reports a Windows error without throwing an exception.
// Can be used to report errors from destructors. // Can be used to report errors from destructors.
FMT_API void report_windows_error(int error_code, FMT_API void report_windows_error(int error_code, const char* message) noexcept;
const char* message) FMT_NOEXCEPT;
#else #else
inline const std::error_category& system_category() FMT_NOEXCEPT { inline const std::error_category& system_category() noexcept {
return std::system_category(); return std::system_category();
} }
#endif // _WIN32 #endif // _WIN32
@ -237,13 +236,13 @@ class buffered_file {
void operator=(const buffered_file&) = delete; void operator=(const buffered_file&) = delete;
// Constructs a buffered_file object which doesn't represent any file. // Constructs a buffered_file object which doesn't represent any file.
buffered_file() FMT_NOEXCEPT : file_(nullptr) {} buffered_file() noexcept : file_(nullptr) {}
// Destroys the object closing the file it represents if any. // Destroys the object closing the file it represents if any.
FMT_API ~buffered_file() FMT_NOEXCEPT; FMT_API ~buffered_file() noexcept;
public: public:
buffered_file(buffered_file&& other) FMT_NOEXCEPT : file_(other.file_) { buffered_file(buffered_file&& other) noexcept : file_(other.file_) {
other.file_ = nullptr; other.file_ = nullptr;
} }
@ -261,7 +260,7 @@ class buffered_file {
FMT_API void close(); FMT_API void close();
// Returns the pointer to a FILE object representing this file. // Returns the pointer to a FILE object representing this file.
FILE* get() const FMT_NOEXCEPT { return file_; } FILE* get() const noexcept { return file_; }
// We place parentheses around fileno to workaround a bug in some versions // We place parentheses around fileno to workaround a bug in some versions
// of MinGW that define fileno as a macro. // of MinGW that define fileno as a macro.
@ -280,7 +279,7 @@ class buffered_file {
#if FMT_USE_FCNTL #if FMT_USE_FCNTL
// A file. Closed file is represented by a file object with descriptor -1. // A file. Closed file is represented by a file object with descriptor -1.
// Methods that are not declared with FMT_NOEXCEPT may throw // Methods that are not declared with noexcept may throw
// fmt::system_error in case of failure. Note that some errors such as // fmt::system_error in case of failure. Note that some errors such as
// closing the file multiple times will cause a crash on Windows rather // closing the file multiple times will cause a crash on Windows rather
// than an exception. You can get standard behavior by overriding the // than an exception. You can get standard behavior by overriding the
@ -304,7 +303,7 @@ class file {
}; };
// Constructs a file object which doesn't represent any file. // Constructs a file object which doesn't represent any file.
file() FMT_NOEXCEPT : fd_(-1) {} file() noexcept : fd_(-1) {}
// Opens a file and constructs a file object representing this file. // Opens a file and constructs a file object representing this file.
FMT_API file(cstring_view path, int oflag); FMT_API file(cstring_view path, int oflag);
@ -313,7 +312,7 @@ class file {
file(const file&) = delete; file(const file&) = delete;
void operator=(const file&) = delete; void operator=(const file&) = delete;
file(file&& other) FMT_NOEXCEPT : fd_(other.fd_) { other.fd_ = -1; } file(file&& other) noexcept : fd_(other.fd_) { other.fd_ = -1; }
// Move assignment is not noexcept because close may throw. // Move assignment is not noexcept because close may throw.
file& operator=(file&& other) { file& operator=(file&& other) {
@ -324,10 +323,10 @@ class file {
} }
// Destroys the object closing the file it represents if any. // Destroys the object closing the file it represents if any.
FMT_API ~file() FMT_NOEXCEPT; FMT_API ~file() noexcept;
// Returns the file descriptor. // Returns the file descriptor.
int descriptor() const FMT_NOEXCEPT { return fd_; } int descriptor() const noexcept { return fd_; }
// Closes the file. // Closes the file.
FMT_API void close(); FMT_API void close();
@ -352,7 +351,7 @@ class file {
// Makes fd be the copy of this file descriptor, closing fd first if // Makes fd be the copy of this file descriptor, closing fd first if
// necessary. // necessary.
FMT_API void dup2(int fd, std::error_code& ec) FMT_NOEXCEPT; FMT_API void dup2(int fd, std::error_code& ec) noexcept;
// Creates a pipe setting up read_end and write_end file objects for reading // Creates a pipe setting up read_end and write_end file objects for reading
// and writing respectively. // and writing respectively.

View File

@ -203,7 +203,7 @@ using make_index_sequence = make_integer_sequence<size_t, N>;
#endif #endif
template <class Tuple, class F, size_t... Is> template <class Tuple, class F, size_t... Is>
void for_each(index_sequence<Is...>, Tuple&& tup, F&& f) FMT_NOEXCEPT { void for_each(index_sequence<Is...>, Tuple&& tup, F&& f) noexcept {
using std::get; using std::get;
// using free function get<I>(T) now. // using free function get<I>(T) now.
const int _[] = {0, ((void)f(get<Is>(tup)), 0)...}; const int _[] = {0, ((void)f(get<Is>(tup)), 0)...};

View File

@ -70,10 +70,10 @@ int format_float(char* buf, std::size_t size, const char* format, int precision,
: snprintf_ptr(buf, size, format, precision, value); : snprintf_ptr(buf, size, format, precision, value);
} }
template FMT_API dragonbox::decimal_fp<float> dragonbox::to_decimal(float x) template FMT_API dragonbox::decimal_fp<float> dragonbox::to_decimal(
FMT_NOEXCEPT; float x) noexcept;
template FMT_API dragonbox::decimal_fp<double> dragonbox::to_decimal(double x) template FMT_API dragonbox::decimal_fp<double> dragonbox::to_decimal(
FMT_NOEXCEPT; double x) noexcept;
} // namespace detail } // namespace detail
// Workaround a bug in MSVC2013 that prevents instantiation of format_float. // Workaround a bug in MSVC2013 that prevents instantiation of format_float.

View File

@ -107,7 +107,7 @@ class system_message {
unsigned long result_; unsigned long result_;
wchar_t* message_; wchar_t* message_;
static bool is_whitespace(wchar_t c) FMT_NOEXCEPT { static bool is_whitespace(wchar_t c) noexcept {
return c == L' ' || c == L'\n' || c == L'\r' || c == L'\t' || c == L'\0'; return c == L' ' || c == L'\n' || c == L'\r' || c == L'\t' || c == L'\0';
} }
@ -126,15 +126,15 @@ class system_message {
} }
} }
~system_message() { LocalFree(message_); } ~system_message() { LocalFree(message_); }
explicit operator bool() const FMT_NOEXCEPT { return result_ != 0; } explicit operator bool() const noexcept { return result_ != 0; }
operator basic_string_view<wchar_t>() const FMT_NOEXCEPT { operator basic_string_view<wchar_t>() const noexcept {
return basic_string_view<wchar_t>(message_, result_); return basic_string_view<wchar_t>(message_, result_);
} }
}; };
class utf8_system_category final : public std::error_category { class utf8_system_category final : public std::error_category {
public: public:
const char* name() const FMT_NOEXCEPT override { return "system"; } const char* name() const noexcept override { return "system"; }
std::string message(int error_code) const override { std::string message(int error_code) const override {
system_message msg(error_code); system_message msg(error_code);
if (msg) { if (msg) {
@ -149,7 +149,7 @@ class utf8_system_category final : public std::error_category {
} // namespace detail } // namespace detail
FMT_API const std::error_category& system_category() FMT_NOEXCEPT { FMT_API const std::error_category& system_category() noexcept {
static const detail::utf8_system_category category; static const detail::utf8_system_category category;
return category; return category;
} }
@ -161,7 +161,7 @@ std::system_error vwindows_error(int err_code, string_view format_str,
} }
void detail::format_windows_error(detail::buffer<char>& out, int error_code, void detail::format_windows_error(detail::buffer<char>& out, int error_code,
const char* message) FMT_NOEXCEPT { const char* message) noexcept {
FMT_TRY { FMT_TRY {
system_message msg(error_code); system_message msg(error_code);
if (msg) { if (msg) {
@ -176,12 +176,12 @@ void detail::format_windows_error(detail::buffer<char>& out, int error_code,
format_error_code(out, error_code, message); format_error_code(out, error_code, message);
} }
void report_windows_error(int error_code, const char* message) FMT_NOEXCEPT { void report_windows_error(int error_code, const char* message) noexcept {
report_error(detail::format_windows_error, error_code, message); report_error(detail::format_windows_error, error_code, message);
} }
#endif // _WIN32 #endif // _WIN32
buffered_file::~buffered_file() FMT_NOEXCEPT { buffered_file::~buffered_file() noexcept {
if (file_ && FMT_SYSTEM(fclose(file_)) != 0) if (file_ && FMT_SYSTEM(fclose(file_)) != 0)
report_system_error(errno, "cannot close file"); report_system_error(errno, "cannot close file");
} }
@ -225,7 +225,7 @@ file::file(cstring_view path, int oflag) {
FMT_THROW(system_error(errno, "cannot open file {}", path.c_str())); FMT_THROW(system_error(errno, "cannot open file {}", path.c_str()));
} }
file::~file() FMT_NOEXCEPT { file::~file() noexcept {
// Don't retry close in case of EINTR! // Don't retry close in case of EINTR!
// See http://linux.derkeiler.com/Mailing-Lists/Kernel/2005-09/3000.html // See http://linux.derkeiler.com/Mailing-Lists/Kernel/2005-09/3000.html
if (fd_ != -1 && FMT_POSIX_CALL(close(fd_)) != 0) if (fd_ != -1 && FMT_POSIX_CALL(close(fd_)) != 0)
@ -299,7 +299,7 @@ void file::dup2(int fd) {
} }
} }
void file::dup2(int fd, std::error_code& ec) FMT_NOEXCEPT { void file::dup2(int fd, std::error_code& ec) noexcept {
int result = 0; int result = 0;
FMT_RETRY(result, FMT_POSIX_CALL(dup2(fd_, fd))); FMT_RETRY(result, FMT_POSIX_CALL(dup2(fd_, fd)));
if (result == -1) ec = std::error_code(errno, std::generic_category()); if (result == -1) ec = std::error_code(errno, std::generic_category());

View File

@ -325,7 +325,7 @@ template <typename Allocator, size_t MaxSize>
class max_size_allocator : public Allocator { class max_size_allocator : public Allocator {
public: public:
using typename Allocator::value_type; using typename Allocator::value_type;
size_t max_size() const FMT_NOEXCEPT { return MaxSize; } size_t max_size() const noexcept { return MaxSize; }
value_type* allocate(size_t n) { value_type* allocate(size_t n) {
if (n > max_size()) { if (n > max_size()) {
throw std::length_error("size > max_size"); throw std::length_error("size > max_size");

View File

@ -23,7 +23,7 @@ output_redirect::output_redirect(FILE* f) : file_(f) {
write_end.dup2(fd); write_end.dup2(fd);
} }
output_redirect::~output_redirect() FMT_NOEXCEPT { output_redirect::~output_redirect() noexcept {
try { try {
restore(); restore();
} catch (const std::exception& e) { } catch (const std::exception& e) {

View File

@ -83,7 +83,7 @@ class output_redirect {
public: public:
explicit output_redirect(FILE* file); explicit output_redirect(FILE* file);
~output_redirect() FMT_NOEXCEPT; ~output_redirect() noexcept;
output_redirect(const output_redirect&) = delete; output_redirect(const output_redirect&) = delete;
void operator=(const output_redirect&) = delete; void operator=(const output_redirect&) = delete;

View File

@ -36,7 +36,6 @@
#else #else
# define FMT_USE_FCNTL 0 # define FMT_USE_FCNTL 0
#endif #endif
#define FMT_NOEXCEPT noexcept
#if defined(_WIN32) && !defined(__MINGW32__) #if defined(_WIN32) && !defined(__MINGW32__)
# define FMT_POSIX(call) _##call # define FMT_POSIX(call) _##call
#else #else

View File

@ -236,14 +236,14 @@ namespace fake_qt {
class QString { class QString {
public: public:
QString(const wchar_t* s) : s_(s) {} QString(const wchar_t* s) : s_(s) {}
const wchar_t* utf16() const FMT_NOEXCEPT { return s_.data(); } const wchar_t* utf16() const noexcept { return s_.data(); }
int size() const FMT_NOEXCEPT { return static_cast<int>(s_.size()); } int size() const noexcept { return static_cast<int>(s_.size()); }
private: private:
std::wstring s_; std::wstring s_;
}; };
fmt::basic_string_view<wchar_t> to_string_view(const QString& s) FMT_NOEXCEPT { fmt::basic_string_view<wchar_t> to_string_view(const QString& s) noexcept {
return {s.utf16(), static_cast<size_t>(s.size())}; return {s.utf16(), static_cast<size_t>(s.size())};
} }
} // namespace fake_qt } // namespace fake_qt