[Bug c++/96575] std::ranges::sort is not usable as a 'constexpr' function when saving its return value in lambda function
hewillk at gmail dot com
gcc-bugzilla@gcc.gnu.org
Wed Aug 12 07:33:21 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96575
--- Comment #1 from 康桓瑋 <hewillk at gmail dot com> ---
I don't know whether this is same issue or not:
#include <algorithm>
constexpr auto replace = [](auto old_x, auto new_x) {
return [=](auto r) {
return std::ranges::replace(r, old_x, new_x);
};
};
// this one is ok
constexpr auto f1(auto algo) {
[=]() {
algo(std::array{0});
return 0;
}();
return true;
}
// this one fails with non-constant condition
constexpr auto f2(auto algo) {
constexpr auto it = [=]() {
algo(std::array{0});
return 0;
}();
return true;
}
static_assert(f1(replace(0, 1)));
static_assert(f2(replace(0, 1)));
(https://godbolt.org/z/Kaq4j5)
More information about the Gcc-bugs
mailing list