#include
#include
int main(int argc, char **argv) {
constexpr const std::array arr {{ 0, 1 }};
constexpr const
It looks like clang
is correct, operator [] is not a constexpr in C++11 but is a constexpr in C++14
constexpr const_reference operator[]( size_type pos ) const; (since C++14)
so compiling with -std=c++14
should work though (see it live).
In the C++11 draft standard section 23.3.2.1
Class template array overview has the following for operator []
:
reference operator[](size_type n);
const_reference operator[](size_type n) const;
while the C++14 draft standard has the following:
reference operator[](size_type n);
constexpr const_reference operator[](size_type n) const;
^^^^^^^^^
Update
Draft standard N3485 which came after C++11, contains fixes an enhancements to C++11. It contains a constexpr version of operator []
. If this was part of a defect report then gcc
would be correct and this seems plausible considering clang 3.6.0
also accepts the program in C++11 mode.
Update 2
I found the document that introduced the changes, N3470 and since I can not find any defect reports on this specific issue then this seems like an enhancement and therefore should not be part of C++11.