cpp/language/noexcept spec

Specifies whether a function could throw exceptions.

Syntax
@1@ Same as @2@ If evaluates to, the function is declared not to throw any exceptions. A following  is always a part of this form (it can never start an initializer). @3@ Same as (see  for its semantics before C++17)

Explanation
Every function in C++ is either non-throwing or potentially throwing:
 * potentially-throwing functions are:


 * functions declared with specifier whose  evaluates to
 * functions declared without specifier except for
 * s unless the destructor of any potentially-constructed base or member is potentially-throwing (see below)
 * s, s, s that are implicitly-declared or defaulted on their first declaration unless
 * a constructor for a base or member that the implicit definition of the constructor would call is potentially-throwing (see below)
 * a subexpression of such an initialization, such as a default argument expression, is potentially-throwing (see below)
 * a default member initializer (for default constructor only) is potentially-throwing (see below)
 * operators, operators that are implicitly-declared or defaulted on their first declaration unless the invocation of any assignment operator in the implicit definition is potentially-throwing (see below)


 * deallocation functions


 * non-throwing functions are all others (those with noexcept specifier whose evaluates to  as well as destructors, defaulted special member functions, and deallocation functions)

may use the noexcept specifier, but it is not required. If used, the exception specification must be the same as for all other declarations. A diagnostic is required only if the exception specifications are not the same within a single translation unit.

Functions differing only in their exception specification cannot be overloaded.

Pointers (including pointers to member function) to non-throwing functions pointers to potentially-throwing functions, but not the other way around.

If a virtual function is non-throwing, all declarations, including the definition, of every overrider must be non-throwing as well, unless the overrider is defined as deleted:

Non-throwing functions are permitted to call potentially-throwing functions. Whenever an exception is thrown and the search for a handler encounters the outermost block of a non-throwing function, the function std is called:

Formal definition of potentially-throwing expression (used to determine the default exception specification of destructors, constructors, and assignment operators as described above):

An expression is potentially-throwing if:
 * is a function call to a function, pointer to function, or pointer to member function which is potentially-throwing
 * makes an implicit call to a potentially-throwing function (such as an overloaded operator, an allocation function in a -expression, a constructor for a function argument, or a destructor if is a full-expression)
 * is a
 * is a that casts a polymorphic reference type
 * is a expression applied to a dereferenced pointer to a polymorphic type
 * has an immediate subexpression that is potentially-throwing

Deprecates
is an improved version of, which is deprecated in C++11. Unlike pre-C++17, will not call std, may or may not unwind the stack, and will call std, which potentially allows the compiler to implement  without the runtime overhead of. As of C++17, is redefined to be an exact equivalent of.