Bug 86583 - [DR 1854] exception specification of explicitly defaulted destructor does not match the calculated one
Summary: [DR 1854] exception specification of explicitly defaulted destructor does not...
Status: SUSPENDED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 9.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2018-07-19 01:32 UTC by zhonghao
Modified: 2022-09-19 12:17 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-07-19 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description zhonghao 2018-07-19 01:32:25 UTC
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.
Comment 1 Jonathan Wakely 2018-07-19 12:18:39 UTC
(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.
Comment 2 Andrew Pinski 2021-12-09 01:14:49 UTC
clang 9 and above started to accept the code. I have not looked into why they changed it yet though.