Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

languagelawyer
Copy link
Contributor

@languagelawyer languagelawyer commented Jan 25, 2019

[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.

[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.
@jensmaurer
Copy link
Member

jensmaurer commented Jan 25, 2019

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.

@jensmaurer jensmaurer added the decision-required A decision of the editorial group (or the Project Editor) is required. label Jan 25, 2019
@zygoloid
Copy link
Member

If we rephrase [dcl.init.ref] as suggested, we would lose the cv-qualifiers in the type of the temporary object. That breaks

const int &r = 0;
constexpr int n = r;

@jensmaurer
Copy link
Member

Editorial meeting: say "is immediately applied" and add a note per #2657.

@jensmaurer jensmaurer added changes requested Changes to the wording or approach have been requested and not yet applied. and removed decision-required A decision of the editorial group (or the Project Editor) is required. labels Jun 6, 2019
@jensmaurer jensmaurer added the needs rebase The pull request needs a git rebase to resolve merge conflicts. label Dec 14, 2019
@tkoeppe
Copy link
Contributor

tkoeppe commented Jun 22, 2021

@languagelawyer: could you please take a look (and rebase)?

@languagelawyer
Copy link
Contributor Author

@tkoeppe CWG2481 changed [dcl.init.ref] to say

Otherwise, the initializer expression is implicitly converted to a prvalue of type T1. The temporary materialization conversion is applied, considering the type of the prvalue to be “cv1 T1”, and the reference is bound to the result.

I suppose «considering the type to be» ≠ «has the type», so that this PR can be closed, but I'd like to have confirmation.

@jensmaurer
Copy link
Member

Yes, that's the intent.

@jensmaurer jensmaurer changed the title [basic.lval]/9 all prvalues can have cv-qualified types [basic.lval]/9 all prvalues can have cv-qualified types CWG2481 Feb 22, 2022
@jensmaurer jensmaurer added the cwg Issue must be reviewed by CWG. label Feb 22, 2022
@jensmaurer jensmaurer closed this Feb 22, 2022
@tkoeppe
Copy link
Contributor

tkoeppe commented Feb 22, 2022

Thanks, all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changes requested Changes to the wording or approach have been requested and not yet applied. cwg Issue must be reviewed by CWG. needs rebase The pull request needs a git rebase to resolve merge conflicts.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants