libstdc++: Make std::pointer_traits SFINAE-friendly [PR96416]
authorJonathan Wakely <jwakely@redhat.com>
Thu, 25 Nov 2021 16:49:45 +0000 (16:49 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 25 Nov 2021 23:12:14 +0000 (23:12 +0000)
commitb8018e5c5ec0e9b6948182f13fba47c67b758d8a
treecd93663f7bd2a993e5a5a0feef2b6947e6e8e4a6
parent1b0acc4b800b589a39d637d7312da5cf969a5765
libstdc++: Make std::pointer_traits SFINAE-friendly [PR96416]

This implements the resolution I'm proposing for LWG 3545, to avoid hard
errors when using std::to_address for types that make pointer_traits
ill-formed.

Consistent with std::iterator_traits, instantiating std::pointer_traits
for a non-pointer type will be well-formed, but give an empty type with
no member types. This avoids the problematic cases for std::to_address.
Additionally, the pointer_to member is now only declared when the
element type is not cv void (and for C++20, when the function body would
be well-formed). The rebind member was already SFINAE-friendly in our
implementation.

libstdc++-v3/ChangeLog:

PR libstdc++/96416
* include/bits/ptr_traits.h (pointer_traits): Reimplement to be
SFINAE-friendly (LWG 3545).
* testsuite/20_util/pointer_traits/lwg3545.cc: New test.
* testsuite/20_util/to_address/1_neg.cc: Adjust dg-error line.
* testsuite/20_util/to_address/lwg3545.cc: New test.
libstdc++-v3/include/bits/ptr_traits.h
libstdc++-v3/testsuite/20_util/pointer_traits/lwg3545.cc [new file with mode: 0644]
libstdc++-v3/testsuite/20_util/to_address/1_neg.cc
libstdc++-v3/testsuite/20_util/to_address/lwg3545.cc [new file with mode: 0644]