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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to tim blechmann from comment #0)
> `_GLIBCXX_ASSERTIONS` does not enable any API validation for std::optional.

I don't know why people keep claiming this, but it's nonsense.

tmp$ cat opt.cc
#include <optional>
int main()
{
  std::optional<int> o;
  return *o.operator->();
}
tmp$ g++ -D_GLIBCXX_ASSERTIONS opt.cc
tmp$ ./a.out
/usr/include/c++/12/optional:477: constexpr _Tp& std::_Optional_base_impl<_Tp,
_Dp>::_M_get() [with _Tp = int; _Dp = std::_Optional_base<int, true, true>]:
Assertion 'this->_M_is_engaged()' failed.
Aborted (core dumped)


> it would be great if libstdc++ could perform the same validation

It already does, please try it instead of just skimming the code.

*** This bug has been marked as a duplicate of bug 102712 ***

Reply via email to