May 19, 2018

[C++] how should function's noexcept signature being declared?

https://stackoverflow.com/questions/50273336/noexcept-specifier-with-default-arguments-construction

Question:
function should be mark 'noexcept' base on it's own block expressions or function's argument(including default argument)

Answer:
It's own block expressions.
The function argument(default argument) evaluation should be happened on the caller's expression.
If it fails, it will fail before function being called(stack pile up and run).

ISO:

If an initializer-clause is specified in a parameter-declaration this initializer-clause is used as a default argument. Default arguments will be used in calls where trailing arguments are missing.
Example: the declaration void point(int = 3, int = 4); declares a function that can be called with zero, one, or two arguments of type int. It can be called in any of these ways:point(1,2); point(1); point(); The last two calls are equivalent to point(1,4) and point(3,4) , respectively.
Note (in [intro.execution] Program execution):
Subexpressions involved in evaluating default arguments (8.3.6) are considered to be created in the expression that calls the function, not the expression that defines the default argument

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.