]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Move std::optional assertions out of _M_get()
authorJonathan Wakely <jwakely@redhat.com>
Mon, 22 Jul 2024 19:24:19 +0000 (20:24 +0100)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Sun, 28 Jul 2024 17:05:56 +0000 (19:05 +0200)
commit5b1ead44898908123560a7e4f2be237b2ef53cb9
tree204559133c89c8b6266ac16e770f5c6950601936
parent89dc14d6339ddb95400271f844f19387bb103474
libstdc++: Move std::optional assertions out of _M_get()

Currently we implement the precondition for accessing the contained
value of a std::optional in the _M_get() accessor in the base class.
This means that we always check the assertions even in internal
functions that have an explicit check for a contained value being
present, such as value() and value_or(U&&). Although those redundant
assertions should get optimized out in most cases, they might hurt
inliner heuristics and generally give the compiler more work to do.
And they won't be optimized out at all for non-optimized builds.

The current assertions also result in repeated invalid bug reports, such
as PR 91281, PR 101659, PR 102712, and PR 107894.

We can move the assertions from the internal accessors to the public
member functions where the preconditions are specified.

Reviewed-by: Ville Voutilainen <ville.voutilainen@gmail.com>
libstdc++-v3/ChangeLog:

* include/std/optional (_Optional_base_impl::_M_get()): Move
assertions to ...
(optional::operator->, optional::operator*): ... here.
libstdc++-v3/include/std/optional