Skip to content

[expr.call] The result type of a function call and the value category relying on it #5415

Closed
@xmh0511

Description

@xmh0511

[expr.call] p14 says

A function call is an lvalue if the result type is an lvalue reference type or an rvalue reference to function type, an xvalue if the result type is an rvalue reference to object type, and a prvalue otherwise.

So, the type of the result of a function call is significant to determine the value category of the function call. However, it's unclear the type of the result in a normal function call. [expr.call] p9 just says

The result of a function call is the result of the possibly-converted operand of the return statement ([stmt.return]) that transferred control out of the called function (if any), except in a virtual function call if the return type of the final overrider is different from the return type of the statically chosen function, the value returned from the final overrider is converted to the return type of the statically chosen function.

It does specify the destination type for the case that the return types of the final overrider and the statically chosen function are different. However, for the conversion in the first step, it is vague to the destination type of the conversion(if any).

The result of a function call is the result of the possibly-converted operand of the return statement ([stmt.return]) that transferred control out of the called function (if any)

When we build up a conversion, we usually use the utterance: convert the expression E to type T. For the above case, we lack to specify the destination type T(in the first conversion). The improvement might be:

The result of a function call is:

  • if no conversion is necessary, the operand of the return statement.
  • Otherwise, the result of the conversion that implicitly converts the operand of the return statement to the return type of the called function.

where the return statement transferred control out of the called function (if any), except in a virtual function call if the return type of the final overrider is different from the return type of the statically chosen function, the result of the final overrider is converted to the return type of the statically chosen function.

Moreover, [conv.general] p6 defines what the result of a conversion is.

using the temporary variable as the result of the conversion.

The modified rule together with [conv.general] p6 are clear to clarify the value category that relies on the result type of the function call.

struct A{
   A(int);
};
A fun(){
  return 0;
}

The result of the conversion is defined as

A t = 0;

The result of the call (t) is a prvalue of class A, thus the function call is a prvalue.

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