This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/673: gcc treats temporary as rvalue when passing references
- To: gcc-gnats at gcc dot gnu dot org
- Subject: c++/673: gcc treats temporary as rvalue when passing references
- From: benc at foxboro dot com dot au
- Date: 23 Oct 2000 03:54:39 -0000
- Cc: julied at foxboro dot com dot au
- Reply-To: benc at foxboro dot com dot au
- Resent-Cc: gcc-prs at gcc dot gnu dot org, gcc-bugs at gcc dot gnu dot org, jason at gcc dot gnu dot org, julied at foxboro dot com dot au
- Resent-Reply-To: gcc-gnats@gcc.gnu.org, benc@foxboro.com.au
>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: