C++ Logo

sg16

Advanced search

Re: [isocpp-sg16] Follow up on SG16 review of P2996R2 (Reflection for C++26)

From: Corentin Jabot <corentinjabot_at_[hidden]>
Date: Thu, 9 May 2024 20:48:17 +0200
On Thu, May 9, 2024, 19:37 Mark de Wever <koraq_at_[hidden]> wrote:

> On Tue, Apr 30, 2024 at 12:41:56PM +0200, Corentin Jabot via SG16 wrote:
> > On Tue, Apr 30, 2024 at 12:45 AM Tom Honermann <tom_at_[hidden]>
> wrote:
> >
> > > On 4/29/24 4:11 PM, Peter Dimov via SG16 wrote:
> > > > Tom Honermann wrote:
> > > >> I'm not entirely sure that cout << std::format("{}", u8"...")
> is
> > > We'll have to see what Corentin proposes :)
> > >
> >
> > Very rough draft https://isocpp.org/files/papers/D3258R0.pdf
>
> Thanks for working on this!
>
> I know it is an early rushed draft, but I have some concerns regarding
> the wording changes of [format.arg]
>
> You did not add char8_t, char16_t, and char32_t to the variant, so these
> are in stored in the handle. However you add wording
>

The intent is that they should be in the variant, I will add them.


> otherwise, if TD is a Unicode character type, initializes value with v
>
> This requires storing the Unicode character types in the variant instead
> of in the handle.
>
> You add 6 (or 9) types to the variant. However all major implementations
> use a tagged union instead of a variant. Based on
>
> [format.args]/1
>
> An instance of basic_format_args provides access to formatting
> arguments. Implementations should optimize the representation of
> basic_format_args for a small number of formatting arguments.
>
> [Note 1: For example, by storing indices of type alternatives
> separately from values and packing the former. — end note]
>
> all implementations store the tag in a bit field
> libc++ 5 bits [1]
> libstdc++ 5 bits [2]
> MSVC STL 4 bits [3]
>
> So these new elements don't fit for MSVC STL. Looking at the number of
> extension types in libstdc++'s enum type greatly reduces the number of
> future extensions possible. I'm not sure whether the change in the
> number of variant alternates will be an ABI-issue for MSVC STL or
> libstdc++. (libc++ has sufficient space at the moment.)
>

Thanks for raising that issue. I pinged Jonathan, I'll try to see if we can
get someone from msvc too


> An alternative for implementations is storing these values in the handle
> object. However this would be non-conforming. The difference is
> observable when using basic_format_arg::visit(); elements stored in the
> handle can't be visited.
>
> Another small nit
>
> otherwise, if TD is a specialization of basic_string_view or
> basic_string and TD::value_type is char_type <ins>or a Unicode
> character type</ins>, initializes value with
> basic_string_view<<del>char_type</del><ins>TD<ins>>(v.data(), v.size());
>
> This should be TD::value_type instead of TD.
>

Thanks

>
> [1]
> https://github.com/mordante/llvm-project/blob/main/libcxx/include/__format/format_arg.h#L46
> [2]
> https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/std/format
> [3] https://github.com/microsoft/STL/blob/main/stl/inc/format#L2001
>
> Cheers,
> Mark
>

Received on 2024-05-09 18:48:29