The following code doesn't compile with clang and libc++: https://godbolt.org/z/rDL-_K
#include <array>
int main() {
static constexpr std::array<int, 0> xs{};
constexpr auto i = xs.begin(); // non-constexpr function 'begin' cannot be used in a constant expression
return 0;
}
But if you change the 0
to a 1
, it compiles.
Is this a bug in libc++ or is there a good reason for it? How could I work around this if I have generic constexpr code that uses begin
/end
?
(I've seen this question, but my example intentionally uses static
to avoid this problem.)