Skip to content

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

Closed
cplusplus/draft
#6328

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]

Activity

  1. jensmaurer commented on Apr 9, 2023

    @jensmaurer
    Member

    As specified in [except.throw]

    Where exactly do we say that?

  2. jensmaurer commented on Apr 9, 2023

    @jensmaurer
    Member

    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.

  3. 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
  4. t3nsor commented on Apr 9, 2023

    @t3nsor
    Author

    As specified in [except.throw]

    Where exactly do we say that?

    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.

  5. jensmaurer commented on Apr 9, 2023

    @jensmaurer
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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