g++のデバッグモード
配列外参照はつらい
のでデバッグオプション-D_GLIBCXX_DEBUGでエラーを吐くようにする。
g++ -O2 -std=c++14 -D_GLIBCXX_DEBUG
実行例
$ g++ -O2 -std=c++14 -D_GLIBCXX_DEBUG Main.cpp && ./a.out
3 2
3 5 8
/usr/local/Cellar/gcc/8.2.0/include/c++/8.2.0/debug/vector:417:
Error: attempt to subscript container with out-of-bounds index -1, but
container only holds 3 elements.
Objects involved in the operation:
sequence "this" @ 0x0x7ffee3916830 {
type = std::__debug::vector<long long, std::allocator<long long> >;
}
Abort trap: 6