In a generic context, it is quite often we write something like
return_type f(arg_type1 arg1, ...)
noexcept(noexcept(statement_1) && noexcept(statement_2) && ... && noexcept(statement_n))
{
statement_1;
statement_2;
...
statement_n;
}
When a statement_k is a return statement, things aren't so simple. It is just impossible to write noexcept(return expr). Instead, I should understand what's going on when we say return expr and break down it into several noexcept(something)'s. But it seems quite nontrivial.
I've come up with something like the following algorithm:
- If
return_typeis a reference type, then of coursenoexcept(expr)suffices. - If
return_typeis not a reference type but ifreturn expris a situation where guaranteed copy elision happens then againnoexcept(expr)suffices. - Otherwise,
noexcept(expr) && std::is_nothrow_move_constructible<return_type>::value && std::is_nothrow_destructible<return_type>::value.
Is it right? Or is there any simpler way? The case 1 would be subsumed as a special case of case 3, but how about case 2 and 3?