Subject: standards/5959: c++ language specification error or compiler error??
To: None <gnats-bugs@gnats.netbsd.org>
From: Andrew Brown <twofsonet@graffiti.com>
List: netbsd-bugs
Date: 08/12/1998 19:20:13
>Number: 5959
>Category: standards
>Synopsis: compiler allows something language probably shouldn't?
>Confidential: no
>Severity: serious
>Priority: low
>Responsible: gnats-admin (GNATS administrator)
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed Aug 12 16:35:01 1998
>Last-Modified:
>Originator: Andrew Brown
>Organization:
none
>Release: 1.2 (yeah, i know, i gotta upgrade)
>Environment:
System: NetBSD noc 1.2 NetBSD 1.2 (null) #4: Fri Oct 24 01:27:28 EDT 1997 root@noc:/usr/src/sys/arch/i386/compile/null i386
>Description:
in c and c++ code, rvalues cannot be assigned to, only lvalues
can. ie:
/* "6" is the rvalue (obviously), "foo" is the lvalue (since
it's on the left), and the entire statement yields an rvalue
(since you can assign from it, but not to it) */
int foo;
foo=6;
an "assignment" usually yields an rvalue (unless you write a c++ class
that returns a non-const reference from operator=(), which is yet
another way to make your code confusing :), ie:
int foo, bar;
foo=bar=6;
is legal code. c++ introduces the concept of references as a way of
getting around using pointers. they're kinda neat, but also kinda
confusing (cf. http://www.daemon.org/c++-hoax.html). i was under the
(possible mistaken) impression that rvalues could not be passed by
reference, but i just noticed that i'm doing it quite frequently.
ie:
void function(int &t) { t=4; }
int foo;
...
function(foo=3);
printf("%d\n",foo);
will yield "4" as the output, in effect, assigning to an rvalue. and
int is certainly not a c++ class.
is this the correct behavior? it doesn't strike me as such, from what
i know of the language. perhaps it's a "feature" in the language? or
a "bug" in the compiler?
>How-To-Repeat:
write code that does this thing (that might be wrong?).
>Fix:
contact the people who make the compiler? or define the language? or
not? just please set my mind at rest?
>Audit-Trail:
>Unformatted: