C++ Logo


Advanced search

Re: Segmentation Fault with stack top access.

From: Gennaro Prota <gennaro.prota_at_[hidden]>
Date: Tue, 26 Oct 2021 22:11:01 +0200
On Tue, Oct 26, 2021, 10:06 John McFarlane via Std-Discussion <
std-discussion_at_[hidden]> wrote:

> On Mon, 11 Oct 2021 at 07:54, Anubhav Guleria via Std-Discussion <
> std-discussion_at_[hidden]> 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
> <https://github.com/johnmcfarlane/papers/blob/master/cpp/contractual-disappointment.md#appendix-a---toolchain-specific-recommendations>
> .

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

Received on 2021-10-26 15:11:15