You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
CWG2715 [expr.call] "Calling function" is not clearly defined, and may not exist #287
Issue description: [expr.call]/6 states: "[...] The initialization and destruction of each parameter occurs within the context of the calling function." However, a function call that is a subexpression of an init-declarator for a non-local variable does not have a calling function, and some expressions that are evaluated during translation do not have calling functions:
class C {
private:
constexpr int C(int) {}
friend void foo(int (*a)[1]) noexcept;
};
constexpr int bar(C) { return 1; }
void foo(int (&a)[bar(1)]) noexcept(bar(2) > 0); // presumably OK because of friendship
Example 2 suggests that the purpose of this sentence is to clarify access control and exception handling. Are there any other language concepts that care about whether the context is that of the caller or the callee?
Suggested resolution:
Edit [expr.call]/6:
[...] It is implementation-defined whether the lifetime of a parameter ends when the function in which it is defined returns or at the end of the enclosing full-expression. For purposes of access control ([class.access.general]), tThe initialization and destruction of each parameter occurs within the context of the calling function full-expression to which it belongs ([intro.execution]).
[Example 2 : The access of the constructor, conversion functions or destructor is checked at the point of call in the calling function. If a constructor or destructor for a function parameter throws an exception, the search for a handler
starts in the calling function; in particular, if the function called has a function-try-block (14.1) with a handler that
can handle the exception, this handler is not considered. —end example]
[Note -?-: As specified in [except.throw], if a constructor or destructor for a function parameter throws an exception, the search for a handler starts in the calling function, if any; in particular, if the function called has a function-try-block ([except.pre]) with a handler that can handle the exception, this handler is not considered. —end note]
I've altered the proposed resolution so that it keeps the general thrust of "in the calling function" instead of limiting the normative rule to access control.
changed the title [-][expr.call] "Calling function" is not clearly defined, and may not exist[/-][+]CWG2715 [expr.call] "Calling function" is not clearly defined, and may not exist[/+]on Apr 9, 2023
http://eel.is/c++draft/except.throw#2 explains how to find the nearest handler. Any try-block or function-try-block has not been "entered" yet if the parameters are still being initialized.
Well, it still seems possible to (e.g.) destroy a parameter inside the called function, making the function-try-block relevant. We don't want that, so we should have a general rule that parameters are created and destroyed in the caller's context.
Activity
jensmaurer commentedon Apr 9, 2023
Where exactly do we say that?
jensmaurer commentedon Apr 9, 2023
CWG2715
I've altered the proposed resolution so that it keeps the general thrust of "in the calling function" instead of limiting the normative rule to access control.
[-][expr.call] "Calling function" is not clearly defined, and may not exist[/-][+]CWG2715 [expr.call] "Calling function" is not clearly defined, and may not exist[/+]t3nsor commentedon Apr 9, 2023
http://eel.is/c++draft/except.throw#2 explains how to find the nearest handler. Any try-block or function-try-block has not been "entered" yet if the parameters are still being initialized.
jensmaurer commentedon Apr 9, 2023
Well, it still seems possible to (e.g.) destroy a parameter inside the called function, making the function-try-block relevant. We don't want that, so we should have a general rule that parameters are created and destroyed in the caller's context.