-
Notifications
You must be signed in to change notification settings - Fork 10.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Clang] std::ranges::copy
in libstdc++ not constant expression.
#92315
Comments
std::ranges::copy
in libstdc++ not constant expresion.std::ranges::copy
in libstdc++ not constant expression.
Note works fine w/ libc++: https://godbolt.org/z/7fe1PdjWW |
This correctly compiles (Godbolt link). #include <array>
#include <ranges>
// #include <algorithm>
constexpr auto arr = [] {
std::array<int, 2> arr{};
for (auto it = arr.data();
decltype(auto) x : std::array{std::array{1}, std::array{2}} | std::views::join) {
*it = static_cast<decltype(x)&&>(x);
++it;
}
// std::ranges::copy(arrarr | std::views::join, arr.data());
return arr;
}();
static_assert(arr == std::array<int, 2>{1, 2}); Note that libstdc++'s Reduced example (Godbolt link): #include <optional>
#include <utility>
constexpr int zero = []
{
std::optional<int> opt{};
opt.emplace(42);
opt.reset();
auto opt2 [[maybe_unused]] = std::move(opt);
return 0;
}(); |
libstdc++'s llvm-project/libcxx/include/optional Lines 309 to 314 in 83e61d0
llvm-project/libcxx/include/optional Lines 340 to 344 in 83e61d0
I think I've reached a library-free example Godbolt link. constexpr int zero = []
{
using I = int;
struct OptionalLike {
union U {
I n;
};
U u;
};
OptionalLike opt;
opt.u.n = 42;
opt.u.n.~I();
auto opt2 [[maybe_unused]] = opt;
return 0;
}(); GCC & MSVC accept this, EDG & Clang reject this with the same reason. (ICC is probably buggy here and rejects this with an unreasonable reason.) IIUC this issue is probably covered by CWG2658. |
@llvm/issue-subscribers-clang-frontend Author: None (SainoNamkho)
https://godbolt.org/z/j3KnMGocn
```c++
#include <array>
#include <ranges>
#include <algorithm>
#include <print>
constexpr auto arr = [] { int main()
<source>:6:16: error: constexpr variable 'arr' must be initialized by a constant expression
|
https://godbolt.org/z/j3KnMGocn
Clang together with libstdc++ reports
I can't see why
_M_value
is not initialized, the implementation of ranges library from libstdc++ is almost the same as that from libc++, so the difference might be fromstd::optional
.It is only rejected since clang 17: https://godbolt.org/z/354TGGrGq
@YexuanXiao
The text was updated successfully, but these errors were encountered: