The code is as follow: struct T { T() noexcept(false) { } ~T() noexcept(false) { } }; struct A { A() noexcept = default; ~A() noexcept = default; T t; }; g++ accepts the code, but I think it shouldn't be. In fact, g++4.9.0 rejects the code: ex.cc:8:5: error: function 'A::A()' defaulted on its first declaration with an exception-specification that differs from the implicit declaration 'A::A()' A() noexcept = default; ^ ex.cc:9:5: error: function 'A::~A()' defaulted on its first declaration with an exception-specification that differs from the implicit declaration 'A::~A()' ~A() noexcept = default; I tried clang++. It also rejects the code: ex.cc:8:2: error: exception specification of explicitly defaulted default constructor does not match the calculated one A() noexcept = default; ^ ex.cc:9:2: error: exception specification of explicitly defaulted destructor does not match the calculated one ~A() noexcept = default; ^ 2 errors generated.
(In reply to zhonghao from comment #0) > g++ accepts the code, but I think it shouldn't be. GCC defines the members as deleted, so you don't get an error unless you try to use them. That seems to be correct according to [dcl.fct.def.default] p2 which has a very similar example: ~S() noexcept(false) = default; // deleted: exception specification does not match I think Clang might implement the suggested direction for https://wg21.link/cwg1854 but GCC is correct according to the current standard. > In fact, g++4.9.0 rejects the code: 4.9.0 accepts it, but 4.8.x rejects it.
clang 9 and above started to accept the code. I have not looked into why they changed it yet though.