diff --git a/include/fmt/color.h b/include/fmt/color.h index 0d0204f3..e46843c3 100644 --- a/include/fmt/color.h +++ b/include/fmt/color.h @@ -214,17 +214,16 @@ FMT_BEGIN_DETAIL_NAMESPACE // color is a struct of either a rgb color or a terminal color. struct color_type { - FMT_CONSTEXPR color_type() FMT_NOEXCEPT : is_rgb(), value{} {} - FMT_CONSTEXPR color_type(color rgb_color) FMT_NOEXCEPT : is_rgb(true), - value{} { + FMT_CONSTEXPR color_type() noexcept : is_rgb(), value{} {} + FMT_CONSTEXPR color_type(color rgb_color) noexcept : is_rgb(true), value{} { value.rgb_color = static_cast(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(rgb_color.r) << 16) | (static_cast(rgb_color.g) << 8) | rgb_color.b; } - FMT_CONSTEXPR color_type(terminal_color term_color) FMT_NOEXCEPT : is_rgb(), - value{} { + FMT_CONSTEXPR color_type(terminal_color term_color) noexcept + : is_rgb(), value{} { value.term_color = static_cast(term_color); } bool is_rgb; @@ -239,10 +238,8 @@ FMT_END_DETAIL_NAMESPACE /** A text style consisting of foreground and background colors and emphasis. */ class text_style { public: - FMT_CONSTEXPR text_style(emphasis em = emphasis()) FMT_NOEXCEPT - : set_foreground_color(), - set_background_color(), - ems(em) {} + FMT_CONSTEXPR text_style(emphasis em = emphasis()) noexcept + : set_foreground_color(), set_background_color(), ems(em) {} FMT_CONSTEXPR text_style& operator|=(const text_style& rhs) { if (!set_foreground_color) { @@ -283,34 +280,32 @@ class text_style { return lhs.and_assign(rhs); } - FMT_CONSTEXPR bool has_foreground() const FMT_NOEXCEPT { + FMT_CONSTEXPR bool has_foreground() const noexcept { return set_foreground_color; } - FMT_CONSTEXPR bool has_background() const FMT_NOEXCEPT { + FMT_CONSTEXPR bool has_background() const noexcept { return set_background_color; } - FMT_CONSTEXPR bool has_emphasis() const FMT_NOEXCEPT { + FMT_CONSTEXPR bool has_emphasis() const noexcept { return static_cast(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"); 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"); 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"); return ems; } private: FMT_CONSTEXPR text_style(bool is_foreground, - detail::color_type text_color) FMT_NOEXCEPT - : set_foreground_color(), - set_background_color(), - ems() { + detail::color_type text_color) noexcept + : set_foreground_color(), set_background_color(), ems() { if (is_foreground) { foreground_color = text_color; set_foreground_color = true; @@ -345,11 +340,11 @@ class text_style { return *this; } - friend FMT_CONSTEXPR_DECL text_style fg(detail::color_type foreground) - FMT_NOEXCEPT; + friend FMT_CONSTEXPR_DECL text_style + fg(detail::color_type foreground) noexcept; - friend FMT_CONSTEXPR_DECL text_style bg(detail::color_type background) - FMT_NOEXCEPT; + friend FMT_CONSTEXPR_DECL text_style + bg(detail::color_type background) noexcept; detail::color_type foreground_color; detail::color_type background_color; @@ -359,17 +354,16 @@ class text_style { }; /** 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); } /** 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); } -FMT_CONSTEXPR inline text_style operator|(emphasis lhs, - emphasis rhs) FMT_NOEXCEPT { +FMT_CONSTEXPR inline text_style operator|(emphasis lhs, emphasis rhs) noexcept { return text_style(lhs) | rhs; } @@ -377,7 +371,7 @@ FMT_BEGIN_DETAIL_NAMESPACE template struct ansi_color_escape { 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 // sequence. if (!text_color.is_rgb) { @@ -412,7 +406,7 @@ template struct ansi_color_escape { to_esc(color.b, buffer + 15, 'm'); buffer[19] = static_cast(0); } - FMT_CONSTEXPR ansi_color_escape(emphasis em) FMT_NOEXCEPT { + FMT_CONSTEXPR ansi_color_escape(emphasis em) noexcept { uint8_t em_codes[num_emphases] = {}; if (has_emphasis(em, emphasis::bold)) em_codes[0] = 1; if (has_emphasis(em, emphasis::faint)) em_codes[1] = 2; @@ -433,10 +427,10 @@ template struct ansi_color_escape { } buffer[index++] = static_cast(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_CHAR_TRAITS const Char* end() const FMT_NOEXCEPT { + FMT_CONSTEXPR const Char* begin() const noexcept { return buffer; } + FMT_CONSTEXPR_CHAR_TRAITS const Char* end() const noexcept { return buffer + std::char_traits::length(buffer); } @@ -445,32 +439,31 @@ template struct ansi_color_escape { Char buffer[7u + 3u * num_emphases + 1u]; static FMT_CONSTEXPR void to_esc(uint8_t c, Char* out, - char delimiter) FMT_NOEXCEPT { + char delimiter) noexcept { out[0] = static_cast('0' + c / 100); out[1] = static_cast('0' + c / 10 % 10); out[2] = static_cast('0' + c % 10); out[3] = static_cast(delimiter); } - static FMT_CONSTEXPR bool has_emphasis(emphasis em, - emphasis mask) FMT_NOEXCEPT { + static FMT_CONSTEXPR bool has_emphasis(emphasis em, emphasis mask) noexcept { return static_cast(em) & static_cast(mask); } }; template FMT_CONSTEXPR ansi_color_escape make_foreground_color( - detail::color_type foreground) FMT_NOEXCEPT { + detail::color_type foreground) noexcept { return ansi_color_escape(foreground, "\x1b[38;2;"); } template FMT_CONSTEXPR ansi_color_escape make_background_color( - detail::color_type background) FMT_NOEXCEPT { + detail::color_type background) noexcept { return ansi_color_escape(background, "\x1b[48;2;"); } template -FMT_CONSTEXPR ansi_color_escape make_emphasis(emphasis em) FMT_NOEXCEPT { +FMT_CONSTEXPR ansi_color_escape make_emphasis(emphasis em) noexcept { return ansi_color_escape(em); } diff --git a/include/fmt/core.h b/include/fmt/core.h index 12571ce0..44fb16b3 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -144,9 +144,6 @@ # define FMT_EXCEPTIONS 1 # endif #endif -#ifndef FMT_NOEXCEPT -# define FMT_NOEXCEPT noexcept -#endif // [[noreturn]] is disabled on MSVC and NVCC because of bogus unreachable code // warnings. @@ -333,7 +330,7 @@ FMT_BEGIN_DETAIL_NAMESPACE template FMT_CONSTEXPR void ignore_unused(const T&...) {} constexpr FMT_INLINE auto is_constant_evaluated(bool default_value = false) - FMT_NOEXCEPT -> bool { + noexcept -> bool { #ifdef __cpp_lib_is_constant_evaluated ignore_unused(default_value); return std::is_constant_evaluated(); @@ -435,10 +432,10 @@ template class basic_string_view { using value_type = 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. */ - 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), size_(count) {} @@ -460,29 +457,29 @@ template class basic_string_view { /** Constructs a string reference from a ``std::basic_string`` object. */ template FMT_CONSTEXPR basic_string_view( - const std::basic_string& s) FMT_NOEXCEPT + const std::basic_string& s) noexcept : data_(s.data()), size_(s.size()) {} template >::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()) {} /** 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. */ - 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 end() const FMT_NOEXCEPT -> iterator { return data_ + size_; } + constexpr auto begin() const noexcept -> iterator { return data_; } + 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]; } - FMT_CONSTEXPR void remove_prefix(size_t n) FMT_NOEXCEPT { + FMT_CONSTEXPR void remove_prefix(size_t n) noexcept { data_ += 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 parsed. */ - constexpr auto begin() const FMT_NOEXCEPT -> iterator { + constexpr auto begin() const noexcept -> iterator { return format_str_.begin(); } /** 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(); } @@ -765,10 +762,10 @@ template class buffer { protected: // Don't initialize ptr_ since it is not accessed to save a few cycles. 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, - size_t cap = 0) FMT_NOEXCEPT : ptr_(p), + size_t cap = 0) noexcept : ptr_(p), size_(sz), capacity_(cap) {} @@ -776,7 +773,7 @@ template class buffer { buffer(buffer&&) = default; /** 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; capacity_ = buf_capacity; } @@ -791,23 +788,23 @@ template class buffer { buffer(const buffer&) = delete; void operator=(const buffer&) = delete; - auto begin() FMT_NOEXCEPT -> T* { return ptr_; } - auto end() FMT_NOEXCEPT -> T* { return ptr_ + size_; } + auto begin() noexcept -> T* { return ptr_; } + auto end() noexcept -> T* { return ptr_ + size_; } - auto begin() const FMT_NOEXCEPT -> const T* { return ptr_; } - auto end() const FMT_NOEXCEPT -> const T* { return ptr_ + size_; } + auto begin() const noexcept -> const T* { return ptr_; } + auto end() const noexcept -> const T* { return ptr_ + size_; } /** 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. */ - 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. */ - FMT_CONSTEXPR auto data() FMT_NOEXCEPT -> T* { return ptr_; } + FMT_CONSTEXPR auto data() noexcept -> T* { return ptr_; } /** 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. */ void clear() { size_ = 0; } @@ -1495,12 +1492,12 @@ class appender : public std::back_insert_iterator> { public: using std::back_insert_iterator>::back_insert_iterator; - appender(base it) FMT_NOEXCEPT : base(it) {} + appender(base it) noexcept : base(it) {} 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 @@ -1546,7 +1543,7 @@ template class basic_format_arg { 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; } @@ -1656,7 +1653,7 @@ class locale_ref { constexpr locale_ref() : locale_(nullptr) {} template explicit locale_ref(const Locale& loc); - explicit operator bool() const FMT_NOEXCEPT { return locale_ != nullptr; } + explicit operator bool() const noexcept { return locale_ != nullptr; } template auto get() const -> Locale; }; diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index 92c3039c..76da3aa2 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -58,7 +58,7 @@ inline int fmt_snprintf(char* buffer, size_t size, const char* format, ...) { #endif // _MSC_VER FMT_FUNC void format_error_code(detail::buffer& out, int error_code, - string_view message) FMT_NOEXCEPT { + string_view message) noexcept { // Report error code making sure that the output fits into // inline_buffer_size to avoid dynamic memory allocation and potential // bad_alloc. @@ -81,7 +81,7 @@ FMT_FUNC void format_error_code(detail::buffer& out, 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; func(full_message, error_code, message); // Don't use fwrite_fully because the latter may throw. @@ -130,7 +130,7 @@ template FMT_FUNC Char decimal_point_impl(locale_ref) { } // namespace detail #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 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 low_; - constexpr uint128_wrapper(uint64_t high, uint64_t low) FMT_NOEXCEPT - : high_{high}, - low_{low} {} + constexpr uint128_wrapper(uint64_t high, uint64_t low) noexcept + : high_{high}, low_{low} {} - constexpr uint64_t high() const FMT_NOEXCEPT { return high_; } - constexpr uint64_t low() const FMT_NOEXCEPT { return low_; } + constexpr uint64_t high() const noexcept { return high_; } + 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) unsigned long long 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. namespace dragonbox { // 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 auto p = static_cast(x) * static_cast(y); return {static_cast(p >> 64), static_cast(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. -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 auto p = static_cast(x) * static_cast(y); return static_cast(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 // 128-bit unsigned integer. inline uint128_wrapper umul192_upper128(uint64_t x, - uint128_wrapper y) FMT_NOEXCEPT { + uint128_wrapper y) noexcept { uint128_wrapper r = umul128(x, y.high()); r += umul128_upper64(x, y.low()); 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 // 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); } // Computes lower 128 bits of multiplication of a 64-bit unsigned integer and a // 128-bit unsigned integer. inline uint128_wrapper umul192_lower128(uint64_t x, - uint128_wrapper y) FMT_NOEXCEPT { + uint128_wrapper y) noexcept { uint64_t high = x * y.high(); uint128_wrapper high_low = umul128(x, y.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 // 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; } // 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. -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"); static_assert((-1 >> 1) == -1, "right shift is not arithmetic"); const int shift = 22; @@ -903,7 +902,7 @@ inline int floor_log10_pow2(int e) FMT_NOEXCEPT { } // 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"); const uint64_t log2_10_integer_part = 3; 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)))) >> 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"); const uint64_t log10_4_over_3_fractional_digits = 0x1ffbfc2bbc780375; 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). // Precondition: n <= pow(10, N + 1). template -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 { uint32_t magic_number; 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. // Precondition: n <= pow(10, N + 1). -template uint32_t small_division_by_pow10(uint32_t n) FMT_NOEXCEPT { +template uint32_t small_division_by_pow10(uint32_t n) noexcept { static constexpr struct { uint32_t magic_number; int shift_amount; @@ -956,11 +955,11 @@ template uint32_t small_division_by_pow10(uint32_t n) FMT_NOEXCEPT { } // 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::big_divisor; } // 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; } @@ -971,7 +970,7 @@ template <> struct cache_accessor { using carrier_uint = float_info::carrier_uint; 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::min_k && k <= float_info::max_k, "k is out of range"); static constexpr const uint64_t pow10_significands[] = { @@ -1014,20 +1013,20 @@ template <> struct cache_accessor { }; 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); return {static_cast(r >> 32), static_cast(r) == 0}; } static uint32_t compute_delta(const cache_entry_type& cache, - int beta_minus_1) FMT_NOEXCEPT { + int beta_minus_1) noexcept { return static_cast(cache >> (64 - 1 - beta_minus_1)); } static compute_mul_parity_result compute_mul_parity( 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 < 64, ""); @@ -1037,21 +1036,21 @@ template <> struct cache_accessor { } 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( (cache - (cache >> (float_info::significand_bits + 2))) >> (64 - float_info::significand_bits - 1 - beta_minus_1)); } 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( (cache + (cache >> (float_info::significand_bits + 1))) >> (64 - float_info::significand_bits - 1 - beta_minus_1)); } 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( cache >> (64 - float_info::significand_bits - 2 - beta_minus_1)) + @@ -1064,7 +1063,7 @@ template <> struct cache_accessor { using carrier_uint = float_info::carrier_uint; 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::min_k && k <= float_info::max_k, "k is out of range"); @@ -1775,19 +1774,19 @@ template <> struct cache_accessor { }; 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); return {r.high(), r.low() == 0}; } static uint32_t compute_delta(cache_entry_type const& cache, - int beta_minus_1) FMT_NOEXCEPT { + int beta_minus_1) noexcept { return static_cast(cache.high() >> (64 - 1 - beta_minus_1)); } static compute_mul_parity_result compute_mul_parity( 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 < 64, ""); @@ -1798,21 +1797,21 @@ template <> struct cache_accessor { } 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() - (cache.high() >> (float_info::significand_bits + 2))) >> (64 - float_info::significand_bits - 1 - beta_minus_1); } 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() + (cache.high() >> (float_info::significand_bits + 1))) >> (64 - float_info::significand_bits - 1 - beta_minus_1); } 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() >> (64 - float_info::significand_bits - 2 - beta_minus_1)) + 1) / @@ -1822,7 +1821,7 @@ template <> struct cache_accessor { // Various integer checks template -bool is_left_endpoint_integer_shorter_interval(int exponent) FMT_NOEXCEPT { +bool is_left_endpoint_integer_shorter_interval(int exponent) noexcept { return exponent >= float_info< 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) -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 int t = FMT_BUILTIN_CTZ(n); #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) -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 int t = FMT_BUILTIN_CTZLL(n); #else @@ -1945,7 +1944,7 @@ FMT_INLINE int remove_trailing_zeros(uint64_t& n) FMT_NOEXCEPT { // The main algorithm for shorter interval case template -FMT_INLINE decimal_fp shorter_interval_case(int exponent) FMT_NOEXCEPT { +FMT_INLINE decimal_fp shorter_interval_case(int exponent) noexcept { decimal_fp ret_value; // Compute k and beta const int minus_k = floor_log10_pow2_minus_log10_4_over_3(exponent); @@ -1991,7 +1990,7 @@ FMT_INLINE decimal_fp shorter_interval_case(int exponent) FMT_NOEXCEPT { return ret_value; } -template decimal_fp to_decimal(T x) FMT_NOEXCEPT { +template decimal_fp to_decimal(T x) noexcept { // Step 1: integer promotion & Schubfach multiplier calculation. using carrier_uint = typename float_info::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& out, int error_code, - const char* message) FMT_NOEXCEPT { + const char* message) noexcept { FMT_TRY { auto ec = std::error_code(error_code, std::generic_category()); write(std::back_inserter(out), std::system_error(ec, message).what()); @@ -2490,7 +2489,7 @@ FMT_FUNC void format_system_error(detail::buffer& out, 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); } diff --git a/include/fmt/format.h b/include/fmt/format.h index b5e35c86..a58c538b 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -735,8 +735,7 @@ class basic_memory_buffer final : public detail::buffer { of the other object to it. \endrst */ - FMT_CONSTEXPR20 basic_memory_buffer(basic_memory_buffer&& other) - FMT_NOEXCEPT { + FMT_CONSTEXPR20 basic_memory_buffer(basic_memory_buffer&& other) noexcept { move(other); } @@ -745,8 +744,7 @@ class basic_memory_buffer final : public detail::buffer { Moves the content of the other ``basic_memory_buffer`` object to this one. \endrst */ - auto operator=(basic_memory_buffer&& other) FMT_NOEXCEPT - -> basic_memory_buffer& { + auto operator=(basic_memory_buffer&& other) noexcept -> basic_memory_buffer& { FMT_ASSERT(this != &other, ""); deallocate(); move(other); @@ -820,7 +818,7 @@ class FMT_API format_error : public std::runtime_error { format_error& operator=(const format_error&) = default; format_error(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); } -template constexpr auto digits10() FMT_NOEXCEPT -> int { +template constexpr auto digits10() noexcept -> int { return std::numeric_limits::digits10; } -template <> constexpr auto digits10() FMT_NOEXCEPT -> int { - return 38; -} -template <> constexpr auto digits10() FMT_NOEXCEPT -> int { - return 38; -} +template <> constexpr auto digits10() noexcept -> int { return 38; } +template <> constexpr auto digits10() noexcept -> int { return 38; } template struct thousands_sep_result { std::string grouping; @@ -1254,8 +1248,7 @@ template struct decimal_fp { int exponent; }; -template -FMT_API auto to_decimal(T x) FMT_NOEXCEPT -> decimal_fp; +template FMT_API auto to_decimal(T x) noexcept -> decimal_fp; } // namespace dragonbox template @@ -2435,10 +2428,10 @@ auto vformat(const Locale& loc, basic_string_view format_str, using format_func = void (*)(detail::buffer&, int, const char*); FMT_API void format_error_code(buffer& out, int error_code, - string_view message) FMT_NOEXCEPT; + string_view message) noexcept; 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_API auto vsystem_error(int error_code, string_view format_str, @@ -2484,12 +2477,11 @@ auto system_error(int error_code, format_string fmt, T&&... args) \endrst */ FMT_API void format_system_error(detail::buffer& out, int error_code, - const char* message) FMT_NOEXCEPT; + const char* message) noexcept; // Reports a system error without throwing an exception. // Can be used to report errors from destructors. -FMT_API void report_system_error(int error_code, - const char* message) FMT_NOEXCEPT; +FMT_API void report_system_error(int error_code, const char* message) noexcept; /** Fast integer formatter. */ class format_int { diff --git a/include/fmt/os.h b/include/fmt/os.h index 9793061a..70cd26bf 100644 --- a/include/fmt/os.h +++ b/include/fmt/os.h @@ -141,7 +141,7 @@ template struct formatter { }; #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 // A converter from UTF-16 to UTF-8. @@ -165,7 +165,7 @@ class utf16_to_utf8 { }; FMT_API void format_windows_error(buffer& out, int error_code, - const char* message) FMT_NOEXCEPT; + const char* message) noexcept; FMT_END_DETAIL_NAMESPACE 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. // Can be used to report errors from destructors. -FMT_API void report_windows_error(int error_code, - const char* message) FMT_NOEXCEPT; +FMT_API void report_windows_error(int error_code, const char* message) noexcept; #else -inline const std::error_category& system_category() FMT_NOEXCEPT { +inline const std::error_category& system_category() noexcept { return std::system_category(); } #endif // _WIN32 @@ -237,13 +236,13 @@ class buffered_file { void operator=(const buffered_file&) = delete; // 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. - FMT_API ~buffered_file() FMT_NOEXCEPT; + FMT_API ~buffered_file() noexcept; public: - buffered_file(buffered_file&& other) FMT_NOEXCEPT : file_(other.file_) { + buffered_file(buffered_file&& other) noexcept : file_(other.file_) { other.file_ = nullptr; } @@ -261,7 +260,7 @@ class buffered_file { FMT_API void close(); // 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 // of MinGW that define fileno as a macro. @@ -280,7 +279,7 @@ class buffered_file { #if FMT_USE_FCNTL // 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 // closing the file multiple times will cause a crash on Windows rather // 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. - file() FMT_NOEXCEPT : fd_(-1) {} + file() noexcept : fd_(-1) {} // Opens a file and constructs a file object representing this file. FMT_API file(cstring_view path, int oflag); @@ -313,7 +312,7 @@ class file { file(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. file& operator=(file&& other) { @@ -324,10 +323,10 @@ class file { } // Destroys the object closing the file it represents if any. - FMT_API ~file() FMT_NOEXCEPT; + FMT_API ~file() noexcept; // Returns the file descriptor. - int descriptor() const FMT_NOEXCEPT { return fd_; } + int descriptor() const noexcept { return fd_; } // Closes the file. FMT_API void close(); @@ -352,7 +351,7 @@ class file { // Makes fd be the copy of this file descriptor, closing fd first if // 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 // and writing respectively. diff --git a/include/fmt/ranges.h b/include/fmt/ranges.h index 681377b2..d30d5f3d 100644 --- a/include/fmt/ranges.h +++ b/include/fmt/ranges.h @@ -203,7 +203,7 @@ using make_index_sequence = make_integer_sequence; #endif template -void for_each(index_sequence, Tuple&& tup, F&& f) FMT_NOEXCEPT { +void for_each(index_sequence, Tuple&& tup, F&& f) noexcept { using std::get; // using free function get(T) now. const int _[] = {0, ((void)f(get(tup)), 0)...}; diff --git a/src/format.cc b/src/format.cc index ecb8cc79..a65b7d3e 100644 --- a/src/format.cc +++ b/src/format.cc @@ -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); } -template FMT_API dragonbox::decimal_fp dragonbox::to_decimal(float x) - FMT_NOEXCEPT; -template FMT_API dragonbox::decimal_fp dragonbox::to_decimal(double x) - FMT_NOEXCEPT; +template FMT_API dragonbox::decimal_fp dragonbox::to_decimal( + float x) noexcept; +template FMT_API dragonbox::decimal_fp dragonbox::to_decimal( + double x) noexcept; } // namespace detail // Workaround a bug in MSVC2013 that prevents instantiation of format_float. diff --git a/src/os.cc b/src/os.cc index 04b4dc50..d5bee7aa 100644 --- a/src/os.cc +++ b/src/os.cc @@ -107,7 +107,7 @@ class system_message { unsigned long result_; 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'; } @@ -126,15 +126,15 @@ class system_message { } } ~system_message() { LocalFree(message_); } - explicit operator bool() const FMT_NOEXCEPT { return result_ != 0; } - operator basic_string_view() const FMT_NOEXCEPT { + explicit operator bool() const noexcept { return result_ != 0; } + operator basic_string_view() const noexcept { return basic_string_view(message_, result_); } }; class utf8_system_category final : public std::error_category { 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 { system_message msg(error_code); if (msg) { @@ -149,7 +149,7 @@ class utf8_system_category final : public std::error_category { } // 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; 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& out, int error_code, - const char* message) FMT_NOEXCEPT { + const char* message) noexcept { FMT_TRY { system_message msg(error_code); if (msg) { @@ -176,12 +176,12 @@ void detail::format_windows_error(detail::buffer& out, int error_code, 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); } #endif // _WIN32 -buffered_file::~buffered_file() FMT_NOEXCEPT { +buffered_file::~buffered_file() noexcept { if (file_ && FMT_SYSTEM(fclose(file_)) != 0) 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())); } -file::~file() FMT_NOEXCEPT { +file::~file() noexcept { // Don't retry close in case of EINTR! // See http://linux.derkeiler.com/Mailing-Lists/Kernel/2005-09/3000.html 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; FMT_RETRY(result, FMT_POSIX_CALL(dup2(fd_, fd))); if (result == -1) ec = std::error_code(errno, std::generic_category()); diff --git a/test/format-test.cc b/test/format-test.cc index a8592ef0..48d31e29 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -325,7 +325,7 @@ template class max_size_allocator : public Allocator { public: 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) { if (n > max_size()) { throw std::length_error("size > max_size"); diff --git a/test/gtest-extra.cc b/test/gtest-extra.cc index 1d48a173..542e4b5e 100644 --- a/test/gtest-extra.cc +++ b/test/gtest-extra.cc @@ -23,7 +23,7 @@ output_redirect::output_redirect(FILE* f) : file_(f) { write_end.dup2(fd); } -output_redirect::~output_redirect() FMT_NOEXCEPT { +output_redirect::~output_redirect() noexcept { try { restore(); } catch (const std::exception& e) { diff --git a/test/gtest-extra.h b/test/gtest-extra.h index df2b1d8c..ef2a04e7 100644 --- a/test/gtest-extra.h +++ b/test/gtest-extra.h @@ -83,7 +83,7 @@ class output_redirect { public: explicit output_redirect(FILE* file); - ~output_redirect() FMT_NOEXCEPT; + ~output_redirect() noexcept; output_redirect(const output_redirect&) = delete; void operator=(const output_redirect&) = delete; diff --git a/test/module-test.cc b/test/module-test.cc index 39c83983..7fbf763d 100644 --- a/test/module-test.cc +++ b/test/module-test.cc @@ -36,7 +36,6 @@ #else # define FMT_USE_FCNTL 0 #endif -#define FMT_NOEXCEPT noexcept #if defined(_WIN32) && !defined(__MINGW32__) # define FMT_POSIX(call) _##call #else diff --git a/test/xchar-test.cc b/test/xchar-test.cc index 346cd212..025a670b 100644 --- a/test/xchar-test.cc +++ b/test/xchar-test.cc @@ -236,14 +236,14 @@ namespace fake_qt { class QString { public: QString(const wchar_t* s) : s_(s) {} - const wchar_t* utf16() const FMT_NOEXCEPT { return s_.data(); } - int size() const FMT_NOEXCEPT { return static_cast(s_.size()); } + const wchar_t* utf16() const noexcept { return s_.data(); } + int size() const noexcept { return static_cast(s_.size()); } private: std::wstring s_; }; -fmt::basic_string_view to_string_view(const QString& s) FMT_NOEXCEPT { +fmt::basic_string_view to_string_view(const QString& s) noexcept { return {s.utf16(), static_cast(s.size())}; } } // namespace fake_qt