2

If I read implicit conversions correctly:

Lvalue to rvalue conversion

A glvalue of any non-function, non-array type T can be implicitly converted to a prvalue of the same type. [..]

Unless encountered in unevaluated context (in an operand of sizeof, typeid, noexcept, or decltype), this conversion effectively copy-constructs a temporary object of type T using the original glvalue as the constructor argument, and that temporary object is returned as a prvalue.

Then why does this not work?

int* iptr = nullptr;
int*&& irr = iptr; // Cannot bind lvalue to rvalue reference

The type int* should have been implicitly converted to a prvalue of the same type via a temporary - thus binding to the rvalue reference without issues.

Community
  • 1
  • 1
Dean
  • 6,610
  • 6
  • 40
  • 90

1 Answers1

2

The standard states that this is ill-formed explicitly; lvalue-to-rvalue conversion won't (shouldn't) be considered.

From [dcl.init.ref]/5.4.4:

if the reference is an rvalue reference, the initializer expression shall not be an lvalue.

[ Example:

double d2 = 1.0;
double&& rrd2 = d2;                 // error: initializer is lvalue of related type
songyuanyao
  • 169,198
  • 16
  • 310
  • 405
  • I kinda hate C++ for this sort of things: exceptions and corner cases. – Dean Apr 20 '18 at 10:44
  • @Dean Well, the basic idea is clear; i.e. can't bind lvalues to rvalue-reference. So it might be better just don't consider too much, including why not applying lvalue-to-rvalue conversion in reference binding; they're also kinda corner cases. :) – songyuanyao Apr 20 '18 at 10:50