https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79950
--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to David Binderman from comment #4)
> (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.
Of course it can:
#include <iostream>
std::vector<int> v;
void g(int i) {
std::cout << i << '\n';
if (i < 5)
v.push_back(i + 5);
}
int main()
{
v = { 1, 10 };
f1(v);
}
This is entirely valid. If linked to your code in comment 0 it has undefined
behaviour but that's because of your i <= size() not because of this code.
> 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.
That's what I said, it would have to be a special case built in to the
front-end.