Fix some warnings (#1667)

* Fix sign-conversion warning

* Add missing "extern template" declarations for non-header-only build

* Use typed enums to fix Wsigned-enum-bitfield warnings

* Consolidate FMT_HEADER_ONLY code
This commit is contained in:
peterbell10
2020-05-07 14:14:07 +01:00
committed by GitHub
parent 1c86a99e8f
commit 44639b11fe
2 changed files with 25 additions and 3 deletions

View File

@@ -1022,12 +1022,12 @@ template <typename Char> struct fill_t {
// We cannot use enum classes as bit fields because of a gcc bug // We cannot use enum classes as bit fields because of a gcc bug
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61414. // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61414.
namespace align { namespace align {
enum type { none, left, right, center, numeric }; enum type : uint8_t { none, left, right, center, numeric };
} }
using align_t = align::type; using align_t = align::type;
namespace sign { namespace sign {
enum type { none, minus, plus, space }; enum type : uint8_t { none, minus, plus, space };
} }
using sign_t = sign::type; using sign_t = sign::type;
@@ -3331,6 +3331,28 @@ typename buffer_context<Char>::iterator internal::vformat_to(
#ifndef FMT_HEADER_ONLY #ifndef FMT_HEADER_ONLY
extern template format_context::iterator internal::vformat_to( extern template format_context::iterator internal::vformat_to(
internal::buffer<char>&, string_view, basic_format_args<format_context>); internal::buffer<char>&, string_view, basic_format_args<format_context>);
namespace internal {
extern template FMT_API std::string grouping_impl<char>(locale_ref loc);
extern template FMT_API std::string grouping_impl<wchar_t>(locale_ref loc);
extern template FMT_API char thousands_sep_impl<char>(locale_ref loc);
extern template FMT_API wchar_t thousands_sep_impl<wchar_t>(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>(double value, int precision, float_specs specs,
buffer<char>& buf);
extern template
int format_float<long double>(long double value, int precision,
float_specs specs, buffer<char>& buf);
int snprintf_float(float value, int precision, float_specs specs,
buffer<char>& buf) = delete;
extern template
int snprintf_float<double>(double value, int precision, float_specs specs,
buffer<char>& buf);
extern template
int snprintf_float<long double>(long double value, int precision,
float_specs specs, buffer<char>& buf);
}
#endif #endif
template <typename S, typename Char = char_t<S>, template <typename S, typename Char = char_t<S>,

View File

@@ -507,7 +507,7 @@ OutputIt basic_printf_context<OutputIt, Char>::format() {
auto str_end = str + specs.precision; auto str_end = str + specs.precision;
auto nul = std::find(str, str_end, Char()); auto nul = std::find(str, str_end, Char());
arg = internal::make_arg<basic_printf_context>(basic_string_view<Char>( arg = internal::make_arg<basic_printf_context>(basic_string_view<Char>(
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)) if (specs.alt && visit_format_arg(internal::is_zero_int(), arg))
specs.alt = false; specs.alt = false;