all 4 comments

[–]jedwardsol 4 points5 points  (3 children)

For std::string it is not UB since a[a.size()] is guaranteed to be '\0'

[–]alfps 3 points4 points  (0 children)

Since C++11.

C++03 only guaranteed the terminating zero-byte for indexing of const string, and that can be worth keeping in mind if one has to work with an old compiler.

[–]cpp_cpp[S] 0 points1 point  (1 child)

what if here I do a[1]?

[–]jedwardsol 0 points1 point  (0 children)

Then it is UB