<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/122222>122222</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [libc++][ranges] `elements_view` determines the tuple-like property with C++23 rules in C++20 mode
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            ranges
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          frederick-vs-ja
      </td>
    </tr>
</table>

<pre>
    The _`has-tuple-element`_ exposition-only concept (used for `std::ranges::elements_view`) was modified by [P2165R4](https://wg21.link/p2165r4) in C++23. Previously, the constrains were more relaxed.

As a result, the following program should be well-formed in C++20 but ill-formed in C++23.

```C++
#include <cstddef>
#include <ranges>
#include <utility>
#include <type_traits>

template<class T, class U>
struct MyPair : std::pair<T, U> { // std::get works with MyPair specializations.
    using std::pair<T, U>::pair;
};

template<class T, class U>
struct std::tuple_size<MyPair<T, U>> : std::integral_constant<std::size_t, 2> {};

template<class T, class U>
struct std::tuple_element<0, MyPair<T, U>> {
    using type = T;
};

template<class T, class U>
struct std::tuple_element<1, MyPair<T, U>> {
    using type = U;
};

int main() {
    MyPair<int, double> mps[42]{};
    (void)(mps | std::views::elements<0>);
}
```

Currently, libstdc++ and MSVC STL accept it in C++20 and reject it in C++23 as specified by the standard, but libc++ rejects it in C++20 ([Godbolt link](https://godbolt.org/z/abKco9E8x)).

This might be intended, as the commit adding `elements_view` (94461822c75d5080bf648f86552f7a59b76905c9, https://reviews.llvm.org/D136268) used the C++23 rules in the first place. I wonder whether we should use the old rules in C++20 mode.

CC @huixie90 
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysVU9v47gP_TTKhUggy39iH3JI0uaHH3YHGOx09hrIFhNrKluGJDfNfPoFbSdp2s5hFxMEsGGK5OMj-SS918cWccXSDUsfZrIPtXWrg0OFTlfP8xc__yFnpVXn1VONsGcZr6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