Disable locale more

This commit is contained in:
Victor Zverovich 2024-08-29 16:22:30 -07:00
parent b3ccc2d210
commit f213d83306
3 changed files with 42 additions and 40 deletions

View File

@ -213,6 +213,20 @@
# define FMT_DEPRECATED /* deprecated */ # define FMT_DEPRECATED /* deprecated */
#endif #endif
#ifndef FMT_NO_UNIQUE_ADDRESS
# if FMT_CPLUSPLUS >= 202002L
# if FMT_HAS_CPP_ATTRIBUTE(no_unique_address)
# define FMT_NO_UNIQUE_ADDRESS [[no_unique_address]]
// VS2019 v16.10 and later except clang-cl (https://reviews.llvm.org/D110485).
# elif (FMT_MSC_VERSION >= 1929) && !FMT_CLANG_VERSION
# define FMT_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
# endif
# endif
#endif
#ifndef FMT_NO_UNIQUE_ADDRESS
# define FMT_NO_UNIQUE_ADDRESS
#endif
#ifdef FMT_INLINE #ifdef FMT_INLINE
// Use the provided definition. // Use the provided definition.
#elif FMT_GCC_VERSION || FMT_CLANG_VERSION #elif FMT_GCC_VERSION || FMT_CLANG_VERSION
@ -1643,8 +1657,17 @@ struct is_output_iterator<
void_t<decltype(*std::declval<decay_t<It>&>()++ = std::declval<T>())>> void_t<decltype(*std::declval<decay_t<It>&>()++ = std::declval<T>())>>
: std::true_type {}; : std::true_type {};
#ifdef FMT_USE_LOCALE
// Use the provided definition.
#elif defined(FMT_STATIC_THOUSANDS_SEPARATOR)
# define FMT_USE_LOCALE 0
#else
# define FMT_USE_LOCALE 1
#endif
// A type-erased reference to an std::locale to avoid a heavy <locale> include. // A type-erased reference to an std::locale to avoid a heavy <locale> include.
class locale_ref { struct locale_ref {
#if FMT_USE_LOCALE
private: private:
const void* locale_; // A type-erased pointer to std::locale. const void* locale_; // A type-erased pointer to std::locale.
@ -1653,6 +1676,7 @@ class locale_ref {
template <typename Locale> explicit locale_ref(const Locale& loc); template <typename Locale> explicit locale_ref(const Locale& loc);
explicit operator bool() const noexcept { return locale_ != nullptr; } explicit operator bool() const noexcept { return locale_ != nullptr; }
#endif
template <typename Locale> auto get() const -> Locale; template <typename Locale> auto get() const -> Locale;
}; };
@ -2012,7 +2036,7 @@ class context {
private: private:
appender out_; appender out_;
basic_format_args<context> args_; basic_format_args<context> args_;
detail::locale_ref loc_; FMT_NO_UNIQUE_ADDRESS detail::locale_ref loc_;
public: public:
/// The character type for the output. /// The character type for the output.

View File

@ -83,6 +83,11 @@ inline void fwrite_fully(const void* ptr, size_t count, FILE* stream) {
using std::locale; using std::locale;
using std::numpunct; using std::numpunct;
using std::use_facet; using std::use_facet;
template <typename Locale>
locale_ref::locale_ref(const Locale& loc) : locale_(&loc) {
static_assert(std::is_same<Locale, locale>::value, "");
}
#else #else
struct locale {}; struct locale {};
template <typename Char> struct numpunct { template <typename Char> struct numpunct {
@ -93,14 +98,12 @@ template <typename Char> struct numpunct {
template <typename Facet> Facet use_facet(locale) { return {}; } template <typename Facet> Facet use_facet(locale) { return {}; }
#endif // FMT_USE_LOCALE #endif // FMT_USE_LOCALE
template <typename Locale>
locale_ref::locale_ref(const Locale& loc) : locale_(&loc) {
static_assert(std::is_same<Locale, locale>::value, "");
}
template <typename Locale> auto locale_ref::get() const -> Locale { template <typename Locale> auto locale_ref::get() const -> Locale {
static_assert(std::is_same<Locale, locale>::value, ""); static_assert(std::is_same<Locale, locale>::value, "");
return locale_ ? *static_cast<const locale*>(locale_) : locale(); #if FMT_USE_LOCALE
if (locale_) return *static_cast<const locale*>(locale_);
#endif
return locale();
} }
template <typename Char> template <typename Char>
@ -1020,8 +1023,7 @@ template <> struct cache_accessor<double> {
{0xe4d5e82392a40515, 0x0fabaf3feaa5334b}, {0xe4d5e82392a40515, 0x0fabaf3feaa5334b},
{0xb8da1662e7b00a17, 0x3d6a751f3b936244}, {0xb8da1662e7b00a17, 0x3d6a751f3b936244},
{0x95527a5202df0ccb, 0x0f37801e0c43ebc9}, {0x95527a5202df0ccb, 0x0f37801e0c43ebc9},
{ 0xf13e34aabb430a15, {0xf13e34aabb430a15, 0x647726b9e7c68ff0}
0x647726b9e7c68ff0 }
#endif #endif
}; };

View File

@ -73,20 +73,6 @@
# define FMT_INLINE_VARIABLE # define FMT_INLINE_VARIABLE
#endif #endif
#ifndef FMT_NO_UNIQUE_ADDRESS
# if FMT_CPLUSPLUS >= 202002L
# if FMT_HAS_CPP_ATTRIBUTE(no_unique_address)
# define FMT_NO_UNIQUE_ADDRESS [[no_unique_address]]
// VS2019 v16.10 and later except clang-cl (https://reviews.llvm.org/D110485).
# elif (FMT_MSC_VERSION >= 1929) && !FMT_CLANG_VERSION
# define FMT_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
# endif
# endif
#endif
#ifndef FMT_NO_UNIQUE_ADDRESS
# define FMT_NO_UNIQUE_ADDRESS
#endif
// Visibility when compiled as a shared library/object. // Visibility when compiled as a shared library/object.
#if defined(FMT_LIB_EXPORT) || defined(FMT_SHARED) #if defined(FMT_LIB_EXPORT) || defined(FMT_SHARED)
# define FMT_SO_VISIBILITY(value) FMT_VISIBILITY(value) # define FMT_SO_VISIBILITY(value) FMT_VISIBILITY(value)
@ -799,14 +785,6 @@ using is_double_double = bool_constant<std::numeric_limits<T>::digits == 106>;
# define FMT_USE_FULL_CACHE_DRAGONBOX 0 # define FMT_USE_FULL_CACHE_DRAGONBOX 0
#endif #endif
#ifdef FMT_USE_LOCALE
// Use the provided definition.
#elif defined(FMT_STATIC_THOUSANDS_SEPARATOR)
# define FMT_USE_LOCALE 0
#else
# define FMT_USE_LOCALE 1
#endif
template <typename T, typename Enable = void> template <typename T, typename Enable = void>
struct is_locale : std::false_type {}; struct is_locale : std::false_type {};
template <typename T> template <typename T>
@ -2207,8 +2185,7 @@ template <typename Char = char> struct loc_writer {
template <typename Char, typename OutputIt, typename T> template <typename Char, typename OutputIt, typename T>
FMT_CONSTEXPR FMT_INLINE auto write_int(OutputIt out, write_int_arg<T> arg, FMT_CONSTEXPR FMT_INLINE auto write_int(OutputIt out, write_int_arg<T> arg,
const format_specs& specs, locale_ref) const format_specs& specs) -> OutputIt {
-> OutputIt {
static_assert(std::is_same<T, uint32_or_64_or_128_t<T>>::value, ""); static_assert(std::is_same<T, uint32_or_64_or_128_t<T>>::value, "");
auto abs_value = arg.abs_value; auto abs_value = arg.abs_value;
auto prefix = arg.prefix; auto prefix = arg.prefix;
@ -2260,9 +2237,9 @@ FMT_CONSTEXPR FMT_INLINE auto write_int(OutputIt out, write_int_arg<T> arg,
template <typename Char, typename OutputIt, typename T> template <typename Char, typename OutputIt, typename T>
FMT_CONSTEXPR FMT_NOINLINE auto write_int_noinline(OutputIt out, FMT_CONSTEXPR FMT_NOINLINE auto write_int_noinline(OutputIt out,
write_int_arg<T> arg, write_int_arg<T> arg,
const format_specs& specs, const format_specs& specs)
locale_ref loc) -> OutputIt { -> OutputIt {
return write_int<Char>(out, arg, specs, loc); return write_int<Char>(out, arg, specs);
} }
template <typename Char, typename T, template <typename Char, typename T,
FMT_ENABLE_IF(is_integral<T>::value && FMT_ENABLE_IF(is_integral<T>::value &&
@ -2273,7 +2250,7 @@ FMT_CONSTEXPR FMT_INLINE auto write(basic_appender<Char> out, T value,
-> basic_appender<Char> { -> basic_appender<Char> {
if (specs.localized() && write_loc(out, value, specs, loc)) return out; if (specs.localized() && write_loc(out, value, specs, loc)) return out;
return write_int_noinline<Char>(out, make_write_int_arg(value, specs.sign()), return write_int_noinline<Char>(out, make_write_int_arg(value, specs.sign()),
specs, loc); specs);
} }
// An inlined version of write used in format string compilation. // An inlined version of write used in format string compilation.
template <typename Char, typename OutputIt, typename T, template <typename Char, typename OutputIt, typename T,
@ -2285,8 +2262,7 @@ FMT_CONSTEXPR FMT_INLINE auto write(OutputIt out, T value,
const format_specs& specs, locale_ref loc) const format_specs& specs, locale_ref loc)
-> OutputIt { -> OutputIt {
if (specs.localized() && write_loc(out, value, specs, loc)) return out; if (specs.localized() && write_loc(out, value, specs, loc)) return out;
return write_int<Char>(out, make_write_int_arg(value, specs.sign()), specs, return write_int<Char>(out, make_write_int_arg(value, specs.sign()), specs);
loc);
} }
template <typename Char, typename OutputIt> template <typename Char, typename OutputIt>