How do I get an error from `pop_back()` if `size()` is 0?

  c++, vector

I was explaining to a coworker why we have small test with sanitizers on them. He asked about popping a vector too many times and if it was an exception, assert, UB and which sanitizer catches it

It appears NONE catches them. Address and memory will if you call back() after popping too many times but if you pop and do size() you can get negative values

Is there a way I can get an assert or exception or runtime termination when I pop too many times? I really thought a debug build without sanitizers would have caught that (with an assert or exception)

I use clang sanitizer but build options with gcc will also be helpful

Source: Windows Questions C++

LEAVE A COMMENT