1
votes

I have a question about wording in N3797::8.5.3/5 [dcl.init.ref]:

A reference to type “cv1 T1” is initialized by an expression of type “cv2 T2” as follows:

— If the reference is an lvalue reference and the initializer expression

  • is an lvalue (but is not a bit-field), and “cv1 T1” is reference-compatible with “cv2 T2,” or

  • has a class type (i.e., T2 is a class type), where T1 is not reference-related to T2, and can be converted to an lvalue of type “cv3 T3,” where “cv1 T1” is reference-compatible with “cv3 T3”

Does the second case mean the initializer expression is a class-type as well as an lvalue?

1
It must have a class type. Not necessarily an lvalue..T.C.

1 Answers

0
votes

The clause says:

has a class type

so it must be a class type. The examples further down in the document show it does not have to be an lvalue though, taking selected parts of the code example we have:

struct A { };
struct B : A { operator int&(); } b;

int& ir = B(); // ir refers to the result of B::operator int&

B() is not a lvalue but as 8.5.3/5 says:

can be converted to an lvalue of type “cv3 T3,” where “cv1 T1” is reference-compatible with “cv3 T3”

which in this case applies.