diff --git a/include/fmt/format.h b/include/fmt/format.h index d52a6668..37b3616f 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -2793,7 +2793,9 @@ template OutputIt { - Char point = specs.localized() ? detail::decimal_point(loc) : Char('.'); + Char point = FMT_USE_LOCALE && specs.localized() + ? detail::decimal_point(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 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>(out, f, specs, s, exp_upper, loc); } else { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 48c5f93a..1cd0f5ee 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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 $<$:/utf-8>) + add_test(NAME nolocale-test COMMAND nolocale-test) endif () # These tests are disabled on Windows because they take too long. diff --git a/test/nolocale-test.cc b/test/nolocale-test.cc new file mode 100644 index 00000000..17cf1ed1 --- /dev/null +++ b/test/nolocale-test.cc @@ -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; +}