From 8d3f731763bcbb4a11e3d714c551e509007957b1 Mon Sep 17 00:00:00 2001 From: Aaron Gokaslan Date: Mon, 23 Feb 2026 20:08:35 -0500 Subject: [PATCH] Mark static arrays as constexpr for binary opt (#4680) --- include/fmt/format-inl.h | 4 ++-- include/fmt/format.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index 76eed5f1..cc110198 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -92,8 +92,8 @@ FMT_FUNC void format_error_code(detail::buffer& out, int error_code, // Report error code making sure that the output fits into inline_buffer_size // to avoid dynamic memory allocation and potential bad_alloc. out.try_resize(0); - static const char SEP[] = ": "; - static const char ERROR_STR[] = "error "; + static constexpr char SEP[] = ": "; + static constexpr char ERROR_STR[] = "error "; // Subtract 2 to account for terminating null characters in SEP and ERROR_STR. size_t error_code_size = sizeof(SEP) + sizeof(ERROR_STR) - 2; auto abs_value = static_cast>(error_code); diff --git a/include/fmt/format.h b/include/fmt/format.h index 3f67b22a..94c98701 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -1071,7 +1071,7 @@ using uint64_or_128_t = conditional_t() <= 64, uint64_t, uint128_t>; inline auto digits2(size_t value) noexcept -> const char* { // Align data since unaligned access may be slower when crossing a // hardware-specific boundary. - alignas(2) static const char data[] = + alignas(2) static constexpr char data[] = "0001020304050607080910111213141516171819" "2021222324252627282930313233343536373839" "4041424344454647484950515253545556575859" @@ -1084,7 +1084,7 @@ inline auto digits2(size_t value) noexcept -> const char* { // the decimal point of i / 100 in base 2, the first 2 bytes // after digits2_i(x) is the string representation of i. inline auto digits2_i(size_t value) noexcept -> const char* { - alignas(2) static const char data[] = + alignas(2) static constexpr char data[] = "00010203 0405060707080910 1112" "131414151617 18192021 222324 " "25262728 2930313232333435 3637"