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
The operand in the copy-initialization of the result object of a function should be the possibly-converted one #4847
Comments
No, copy-initialization subsumes the conversion. |
Do you mean the copy-initialization that occurred in the return statement subsumes the conversion of
To make this thought more clear, the B const& rf(a.operator B());
// where the materialization conversion is equivalent to
B temporary_object = a.operator B();
// where the return statement in `A::operator B` has the effect, which is like
B temporary_object = 0;
// In the above copy-initialization, user-defined conversion(B::B(int)) is considered
// which is considered in direct-initialization of the reference rf |
@jensmaurer Is any thought here? |
I'm not seeing a problem. We copy-initialize the temporary (conversion function is fine). This completes the evaluation of the conversion function and any talk about operands of "return". As a distinct step, we then direct-initialize the reference with the temporary (no conversion functions involved). |
The temporary direct-initialize the reference is not specifying by [dcl.init.ref#5.4.1]. It just say
Where the call to the conversion function is a prvalue, bind it to a reference will trigger the materialization, which means a temporary object will copy-initialized from the operand, which requires the user-defined conversion, Occurs in direct-initializ the reference from a prvalue. |
The relevant wording in C++11 standard was saying that the reference is bound to the temporary
However, the concern in CWG1571, make the wording be changed, which claims that the conversion function call is direct-initialized the reference. In my example, this rule means we should continue to fall into [dcl.init.ref] p5 for it. What I'm concerning here is what's the extent of the application of the restriction that the user-defined conversions are not considered in this direct-initialization. Since we fall into [dcl.init.ref#5.3] for this direct-initialization, materialization conversion would apply to the conversion function call(prvalue), as discussed in the above comment, the copy-initialization of the temporary object does consider the user-defined conversion. |
Maybe clarified by cplusplus/CWG#186 |
[stmt.return] p2 says
where the operand is defined as
Instead, [expr.call] p9 says
It seems to be a bit inconsistent. It is not clear whether the return statement uses the possible-converted operand to copy-initialize the result object or just the original operand. The concern comes from the following example
According to [dcl.init.ref#5.4.1], the initializer expression at
#1
should be first converted to typeB
with a user-defined conversion, which isB::operator B
, and [dcl.init.ref#5.4.1] also saysFor the direct-initialization of the reference, temporary materialization conversion will be applied to the conversion function call, which means the temporary object is used as the result object that is copy-initialization from the operand of the return statement, as aforementioned. At this point, according to [dcl.init#general-15.6.3], it will invoke user-defined conversions to transform the operand (
0
) to the destination type to initialize the result object(temporary object ). However, as [dcl.init.ref#5.4.1] said, user-defined conversions are not considered.I think the wording about the return statement may be that
The text was updated successfully, but these errors were encountered: