diff --git a/include/fmt/base.h b/include/fmt/base.h index 11d3ccff..fe73e377 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -1064,16 +1064,13 @@ template struct named_arg_info { int id; }; +// named_args is non-const to suppress a bogus -Wmaybe-uninitalized in gcc 13. template FMT_CONSTEXPR void check_for_duplicate(named_arg_info* named_args, int named_arg_index, basic_string_view arg_name) { - if (named_arg_index <= 0) return; - - for (auto i = 0; i < named_arg_index; ++i) { - if (basic_string_view(named_args[i].name) == arg_name) { - report_error("duplicate named args found"); - } + for (int i = 0; i < named_arg_index; ++i) { + if (named_args[i].name == arg_name) report_error("duplicate named arg"); } } @@ -1081,7 +1078,6 @@ template ::value)> void init_named_arg(named_arg_info*, int& arg_index, int&, const T&) { ++arg_index; } - template ::value)> void init_named_arg(named_arg_info* named_args, int& arg_index, int& named_arg_index, const T& arg) { diff --git a/include/fmt/color.h b/include/fmt/color.h index b65b42d6..638f15b4 100644 --- a/include/fmt/color.h +++ b/include/fmt/color.h @@ -190,11 +190,11 @@ enum class emphasis : uint8_t { // rgb is a struct for red, green and blue colors. // Using the name "rgb" makes some editors show the color in a tooltip. struct rgb { - FMT_CONSTEXPR rgb() : r(0), g(0), b(0) {} - FMT_CONSTEXPR rgb(uint8_t r_, uint8_t g_, uint8_t b_) : r(r_), g(g_), b(b_) {} - FMT_CONSTEXPR rgb(uint32_t hex) + constexpr rgb() : r(0), g(0), b(0) {} + constexpr rgb(uint8_t r_, uint8_t g_, uint8_t b_) : r(r_), g(g_), b(b_) {} + constexpr rgb(uint32_t hex) : r((hex >> 16) & 0xFF), g((hex >> 8) & 0xFF), b(hex & 0xFF) {} - FMT_CONSTEXPR rgb(color hex) + constexpr rgb(color hex) : r((uint32_t(hex) >> 16) & 0xFF), g((uint32_t(hex) >> 8) & 0xFF), b(uint32_t(hex) & 0xFF) {} @@ -205,30 +205,30 @@ struct rgb { namespace detail { -// a bit-packed variant of an RGB color, a terminal color, or unset color. +// A bit-packed variant of an RGB color, a terminal color, or unset color. // see text_style for the bit-packing scheme. struct color_type { - FMT_CONSTEXPR color_type() noexcept = default; - FMT_CONSTEXPR color_type(color rgb_color) noexcept + constexpr color_type() noexcept = default; + constexpr color_type(color rgb_color) noexcept : value_(static_cast(rgb_color) | (1 << 24)) {} - FMT_CONSTEXPR color_type(rgb rgb_color) noexcept + constexpr color_type(rgb rgb_color) noexcept : color_type(static_cast( (static_cast(rgb_color.r) << 16) | (static_cast(rgb_color.g) << 8) | rgb_color.b)) {} - FMT_CONSTEXPR color_type(terminal_color term_color) noexcept + constexpr color_type(terminal_color term_color) noexcept : value_(static_cast(term_color) | (3 << 24)) {} - FMT_CONSTEXPR auto is_terminal_color() const noexcept -> bool { + constexpr auto is_terminal_color() const noexcept -> bool { return (value_ & (1 << 25)) != 0; } - FMT_CONSTEXPR auto value() const noexcept -> uint32_t { + constexpr auto value() const noexcept -> uint32_t { return value_ & 0xFFFFFF; } - FMT_CONSTEXPR color_type(uint32_t value) noexcept : value_(value) {} + constexpr color_type(uint32_t value) noexcept : value_(value) {} - uint32_t value_{}; + uint32_t value_ = 0; }; } // namespace detail @@ -341,7 +341,7 @@ class text_style { friend FMT_CONSTEXPR auto bg(detail::color_type background) noexcept -> text_style; - uint64_t style_{}; + uint64_t style_ = 0; }; /// Creates a text style from the foreground (text) color. @@ -490,7 +490,7 @@ void vformat_to(buffer& buf, text_style ts, basic_string_view fmt, buf.append(background.begin(), background.end()); } vformat_to(buf, fmt, args); - if (ts != text_style{}) reset_color(buf); + if (ts != text_style()) reset_color(buf); } } // namespace detail diff --git a/test/color-test.cc b/test/color-test.cc index 73c9eed0..e295ab5e 100644 --- a/test/color-test.cc +++ b/test/color-test.cc @@ -12,9 +12,9 @@ #include "gtest-extra.h" // EXPECT_WRITE, EXPECT_THROW_MSG TEST(color_test, text_style) { - EXPECT_FALSE(fmt::text_style{}.has_foreground()); - EXPECT_FALSE(fmt::text_style{}.has_background()); - EXPECT_FALSE(fmt::text_style{}.has_emphasis()); + EXPECT_FALSE(fmt::text_style().has_foreground()); + EXPECT_FALSE(fmt::text_style().has_background()); + EXPECT_FALSE(fmt::text_style().has_emphasis()); EXPECT_TRUE(fg(fmt::rgb(0)).has_foreground()); EXPECT_FALSE(fg(fmt::rgb(0)).has_background()); @@ -57,18 +57,20 @@ TEST(color_test, text_style) { EXPECT_NO_THROW(fg(fmt::terminal_color::white) | bg(fmt::terminal_color::white)); EXPECT_NO_THROW(fg(fmt::terminal_color::white) | bg(fmt::rgb(0xFFFFFF))); - EXPECT_NO_THROW(fg(fmt::terminal_color::white) | fmt::text_style{}); - EXPECT_NO_THROW(bg(fmt::terminal_color::white) | fmt::text_style{}); + EXPECT_NO_THROW(fg(fmt::terminal_color::white) | fmt::text_style()); + EXPECT_NO_THROW(bg(fmt::terminal_color::white) | fmt::text_style()); } TEST(color_test, format) { - EXPECT_EQ(fmt::format(fmt::text_style{}, "no style"), "no style"); + EXPECT_EQ(fmt::format(fmt::text_style(), "no style"), "no style"); EXPECT_EQ(fmt::format(fg(fmt::rgb(255, 20, 30)), "rgb(255,20,30)"), "\x1b[38;2;255;020;030mrgb(255,20,30)\x1b[0m"); - EXPECT_EQ(fmt::format(fg(fmt::rgb(255, 0, 0)) | fg(fmt::rgb(0, 20, 30)), "rgb(255,20,30)"), + EXPECT_EQ(fmt::format(fg(fmt::rgb(255, 0, 0)) | fg(fmt::rgb(0, 20, 30)), + "rgb(255,20,30)"), "\x1b[38;2;255;020;030mrgb(255,20,30)\x1b[0m"); - EXPECT_EQ(fmt::format(fg(fmt::rgb(0, 0, 0)) | fg(fmt::rgb(0, 0, 0)), "rgb(0,0,0)"), - "\x1b[38;2;000;000;000mrgb(0,0,0)\x1b[0m"); + EXPECT_EQ( + fmt::format(fg(fmt::rgb(0, 0, 0)) | fg(fmt::rgb(0, 0, 0)), "rgb(0,0,0)"), + "\x1b[38;2;000;000;000mrgb(0,0,0)\x1b[0m"); EXPECT_EQ(fmt::format(fg(fmt::color::blue), "blue"), "\x1b[38;2;000;000;255mblue\x1b[0m"); EXPECT_EQ( diff --git a/test/format-test.cc b/test/format-test.cc index e2c595c9..f83d1626 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -600,7 +600,7 @@ TEST(format_test, named_arg) { format_error, "cannot switch from manual to automatic argument indexing"); EXPECT_THROW_MSG((void)fmt::format("{a}", fmt::arg("a", 1), - fmt::arg("a", 10)), format_error, "duplicate named args found"); + fmt::arg("a", 10)), format_error, "duplicate named arg"); } TEST(format_test, auto_arg_index) {