public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/115222] New: clang does not think libstdc++'s std::optional is nothrow destructible
@ 2024-05-25  0:53 pobrn at protonmail dot com
  2024-05-25  1:12 ` [Bug c++/115222] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: pobrn at protonmail dot com @ 2024-05-25  0:53 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 115222
           Summary: clang does not think libstdc++'s std::optional is
                    nothrow destructible
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pobrn at protonmail dot com
  Target Milestone: ---

clang and gcc disagree whether libstdc++'s std::optional<T> is nothrow
destructible when T is not. My reading of https://eel.is/c++draft/optional.dtor
suggests that the destructor should be `noexcept(true)` (by omission).

Consider the following piece of C++ code:

```
#include <optional>
#include <type_traits>

struct A { ~A() noexcept(false); };

static_assert(std::is_nothrow_destructible_v<std::optional<A>>);
```

the assertion passes on gcc, while it fails on clang:
https://gcc.godbolt.org/z/1ndxK1avM

Now I have tried to reduce the input, and arrived at something like this (
https://gcc.godbolt.org/z/orx5j1Eaf ):

```
template <typename _Tp> _Tp declval() noexcept;

template <typename _Tp>
inline constexpr bool is_nothrow_destructible_v = noexcept(declval<_Tp>());

template <typename _Tp>
struct _Optional_payload_base {
  union _Storage {
    _Tp _M_value;
  } _M_payload;
};

template <typename _Tp>
struct _Optional_payload : _Optional_payload_base<_Tp> {
    ~_Optional_payload();
};

struct A {
  ~A() noexcept(false);
};

static_assert(is_nothrow_destructible_v<_Optional_payload<A>>);
```

The assertion passes on gcc, but fails on clang (and edg).

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

end of thread, other threads:[~2024-06-10 16:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-25  0:53 [Bug c++/115222] New: clang does not think libstdc++'s std::optional is nothrow destructible pobrn at protonmail dot com
2024-05-25  1:12 ` [Bug c++/115222] " pinskia at gcc dot gnu.org
2024-05-25  2:07 ` [Bug c++/115222] gcc ignores noexcept on fields' deconstructors in an union pinskia at gcc dot gnu.org
2024-05-25  2:16 ` pinskia at gcc dot gnu.org
2024-05-25  2:29 ` pinskia at gcc dot gnu.org
2024-05-25 12:44 ` harald at gigawatt dot nl
2024-06-10 16:35 ` pinskia 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).