Date: Thu, 22 Dec 2022 11:46:28 -0500
On Thu, Dec 22, 2022 at 11:02 AM Edward Catmur via Std-Proposals <
std-proposals_at_[hidden]> wrote:
> On Thu, 22 Dec 2022 at 12:17, Sebastian Wittmeier <
wittmeier_at_[hidden]> wrote:
>>
>> If the destructor is called on the reference, the original object would
be destroyed.
>
> Then it's just as well that that isn't what happens. Instead, the
lifetime of the variable is ended in the same manner as when an automatic
variable reaches end of scope:
>
> std::string s;
> {
> auto& r = s;
> } // #1
> auto& q = s;
> reloc q; // #2
>
> The effect of #2 (as a discarded-value relocation expression) is
precisely the same as that of #1.
I don't know the context here, but that seems to mix together two different
factors:
- whether `reloc` operates on variables or objects
- whether it matters if the result of `reloc` is discarded
Ed, what would you say about each of the following eight cases?
std::string s1;
reloc s1; // discarded, operates on object variable
std::string s2;
std::string *f2() { return &s2; }
reloc *f2(); // discarded, operates on expression that refers to an
object (but is not a variable)
std::string s3;
std::string& f3() { return s3; }
reloc f3(); // discarded, operates on expression that refers to an
object (but is not a variable)
std::string s4;
std::string& r4 = s4;
reloc r4; // discarded, operates on reference variable
std::string s1b;
std::cout << reloc s1b; // non-discarded, operates on object variable
std::string s2b;
std::string *f2b() { return &s2b; }
std::cout << reloc *f2b(); // non-discarded, operates on expression
that refers to an object (but is not a variable)
std::string s3b;
std::string& f3b() { return s3b; }
std::cout << reloc f3b(); // non-discarded, operates on expression
that refers to an object (but is not a variable)
std::string s4b;
std::string& r4b = s4b;
std::cout << reloc r4b; // non-discarded, operates on reference
variable
Again, having *even a simple draft proposal* would make it easier to talk
about semantics, because we would have an actual place that the intention
was written down, instead of everyone making their own guesses that differ
from person to person and (even for the same person) from day to day. I
encourage Sébastien to *write something down*.
–Arthur
std-proposals_at_[hidden]> wrote:
> On Thu, 22 Dec 2022 at 12:17, Sebastian Wittmeier <
wittmeier_at_[hidden]> wrote:
>>
>> If the destructor is called on the reference, the original object would
be destroyed.
>
> Then it's just as well that that isn't what happens. Instead, the
lifetime of the variable is ended in the same manner as when an automatic
variable reaches end of scope:
>
> std::string s;
> {
> auto& r = s;
> } // #1
> auto& q = s;
> reloc q; // #2
>
> The effect of #2 (as a discarded-value relocation expression) is
precisely the same as that of #1.
I don't know the context here, but that seems to mix together two different
factors:
- whether `reloc` operates on variables or objects
- whether it matters if the result of `reloc` is discarded
Ed, what would you say about each of the following eight cases?
std::string s1;
reloc s1; // discarded, operates on object variable
std::string s2;
std::string *f2() { return &s2; }
reloc *f2(); // discarded, operates on expression that refers to an
object (but is not a variable)
std::string s3;
std::string& f3() { return s3; }
reloc f3(); // discarded, operates on expression that refers to an
object (but is not a variable)
std::string s4;
std::string& r4 = s4;
reloc r4; // discarded, operates on reference variable
std::string s1b;
std::cout << reloc s1b; // non-discarded, operates on object variable
std::string s2b;
std::string *f2b() { return &s2b; }
std::cout << reloc *f2b(); // non-discarded, operates on expression
that refers to an object (but is not a variable)
std::string s3b;
std::string& f3b() { return s3b; }
std::cout << reloc f3b(); // non-discarded, operates on expression
that refers to an object (but is not a variable)
std::string s4b;
std::string& r4b = s4b;
std::cout << reloc r4b; // non-discarded, operates on reference
variable
Again, having *even a simple draft proposal* would make it easier to talk
about semantics, because we would have an actual place that the intention
was written down, instead of everyone making their own guesses that differ
from person to person and (even for the same person) from day to day. I
encourage Sébastien to *write something down*.
–Arthur
Received on 2022-12-22 16:46:41