C++ Logo

std-discussion

Advanced search

Re: Segmentation Fault with stack top access.

From: Peter Olsson <olssonpeter87_at_[hidden]>
Date: Mon, 11 Oct 2021 14:46:01 +0200
> 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?

Calling pop() on an empty stack is usually a mistake but defining it as a
no-op would hide the mistake, making it harder to spot. Leaving it as UB
allows people to have verbose checks in "debug mode" without having to pay
the cost in "release mode".

Received on 2021-10-11 07:46:14