libstdc++: Update std::pointer_traits to match new LWG 3545 wording
authorJonathan Wakely <jwakely@redhat.com>
Mon, 26 Sep 2022 17:59:45 +0000 (18:59 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Mon, 26 Sep 2022 22:47:37 +0000 (23:47 +0100)
commit03cb9ed8dd603dbb77762ca948fc6381ba190731
treeb7259318f6ef5cf0fa4309f22452c303287e49f2
parentaf85ad891703db220b25e7847f10d0bbec4becf4
libstdc++: Update std::pointer_traits to match new LWG 3545 wording

It was pointed out in recent LWG 3545 discussion that having a
constrained partial specialization of std::pointer_traits can cause
ambiguities with program-defined specializations. For example, the
addition to the testcase has:

template<typename P> requires std::derived_from<P, base_type
struct std::pointer_traits<P>;

This would be ambiguous with the library's own constrained partial
specialization:

template<typename Ptr> requires requires { typename Ptr::element_type; }
struct std::pointer_traits<Ptr>;

Neither specialization is more specialized than the other for a type
that is derived from base_type and also has an element_type member.

The solution is to remove the library's partial specialization, and do
the check for Ptr::element_type in the __ptr_traits_elem helper (which
is what we already do for !__cpp_concepts anyway).

libstdc++-v3/ChangeLog:

* include/bits/ptr_traits.h (__ptr_traits_elem) [__cpp_concepts]:
Also define the __ptr_traits_elem class template for the
concepts case.
(pointer_traits<Ptr>): Remove constrained partial
specialization.
* testsuite/20_util/pointer_traits/lwg3545.cc: Check for
ambiguitiy with program-defined partial specialization.
libstdc++-v3/include/bits/ptr_traits.h
libstdc++-v3/testsuite/20_util/pointer_traits/lwg3545.cc