This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

c++/673: gcc treats temporary as rvalue when passing references



>Number:         673
>Category:       c++
>Synopsis:       gcc treats temporary as rvalue when passing references
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Sun Oct 22 20:56:01 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     Benjamin Carlyle
>Release:        gcc version 2.95.2
>Organization:
>Environment:
Both solaris and linux
>Description:
When generating references to pass as non-const parameters of functions
temporary objects cannot be used, issuing the error:

initialisation of non-const reference type `class xxx&'
from rvalue of type `xxx'

There is (naturally) no problem for const references, but I believe this
is an error.  Stroustrup in the C++ programming language third edition 
defines an lvalue thusly:
"an lvalue is an expression that refers to an object"
and "an object is a contiguous region of storage".
p84, section 4.9.6
Under this definition I understand the temporary to be an
lvalue rather than an rvalue.

If that definition disagrees with the standard, then this bug
report is in error.
>How-To-Repeat:
The simplest snippet of code I could cause this in is as follows:

struct simpleclass {int i;};
void func(simpleclass &) {};
int main(void) { func(simpleclass()); };

>Fix:
Unknown
One work-around is to assign the new object to a name in a
small namespace:
{
	xxx myobj = obj();
	func(myobj);
}
... but this is not appropriate for objects that cannot be
explicitly copied (such as the objects I'm working with),
and makes the code convoluted.
>Release-Note:
>Audit-Trail:
>Unformatted:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]