C ++ 4.3.2 GCC错误的字符数组的矢量 [英] C++ GCC 4.3.2 error on vector of char-array
问题描述
这是问题类似于这样的错误。
It is similar in problem to this bug
<一个href=\"http://stackoverflow.com/questions/1468058/question-about-storing-array-in-a-stdvector-in-c\">http://stackoverflow.com/questions/1468058/question-about-storing-array-in-a-stdvector-in-c
但出于不同原因(见下文)。
but for a different reason (see below).
有关在C ++中下面的示例程序:
For the following sample program in C++:
#include <vector>
int main(int c_, char ** v_)
{
const int LENGTH = 100;
std::vector<char[LENGTH]> ca_vector;
return 0;
}
GCC 4.2.3编译干净。
GCC 4.3.2发出以下错误:
GCC 4.2.3 compiles cleanly. GCC 4.3.2 emits the following errors:
/usr/lib/gcc/i686-pc-linux-gnu/4.3.2/include/g++-v4/bits/stl_construct.h: In function ‘void std::_Destroy(_Tp*) [with _Tp = char [100]]’:
/usr/lib/gcc/i686-pc-linux-gnu/4.3.2/include/g++-v4/bits/stl_construct.h:103: instantiated from ‘void std::_Destroy(_ForwardIterator, _ForwardIterator) [with _ForwardIterator = char (*)[100]]’
/usr/lib/gcc/i686-pc-linux-gnu/4.3.2/include/g++-v4/bits/stl_construct.h:128: instantiated from ‘void std::_Destroy(_ForwardIterator, _ForwardIterator, std::allocator&) [with _ForwardIterator = char (*)[100], _Tp = char [100]]’
/usr/lib/gcc/i686-pc-linux-gnu/4.3.2/include/g++-v4/bits/stl_vector.h:300: instantiated from ‘std::vector::~vector() [with _Tp = char [100], _Alloc = std::allocator]’
test.cpp:7: instantiated from here
/usr/lib/gcc/i686-pc-linux-gnu/4.3.2/include/g++-v4/bits/stl_construct.h:88: error: request for member ‘~char [100]’ in ‘* __pointer’, which is of non-class type ‘char [100]’
究其原因显然是此位
The reason apparently is this bit in
include/g++-v4/bits/stl_construct.h
template
inline void
_Destroy(_Tp* __pointer)
{ __pointer->~_Tp(); }
这就是所谓的,我认为,由于不正确的阵列到指针衰减。
which is called, I think, due to incorrect array-to-pointer-decay.
我的问题是:
是否有在的std ::矢量阵列的语言标准preventing存储什么?还是只是在特殊的GCC版中的错误?
My question is: Is there anything in language standard preventing storage of arrays in std::vector? Or is it just a bug in that special GCC version?
我不相信这应该编译(即4.2.3是正确的)。
I do believe that this should compile (i.e. 4.2.3 is correct).
谢谢
马丁
推荐答案
是的,有一些是在使用数组使用的草案C ++ 98标准
Yes there is something in the standard stopping using arrays Using Draft C++98 Standard
第23条货柜
的类型存储在这些组件的对象必须满足复制构造的要求
类型(20.1.3)以及Assignabletypes的附加要求。
The type of objects stored in these components must meet the requirements of CopyConstructible types (20.1.3), and the additional requirements of Assignabletypes.
其中组件是各种容器
20.1.3包括该类型必须有一个析构函数的要求。
20.1.3 includes the requirement that the type has to have a destructor.
我认为它作为一个载体具有复制分配和删除元素。如何C ++知道复制或删除一个char []?
I think of it as a vector has to copy allocate and delete elements. How does C++ know to copy or delete a char[] ?
这篇关于C ++ 4.3.2 GCC错误的字符数组的矢量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!