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).

Reply via email to