From f2ca185fdd4388a97205c026d4ed2b91a696d092 Mon Sep 17 00:00:00 2001 From: kcgen <1557255+kcgen@users.noreply.github.com> Date: Sat, 21 Aug 2021 15:06:44 -0700 Subject: [PATCH] Ignore a false-positive -Weffc++ operator-return value warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modern versions of GCC (11) mis-identify this template operator as a class assignment operator, generating repeat warnings (below) for every source file in which spdlog is included. This commit uses a pragma to prevent this false-positive from being generated. --- False positive warning follows: ../../submodules/spdlog/include/spdlog/fmt/bundled/core.h: In instantiation of ‘constexpr void fmt::v8::detail::fill_t::operator=(fmt::v8::basic_string_view) [with Char = char]’: ../../submodules/spdlog/include/spdlog/fmt/bundled/core.h:1974:17: required from ‘constexpr void fmt::v8::detail::specs_setter::on_fill(fmt::v8::basic_string_view) [with Char = char]’ ../../submodules/spdlog/include/spdlog/fmt/bundled/core.h:2146:24: required from ‘constexpr const Char* fmt::v8::detail::parse_align(const Char*, const Char*, Handler&&) [with Char = char; Handler = fmt::v8::detail::specs_checker > >&]’ ../../submodules/spdlog/include/spdlog/fmt/bundled/core.h:2290:22: required from ‘void fmt::v8::detail::check_format_string(S) [with = {unsigned int&}; S = fmt::v8::formatter::format(const fmt::v8::detail::bigint&, fmt::v8::format_context&)::::FMT_COMPILE_STRING; typename std::enable_if::value, int>::type = 0]’ ../../submodules/spdlog/include/spdlog/fmt/bundled/core.h:2849:41: required from ‘fmt::v8::basic_format_string::basic_format_string(const S&) [with S = fmt::v8::formatter::format(const fmt::v8::detail::bigint&, fmt::v8::format_context&)::::FMT_COMPILE_STRING; typename std::enable_if >::value, int>::type = 0; Char = char; Args = {unsigned int&}]’ ../../submodules/spdlog/include/spdlog/fmt/bundled/format-inl.h:2518:22: required from here ../../submodules/spdlog/include/spdlog/fmt/bundled/core.h:1879:22: warning: ‘operator=’ should return a reference to ‘*this’ [-Weffc++] 1879 | FMT_CONSTEXPR void operator=(basic_string_view s) { | ^~~~~~~~ ../../submodules/spdlog/include/spdlog/fmt/bundled/core.h:1881:66: warning: ‘operator=’ should return a reference to ‘*this’ [-Weffc++] 1881 | if (size > max_size) return throw_format_error("invalid fill"); --- include/spdlog/fmt/bundled/core.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/include/spdlog/fmt/bundled/core.h b/include/spdlog/fmt/bundled/core.h index d058398a..b33293eb 100644 --- a/include/spdlog/fmt/bundled/core.h +++ b/include/spdlog/fmt/bundled/core.h @@ -1876,12 +1876,20 @@ template struct fill_t { unsigned char size_ = 1; public: +// GCC's effective C++ warning mis-identifies this as an assignment +// operator, and therefore recommends returning a reference to *this. +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Weffc++" FMT_CONSTEXPR void operator=(basic_string_view s) { auto size = s.size(); - if (size > max_size) return throw_format_error("invalid fill"); + if (size > max_size) { + throw_format_error("invalid fill"); + return; + } for (size_t i = 0; i < size; ++i) data_[i] = s[i]; size_ = static_cast(size); } +#pragma GCC diagnostic pop constexpr auto size() const -> size_t { return size_; } constexpr auto data() const -> const Char* { return data_; }