Subject: Re: standards/5959: c++ language specification error or compiler
To: None <gnats-bugs@gnats.netbsd.org, netbsd-bugs@netbsd.org>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: netbsd-bugs
Date: 08/13/1998 06:42:41
> Let's look at the code:

> 	void function(int &t) { t=4; }
[...]
> 	int foo;
> 	function(foo=3);

> What happens is:

> (a) you assign 3 to variable "foo"
> (b) you pass a reference to "foo" to "function"

This is the question: why, when "foo=3" is passed to a function taking
a reference, does the reference seem to refer to the variable "foo"
rather than to an anonymous value?  "function(1+2)", or anything else
producing a non-lvalue, wouldn't work that way; why does the non-lvalue
"foo=3" do it?

> Parameters are evaluated before calling the function.  This is true
> also for parameters with side effects.

Yes...but the parameter here *isn't an lvalue*!  Yes, it's evaluated
before the call, and there's a sequence point just before the call.
But why does the reference refer to foo?  What's being passed isn't
foo, but rather the value that just got assigned to foo.

Or are assignments lvalues in C++?  I would certainly hope not.

					der Mouse

			       mouse@rodents.montreal.qc.ca
		     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B