Topic: Issue #240


Author: Valentin.Bonnard@free.fr (Valentin Bonnard)
Date: Sun, 13 May 2001 11:47:52 GMT
Raw View
John Potter wrote:
> On Fri, 11 May 2001 13:38:15 GMT, "TiTi" <titi_@skynet.be> wrote:
>
>> Alexander Krotov <ank@nixu.fi> schreef in berichtnieuws
>> 20010507123750.B74552@namesurfer.com...
>
>> > A g();
>> > void f()
>> > {
>> > g()=g();
>> > }
>> > Is there any rationale why this restriction has been relaxed ?

> But, that is the point of the question.  You may call a non-const
> member function on an rvalue.  Of course, operator= is a member and
> the code is perfectly valid.  With the standard A& return of operator=,
> the following is interesting.
>
> void h(A&);
> void e () {
>    h(g());  // error binding rvalue to non-const reference
>    h(g() = g()); // no error
>    }
>
> The rule is not there to allow these silly things.

The point isn't so much disallowing silly things (if the
programmer wants them, why do we care), but avoiding
coding errors.

In this case, the programmer probably thinks that g() returns
a reference, and expects the compiler to protect him if it
isn't actually the case.

There is also the issue, discussed a lot by AFNOR, that l- and
r-values are only very remotely related to left and right.

  -- VB

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]