<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/67449>67449</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[libc++] `std::to_address()` fails with explcitly-specified template arguments
</td>
</tr>
<tr>
<th>Labels</th>
<td>
libc++
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
bregma
</td>
</tr>
</table>
<pre>
See https://godbolt.org/z/fan4Eddhr for a reproducer.
When `std::to_address()` is invoked in the simple case with explicitly-specified template arguments it fails to compile.
Example code:
```
#include <memory>
struct S { };
int main() {
S s;
S* a = std::to_address<S>(&s);
}
```
This conforms to ISO/IEC 14882:2020 (E) 20.10.4/1 [pointer.conversion] and should compile but instead gives the following for clang 17
```
In file included from <source>:1:
In file included from /opt/compiler-explorer/clang-17.0.1/bin/../include/c++/v1/memory:884:
In file included from /opt/compiler-explorer/clang-17.0.1/bin/../include/c++/v1/__memory/allocate_at_least.h:13:
In file included from /opt/compiler-explorer/clang-17.0.1/bin/../include/c++/v1/__memory/allocator_traits.h:15:
/opt/compiler-explorer/clang-17.0.1/bin/../include/c++/v1/__memory/pointer_traits.h:118:22: error: implicit instantiation of undefined template 'std::__pointer_traits_element_type<S>'
118 | typedef typename __pointer_traits_element_type<pointer>::type element_type;
| ^
/opt/compiler-explorer/clang-17.0.1/bin/../include/c++/v1/__memory/pointer_traits.h:182:20: note: in instantiation of template class 'std::pointer_traits<S>' requested here
182 | decltype((void)pointer_traits<_Pointer>::to_address(std::declval<const _Pointer&>()))
| ^
/opt/compiler-explorer/clang-17.0.1/bin/../include/c++/v1/__memory/pointer_traits.h:195:59: note: during template argument deduction for class template partial specialization '_HasToAddress<_Pointer, decltype((void)pointer_traits<_Pointer>::to_address(std::declval<const _Pointer &>()))>' [with _Pointer = S]
195 | static const bool value = _HasArrow<_Pointer>::value || _HasToAddress<_Pointer>::value;
| ^
/opt/compiler-explorer/clang-17.0.1/bin/../include/c++/v1/__memory/pointer_traits.h:195:59: note: in instantiation of template class 'std::_HasToAddress<S>' requested here
/opt/compiler-explorer/clang-17.0.1/bin/../include/c++/v1/__type_traits/conjunction.h:27:32: note: in instantiation of template class 'std::_IsFancyPointer<S>' requested here
27 | __expand_to_true<__enable_if_t<_Pred::value>...> __and_helper(int);
| ^
/opt/compiler-explorer/clang-17.0.1/bin/../include/c++/v1/__type_traits/conjunction.h:38:39: note: while substituting explicitly-specified template arguments into function template '__and_helper'
38 | using _And _LIBCPP_NODEBUG = decltype(std::__and_helper<_Pred...>(0));
| ^
/opt/compiler-explorer/clang-17.0.1/bin/../include/c++/v1/__memory/pointer_traits.h:200:5: note: in instantiation of template type alias '_And' requested here
200 | _And<is_class<_Pointer>, _IsFancyPointer<_Pointer> >::value
| ^
/opt/compiler-explorer/clang-17.0.1/bin/../include/c++/v1/__memory/pointer_traits.h:204:1: note: in instantiation of default argument for '__to_address<S>' required here
204 | __to_address(const _Pointer& __p) _NOEXCEPT {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
205 | return __to_address_helper<_Pointer>::__call(__p);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
206 | }
| ~
/opt/compiler-explorer/clang-17.0.1/bin/../include/c++/v1/__memory/pointer_traits.h:235:59: note: while substituting deduced template arguments into function template '__to_address' [with _Pointer = S, $1 = (no value)]
235 | auto to_address(const _Pointer& __p) noexcept -> decltype(std::__to_address(__p)) {
| ^
<source>:8:12: note: while substituting explicitly-specified template arguments into function template 'to_address'
8 | S* a = std::to_address<S>(&s);
| ^
/opt/compiler-explorer/clang-17.0.1/bin/../include/c++/v1/__memory/pointer_traits.h:38:8: note: template is declared here
38 | struct __pointer_traits_element_type;
| ^
1 error generated.
Compiler returned: 1
```
Similarly for GCC 12.
It looks like perhaps the declarations need to be refined with some SFINAE.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/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