Movatterモバイル変換


[0]ホーム

URL:


Issue 1778 - WG21 CWG Issues
Title
exception-specification in explicitly-defaulted functions
Status
c++14
Section
9.6.2 [dcl.fct.def.default]
Submitter
USA

Created on2013-09-25.00:00:00 last changed136 months ago

Messages

msg4951 (view)
Date: 2014-02-15.00:00:00

[Moved to DR at the February, 2014 meeting.]

msg4743 (view)
Date: 2014-01-20.00:00:00

Additional note, January, 2014:

The proposed resolution appears to have the undesirable implicationthat a special member function could become deleted after theclass is complete. For example, given

  struct S {    S() noexcept(false) = default;  };

we need to check that the explicit exception specificationis compatible with the one on the implicit declaration. Afterthe resolution ofissue 1330, theclass is regarded as complete withinexception-specifications,per 11.4 [class.mem] paragraph 2. This implies that theexplicitexception-specification can only be checked oncethe class is complete.

The issue has been returned to "review" status to allow discussionof this concern.

msg4592 (view)
Date: 2013-09-15.00:00:00

Proposed resolution (September, 2013):

Change 9.6.2 [dcl.fct.def.default] paragraphs 2 and 3 as follows:

An explicitly-defaulted function may be declaredconstexpr onlyif it would have been implicitly declared asconstexpr, andmay have an explicitexception-specification only if it iscompatible (14.5 [except.spec]) withtheexception-specification on the implicit declaration. If afunction is explicitly defaulted on its first declaration,

  • it is implicitly considered to beconstexpr if theimplicit declaration would be, and,

  • it is implicitly considered to have thesameexception-specification as if it had been implicitly declared(14.5 [except.spec]).

If a function that is explicitly defaulted has anexplicitexception-specification that is not compatible(14.5 [except.spec]) with theexception-specification on theimplicit declaration, then

  • if the function is explicitly defaulted on its firstdeclaration, it is defined as deleted;

  • otherwise, the program is ill-formed.

[Example:

  struct S {    constexpr S() = default;            // ill-formed: implicitS() is not constexpr    S(int a = 0) = default;             // ill-formed: default argument    void operator=(const S&) = default; // ill-formed: non-matching return type    ~S() throw(int) = default;          //ill-formeddeleted: exception specification does not match  private:    int i;    S(S&);                              // OK: private copy constructor  };  S::S(S&) = default;                   // OK: defines copy constructor

end example]

msg4591 (view)
Date: 2013-09-25.00:00:00
N3690 comment US 23

According to 9.6.2 [dcl.fct.def.default] paragraph 2,

An explicitly-defaulted function may be declaredconstexpr only ifit would have been implicitly declared asconstexpr, and may have anexplicitexception-specification only if it is compatible(14.5 [except.spec]) with theexception-specification on theimplicit declaration.

The requirement forexception-specifications has unfortunateconsequences for the standard library componentatomic, asdescribedinLWGissue 2165: the component cannot be used with aTunlessT is nothrow default constructible, even ifthestd::atomic<T> variable is never defaultinitialized.

History
DateUserActionArgs
2014-11-24 00:00:00adminsetstatus: dr -> c++14
2014-03-03 00:00:00adminsetmessages: +msg4951
2014-03-03 00:00:00adminsetstatus: review -> dr
2014-01-20 00:00:00adminsetmessages: +msg4743
2014-01-20 00:00:00adminsetstatus: ready -> review
2013-10-14 00:00:00adminsetmessages: +msg4592
2013-09-25 00:00:00admincreate

[8]ページ先頭

©2009-2026 Movatter.jp