- CentOS 7.0 g++ 4.8.2
- Arch Linux g++ 4.9. 0 20140604 (предварительная версия)
- Arch Linux g++ 4.9.1
- PASS: g++ -Wall t.cpp
- FAIL: g++ -Wall -O2 t.cpp
- PASS: g++ -Wall -O2 t.cpp # и замените 2 на 3 в строке 13
- PASS: g++ -Wall - O2 t.cpp # и закомментируйте строку 14
- PASS: g++ -Wall -O2 --std=c++11 t.cpp # для g++ 4.8/4.9
t.cpp: In member function ‘void std::vector::_M_insert_aux(std::vecto
::iterator, const _Tp&) [with _Tp = Object; _Alloc = std::allocator; std::vector::iterator = __gnu_cxx::__normal_iterator; typename std::_Vector_base::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
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 m_obj;
Container() {};
~Container() {};
};
int main() {
Container con;
Object obj;
con.m_obj.push_back(obj);
}
Подробнее здесь: https://stackoverflow.com/questions/250 ... ray-bounds
Мобильная версия