diff --git a/include/fmt/core.h b/include/fmt/core.h index babb162d..1c9a4965 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -2245,10 +2245,8 @@ template class value { FMT_ENABLE_IF(use_formatter::value || !FMT_BUILTIN_TYPES)> FMT_CONSTEXPR FMT_INLINE value(T& x) : value(x, custom_tag()) {} - // Could accept const pointer instead, but this avoids a GCC 16+ false - // positive from `-Wmaybe-uninitialized` in Debug builds, in `named_arg_store` - // constructor. Related bug report: - // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127470 + // A non-const pointer avoids a bogus gcc 16 -Wmaybe-uninitialized at -O0 in + // named_arg_store: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127470. FMT_ALWAYS_INLINE value(named_arg_info* args, size_t size) : named_args{args, size} {} diff --git a/include/fmt/format.h b/include/fmt/format.h index 37b3616f..922b16c2 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -2793,9 +2793,8 @@ template OutputIt { - Char point = FMT_USE_LOCALE && specs.localized() - ? detail::decimal_point(loc) - : Char('.'); + bool localized = FMT_USE_LOCALE && specs.localized(); + Char point = 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 || diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 1cd0f5ee..faa4705d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -128,11 +128,13 @@ if (FMT_PEDANTIC) target_compile_options(noexception-test PRIVATE ${PEDANTIC_COMPILE_FLAGS}) endif () - # Test that the library compiles without locale. - add_executable(nolocale-test ../src/format.cc nolocale-test.cc) + # Test that the library works without locale support. + add_executable(nolocale-test format-test.cc mock-allocator.h ${TEST_MAIN_SRC} + ../src/format.cc ../src/os.cc) target_include_directories(nolocale-test PRIVATE ${PROJECT_SOURCE_DIR}/include) target_compile_definitions(nolocale-test PRIVATE FMT_USE_LOCALE=0) + target_link_libraries(nolocale-test gtest) target_compile_options(nolocale-test PRIVATE $<$:/utf-8>) add_test(NAME nolocale-test COMMAND nolocale-test) diff --git a/test/format-test.cc b/test/format-test.cc index 772ecb09..9f8eda7c 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1560,6 +1560,7 @@ TEST(format_test, format_int_locale) { TEST(format_test, format_float) { EXPECT_EQ(fmt::format("{}", 0.0f), "0"); EXPECT_EQ(fmt::format("{0:f}", 392.5f), "392.500000"); + EXPECT_EQ(fmt::format("{:L}", 1234.5), "1234.5"); } TEST(format_test, format_double) { @@ -2250,7 +2251,9 @@ TEST(format_test, fill_via_appender) { TEST(format_test, formatted_size) { EXPECT_EQ(2u, fmt::formatted_size("{}", 42)); +#if FMT_USE_LOCALE EXPECT_EQ(2u, fmt::formatted_size(std::locale(), "{}", 42)); +#endif } TEST(format_test, format_to_no_args) { @@ -2483,7 +2486,9 @@ TEST(format_int_test, format_int) { std::to_string(max_value())); } -#ifndef FMT_STATIC_THOUSANDS_SEPARATOR +// This file is also compiled with FMT_USE_LOCALE=0 by nolocale-test, so tests +// that use std::locale must go in this block. +#if FMT_USE_LOCALE # include @@ -2548,7 +2553,7 @@ TEST(format_test, format_locale) { EXPECT_EQ(fmt::format(loc, "{:10Lo}", 12345), " 30,071"); } -#endif // FMT_STATIC_THOUSANDS_SEPARATOR +#endif // FMT_USE_LOCALE struct convertible_to_nonconst_cstring { operator char*() const { diff --git a/test/nolocale-test.cc b/test/nolocale-test.cc deleted file mode 100644 index 17cf1ed1..00000000 --- a/test/nolocale-test.cc +++ /dev/null @@ -1,13 +0,0 @@ -// 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; -}