[PATCH] c++, libstdc++: Add __make_signed and __make_unsigned intrinsic traits
Jonathan Wakely
jwakely@redhat.com
Mon Nov 9 11:26:05 GMT 2026
On Mon, 9 Nov 2026 at 11:24, Jonathan Wakely <jwakely@redhat.com> wrote:
>
> On Mon, 9 Nov 2026 at 11:21, Jakub Jelinek <jakub@redhat.com> wrote:
> >
> > On Mon, Nov 09, 2026 at 11:05:51AM +0000, Jonathan Wakely wrote:
> > > On Mon, 09 Nov 2026 at 10:46 +0000, Jonathan Wakely wrote:
> > > > On Sat, 07 Nov 2026 at 15:00 +0100, Jakub Jelinek wrote:
> > > > > Another complication is that simd_details.h was using __make_unsigned
> > > > > trait instead of make_unsigned and was doing that intentionally, seems
> > > > > it wants make_unsigned<_From>::type if the type is integral and
> > > > > _From otherwise. Dunno if what I wrote is the simplest.
> > > >
> > > > It looks good to me.
> > >
> > > I suppose an alternative would be:
> > >
> > > template<typename _Tp>
> > > using __maybe_make_unsigned
> > > = typename __conditional_t<integral<_Tp>, make_unsigned<_Tp>,
> > > type_identity<_Tp>>::type;
> >
> > I was thinking about using conditional, but thought that the template
> > argument in that case (make_unsigned<_Tp>) is instantiated even
> > if the condition is false.
>
> Not as written above. Just naming make_unsigned<_Tp> doesn't
> instantiate it, that only happens when you use
> make_unsigned<_Tp>::type, which is only done on the result of
> __conditional_t<>::type, so we only access ::type for the one that is
> selected by the condition.
>
> i.e. equivalent to:
>
> using A = make_unsigned<T>;
> using B = type_identity<T>;
> using C = conditional_t<Cond, A, B>;
> using D = typename C::type;
>
> The aliases A and B do not instantiate anything. The alias C just
> selects one of A or B. The alias D instantiates the selected one to
> get its ::type member.
That uses conditional_t for clarity, but in the real library code we
should use __conditional_t in most places, because it has a more
efficient implementation than conditional_t.
>
> > Working on something else right now, so don't
> > have the _BitInt patches in my tree, but can verify that later.
> > And already the instantiation of it results in an error now I think (both
> > in the g++ implementation in the patch and in the clang++ implementation).
> >
> > Jakub
> >
More information about the Libstdc++
mailing list