noexcept move on containers (e.g. list)
Jonathan Wakely
jwakely.gcc@gmail.com
Wed Sep 18 08:58:00 GMT 2013
Hi Kenny,
On 18 September 2013 05:42, Kenny Simpson wrote:
> http://channel9.msdn.com/Events/GoingNative/2013/An-Effective-Cpp11-14-Sampler
>
> at 48:40, Scott goes into pointing out that none of the Standard containers are defined as having noexcept move constructors, and that fishing around in the Standard library will show very few noexcept things... but as of current trunk, I do see that many of these noexcept specifiers were added in 2011 (c95bf15b in the git mirror).
>
> STL explains something about why these are not noexcept in the Standard (and presumably also in VC++'s library), but the audio is too low for me to make out what he says.
I haven't seen the video, but he might be referring to the guidelines
used in http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3279.pdf
which say that functions should only be unconditionally noexcept if
they have no preconditions. So e.g. vector::operator[](size_type n)
cannot be noexcept because it has a precondition that n < size().
The rule is used throughout the standard library and is meant to allow
debugging implementations or testing frameworks that check
preconditions and indicate violations by throwing exceptions.
> A Scott stresses that noexcept is a property of the interface, is gcc just taking some freedom in making its implementation more strict than required by the Standard?
Yes, because our debug mode aborts, so we don't need to throw from
those functions and can tighten the exception specs.
> which seems fine as of: "17.6.5.12 Restrictions on exception handling
> ... An implementation may strengthen the exception-specification
> for a non-virtual function by adding a non-throwing noexcept-specification."
Right.
More information about the Libstdc++
mailing list