Use classic locale grouping without locale support (#4947)

This commit is contained in:
Tiago 2026-09-27 08:19:52 -07:00 committed by GitHub
parent 0482001875
commit 1ffdc7687f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 3 deletions

View File

@ -2793,7 +2793,9 @@ template <typename Char, typename Grouping, typename OutputIt,
FMT_CONSTEXPR20 auto do_write_float(OutputIt out, const DecimalFP& f,
const format_specs& specs, sign s,
int exp_upper, locale_ref loc) -> OutputIt {
Char point = specs.localized() ? detail::decimal_point<Char>(loc) : Char('.');
Char point = FMT_USE_LOCALE && specs.localized()
? detail::decimal_point<Char>(loc)
: Char('.');
int significand_size = get_significand_size(f);
int exp = f.exponent + significand_size - 1;
if (specs.type() == presentation_type::fixed ||
@ -2832,7 +2834,7 @@ template <typename Char, typename OutputIt, typename DecimalFP>
FMT_CONSTEXPR20 auto write_float(OutputIt out, const DecimalFP& f,
const format_specs& specs, sign s,
int exp_upper, locale_ref loc) -> OutputIt {
if (is_constant_evaluated()) {
if (is_constant_evaluated() || !FMT_USE_LOCALE) {
return do_write_float<Char, fallback_digit_grouping<Char>>(out, f, specs, s,
exp_upper, loc);
} else {

View File

@ -129,12 +129,13 @@ if (FMT_PEDANTIC)
endif ()
# Test that the library compiles without locale.
add_library(nolocale-test ../src/format.cc)
add_executable(nolocale-test ../src/format.cc nolocale-test.cc)
target_include_directories(nolocale-test
PRIVATE ${PROJECT_SOURCE_DIR}/include)
target_compile_definitions(nolocale-test PRIVATE FMT_USE_LOCALE=0)
target_compile_options(nolocale-test
PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/utf-8>)
add_test(NAME nolocale-test COMMAND nolocale-test)
endif ()
# These tests are disabled on Windows because they take too long.

13
test/nolocale-test.cc Normal file
View File

@ -0,0 +1,13 @@
// Formatting library for C++ - no-locale tests
//
// Copyright (c) 2012 - present, Victor Zverovich and {fmt} contributors
// All rights reserved.
//
// For the license information refer to format.h.
#include "fmt/format.h"
int main() {
if (fmt::format("{:L}", 1234567) != "1234567") return 1;
if (fmt::format("{:L}", 1234.5) != "1234.5") return 1;
}