From b4f40245729db11306efa2248bafde7a0f556b0f Mon Sep 17 00:00:00 2001 From: Peter Bell Date: Wed, 6 May 2020 20:38:08 +0100 Subject: [PATCH 1/4] Fix sign-conversion warning --- include/fmt/printf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/fmt/printf.h b/include/fmt/printf.h index ed84f1b25067..6f2c2adaa030 100644 --- a/include/fmt/printf.h +++ b/include/fmt/printf.h @@ -507,7 +507,7 @@ OutputIt basic_printf_context::format() { auto str_end = str + specs.precision; auto nul = std::find(str, str_end, Char()); arg = internal::make_arg(basic_string_view( - str, nul != str_end ? nul - str : specs.precision)); + str, internal::to_unsigned(nul != str_end ? nul - str : specs.precision))); } if (specs.alt && visit_format_arg(internal::is_zero_int(), arg)) specs.alt = false; From 5147edc5e7b463134a999e27a7ccbb229a51d947 Mon Sep 17 00:00:00 2001 From: Peter Bell Date: Wed, 6 May 2020 20:38:52 +0100 Subject: [PATCH 2/4] Add missing "extern template" declarations for non-header-only build --- include/fmt/format.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/include/fmt/format.h b/include/fmt/format.h index ed4ef1a2817e..6d6c2d4cce79 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -849,6 +849,10 @@ inline int count_digits(uint32_t n) { #endif template FMT_API std::string grouping_impl(locale_ref loc); +#ifndef FMT_HEADER_ONLY +extern template FMT_API std::string grouping_impl(locale_ref loc); +extern template FMT_API std::string grouping_impl(locale_ref loc); +#endif template inline std::string grouping(locale_ref loc) { return grouping_impl(loc); } @@ -857,6 +861,10 @@ template <> inline std::string grouping(locale_ref loc) { } template FMT_API Char thousands_sep_impl(locale_ref loc); +#ifndef FMT_HEADER_ONLY +extern template FMT_API char thousands_sep_impl(locale_ref loc); +extern template FMT_API wchar_t thousands_sep_impl(locale_ref loc); +#endif template inline Char thousands_sep(locale_ref loc) { return Char(thousands_sep_impl(loc)); } @@ -865,6 +873,10 @@ template <> inline wchar_t thousands_sep(locale_ref loc) { } template FMT_API Char decimal_point_impl(locale_ref loc); +#ifndef FMT_HEADER_ONLY +extern template FMT_API char decimal_point_impl(locale_ref loc); +extern template FMT_API wchar_t decimal_point_impl(locale_ref loc); +#endif template inline Char decimal_point(locale_ref loc) { return Char(decimal_point_impl(loc)); } @@ -1205,11 +1217,31 @@ template class float_writer { template int format_float(T value, int precision, float_specs specs, buffer& buf); +#ifndef FMT_HEADER_ONLY +extern template +int format_float(double value, int precision, float_specs specs, + buffer& buf); +extern template +int format_float(long double value, int precision, + float_specs specs, buffer& buf); +#endif + // Formats a floating-point number with snprintf. template int snprintf_float(T value, int precision, float_specs specs, buffer& buf); +#ifndef FMT_HEADER_ONLY +int snprintf_float(float value, int precision, float_specs specs, + buffer& buf) = delete; +extern template +int snprintf_float(double value, int precision, float_specs specs, + buffer& buf); +extern template +int snprintf_float(long double value, int precision, + float_specs specs, buffer& buf); +#endif + template T promote_float(T value) { return value; } inline double promote_float(float value) { return static_cast(value); } From 6a7c7eac0b6a56f38fed88a217786c31b0a8439d Mon Sep 17 00:00:00 2001 From: Peter Bell Date: Wed, 6 May 2020 20:39:33 +0100 Subject: [PATCH 3/4] Use typed enums to fix Wsigned-enum-bitfield warnings --- include/fmt/format.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 6d6c2d4cce79..bbc5ef702b53 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -1034,12 +1034,12 @@ template struct fill_t { // We cannot use enum classes as bit fields because of a gcc bug // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61414. namespace align { -enum type { none, left, right, center, numeric }; +enum type : uint8_t { none, left, right, center, numeric }; } using align_t = align::type; namespace sign { -enum type { none, minus, plus, space }; +enum type : uint8_t { none, minus, plus, space }; } using sign_t = sign::type; From 905d7c47f54864e6ed25ddfc7add21825d5d2675 Mon Sep 17 00:00:00 2001 From: Peter Bell Date: Thu, 7 May 2020 00:47:01 +0100 Subject: [PATCH 4/4] Consolidate FMT_HEADER_ONLY code --- include/fmt/format.h | 54 ++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 32 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index bbc5ef702b53..d06db1cdeb99 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -849,10 +849,6 @@ inline int count_digits(uint32_t n) { #endif template FMT_API std::string grouping_impl(locale_ref loc); -#ifndef FMT_HEADER_ONLY -extern template FMT_API std::string grouping_impl(locale_ref loc); -extern template FMT_API std::string grouping_impl(locale_ref loc); -#endif template inline std::string grouping(locale_ref loc) { return grouping_impl(loc); } @@ -861,10 +857,6 @@ template <> inline std::string grouping(locale_ref loc) { } template FMT_API Char thousands_sep_impl(locale_ref loc); -#ifndef FMT_HEADER_ONLY -extern template FMT_API char thousands_sep_impl(locale_ref loc); -extern template FMT_API wchar_t thousands_sep_impl(locale_ref loc); -#endif template inline Char thousands_sep(locale_ref loc) { return Char(thousands_sep_impl(loc)); } @@ -873,10 +865,6 @@ template <> inline wchar_t thousands_sep(locale_ref loc) { } template FMT_API Char decimal_point_impl(locale_ref loc); -#ifndef FMT_HEADER_ONLY -extern template FMT_API char decimal_point_impl(locale_ref loc); -extern template FMT_API wchar_t decimal_point_impl(locale_ref loc); -#endif template inline Char decimal_point(locale_ref loc) { return Char(decimal_point_impl(loc)); } @@ -1217,31 +1205,11 @@ template class float_writer { template int format_float(T value, int precision, float_specs specs, buffer& buf); -#ifndef FMT_HEADER_ONLY -extern template -int format_float(double value, int precision, float_specs specs, - buffer& buf); -extern template -int format_float(long double value, int precision, - float_specs specs, buffer& buf); -#endif - // Formats a floating-point number with snprintf. template int snprintf_float(T value, int precision, float_specs specs, buffer& buf); -#ifndef FMT_HEADER_ONLY -int snprintf_float(float value, int precision, float_specs specs, - buffer& buf) = delete; -extern template -int snprintf_float(double value, int precision, float_specs specs, - buffer& buf); -extern template -int snprintf_float(long double value, int precision, - float_specs specs, buffer& buf); -#endif - template T promote_float(T value) { return value; } inline double promote_float(float value) { return static_cast(value); } @@ -3369,6 +3337,28 @@ typename buffer_context::iterator internal::vformat_to( #ifndef FMT_HEADER_ONLY extern template format_context::iterator internal::vformat_to( internal::buffer&, string_view, basic_format_args); +namespace internal { +extern template FMT_API std::string grouping_impl(locale_ref loc); +extern template FMT_API std::string grouping_impl(locale_ref loc); +extern template FMT_API char thousands_sep_impl(locale_ref loc); +extern template FMT_API wchar_t thousands_sep_impl(locale_ref loc); +extern template FMT_API char decimal_point_impl(locale_ref loc); +extern template FMT_API wchar_t decimal_point_impl(locale_ref loc); +extern template +int format_float(double value, int precision, float_specs specs, + buffer& buf); +extern template +int format_float(long double value, int precision, + float_specs specs, buffer& buf); +int snprintf_float(float value, int precision, float_specs specs, + buffer& buf) = delete; +extern template +int snprintf_float(double value, int precision, float_specs specs, + buffer& buf); +extern template +int snprintf_float(long double value, int precision, + float_specs specs, buffer& buf); +} #endif template ,