http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47999
Summary: [C++0x] auto type deduction works incorrectly in a function template Product: gcc Version: 4.6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: mimomo...@gmail.com Created attachment 23554 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=23554 Test case When `auto&&` is initialized with a function return value that is an lvalue reference, the deduced type should be an lvalue reference. int& identity(int& i) { return i; } void f() { int i = 0; auto&& x = identity(i); // x has type `int&` } But, in a function template, auto type deduction incorrectly deduces the type as an rvalue reference. template <typename T> void f() { int i = 0; auto&& x = identity(i); // BUG: x has type `int&&` } This bug leads to compilation error in gcc 4.5 and 4.6, because lvalues cannot bind to rvalue references. In gcc 4.4, the code compiles fine because lvalues are allowed to bind to rvalue references. Tested compilers: gcc-4.4.5, 4.5.2, 4.6-20110219. (This problem was found by Nathan Ridge.)