From 105d23c09ecffc0c8144d38aacc637dc6b985491 Mon Sep 17 00:00:00 2001 From: Mike Gelfand Date: Mon, 2 Jan 2023 14:59:53 -0800 Subject: [PATCH] Fix clang-tidy issue in `iconv` 2nd argument helper (#4520) Since operators were intentionally implicit and we don't want to add more `NOLINT` comments than necessary, rework the approach to deduce the argument type instead and cast to it. --- libtransmission/utils.cc | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/libtransmission/utils.cc b/libtransmission/utils.cc index 880750576..822adb712 100644 --- a/libtransmission/utils.cc +++ b/libtransmission/utils.cc @@ -19,6 +19,7 @@ #include #include #include +#include #include #ifdef _WIN32 @@ -307,28 +308,17 @@ namespace namespace tr_strvUtf8Clean_impl { -class SecondIconvArg +template +struct ArgTypeImpl; + +template +struct ArgTypeImpl : std::tuple_element<1, std::tuple> { -public: - explicit SecondIconvArg(char const* arg) - : arg_(arg) - { - } - - operator char**() && - { - return const_cast(&arg_); - } - - operator char const**() && - { - return &arg_; - } - -private: - char const* arg_; }; +template +using ArgType = typename ArgTypeImpl::type; + bool validateUtf8(std::string_view sv, char const** good_end) { auto const* begin = std::data(sv); @@ -381,10 +371,11 @@ std::string to_utf8(std::string_view sv) continue; } + auto const* inbuf = std::data(sv); size_t inbytesleft = std::size(sv); char* out = std::data(buf); size_t outbytesleft = std::size(buf); - auto const rv = iconv(cd, SecondIconvArg(std::data(sv)), &inbytesleft, &out, &outbytesleft); + auto const rv = iconv(cd, const_cast>(&inbuf), &inbytesleft, &out, &outbytesleft); iconv_close(cd); if (rv != size_t(-1)) {