This page is a snapshot from the LWG issues list, see theLibrary Active Issues List for more information and the meaning ofCD1 status.
Section: 22.2.4[forward]Status:CD1Submitter: Jens MaurerOpened: 2008-03-13Last modified: 2016-02-01
Priority:Not Prioritized
View all otherissues in [forward].
View all issues withCD1 status.
Discussion:
p4 (forward) says:
Return type: If
Tis an lvalue-reference type, an lvalue; otherwise, an rvalue.
First of all, lvalue-ness and rvalue-ness are properties of an expression,not of a type (see 7.2.1[basic.lval]). Thus, the phrasing "Return type" is wrong.Second, the phrase says exactly what the core language wording says forfolding references in 13.4.2[temp.arg.type]/p4 and for function return valuesin 7.6.1.3[expr.call]/p10. (If we feel the wording should be retained, it shouldat most be a note with cross-references to those sections.)
The prose after the example talks about "forwarding as anint& (an lvalue)" etc.In my opinion, this is a category error: "int&" is a type, "lvalue" is aproperty of an expression, orthogonal to its type. (Btw, expressions cannothave reference type, ever.)
Similar with move:
Return type: an rvalue.
is just wrong and also redundant.
Proposed resolution:
Change 22.2.4[forward] as indicated:
template <class T> T&& forward(typename identity<T>::type&& t);...
Return type: IfTis an lvalue-reference type, an lvalue; otherwise, an rvalue....
-7- In the first call to
factory,A1is deduced asint, so 2 is forwarded toA's constructorasanan rvalueint&&(). In the second call to factory,A1is deducedasint&, soiis forwarded toA's constructor asanan lvalueint&().In both cases,A2is deduced as double, so 1.414 is forwarded toA's constructor asan rvaluedouble&&().template <class T> typename remove_reference<T>::type&& move(T&& t);...
Return type: an rvalue.