<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/132133>132133</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[libc++][ranges] `ranges::to` can have non-class return type
</td>
</tr>
<tr>
<th>Labels</th>
<td>
libc++,
accepts-invalid,
ranges
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
frederick-vs-ja
</td>
</tr>
</table>
<pre>
Currently, this ill-formed program which violates [[range.utility.conv.to]/1](https://eel.is/c++draft/range.utility.conv.to#1) and [[range.utility.conv.adaptors]/1](https://eel.is/c++draft/range.utility.conv.adaptors#1) isn't rejected when using libc++ ([Godbolt link](https://godbolt.org/z/6bce8Pj98)):
```C++
#include <concepts>
#include <ranges>
int main() {
struct R {
int* begin() const;
int* end() const;
operator int() const { return 0; }
};
std::same_as<int> auto m [[maybe_unused]] = std::ranges::to<int>(R{});
std::same_as<int> auto n [[maybe_unused]] = R{} | std::ranges::to<int>();
}
```
It's weird that the "class" part is mentioned in comments but not actually implemented.
https://github.com/llvm/llvm-project/blob/ead272460004519ccbd98d08d68c70123892cd4e/libcxx/include/__ranges/to.h#L80-L83
https://github.com/llvm/llvm-project/blob/ead272460004519ccbd98d08d68c70123892cd4e/libcxx/include/__ranges/to.h#L207-L210
Note that libstdc++ and MSVC STL also reject union types by only using `is_class_v`, despite that the term "class type" in the C++ core language specification also covers union types. Perhaps we should also only accept non-union class types here and submit an LWG issue for this.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzMVU-P27YT_TT0ZWCDGlqWfPBh7Y2CH7C_IkiK9rigyFmLCUUKJOXE_fQFJa0dJGmRAj0UEECbM3xv_jwOZYzm7IgOrDyy8nElx9T5cHgJpCkY9Wl9ieuPctV6fT2cxhDIJXtleILUmQjG2vWLDz1pGII_B9nD586oDi7GW5kowgR7DNKdaTMmY026bpR3l03yrHxk2BTTUncpDZGJB4YNw4bI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