On https://en.cppreference.com/w/cpp/compiler_support, cosnstexpr vector
is stated to be supported.
But when I wrote
#include <vector>
constexpr std::vector<int> vec{2, 3, 3, 3};
int main()
{
}
and compiles it using -std=gnu++2b
flag,
it still triggers a error
In file included from /usr/include/c++/12/vector:61,
from test.cpp:1:
/usr/include/c++/12/bits/allocator.h:182:50: error: ‘std::vector<int>(std::initializer_list<int>{((const int*)(& const int [4]{2, 3, 3, 3})), 4}, std::allocator<int>())’ is not a constant expression because it refers to a result of ‘operator new’
182 | return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp)));
| ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
I don't understand why, can someone help me?
My gcc version gcc version 12.1.0 (Ubuntu 12.1.0-2ubuntu1~22.04)
and __cpp_constexpr == 202110L