From ed409c5ba99c65742d3f615000b74f28506044e2 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 29 Jan 2026 09:05:07 -0800 Subject: [PATCH] Relax constexpr --- include/fmt/base.h | 48 ++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/include/fmt/base.h b/include/fmt/base.h index c4e61207..02840efd 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -536,7 +536,7 @@ template class basic_string_view { #if FMT_GCC_VERSION FMT_ALWAYS_INLINE #endif - FMT_CONSTEXPR20 basic_string_view(const Char* s) : data_(s) { + FMT_CONSTEXPR basic_string_view(const Char* s) : data_(s) { #if FMT_HAS_BUILTIN(__builtin_strlen) || FMT_GCC_VERSION || FMT_CLANG_VERSION if (std::is_same::value && !detail::is_constant_evaluated()) { size_ = __builtin_strlen(detail::narrow(s)); // strlen is not constexpr. @@ -553,7 +553,7 @@ template class basic_string_view { template ::value&& std::is_same< typename S::value_type, Char>::value)> - FMT_CONSTEXPR basic_string_view(const S& s) noexcept + constexpr basic_string_view(const S& s) noexcept : data_(s.data()), size_(s.size()) {} /// Returns a pointer to the string data. @@ -574,15 +574,14 @@ template class basic_string_view { size_ -= n; } - FMT_CONSTEXPR auto starts_with(basic_string_view sv) const noexcept - -> bool { + FMT_CONSTEXPR auto starts_with(basic_string_view sv) const noexcept -> bool { return size_ >= sv.size_ && detail::compare(data_, sv.data_, sv.size_) == 0; } FMT_CONSTEXPR auto starts_with(Char c) const noexcept -> bool { return size_ >= 1 && *data_ == c; } FMT_CONSTEXPR auto starts_with(const Char* s) const -> bool { - return starts_with(basic_string_view(s)); + return starts_with(basic_string_view(s)); } FMT_CONSTEXPR auto compare(basic_string_view other) const -> int { @@ -612,7 +611,6 @@ template class basic_string_view { return lhs.compare(rhs) >= 0; } }; - using string_view = basic_string_view; template class basic_appender; @@ -1257,9 +1255,9 @@ class compile_parse_context : public parse_context { using base = parse_context; public: - FMT_CONSTEXPR explicit compile_parse_context(basic_string_view fmt, - int num_args, const type* types, - int next_arg_id = 0) + constexpr explicit compile_parse_context(basic_string_view fmt, + int num_args, const type* types, + int next_arg_id = 0) : base(fmt, next_arg_id), num_args_(num_args), types_(types) {} constexpr auto num_args() const -> int { return num_args_; } @@ -1781,7 +1779,7 @@ template class buffer { protected: // Don't initialize ptr_ since it is not accessed to save a few cycles. FMT_MSC_WARNING(suppress : 26495) - FMT_CONSTEXPR buffer(grow_fun grow, size_t sz) noexcept + constexpr buffer(grow_fun grow, size_t sz) noexcept : size_(sz), capacity_(sz), grow_(grow) {} constexpr buffer(grow_fun grow, T* p = nullptr, size_t sz = 0, @@ -1873,7 +1871,7 @@ template class buffer { return ptr_[index]; } template - FMT_CONSTEXPR auto operator[](Idx index) const -> const T& { + constexpr auto operator[](Idx index) const -> const T& { return ptr_[index]; } }; @@ -2043,7 +2041,7 @@ template class counting_buffer : public buffer { } public: - FMT_CONSTEXPR counting_buffer() : buffer(grow, data_, 0, buffer_size) {} + constexpr counting_buffer() : buffer(grow, data_, 0, buffer_size) {} constexpr auto count() const noexcept -> size_t { return count_ + this->size(); @@ -2201,8 +2199,8 @@ template class value { constexpr FMT_INLINE value(unsigned short x FMT_BUILTIN) : uint_value(x) {} constexpr FMT_INLINE value(int x) : int_value(x) {} constexpr FMT_INLINE value(unsigned x FMT_BUILTIN) : uint_value(x) {} - FMT_CONSTEXPR FMT_INLINE value(long x FMT_BUILTIN) : value(long_type(x)) {} - FMT_CONSTEXPR FMT_INLINE value(unsigned long x FMT_BUILTIN) + constexpr FMT_INLINE value(long x FMT_BUILTIN) : value(long_type(x)) {} + constexpr FMT_INLINE value(unsigned long x FMT_BUILTIN) : value(ulong_type(x)) {} constexpr FMT_INLINE value(long long x FMT_BUILTIN) : long_long_value(x) {} constexpr FMT_INLINE value(unsigned long long x FMT_BUILTIN) @@ -2279,7 +2277,7 @@ template class value { template ::value || !FMT_BUILTIN_TYPES)> - FMT_CONSTEXPR20 FMT_INLINE value(T& x) : value(x, custom_tag()) {} + FMT_CONSTEXPR FMT_INLINE value(T& x) : value(x, custom_tag()) {} FMT_ALWAYS_INLINE value(const named_arg_info* args, size_t size) : named_args{args, size} {} @@ -2439,11 +2437,11 @@ template struct locking>::nonlocking>> : std::false_type {}; -template FMT_CONSTEXPR inline auto is_locking() -> bool { +template constexpr inline auto is_locking() -> bool { return locking::value; } template -FMT_CONSTEXPR inline auto is_locking() -> bool { +constexpr inline auto is_locking() -> bool { return locking::value || is_locking(); } @@ -2487,15 +2485,15 @@ template class basic_appender { public: using container_type = detail::buffer; - FMT_CONSTEXPR basic_appender(detail::buffer& buf) : container(&buf) {} + constexpr basic_appender(detail::buffer& buf) : container(&buf) {} - FMT_CONSTEXPR20 auto operator=(T c) -> basic_appender& { + FMT_CONSTEXPR auto operator=(T c) -> basic_appender& { container->push_back(c); return *this; } - FMT_CONSTEXPR20 auto operator*() -> basic_appender& { return *this; } - FMT_CONSTEXPR20 auto operator++() -> basic_appender& { return *this; } - FMT_CONSTEXPR20 auto operator++(int) -> basic_appender { return *this; } + FMT_CONSTEXPR auto operator*() -> basic_appender& { return *this; } + FMT_CONSTEXPR auto operator++() -> basic_appender& { return *this; } + FMT_CONSTEXPR auto operator++(int) -> basic_appender { return *this; } }; // A formatting argument. Context is a template parameter for the compiled API @@ -2693,7 +2691,7 @@ class context { /// Constructs a `context` object. References to the arguments are stored /// in the object so make sure they have appropriate lifetimes. - FMT_CONSTEXPR context(iterator out, format_args args, locale_ref loc = {}) + constexpr context(iterator out, format_args args, locale_ref loc = {}) : out_(out), args_(args), loc_(loc) {} context(context&&) = default; context(const context&) = delete; @@ -2709,12 +2707,12 @@ class context { auto args() const -> const format_args& { return args_; } // Returns an iterator to the beginning of the output range. - FMT_CONSTEXPR auto out() const -> iterator { return out_; } + constexpr auto out() const -> iterator { return out_; } // Advances the begin iterator to `it`. FMT_CONSTEXPR void advance_to(iterator) {} - FMT_CONSTEXPR auto locale() const -> locale_ref { return loc_; } + constexpr auto locale() const -> locale_ref { return loc_; } }; template struct runtime_format_string {