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.
This commit is contained in:
Mike Gelfand 2023-01-02 14:59:53 -08:00 committed by GitHub
parent eb27220662
commit 105d23c09e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 20 deletions

View File

@ -19,6 +19,7 @@
#include <set>
#include <string>
#include <string_view>
#include <tuple>
#include <vector>
#ifdef _WIN32
@ -307,28 +308,17 @@ namespace
namespace tr_strvUtf8Clean_impl
{
class SecondIconvArg
template<std::size_t N, typename F>
struct ArgTypeImpl;
template<std::size_t N, typename R, typename... ArgTs>
struct ArgTypeImpl<N, R (*)(ArgTs...)> : std::tuple_element<1, std::tuple<ArgTs...>>
{
public:
explicit SecondIconvArg(char const* arg)
: arg_(arg)
{
}
operator char**() &&
{
return const_cast<char**>(&arg_);
}
operator char const**() &&
{
return &arg_;
}
private:
char const* arg_;
};
template<std::size_t N, typename F>
using ArgType = typename ArgTypeImpl<N, F>::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<ArgType<1, decltype(&iconv)>>(&inbuf), &inbytesleft, &out, &outbytesleft);
iconv_close(cd);
if (rv != size_t(-1))
{