https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85155
Bug ID: 85155 Summary: Suboptimal error messages when using noexcept(false) on defaulted dtor Product: gcc Version: 8.0.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: vz-gcc at zeitlins dot org Target Milestone: --- Consider the following test program: % cat -n dtor_def_noexcept.cpp 1 struct B { 2 virtual ~B() noexcept(false) = default; 3 }; 4 5 struct D : B { 6 virtual ~D() { throw 17; } 7 }; 8 9 int main() 10 { 11 try { 12 D d; 13 return 1; 14 } catch (int n) { 15 return n; 16 } 17 18 return 0; 19 } Compiling it with g++ 8 (gcc version 8.0.1 20180321 (experimental) [trunk revision 258712] (Debian 8-20180321-1)) results in the following not really obvious to interpret errors: % g++-8 -std=c++17 -Wall dtor_def_noexcept.cpp dtor_def_noexcept.cpp:6:13: error: non-deleted function ‘virtual D::~D()’ virtual ~D() { throw 17; } ^ dtor_def_noexcept.cpp:2:13: error: overriding deleted function ‘virtual B::~B()’ virtual ~B() noexcept(false) = default; ^ dtor_def_noexcept.cpp: In destructor ‘virtual D::~D()’: dtor_def_noexcept.cpp:6:18: error: use of deleted function ‘B::~B()’ virtual ~D() { throw 17; } ^ dtor_def_noexcept.cpp:2:13: note: ‘virtual B::~B() noexcept (false)’ is implicitly deleted because its exception-specification does not match the implicit exception-specification ‘noexcept’ virtual ~B() noexcept(false) = default; ^ dtor_def_noexcept.cpp:6:26: warning: throw will always call terminate() [-Wterminate] virtual ~D() { throw 17; } ^~ dtor_def_noexcept.cpp:6:26: note: in C++11 destructors default to noexcept dtor_def_noexcept.cpp: In function ‘int main()’: dtor_def_noexcept.cpp:12:11: error: use of deleted function ‘D::D()’ D d; ^ dtor_def_noexcept.cpp:5:8: note: ‘D::D()’ is implicitly deleted because the default definition would be ill-formed: struct D : B { ^ dtor_def_noexcept.cpp:5:8: error: use of deleted function ‘virtual B::~B()’ All of this is correct, of course, but compare it with the error message given by clang: % clang-7 -std=c++17 -Wall dtor_def_noexcept.cpp dtor_def_noexcept.cpp:2:13: error: exception specification of explicitly defaulted destructor does not match the calculated one virtual ~B() noexcept(false) = default; ^ 1 error generated. which seems much more clear. It would be nice if gcc error messages could be improved to emphasize the important one, i.e. that noexcept(false) doesn't match "= default".