Topic: Isuue #240


Author: "TiTi" <titi_@skynet.be>
Date: Fri, 11 May 2001 13:38:15 GMT
Raw View
Alexander Krotov <ank@nixu.fi> schreef in berichtnieuws
20010507123750.B74552@namesurfer.com...
> Concerning issue #240:
> As far as i remember at some point (CD I?) it was not allowed
> to call non-const qualified member functions for rvalue class
> objects. In the standard there is no such rule, and because
> of this the trick with get() function compiles, but direct
> access to the member does not (there is the same rule in C
> standard).
> Because of absence of the restriction following silly
> code compiles as well:
> struct A { int a; };
> A g();
> void f()
> {
> g()=g();
> }
> Is there any rationale why this restriction has been relaxed ?


This may be a silly remark, but I think it should not compile, as you didn't
return an lvalue, but you did assign to it. You can't assign to a temporary.

Cheers,
TiTi


---
[ 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                ]





Author: jpotter@falcon.lhup.edu (John Potter)
Date: Sat, 12 May 2001 15:34:19 GMT
Raw View
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 ?
>
> This may be a silly remark, but I think it should not compile, as you
> didn't return an lvalue, but you did assign to it. You can't assign to
> a temporary.

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.  Maybe someone can
remember why it is there.

John

---
[ 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                ]





Author: Alexander Krotov <ank@nixu.fi>
Date: Mon, 7 May 2001 11:23:13 GMT
Raw View
Concerning issue #240:
As far as i remember at some point (CD I?) it was not allowed
to call non-const qualified member functions for rvalue class
objects. In the standard there is no such rule, and because
of this the trick with get() function compiles, but direct
access to the member does not (there is the same rule in C
standard).
Because of absence of the restriction following silly
code compiles as well:
struct A { int a; };
A g();
void f()
{
 g()=g();
}
Is there any rationale why this restriction has been relaxed ?

--
Alexander Krotov gsm: +358 40-725 7216
Product Developer fax: +358  9-478 1030
NIXU Ltd.  http://www.nixu.com

---
[ 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                ]