#include <iostream>
#include <array>
int main(int argc, char **argv) {
constexpr const std::array<int, 2> arr {{ 0, 1 }};
constexpr const int arr2[] = { 0, 1};
static_assert(arr[0] == arr2[0], "asdf");
static_assert(arr[1] == arr2[1], "asdfasdf");
return 0;
}
When compiled with gcc 4.8.2 and 4.9.1 using g++ test.cpp --std=c++11, the compilation succeeds.
When compiled with clang 3.4 and 3.5 using clang++ test.cpp --std=c++11 however, the compilation fails:
test.cpp:8:16: error: static_assert expression is not an integral constant expression
static_assert(arr[0] == arr2[0], "asdf");
^~~~~~~~~~~~~~~~~
test.cpp:8:16: note: non-constexpr function 'operator[]' cannot be used in a constant expression
So my question is, which compiler is "right" in the sense of being compliant with C++11? And, if clang is correct, then why is std::array's operator[] not constexpr capable? Isn't that rather one of the things that std::array was supposed to help resolve?