std::to_address implementation and std::pointer_traits's static_assert
Jonathan Wakely
jwakely@redhat.com
Tue Apr 20 13:36:19 GMT 2021
On 20/04/21 15:34 +0200, Ion Gaztañaga via Libstdc++ wrote:
>Hi,
>
>While trying to add contiguous_iterator support for Boost.Container so
>that users can use std::span with boost::container::vector, I've found
>a possible issue with libstdc++ (not sure about it) triggered when
>evaluating the "std::contiguous_iterator" concept.
>
>According to the standard, "std::to_address" should evaluate if
>"std::pointer_traits<Ptr>::to_address(p)" is well-formed and call
>"std::to_address(p.operator->())" if it is not. However, if "Ptr" does
>not define "element_type", std::pointer_traits's static assert
>triggers:
>
>static_assert(!is_same<element_type, __undefined>::value, "...");
>
>
>which makes std::pointer_traits sfinae-unfriendly. The standard says
>that if element_type can't be deduced, pointer_traits specialization
>is ill-formed but I expected that std::to_address would select the
>"operator->" way of obtaining the address. Is my expectation correct?
No, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96416
I consider it a defect in the standard that pointer_traits is not
SFINAE friendly, but that's what the current standard requires.
I hope it will be changed for C++23.
More information about the Libstdc++
mailing list