-
Notifications
You must be signed in to change notification settings - Fork 41
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
Bind const lvalue reference to a temporary of a class type #496
Comments
I would like some code for reference binding, namely One way to do so is to do One way to solve the problem would be to make sure that the reference result of reference binding does not rewrite to the object being referred. We could for example wrap it in a newly created Another way would be to create a new reference referring to the same object as the rewritten reference does, using |
After #522, the above code still does not work - but now it gets stuck in the translation semantics, in EDIT2: It fails when processing a call to the copy-constructor, in reference binding, when strict-evaluating the RHS - a Also, I can not reproduce the situation from June 25, even with version from that time. |
According to n4296 12.2/5, a temporary bound to a reference lives either to the end of the full-expression (if bound to a function parameter in function call expression, to returned value in return statement, or a to new-initializer), or to the end of life of the reference (in other cases; I can think only of a declaration of a reference). How do we destroy non-lifetime-extended (i.e. those that are destroyed at the end of full-expression) temporaries? We might collect them in a cell and then use the Q: what happens with temporaries now? I can think of the following cases:
How do we destroy lifetime-extended temporaries? We already deal with those temporaries that are created as a part of reference binding - see the rule for Currently, destructors of global objects are not called TODOs
I can see two ways how can we extend the lifetime of a temporary that is bound to a reference. Either we change the semantics of Which C++ constructs produce temporary? Those constructs might create an expression of the shape http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0135r0.html says:
So while in C++14 TODOs
prvalues:
Temporary materialization
what is "temporary expression"? Clang-kast also generates |
Suppose we have a class
A
and a functionfoo
returningA
by value:Then an expression that consists only of a call to
foo()
is a prvalue. As in the followin snippet, an attempt to bind that prvalue to a const lvalue reference (or to an rvalue reference?) should result in a temporary materialization, according to dcl.init.ref/5.3, and the reference should be bound to the temporary. (The temporary materialization includes copy-constructing the classA
.In that case, the execution semantics get stuck at
bindReference3
, where a side condition requires the initializer to have a non-class type:For non-class types as in
everything works.
The same problematic situation occurs when the reference binding is done as a part of a function call:
However, if the parameter of function
bar
is unnamed, the problem disappears (and the copy constructor of A is called).The text was updated successfully, but these errors were encountered: