On Tue, Oct 26, 2021, 10:06 John McFarlane via Std-Discussion <std-discussion@lists.isocpp.org> wrote:
On Mon, 11 Oct 2021 at 07:54, Anubhav Guleria via Std-Discussion <std-discussion@lists.isocpp.org> wrote:
Thanks for clarifying.

Any specific reason why container's pop_back method can't check for
current size and if it is 0 then make the pop operation a no-op?

It would be a very poor design indeed to identify a bug at run-time and then to hide it from the user.

However, there's no reason why container's pop_back method can't check for this bug and trap the error. In your example, simply define `_GLIBCXX_ASSERTIONS` and you will get that behaviour (https://godbolt.org/z/WT3Y8qddz). There are more bug-checking options available. I've listed some of them here.

Note that, apart from NDEBUG, the macros you list are library-specific, not compiler-specific (Clang can use either libstdc++ and libc++).

And, of course, NDEBUG should never be defined globally.

--
Gennaro Prota
https://about.me/gennaro