Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is my interpretation correct about n3797 8.5.3/5?

Paragraph 8.5.3/5 in n3797:

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” (this conversion is selected by enumerating the applicable conversion functions (13.3.1.6) and choosing the best one through overload resolution (13.3)),

...

English is not my native language, but the phrase in bold (my emphasis) seems to me to give the idea that T1 can be converted to an lvalue of type cv3 T3, which I believe is not correct. According to my understanding, T2 is the type who has to be convertible to cv3 T3, as the example:

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

shows.

like image 446
Wake up Brazil Avatar asked Feb 20 '14 18:02

Wake up Brazil


2 Answers

You are not reading it correctly, this is how you should be reading it:

the initializer expression ... has a class type (i.e., T2 is a class type) ... and can be converted to an lvalue of type “cv3 T3,”

where the initializer expression refers back to:

[...]is initialized by an expression of type “cv2 T2” as follows

like image 63
Shafik Yaghmour Avatar answered Sep 21 '22 20:09

Shafik Yaghmour


No, your interpretation is wrong.

  • T1 = the reference that is initialized
  • T2 = the class type
  • T3 = the lvalue that T2 can be converted to

The quoted snippet is stating that T2 (ie. the class type) can be converted to an lvalue of type T3 where T1 is reference-compatible with T3, but that T1 is not reference-related to T2.

like image 25
Filip Roséen - refp Avatar answered Sep 24 '22 20:09

Filip Roséen - refp