title: Runtime array bounds checking in C++ built with g++
body: <p>Is there any way to do array bounds checking in C++ compiled using <code>g++</code>?</p>
  
  <ul>
  <li><p>Valgrind's Memcheck can't detect overflows on arrays allocated on the stack.</p></li>
  <li><p>The <a href="https://gcc.gnu.org/extensions.html" rel="noreferrer">GCC extension enabled by <code>-fbounds-checking</code></a> is <a href="https://www.lrde.epita.fr/~akim/ccmp/doc/bounds-checking.html" rel="noreferrer">only implemented for the C front end</a>.</p></li>
  </ul>
  
  <p>Ideally, the source code shouldn't be modified in any way. Using <code>std::vector</code>, <code>std::tr1::array</code> or <code>boost::array</code> is not an option because the codebase is large and such shift would be infeasible.</p>