https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125956

--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #7)
> --- a/libstdc++-v3/src/c++20/format.cc
> +++ b/libstdc++-v3/src/c++20/format.cc
> @@ -93,6 +93,19 @@ struct __encoding : locale::facet
>  #ifdef _GLIBCXX_HAVE_ICONV
>    ::iconv_t _M_cd = (::iconv_t)-1;
>    mutable mutex mx;
> +
> +
> +  // This adaptor works around the signature problems of the second
> +  // argument to iconv():  SUSv2 and others use 'const char**', but glibc
> 2.2
> +  // uses 'char**', which matches the POSIX 1003.1-2001 standard.
> +  // Using this adaptor, we deduce the correct type from the function
> pointer
> +  // and then cast the `inbuf` parameter to that type.
> +  template<typename T>
> +    size_t
> +    do_iconv(size_t (*func)(iconv_t, T, size_t*, char**, size_t*),
> +            char** inbuf, size_t* inbytes,
> +            char** outbuf, size_t* outbytes)
> +    { return ::iconv(_M_cd, (T)inbuf, inbytes, outbuf, outbytes); }
>  #endif
>  
>    // Convert `input` to UTF-8, using `out` to hold the result.
> @@ -115,8 +128,7 @@ struct __encoding : locale::facet
>         = const_cast<char*>(input.data()) + input.size() - inbytesleft;
>        char* outbytes = p + written;
>        size_t outbytesleft = n - written;
> -      size_t res = ::iconv(_M_cd, &inbytes, &inbytesleft,
> -                          &outbytes, &outbytesleft);
> +      size_t res = do_iconv(&inbytes, &inbytesleft, &outbytes,
> &outbytesleft);

Oops, this needs ::iconv passed as the first argument.

But I have a better idea anyway.

Reply via email to