This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/34700] New: rvalue erroneously binding to non-const lvalue reference
- From: "eric dot niebler at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 7 Jan 2008 05:49:35 -0000
- Subject: [Bug c++/34700] New: rvalue erroneously binding to non-const lvalue reference
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
Consider the following code, compiled with the latest gcc built from sources,
with the -std=c++0x flag:
#include <iostream>
struct S
{
S() {}
S(S &s) { std::cout << "L-value ref" << std::endl; }
S(S &&s) { std::cout << "R-value ref" << std::endl; }
};
S source() { static S s; return s; }
int main()
{
std::cout << "here 1 \n";
S s;
std::cout << "here 2 \n";
S t(s);
std::cout << "here 3 \n";
S u(source()); // ERROR HERE
}
For me, this prints:
here 1
here 2
L-value ref
here 3
L-value ref
It should print:
here 1
here 2
L-value ref
here 3
R-value ref
An rvalue should under no circumstance bind to a non-const lvalue reference.
--
Summary: rvalue erroneously binding to non-const lvalue reference
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: eric dot niebler at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34700