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

            Bug ID: 115417
           Summary: Destructor is noexcept even though the class has a
                    throwing destructor subobject in an anonymous union
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: janschultke at googlemail dot com
  Target Milestone: ---

Consider the following code:

#include <type_traits>

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

struct B {
    union {
        char c;
        D d;
    };

    ~B() {}
};

static_assert(std::is_nothrow_destructible_v<B>);


This assertion passes only for GCC, but not for other compilers
(https://godbolt.org/z/e5jEKzjfs).

I believe GCC is wrong because 'd' is a potentially constructed subobject of B
(https://eel.is/c++draft/except.spec#8) and therefore, a destructor without a
noexcept-specifier should be potentially throwing.

This bug could be related to
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109768, but I don't think it is a
duplicate.

Reply via email to