C++ Logo

sg16

Advanced search

Re: [SG16] std::print usage experience

From: Tom Honermann <tom_at_[hidden]>
Date: Wed, 14 Jul 2021 01:41:09 -0400
On 7/12/21 5:33 PM, Victor Zverovich via SG16 wrote:
> Thanks, Corentin, that's a great find. This is indeed very close to
> what is proposed and a nice addition to the implementation experience
> in {fmt} and Rust.

There are some notable differences relative to what we've been discussing.

 1. The LLVM implementation has a wide contract; there is no UB if the
    input is not valid UTF-8.
 2. If the provided text is not valid UTF-8, then the raw input is
    written through the file descriptor rather than being transcoded to
    UTF-16 with substitution characters and then written directly to the
    console.

Tangent: the method LLVM is using to determine if a file descriptor
corresponds to a console
<https://github.com/llvm-mirror/llvm/blob/master/lib/Support/raw_ostream.cpp#L589-L593>
looks wrong to me and, I think, will result in attempts to write text to
the console when it was actually directed elsewhere. Such writes likely
fail with the result that the original input ends up getting written to
the file descriptor anyway. We previously discussed how to detect
output directed to a console here
<https://lists.isocpp.org/sg16/2021/01/2008.php> (and some day we'll
have email archives that aren't embarrassing. I hope).

Tom.

>
> Cheers,
> Victor
>
> On Mon, Jul 12, 2021 at 1:59 PM Corentin via SG16
> <sg16_at_[hidden] <mailto:sg16_at_[hidden]>> wrote:
>
> Hello,
>
> LLVM implemented exactly what is proposed by std::print 3 years ago
> https://github.com/llvm-mirror/llvm/blob/master/lib/Support/raw_ostream.cpp#L638-L685
> <https://github.com/llvm-mirror/llvm/blob/master/lib/Support/raw_ostream.cpp#L638-L685>
>
> I thought this might be of interest.
>
> Regards,
> Corentin
> --
> SG16 mailing list
> SG16_at_[hidden] <mailto:SG16_at_[hidden]>
> https://lists.isocpp.org/mailman/listinfo.cgi/sg16
> <https://lists.isocpp.org/mailman/listinfo.cgi/sg16>
>
>


Received on 2021-07-14 00:41:13