I have seen many times that std::string::operator[]
does not do any bounds checking. Even What is the difference between string::at and string::operator[]?, as
The wording is slightly confusing, but if you study it in detail you'll find that it's actually very precise.
It says this:
[]
is either = n or it's < n.charT()
(i.e. the null character).But no rule is defined for when you break the precondition, and the check for = n can be satisfied implicitly (but isn't explicitly mandated to be) by actually storing a charT()
at position n.
So implementations don't need to perform any bounds checking… and the common ones won't.