[Bug libstdc++/101659] _GLIBCXX_DEBUG mode for std::optional ?
cvs-commit at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu Jul 25 10:54:08 GMT 2024
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101659
--- Comment #5 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:
https://gcc.gnu.org/g:eb2c12561c10f78e03b4eb63685f937a107305f0
commit r15-2304-geb2c12561c10f78e03b4eb63685f937a107305f0
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Mon Jul 22 20:24:19 2024 +0100
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.
More information about the Gcc-bugs
mailing list