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

    <tr>
        <th>Summary</th>
        <td>
            [Clang] `std::ranges::copy` in libstdc++ not constant expresion.
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

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

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

<pre>
    https://godbolt.org/z/j3KnMGocn
```c++
#include <array>
#include <ranges>
#include <algorithm>
#include <print>

constexpr auto arr = [] {
    std::array<int, 2> arr;
 std::ranges::copy(std::array{std::array{1}, std::array{2}} | std::views::join, arr.data());
    return arr;
}();

int main()
{
    for(auto i : arr)
 std::println("{}",i);
}
```

Clang together with libstdc++ reports
```
<source>:6:16: error: constexpr variable 'arr' must be initialized by a constant expression
    5 | constexpr auto arr = [] {
 |                ^     ~~~~
    6 |     std::array<int, 2> arr;
 |     ~~~~~~~~~~~~~~~~~~~~~~~
    7 | std::ranges::copy(std::array{std::array{1}, std::array{2}} | std::views::join, arr.data());
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 8 |     return arr;
      |     ~~~~~~~~~~~
    9 | }();
      | ~~~
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/15.0.0/../../../../include/c++/15.0.0/bits/ranges_algobase.h:291:12: note: subobject '_M_value' is not initialized
  291 |           return {std::move(__first), std::move(__result)};
      | ^
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/15.0.0/../../../../include/c++/15.0.0/bits/ranges_algobase.h:291:12: note: in call to '_Iterator(__first)'
  291 |           return {std::move(__first), std::move(__result)};
      | ^~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/15.0.0/../../../../include/c++/15.0.0/optional:230:8: note: subobject declared here
  230 |           _Up _M_value;
      | ^
```

I can't see why `_M_value` is not initialized, if the `constexpr` specifier, `arr` is con the implementation of ranges library from libstdc++ is almost the same as that from libc++, so the difference might be from `std::optioinal`. @YexuanXiao
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUVk2P4zYP_jXKRRjDkfyVQw7ZZPJi8WJ7KQq0p4C2mVhbWTIkOTvZw_z2gsrnZDLFHgp0axi2YVIU-fAhRfBe7QzinOWfWL6awBg66-a_gjL2F-j_7Oyktu1h3oUweCYXTKyZWO9sW1sdEut2TKy_M7H-Kv9vvvzPNoalK5YuWJEe74aJT3Qf_wqpTKPHFjmTS3AODkw-P5I5MDv0HwhB76xToes_kA9OmXCVxWdjjQ_4MjgOY7AcnONMrvgxas7Kk4ecc-5DS4HKxcnBJVkTSy6YfKaFTJ6VL5pnd-m7scOBierOSvnp3Y8pK1dk951AkKAkr26Ee4XfTjt8tcrQQnAuaSEAExUTM7rlTRgOw-jMG4fjhtWt4vGpTOA9kNEoPOne2Npax0QVkVOcyUW0eta8-hiB10czggzQfoKJpXqzZ7m6I8mtL0sNZseD3WHo0PFvKnRcq9qH9kQl7nCwLvjHNuTS29E1SOmXi4LJxZQeHJ2zjj6uRNiDU1Br5EyUMZ6S96MPvEaujAoKtPqOLa8PHI6rwAROK9F7Zc0VnTxm6kcZRrp3F8uf4_v19fX1ara4qP44I88rXh9fV-PlW3b9jATmcf0HkfwT12mr6oLag5K5OnIH61U8i-L3tfUmhnOfWtshMLFubD8oje4JXwZtHTpqqk3z5A0MvrOkolV9_MnE-qUqNkX2pJUZX552ZmRiPc2TNEmZWCfJ-8epGdJGp_57s6BWwTOxPqZ8Q820Bo9Jx-RCzKZUMYIKxdiA9PZjbeuv2ASqk82XzR70iFQsypPOba2c4xaz6R3NT8jesqi3e2Si2my2yvkQ83_DlovUoR91FJerB9Cy_Pm_C60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