https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79950
--- Comment #4 from David Binderman <dcb314 at hotmail dot com> --- (In reply to Jonathan Wakely from comment #3) > And for this example it's possible that g(int) modifies the vector that the > reference v is bound to I doubt g can modify v. Anyway, I think some progress could be made by finding the pattern for (something = 0; something <= somethingElse.size(); ++ something) at compile time, which is what the static analyser 'cppcheck' seems to be doing. $ ~/cppcheck/trunk/cppcheck mar7a.cc [mar7a.cc:22]: (error) Array 'a[10]' accessed at index 10, which is out of bounds. [mar7a.cc:12]: (error) When i==v.size(), v[i] is out of bounds. $ No work required at run time, AFAIK.