Consider this example:
const int& r2 = 5;
The rules governing reference-initialization are found in [dcl.init.ref]/5:
A reference to type “
cv1 T1
” is initialized by an expression of type “cv2 T2
” as follows:
- (5.1) [..]
- (5.2) [..]
- (5.3) Otherwise, if the initializer expression
- (5.3.1) is an rvalue [..] and “
cv1 T1
” is reference-compatible with “cv2 T2
”, or- (5.3.2) [..]
then the initializer expression [..] is called the converted initializer. If the converted initializer is a prvalue, its type
T4
is adjusted to type “cv1 T4
” ([conv.qual]) and the temporary materialization conversion ([conv.rval]) is applied. In any case, the reference is bound to the resulting glvalue [..].
Here, The converted initializer is a prvalue of type T4
(int
); then it's adjusted to cv1 T4
(const int
). But [expr.type]/2 states:
If a prvalue initially has the type “
cv T
”, whereT
is a cv-unqualified non-class, non-array type, the type of the expression is adjusted toT
prior to any further analysis.
One said to me that this rule ([expr.type]/2
) does not apply to specifically this case. And I need to know the reason behind that.
I claim that the reason for not applying [expr.type]/2
is because initially (before adjustment) the type of the prvalue is T4
(int
) i.e, it's cv-unqualified type, so [expr.type]/2
cannot be applied since the initial type of the prvalue is not cv-qualified type. Even after the adjustment to cv1 T4
, the rule [expr.type]/2 also doesn't apply because cv1 T4
is not the initial type of the prvalue. My question is: Are those correct reasons?
Indeed both questions this and this are relatively similar but specifically I'm asking a specific, different question regarding the rule [expr.type]/2.