I build the program below with g++ (g++ - g3 main.cpp) and VisualStudio 2013 (VS) in debug mode.When run - VS exits with assert complaining about index range issue but g++ version under Ubuntu 13.10 runs fine and it prints vi[11] = 11.
I understand - C++ Standard does not specify behavior for my case but warning or crash in my case would be nice.
Is there any flag in gcc(or clang) to enable array index out of range check during build ? If no is any good analysis tool for that ?
int main() {
vector<int> vi(8);
vi.push_back(1);
vi.push_back(2);
vi[11] = 11;
std::cout << "Vi[11]=" << vi[11] << std::endl;
return 0;
}