-
Notifications
You must be signed in to change notification settings - Fork 771
[expr.call]/9 The result of a function call may not be the same as the result of the operand of its return statement #3124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The result of the function call expression |
@zygoloid I don't really agree.
The result of a prvalue is "the value it stores into it's context". The operand of the return statement here is the glvalue |
@zygoloid Addtionally, consider a situation like this: float a = 0;
int f()
{
return a;
}
int b = f(); Here, the "result of the operand of the evaluated return statement" is an object of type |
OK, I see what you're saying now. Yes, it would be clearer if we said the result of the function call is the result of the possibly-converted operand of the evaluated return statement, or something like that. There's another problem here: we can evaluate more than one return statement, in a case like
I think something like this would resolve the issue:
|
The fix seems pretty obvious to me. |
@jensmaurer @zygoloid Hm. I still don't believe the wording is quite fixed. Consider what this means for a lvalue function call in conjunction with [stmt.return] p4, which says the result of the function call is initialized with the operand of the return statement... but we define the operand as being the result of the function call, and we end up saying that the operand initializes itself. |
[expr.call] p9 states:
However, this may not always work. For example:
Additionally, if the result of the function is the result of the operand, then the wording in [stmt.return] p2 sentence 4 would have the operand initialize itself in the case of the function call and the operand being glvalues (the result of the function would be the result of the operand which would be the objects it denotes, so initializing the result of the function would initialize that object). Even crazier, in the case of the operand being a prvalue, this would have the operand initializing a value (result of the function would be the value of the operand).
To remedy this, it could be specified that the result of the function is the operand after any conversions are applied to the operand to convert it to the type and value category of the function call, but this could introduce some problems for prvalues, as they should not be materialized, and instead used to initialize the object itself.
Alternatively, the wording in [stmt.return] p2 sentence 4 could be removed entirely, and instead, [expr.call] p9 could be written to say:
And this would solve the problem, as if the function call is a prvalue, the result would be its value, and if the function call is a glvalue, the result would simply be the object that the operand denoted, or the temporary that results from initializing the result.
The text was updated successfully, but these errors were encountered: