Title
Use of auto with rvalue references
Status
nad
Section
9.2.9.7 [dcl.spec.auto]
Submitter
Jonathan Caves

Created on 2008-08-01.00:00:00 last changed 196 months ago

Messages

Date: 2008-09-15.00:00:00

Rationale (September, 2008):

It is important that the deduction rules be the same in the function and auto cases. The result of this example might be surprising, but maintaining a consistent model for deduction is more important.

Date: 2022-11-20.07:54:16

Because type deduction for the auto specifier is described in 9.2.9.7 [dcl.spec.auto] paragraph 6 as equivalent to the deduction that occurs in a call to a function template, the adjustment of the argument type from A to A& specified in 13.10.3.2 [temp.deduct.call] paragraph 3 is performed when the initializer is an lvalue. As a result, in the following example, ra has the type A& and not, as might be expected, A&&:

    class A { };

    void f() {
       A a;
       auto&& ra = a;
    }

It is unclear whether this is surprising enough, and potentially widely-enough used, to warrant making an exception to the current rules to handle this case differently.

History
Date User Action Args
2008-10-05 00:00:00adminsetmessages: + msg1833
2008-10-05 00:00:00adminsetstatus: open -> nad
2008-08-01 00:00:00admincreate