Skip to content

Commit 61de7d4

Browse files
committed
🐛 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.
1 parent 3a59abb commit 61de7d4

3 files changed

Lines changed: 7 additions & 5 deletions

File tree

include/stdx/detail/fmt.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ CONSTEVAL auto formatted_size(fmt_spec s, I i) -> std::size_t {
7777

7878
while (i != 0) {
7979
++sz;
80-
i /= s.base;
80+
i /= static_cast<I>(s.base);
8181
}
8282
return sz;
8383
}
@@ -131,8 +131,8 @@ CONSTEVAL auto format_to(fmt_spec s, It dest, I i) -> It {
131131

132132
auto b = dest;
133133
while (i != 0) {
134-
auto digit = to_digit(abs(i % s.base));
135-
i /= s.base;
134+
auto digit = to_digit(abs(i % static_cast<I>(s.base)));
135+
i /= static_cast<I>(s.base);
136136
*dest++ = digit;
137137
}
138138

include/stdx/iterator.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <stdx/compiler.hpp>
34
#include <stdx/type_traits.hpp>
45

56
#include <array>
@@ -25,7 +26,8 @@ constexpr auto ct_capacity_v<std::array<T, N>> = N;
2526

2627
template <typename T> constexpr auto ct_capacity_v<T const> = ct_capacity_v<T>;
2728

28-
template <typename T> constexpr auto ct_capacity(T &&) -> std::size_t {
29+
template <typename T>
30+
CONSTEVAL auto ct_capacity([[maybe_unused]] T &&) -> std::size_t {
2931
return ct_capacity_v<remove_cvref_t<T>>;
3032
}
3133

test/ct_format.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ TEST_CASE("FORMAT a constexpr string_view argument", "[ct_format]") {
333333
}
334334

335335
TEST_CASE("FORMAT an integral_constant argument", "[ct_format]") {
336-
auto I = std::integral_constant<int, 17>{};
336+
auto I = std::integral_constant<unsigned int, 17u>{};
337337
STATIC_REQUIRE(STDX_CT_FORMAT("Hello {}", I) == "Hello 17"_fmt_res);
338338
}
339339

0 commit comments

Comments
 (0)