boostorg / container

STL-like containers from Boost
http://www.boost.org/libs/container/
Boost Software License 1.0
96 stars 116 forks source link

Inconsistent noexcept-ness of static_vector::reserve #204

Closed Ukilele closed 2 years ago

Ukilele commented 2 years ago

According to the documentation of static_vector, its member function reserve should be noexcept. But in fact it is not. The documentation is probably generated from the function declaration at line 540. But this code is only defined when the macro BOOST_CONTAINER_DOXYGEN_INVOKED is defined. When actually calling the function, the overload from the base class (boost::container::vector<...>) gets called, which is defined in vector.hpp, line 1567.

I would be willing to provide a pull request with a fix, but I am not sure what needs to be fixed. The first option would be to not mention noexcept in the documentation, i.e. remove the BOOST_NOEXCEPT_OR_NOTHROW from line 540. The second option would be to move the reserve-function at line 540 out of the BOOST_CONTAINER_DOXYGEN_INVOKED-block and to always provide an actual definition of it.

vinniefalco commented 2 years ago

I'm not sure that reserve() can be a no-op. what happens if you try to reserve more than there's capacity? it needs to fail.

igaztanaga commented 2 years ago

Thanks for the report. Throwing on capacity exhaustion depends on the options used by the container (by default it throws when static capacity is exceeded) so the documentation should reflect this.