public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/107894] New: [feature request] _GLIBCXX_ASSERTIONS for std::optional
@ 2022-11-28 10:27 tim at klingt dot org
  2022-11-28 11:08 ` [Bug libstdc++/107894] " redi at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: tim at klingt dot org @ 2022-11-28 10:27 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 107894
           Summary: [feature request] _GLIBCXX_ASSERTIONS for
                    std::optional
           Product: gcc
           Version: 12.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tim at klingt dot org
  Target Milestone: ---

`_GLIBCXX_ASSERTIONS` does not enable any API validation for std::optional.
e.g. `operator->` translates to `address_to`:
https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/std/optional#L969-L970

libc++ on the other hand has assertions that can detect invalid uses:
https://github.com/llvm/llvm-project/blob/main/libcxx/include/optional#L930-L937


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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug libstdc++/107894] [feature request] _GLIBCXX_ASSERTIONS for std::optional
  2022-11-28 10:27 [Bug libstdc++/107894] New: [feature request] _GLIBCXX_ASSERTIONS for std::optional tim at klingt dot org
@ 2022-11-28 11:08 ` redi at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: redi at gcc dot gnu.org @ 2022-11-28 11:08 UTC (permalink / raw)
  To: gcc-bugs

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 ***

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-11-28 11:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-28 10:27 [Bug libstdc++/107894] New: [feature request] _GLIBCXX_ASSERTIONS for std::optional tim at klingt dot org
2022-11-28 11:08 ` [Bug libstdc++/107894] " redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).