From df66516ed35c1a22231f283cc8e4a2dbc8d57c13 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 14 Nov 2020 09:02:14 -0800 Subject: [PATCH] Workaround an issue with mixing std versions in gcc (#2017) --- include/fmt/format.h | 14 +++----------- test/format-test.cc | 7 ++++--- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index b967afea..1a037b02 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -1145,8 +1145,8 @@ template struct null {}; template struct fill_t { private: enum { max_size = 4 }; - Char data_[max_size]; - unsigned char size_; + Char data_[max_size] = {Char(' '), Char(0), Char(0), Char(0)}; + unsigned char size_ = 1; public: FMT_CONSTEXPR void operator=(basic_string_view s) { @@ -1166,13 +1166,6 @@ template struct fill_t { FMT_CONSTEXPR const Char& operator[](size_t index) const { return data_[index]; } - - static FMT_CONSTEXPR fill_t make() { - auto fill = fill_t(); - fill[0] = Char(' '); - fill.size_ = 1; - return fill; - } }; } // namespace detail @@ -1204,8 +1197,7 @@ template struct basic_format_specs { type(0), align(align::none), sign(sign::none), - alt(false), - fill(detail::fill_t::make()) {} + alt(false) {} }; using format_specs = basic_format_specs; diff --git a/test/format-test.cc b/test/format-test.cc index 5626fa28..d3f21b47 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -2423,17 +2423,17 @@ TEST(FormatTest, CharTraitsIsNotAmbiguous) { #endif } +#if __cplusplus > 201103L struct custom_char { int value; custom_char() = default; - template custom_char(T val) : value(static_cast(val)) {} + template + constexpr custom_char(T val) : value(static_cast(val)) {} operator int() const { return value; } }; -int to_ascii(custom_char c) { return c; } - FMT_BEGIN_NAMESPACE template <> struct is_char : std::true_type {}; FMT_END_NAMESPACE @@ -2444,6 +2444,7 @@ TEST(FormatTest, FormatCustomChar) { EXPECT_EQ(result.size(), 1); EXPECT_EQ(result[0], custom_char('x')); } +#endif // Convert a char8_t string to std::string. Otherwise GTest will insist on // inserting `char8_t` NTBS into a `char` stream which is disabled by P1423.