This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.

3626. Is std::basic_stacktrace required to use contiguous storage?

Section: [stacktrace.basic.overview] Status: New Submitter: Jiang An Opened: 2021-10-23 Last modified: 2021-10-27

Priority: 3

View all issues with New status.


Currently std::basic_stacktrace has an exposition-only std::vector member for storing its elements. According to [objects.within.classes]/3, it seems that it is effectively required that elements of a std::basic_stacktrace are contiguously stored. However, the implication seems not used otherwhere. The iterator type of a std::basic_stacktrace is only required to be random access iterator.

IMO if it is required that std::basic_stacktrace uses contiguous storage, we should explicitly strengthen some requirements, perhaps a the member function data should be added.

[2022-01-29; Reflector poll]

Set priority to 3 after reflector poll.
"The problem here is that a handful of member functions (operator[], at, perhaps begin) expose references to the vector elements directly, which can be read to require contiguity. We should rephrase the members at issue to not do that."

Proposed resolution:

This wording is relative to N4901.

[Drafting note: The proposed wording below contains also conditional changes, it is therefore depending upon a decision]

  1. Modify [stacktrace.basic.overview] as indicated:

    -1- The class template basic_stacktrace satisfies the requirements of an allocator-aware container (Table 80 [tab:container.alloc.req]), a sequence container (24.2.4 [sequence.reqmts]), a contiguous container, and a reversible container ( [container.requirements.general]) except that […]

  2. Modify [stacktrace.basic.obs] as indicated:

    using const_iterator = implementation-defined;

    -1- The type models random_access_iteratorcontiguous_iterator ( [iterator.concept.random.access] [iterator.concept.contiguous]) and meets the Cpp17RandomAccessIterator requirements ( [random.access.iterators]).

Optional additional changes (the following parts are proposed only if data() is wanted)

  1. Modify [stacktrace.basic.overview], class template basic_stacktrace synopsis, as indicated:

    const_reference operator[](size_type) const;
    const_reference at(size_type) const;
    const stacktrace_entry* data() const noexcept;
    // [stacktrace.basic.cmp], comparisons
  2. Modify [stacktrace.basic.obs] as indicated:

    const_reference at(size_type frame_no) const;

    -13- […]

    -14- […]

    const stacktrace_entry* data() const noexcept;

    -?- Returns: