On Fri, 23 Sept 2022 at 15:43, Jonathan Wakely wrote: > > 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.
And I just checked that a variable template like std::is_assignable_v also counts as "a context unrelated to either type", even when instantiated inside a member function of the type: #include <type_traits> template<typename T, typename U> constexpr bool is_assignable_v = __is_assignable(T, U); class S { operator int(); friend void g(); // #1 }; void g () { // #1 doesn't matter static_assert(std::is_assignable<int&, S>::value, ""); static_assert(std::is_assignable_v<int&, S>, ""); static_assert(__is_assignable(int&, S), ""); } The first two assertions are consistent, and fail, which is what we want. The direct use of the built-in succeeds, but we don't care.