Ignore a false-positive -Weffc++ operator-return value warning

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<Char>::operator=(fmt::v8::basic_string_view<Char>)
[with Char = char]’:

../../submodules/spdlog/include/spdlog/fmt/bundled/core.h:1974:17: required
from ‘constexpr void
fmt::v8::detail::specs_setter<Char>::on_fill(fmt::v8::basic_string_view<Char>)
[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<fmt::v8::detail::dynamic_specs_handler<fmt::v8::detail::compile_parse_context<char,
fmt::v8::detail::error_handler> > >&]’

../../submodules/spdlog/include/spdlog/fmt/bundled/core.h:2290:22: required
from ‘void fmt::v8::detail::check_format_string(S) [with
<template-parameter-1-1> = {unsigned int&}; S =
fmt::v8::formatter<fmt::v8::detail::bigint>::format(const
fmt::v8::detail::bigint&,
fmt::v8::format_context&)::<lambda()>::FMT_COMPILE_STRING; typename
std::enable_if<fmt::v8::is_compile_string<S>::value, int>::type <anonymous> =
0]’

../../submodules/spdlog/include/spdlog/fmt/bundled/core.h:2849:41: required
from ‘fmt::v8::basic_format_string<Char, Args>::basic_format_string(const S&)
[with S = fmt::v8::formatter<fmt::v8::detail::bigint>::format(const
fmt::v8::detail::bigint&,
fmt::v8::format_context&)::<lambda()>::FMT_COMPILE_STRING; typename
std::enable_if<std::is_convertible<const S&, fmt::v8::basic_string_view<Char>
>::value, int>::type <anonymous> = 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<Char> 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");
pull/2063/head
kcgen 4 years ago
parent 5df9b11141
commit f2ca185fdd
No known key found for this signature in database
GPG Key ID: 4AD3678F4A2C291C

@ -1876,12 +1876,20 @@ template <typename Char> 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<Char> 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<unsigned char>(size);
}
#pragma GCC diagnostic pop
constexpr auto size() const -> size_t { return size_; }
constexpr auto data() const -> const Char* { return data_; }

Loading…
Cancel
Save