Skip to content

Commit 9980308

Browse files
committed
Start phasing out const_check
1 parent 483eddc commit 9980308

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

include/fmt/base.h

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -377,11 +377,6 @@ constexpr auto is_constant_evaluated(bool default_value = false) noexcept
377377
#endif
378378
}
379379

380-
// Suppresses "conditional expression is constant" warnings.
381-
template <typename T> FMT_ALWAYS_INLINE constexpr auto const_check(T val) -> T {
382-
return val;
383-
}
384-
385380
#ifdef FMT_ASSERT
386381
// Use the provided definition.
387382
#elif defined(NDEBUG)
@@ -1299,7 +1294,7 @@ constexpr auto to_ascii(Char c) -> char {
12991294
// Returns the number of code units in a code point or 1 on error.
13001295
template <typename Char>
13011296
FMT_CONSTEXPR auto code_point_length(const Char* begin) -> int {
1302-
if (const_check(sizeof(Char) != 1)) return 1;
1297+
if FMT_CONSTEXPR20 (sizeof(Char) != 1) return 1;
13031298
auto c = static_cast<unsigned char>(*begin);
13041299
return static_cast<int>((0x3a55000000000000ull >> (2 * (c >> 3))) & 3) + 1;
13051300
}
@@ -2394,7 +2389,7 @@ template <typename T, typename Char, type TYPE> struct native_formatter {
23942389
FMT_CONSTEXPR auto parse(parse_context<Char>& ctx) -> const Char* {
23952390
if (ctx.begin() == ctx.end() || *ctx.begin() == '}') return ctx.begin();
23962391
auto end = parse_format_specs(ctx.begin(), ctx.end(), specs_, ctx, TYPE);
2397-
if (const_check(TYPE == type::char_type)) check_char_specs(specs_);
2392+
if FMT_CONSTEXPR20 (TYPE == type::char_type) check_char_specs(specs_);
23982393
return end;
23992394
}
24002395

@@ -2934,7 +2929,7 @@ FMT_API void vprint_buffered(FILE* f, string_view fmt, format_args args);
29342929
template <typename... T>
29352930
FMT_INLINE void print(format_string<T...> fmt, T&&... args) {
29362931
vargs<T...> va = {{args...}};
2937-
if (detail::const_check(!detail::use_utf8))
2932+
if FMT_CONSTEXPR20 (!detail::use_utf8)
29382933
return detail::vprint_mojibake(stdout, fmt.str, va, false);
29392934
return detail::is_locking<T...>() ? vprint_buffered(stdout, fmt.str, va)
29402935
: vprint(fmt.str, va);
@@ -2951,7 +2946,7 @@ FMT_INLINE void print(format_string<T...> fmt, T&&... args) {
29512946
template <typename... T>
29522947
FMT_INLINE void print(FILE* f, format_string<T...> fmt, T&&... args) {
29532948
vargs<T...> va = {{args...}};
2954-
if (detail::const_check(!detail::use_utf8))
2949+
if FMT_CONSTEXPR20 (!detail::use_utf8)
29552950
return detail::vprint_mojibake(f, fmt.str, va, false);
29562951
return detail::is_locking<T...>() ? vprint_buffered(f, fmt.str, va)
29572952
: vprint(f, fmt.str, va);
@@ -2962,7 +2957,7 @@ FMT_INLINE void print(FILE* f, format_string<T...> fmt, T&&... args) {
29622957
template <typename... T>
29632958
FMT_INLINE void println(FILE* f, format_string<T...> fmt, T&&... args) {
29642959
vargs<T...> va = {{args...}};
2965-
if (detail::const_check(detail::use_utf8)) return vprintln(f, fmt.str, va);
2960+
if FMT_CONSTEXPR20 (detail::use_utf8) return vprintln(f, fmt.str, va);
29662961
detail::vprint_mojibake(f, fmt.str, va, true);
29672962
}
29682963

include/fmt/format.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,11 @@ inline auto clzll(uint64_t x) -> int {
248248
# define FMT_BUILTIN_CLZLL(n) detail::clzll(n)
249249
#endif // FMT_MSC_VERSION && !defined(FMT_BUILTIN_CLZLL)
250250

251+
// Suppresses "conditional expression is constant" warnings.
252+
template <typename T> FMT_ALWAYS_INLINE constexpr auto const_check(T val) -> T {
253+
return val;
254+
}
255+
251256
FMT_CONSTEXPR inline void abort_fuzzing_if(bool condition) {
252257
ignore_unused(condition);
253258
#ifdef FMT_FUZZ

0 commit comments

Comments
 (0)