<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - std::to_address should not require std::pointer_traits<Pointer>::element_type to be well-formed"
href="https://bugs.llvm.org/show_bug.cgi?id=49241">49241</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>std::to_address should not require std::pointer_traits<Pointer>::element_type to be well-formed
</td>
</tr>
<tr>
<th>Product</th>
<td>libc++
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>All Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>schottm@google.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
</td>
</tr></table>
<p>
<div>
<pre>Per [pointer.conversion] ¶ 3 (<a href="http://eel.is/c++draft/pointer.conversion#3">http://eel.is/c++draft/pointer.conversion#3</a>), if
the argument to std::to_address matches the overload for const Pointer&, it
uses std::pointer_traits<Pointer>::to_address(p) if that is well-formed,
otherwise to_address(p.operator->()).
Nowhere does it say that std::pointer_traits<Pointer> has to exist at all in
the case where operator->() is chosen. However, in __memory/pointer_traits.h[1]
we see that the return type is dictated as
std::pointer_traits<Pointer>::element_type* despite the fact that there are
many types in the wild that overload operator-> and *should* be expected to
work with std::to_address, but don't.
See [2] for an example of a type that should work per the standard but doesn't
unless we define std::pointer_traits<Pointer>::element_type. (It appears that
godbolt uses libstdc++ even when you select clang, but from my own local
testing [and inspection of libc++'s implementation], I've determined that
libc++ has the same problem.)
It looks like the original implementation in [3] was fine (unless you were on
C++17) but it was broken in [4] when __to_raw_pointer and __to_address were
merged. It seems that priority was given to using __to_address() as an internal
function, and this existing usage clashed with the public std::to_address in
non-obvious ways.
[1]:
<a href="https://github.com/llvm/llvm-project/blob/da59c2e4dc1c7b502cc2098247b2ee38ac297e0c/libcxx/include/__memory/pointer_traits.h#L199">https://github.com/llvm/llvm-project/blob/da59c2e4dc1c7b502cc2098247b2ee38ac297e0c/libcxx/include/__memory/pointer_traits.h#L199</a>
[2]: <a href="https://godbolt.org/z/47cxTG">https://godbolt.org/z/47cxTG</a>
[3]: <a href="https://reviews.llvm.org/D35470">https://reviews.llvm.org/D35470</a>
[4]: <a href="https://reviews.llvm.org/rG0068c5913999b14627c27433c8d846a2ef5fbe00">https://reviews.llvm.org/rG0068c5913999b14627c27433c8d846a2ef5fbe00</a></pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>