[Bug c++/85155] Suboptimal error messages when using noexcept(false) on defaulted dtor

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Jul 3 10:28:00 GMT 2018


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|8.0.1                       |8.1.0

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
struct B {
  virtual ~B() noexcept(false) = default;
};

struct D : B {
  virtual ~D() { throw 17; }
};

int main()
{
  try {
    D d;
    return 1;
  } catch (int n) {
    return n;
  }
}

EDG gives a similar result to GCC:


"85155.cc", line 6: error: nondeleted function overrides deleted function
          "B::~B"
    virtual ~D() { throw 17; }
            ^

"85155.cc", line 6: error: function "B::~B()" (declared at line 2) cannot be
          referenced -- it is a deleted function
    virtual ~D() { throw 17; }
            ^

"85155.cc", line 12: error: the default constructor of "D" cannot be referenced
          -- it is a deleted function
      D d;
        ^

3 errors detected in the compilation of "85155.cc".


Clang gives an error as soon as it sees the defaulted destructor, that's why
there are no errors given for the derived class:

struct B {
  virtual ~B() noexcept(false) = default;
};

85155.cc:2:11: error: exception specification of explicitly defaulted
destructor does not match the calculated one
  virtual ~B() noexcept(false) = default;
          ^
1 error generated.


I can't find any justification in the standard for Clang's behaviour, the
destructor should only be ill-formed if it is potentially invoked.


More information about the Gcc-bugs mailing list