这让我很困惑。这是一个stdlib错误,还是这真的是一个错误,为什么?
#include <vector>
int main(int argc, char** argv) {
struct A { float f[3]; };
std::vector<float[3]> v1(8); // Compiles.
std::vector<float[3]> v2; v2.resize(8); // Does not compile.
std::vector<A> v3(8); // Compiles.
std::vector<A> v4; v4.resize(8); // Compiles.
return 0;
}
我正在使用g++ -std=c++11
编译4.9.3版。这是完整的错误:
In file included from /usr/include/c++/4.9/vector:62:0,
from test.cpp:1:
/usr/include/c++/4.9/bits/stl_construct.h: In instantiation of ‘void std::_Construct(_T1*, _Args&& ...) [with _T1 = float [3]; _Args = {float [3]}]’:
/usr/include/c++/4.9/bits/stl_uninitialized.h:75:53: required from ‘static _ForwardIterator std::__uninitialized_copy<_TrivialValueTypes>::__uninit_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = std::move_iterator<float (*)[3]>; _ForwardIterator = float (*)[3]; bool _TrivialValueTypes = false]’
/usr/include/c++/4.9/bits/stl_uninitialized.h:126:41: required from ‘_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = std::move_iterator<float (*)[3]>; _ForwardIterator = float (*)[3]]’
/usr/include/c++/4.9/bits/stl_uninitialized.h:279:63: required from ‘_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, std::allocator<_Tp>&) [with _InputIterator = std::move_iterator<float (*)[3]>; _ForwardIterator = float (*)[3]; _Tp = float [3]]’
/usr/include/c++/4.9/bits/stl_uninitialized.h:302:69: required from ‘_ForwardIterator std::__uninitialized_move_if_noexcept_a(_InputIterator, _InputIterator, _ForwardIterator, _Allocator&) [with _InputIterator = float (*)[3]; _ForwardIterator = float (*)[3]; _Allocator = std::allocator<float [3]>]’
/usr/include/c++/4.9/bits/vector.tcc:564:42: required from ‘void std::vector<_Tp, _Alloc>::_M_default_append(std::vector<_Tp, _Alloc>::size_type) [with _Tp = float [3]; _Alloc = std::allocator<float [3]>; std::vector<_Tp, _Alloc>::size_type = long unsigned int]’
/usr/include/c++/4.9/bits/stl_vector.h:676:41: required from ‘void std::vector<_Tp, _Alloc>::resize(std::vector<_Tp, _Alloc>::size_type) [with _Tp = float [3]; _Alloc = std::allocator<float [3]>; std::vector<_Tp, _Alloc>::size_type = long unsigned int]’
test.cpp:6:42: required from here
/usr/include/c++/4.9/bits/stl_construct.h:75:7: error: parenthesized initializer in array new [-fpermissive]
{ ::new(static_cast<void*>(__p)) _T1(std::forward<_Args>(__args)...); }