From 61de7d4be1d8db493622f4de09080be5ac02e999 Mon Sep 17 00:00:00 2001 From: Ben Deane Date: Fri, 21 Nov 2025 16:08:55 -0700 Subject: [PATCH] :bug: Fix `ct_capacity`, conversion warnings in freestanding `fmt` Problem: - `ct_capacity` can occur at runtime even though it is always decidable at compile-time. - There are some conversion warnings in the freestanding `fmt` code. Solution: - Mark `ct_capacity` `consteval`. - Silence the conversion warnings. --- include/stdx/detail/fmt.hpp | 6 +++--- include/stdx/iterator.hpp | 4 +++- test/ct_format.cpp | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/include/stdx/detail/fmt.hpp b/include/stdx/detail/fmt.hpp index fd6172a..73c833f 100644 --- a/include/stdx/detail/fmt.hpp +++ b/include/stdx/detail/fmt.hpp @@ -77,7 +77,7 @@ CONSTEVAL auto formatted_size(fmt_spec s, I i) -> std::size_t { while (i != 0) { ++sz; - i /= s.base; + i /= static_cast(s.base); } return sz; } @@ -131,8 +131,8 @@ CONSTEVAL auto format_to(fmt_spec s, It dest, I i) -> It { auto b = dest; while (i != 0) { - auto digit = to_digit(abs(i % s.base)); - i /= s.base; + auto digit = to_digit(abs(i % static_cast(s.base))); + i /= static_cast(s.base); *dest++ = digit; } diff --git a/include/stdx/iterator.hpp b/include/stdx/iterator.hpp index fda8c56..e315343 100644 --- a/include/stdx/iterator.hpp +++ b/include/stdx/iterator.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -25,7 +26,8 @@ constexpr auto ct_capacity_v> = N; template constexpr auto ct_capacity_v = ct_capacity_v; -template constexpr auto ct_capacity(T &&) -> std::size_t { +template +CONSTEVAL auto ct_capacity([[maybe_unused]] T &&) -> std::size_t { return ct_capacity_v>; } diff --git a/test/ct_format.cpp b/test/ct_format.cpp index 5876da8..2808225 100644 --- a/test/ct_format.cpp +++ b/test/ct_format.cpp @@ -333,7 +333,7 @@ TEST_CASE("FORMAT a constexpr string_view argument", "[ct_format]") { } TEST_CASE("FORMAT an integral_constant argument", "[ct_format]") { - auto I = std::integral_constant{}; + auto I = std::integral_constant{}; STATIC_REQUIRE(STDX_CT_FORMAT("Hello {}", I) == "Hello 17"_fmt_res); }