[Bug libstdc++/77528] std::queue default constructor unnecessarily creates temporary of underlying Container

jerry.c.t at web dot de gcc-bugzilla@gcc.gnu.org
Fri Dec 30 23:43:00 GMT 2016


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77528

jerryct <jerry.c.t at web dot de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jerry.c.t at web dot de

--- Comment #4 from jerryct <jerry.c.t at web dot de> ---
Hi,

i would like to add another issue besides the number of allocations. I am using
special containers which have fixed size and don't use dynamic memory
allocation at all. Thus for example we use a static_vector<T, max_size>. The
container can get rather big, e.g., 4 mega byte. Using std::stack from
libstdc++ with this container produces a stack overflow in the constructor,
because of this temporary. Running the same code with libcxx does not produce
this error - it does not use such a temporary in the constructor.

Thus a constructor like libcxx has:
_LIBCPP_INLINE_VISIBILITY
stack()
    _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value)
    : c() {}

would solve two problems:
- reduce the number of allocations
- make container adapaters usable for rather big containers.

jerry


More information about the Gcc-bugs mailing list