Newsgroups: comp.std.c++
Path: utzoo!utgpu!cunews!csi.uottawa.ca!news
From: hitz@sim5.csi.uottawa.ca (Martin Hitz)
Subject: Re: Assignment operators return lvalues / classes and types
Message-ID: <1991Apr25.030006.5849@csi.uottawa.ca>
Keywords: assignment, lvalue, class, type
Sender: news@csi.uottawa.ca
Nntp-Posting-Host: sim5
Organization: University of Ottawa
References: <950@edg1.UUCP> <1991Apr24.184018.23427@kestrel.edu>
Date: Thu, 25 Apr 91 03:00:06 GMT

In article <1991Apr24.184018.23427@kestrel.edu> gyro@kestrel.edu (Scott Layson Burson) writes:
>In article <950@edg1.UUCP> jsa@edg1.UUCP (J. Stephen Adamczyk) writes:
>>The ARM (5.1.7) says that the value of an assignment operator is
>>an lvalue.  That's different than ANSI C (3.3.16).  There must
>>be a reason for the difference; can anyone enlighten me?
>
>I surmise, without really knowing, that people want to write things
>like `(a = b).foo', for which it is required that the assignment
>return an lvalue.

No. Consider the following program:

struct X { int i; };
X f() { X x; return x; }
main()
{
	int i = f().i;	// OK
	X x;
	f() = x;	// !OK
}

f() does NOT return an lvalue, the last line in the program is therefore
illegal. However, f().i is of course allowed, and so would be (a = b).foo, 
even if = didn't return an lvalue.

Martin hitz@csi.uottawa.ca
