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

    <tr>
        <th>Summary</th>
        <td>
            Invalid iterators for empty std::ranges::join_view
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          StailGot
      </td>
    </tr>
</table>

<pre>
    ```c++
#include <iostream>
#include <ranges>
#include <vector>
 
int main()
{
  const std::array<std::vector<int>, 2> v;
  const auto jv = std::ranges::join_view(v);
  
  if (auto it = std::ranges::find(jv, 5); it != jv.end())
    std::cout << std::distance(jv.begin(), it); // should not enter here

   std::cout << 42 << std::endl;
}

// clang++-18 main.cpp --std=c++20 -stdlib=libc++ && ./a.out - # hangs or crash
// clang++-18 main.cpp --std=c++20 -stdlib=libstdc++ && ./a.out - # Ok with libstdc++ or gcc
```

Code compiled with latest clang 18.1.6 and libc++ hangs or crash with Segmentation fault.

https://godbolt.org/z/hxzP7axWj

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyslMGO2zYQhp9mdBlYkIa2LB10SOy46KkFcuixoEhaokuTBjnSZvP0hWR5vUkT5FKAAIUZzvf_HJGUKdneG9PC7iPsjpkceQix_czSut8CZ13Qry1UxX0ooI_zKI5QfAAS1is3aoMgDjYkjkZeQXz6UTpK35v0k-RkFIf4lsT7ZD3jVVoPVAM1a91-FUdUwSfGxBrEBxAfZIzyFcThLfCAHqznGU0HJBCfcALxHUOOHPAyIYjjk_cwPH9fgvV_T9a8ANXT7OVJeMz2jED1QrL8c9LZeg1UX6bZzu6OWgqonGsuU26WBXPmsWdEfMJUGGf8AcThGdQ2sfTKLOS8M_1b0-iAllcZoBPQCdMQRqfRB0bj2UQcTDRrdx96P5Tb0n-EjdfurRmwP77HrHLKSd_fj82mrJcfmqvbDTebhXJcjxQVOAec7UAcne3WMAJVQBXmQCeZz2Y2CCRwkL5PGCKqKNPwfwgm1r_Q_OMffLE84LeLQ8ReqdXB456878MhaIMqXG_WGb0SJJvEd6dY1nmZVyi9xnf7_naD97LPpr8az5Jt8HiWo-P8vdDAfFuO2dKHPuguOM5D7IFOX4FOw5evf-7ll78u9-WZboVuRCMz05b7stpW1VZU2dCqRtZUCmPqpivKfdXslZRNuT0LUdZGq8y2VNC22JEoqRS7Khd71RQ7VZ-l0rU8G9gW5iqty52brrODzKY0mrYRZV1kTnbGpeXBIfLmBZckEM3vT2znmk039gm2hbOJ05PClp1pf_eTdFajZRMlh5jwHCKa641ff3F9szG69rs2WR7GLlfhCnSahdZpc4vhYhQDnRZ7Ceh0tz-19G8AAAD__xo_glE">