[PATCH] c++: Implement __is_{nothrow_,}convertible [PR106784]
Jonathan Wakely
jwakely@redhat.com
Fri Sep 23 14:43:18 GMT 2022
On Fri, 23 Sept 2022 at 15:34, Marek Polacek wrote:
>
> On Thu, Sep 22, 2022 at 06:14:44PM -0400, Jason Merrill wrote:
> > On 9/22/22 09:39, Marek Polacek wrote:
> > > To improve compile times, the C++ library could use compiler built-ins
> > > rather than implementing std::is_convertible (and _nothrow) as class
> > > templates. This patch adds the built-ins. We already have
> > > __is_constructible and __is_assignable, and the nothrow forms of those.
> > >
> > > Microsoft (and clang, for compatibility) also provide an alias called
> > > __is_convertible_to. I did not add it, but it would be trivial to do
> > > so.
> > >
> > > I noticed that our __is_assignable doesn't implement the "Access checks
> > > are performed as if from a context unrelated to either type" requirement,
> > > therefore std::is_assignable / __is_assignable give two different results
> > > here:
> > >
> > > class S {
> > > operator int();
> > > friend void g(); // #1
> > > };
> > >
> > > void
> > > g ()
> > > {
> > > // #1 doesn't matter
> > > static_assert(std::is_assignable<int&, S>::value, "");
> > > static_assert(__is_assignable(int&, S), "");
> > > }
> > >
> > > This is not a problem if __is_assignable is not meant to be used by
> > > the users.
> >
> > That's fine, it's not.
>
> Okay then. libstdc++ needs to make sure then that it's handled right.
That's fine, the type traits in libstdc++ are always "a context
unrelated to either type", unless users do something idiotic like
declare std::is_assignable as a friend.
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1339r1.pdf
wants to explicitly say that's idiotic.
More information about the Gcc-patches
mailing list