cplusplus / draft

C++ standards drafts
http://www.open-std.org/jtc1/sc22/wg21/
5.68k stars 749 forks source link

[expr.type], [expr.call] Draw connection between type adjustment paragraphs #7063

Open Eisenwave opened 4 months ago

Eisenwave commented 4 months ago

We have the general rule [expr.type] p1:

If an expression initially has the type “reference to T” ([dcl.ref], [dcl.init.ref]), the type is adjusted to T prior to any further analysis. The expression designates the object or function denoted by the reference, and the expression is an lvalue or an xvalue, depending on the expression.

For function calls, there is the more concrete rule [expr.call] p13:

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.

I feel like we should connect these paragraphs in some way. The main reason why we need [expr.type] p1 is for function calls anyway. I'm not sure if it even serves any purpose or is completely covered by more concrete rules.

In any case, we could leave some note such as

+ For the type adjustment rules from the return type of a function
+ to the result type of function call expressions, see [expr.call].

If it turns out that [expr.type] p1 is covered by other rules, we could consider turning it into a note or deleting it. The current wording strategy is to always state what type and value category an expression has, so I cannot think of any non-defective wording where [expr.type] p1 would apply.

Eisenwave commented 4 months ago

Yet another option is to make the rules in [expr.type] p1 more complete; references to functions are adjusted to lvalues in all cases, so we could at least say that there instead of keeping it vague with "depending on the expression".