It is clear in the C ++ 11 specification that implicitly generated special functions (i.e. default constructor constructors, destructor, copy / move, and copy / move assignment operators) have exception specifications. But the specification is presented only in terms of legacy dynamic exception specifications (ie, "Throw (T1, T2, T3)"). This is confirmed by the example in 15.4 / 14:
struct A { A(); A(const A&) throw(); A(A&&) throw(); ~A() throw(X); }; struct B { B() throw(); B(const B&) throw(); B(B&&) throw(Y); ~B() throw(Y); }; struct D : public A, public B {
Notes are not normative, I know, but it should be noted that the constructor of the D-copy is declared throw() instead of noexcept . This matters because the behavior of the program is different if a throw() is violated compared to a noexcept violation.
The text in 15.4 / 14 of the above example is normative, and it says:
An implicitly declared special member function (clause 12) must have an exception specification. If f default constructor, copy constructor, move constructor, destructor, copy assignment operator or redirection operator are implicitly declared, its implicit exception-specification indicates the identifier type T if and only if T is allowed by the exception specification of the function called directly by implicit definition fs; f allows all exceptions if there is a function that it calls directly, allows all exceptions, and f allows no exceptions if every function that it calls directly does not allow an exception.
Given that only dynamic exception specifications are mentioned here, I fear that implicitly created special member functions are never declared noexcept . Is this really so?
source share