Skip to content

CWG2715 [expr.call] "Calling function" is not clearly defined, and may not exist #287

Closed
cplusplus/draft
#6328
@t3nsor

Description

@t3nsor

Full name of submitter: Brian Bi

Reference (section label): [expr.call]

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]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions