New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[basic.lval]/9 all prvalues can have cv-qualified types CWG2481 #2655
Conversation
[dcl.init.ref]/5.3: "If the converted initializer is a prvalue, its type T4 is adjusted to type “cv1 T4” and the temporary materialization conversion is applied." The cv-qualifier from the reference being initialized is added to the initializer prvalue's type. [expr.type]/2: "If a prvalue initially has the type “cv T”, where T is a cv-unqualified non-class, non-array type, the type of the expression is adjusted to T prior to any further analysis." is not applicable here, because it says "initially", so it strips qualifiers only when a prvalue is formed, but [dcl.init.ref]/5.3 does not form a new prvalue, it adjusts the type of an existing one.
It would be nice to retain the statement that a non-class non-array prvalue is never cv-qualified. We can get there if we rephrase [dcl.init.ref] p5.3 to say "If the converted initializer is a prvalue, the temporary materialization conversion is applied to produce an xvalue of type cv1 T4." However, the current definition of "temporary materialization conversion" only changes from prvalue to xvalue and cannot change the type. |
If we rephrase [dcl.init.ref] as suggested, we would lose the cv-qualifiers in the type of the temporary object. That breaks
|
Editorial meeting: say "is immediately applied" and add a note per #2657. |
@languagelawyer: could you please take a look (and rebase)? |
@tkoeppe CWG2481 changed [dcl.init.ref] to say
I suppose «considering the type to be» ≠ «has the type», so that this PR can be closed, but I'd like to have confirmation. |
Yes, that's the intent. |
Thanks, all! |
[dcl.init.ref]/5.3: "If the converted initializer is a prvalue, its type T4 is adjusted to type “cv1 T4” and the temporary materialization conversion is applied."
The cv-qualifiers of the reference being initialized are added to the initializer prvalue's type.
[expr.type]/2: "If a prvalue initially has the type “cv T”, where T is a cv-unqualified non-class, non-array type, the type of the expression is adjusted to T prior to any further analysis."
is not applicable here, because it says "initially", so it strips qualifiers only when a prvalue is formed, but [dcl.init.ref]/5.3 does not form a new prvalue, it adjusts the type of an existing one.