[問題] array subscript is above array bounds [-Werror=array
將原問題再整個精簡一下好了,不知是不是和 C++ 11有關系。
CentOS 7.0 g++ 4.8.2
Arch Linux g++ 4.9.0 20140604 (prerelease)
Compile command cases:
PASS: g++ -Wall t.cpp
FAIL: g++ -Wall -O2 t.cpp
PASS: g++ -Wall -O2 t.cpp # and replace 2 with 3 on line 13
PASS: g++ -Wall -O2 t.cpp # and comment out line 14
The FAIL message:
t.cpp: In member function ‘void std::vector<_Tp, _Alloc>::_M_insert_aux(std::vecto
<_Tp, _Alloc>::iterator, const _Tp&) [with _Tp = Object; _Alloc = std::allocator<Ob
ject>; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<Object*, s
td::vector<Object> >; typename std::_Vector_base<_Tp, _Alloc>::pointer = Object*]’
t.cpp:17:15: warning: array subscript is above array bounds [-Warray-bounds]
~Object() {};
^
t.cpp:17:15: warning: array subscript is above array bounds [-Warray-bounds]
============================
t.cpp
#include <vector>
class TestCls {
public:
TestCls() {};
virtual ~TestCls() {};
};
class TestCls1 : public TestCls
{
};
class Object {
public:
TestCls m_member[2];
TestCls1 m_member1[2]; // LINE 13, if change to [3] it works.
TestCls1 m_member2[2]; // LINE 14, if comment out this line, it works.
Object() {};
~Object() {}; // LINE 17 the warning line
};
class Container {
public:
std::vector<Object> m_obj;
Container() {};
~Container() {};
};
int main() {
Container con;
Object obj;
con.m_obj.push_back(obj);
}
--
永遠把希望留給明天,把工作留給今天,把行動留給現在。
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 60.250.19.162
※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1406711005.A.216.html
→
07/30 18:28, , 1F
07/30 18:28, 1F
推
07/30 20:44, , 2F
07/30 20:44, 2F
→
07/30 23:01, , 3F
07/30 23:01, 3F
※ 編輯: TwoDemon (112.104.12.66), 07/31/2014 07:21:05
→
07/31 07:22, , 4F
07/31 07:22, 4F
※ 編輯: TwoDemon (60.250.19.162), 07/31/2014 11:44:59
※ 編輯: TwoDemon (60.250.19.162), 08/01/2014 09:09:26
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章