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

[class.copy.ctor] Clarify the value category of the initializer in the implicit defined function #5450

Open
xmh0511 opened this issue May 5, 2022 · 0 comments

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented May 5, 2022

[class.copy.ctor] p14 says

Let x be either the parameter of the constructor or, for the move constructor, an xvalue referring to the parameter. Each base or non-static data member is copied/moved in the manner appropriate to its type:

  • if the member is an array, each element is direct-initialized with the corresponding subobject of x;
  • if a member m has rvalue reference type T&&, it is direct-initialized with static_­cast<T&&>(x.m);
  • otherwise, the base or member is direct-initialized with the corresponding base or member of x.

Although, we mentioned that x is an xvalue referring to the parameter for move constructor, however, the corresponding subobject used in the initialization cannot transitive that property. The value category directly impacts which function is selected in overload resolution(i.e., the constructor). Only expressions have a value category, objects do not have such a property. The relevant issue is #4917. It makes no sense to clarify an object can have a value category. So, the improvement to these issues might be:

Let x be either an id-expression naming the parameter of type lvalue reference to type cv C of the copy constructor or, for the move constructor, if the parameter P is of type rvalue reference to type C, an xvalue static_cast<C&&>(P). Each base or non-static data member is copied/moved in the manner appropriate to its type:

  • if the member m is an array, let x.m designate the member, each i element is direct-initialized from x.m[i] designating the i element of x.m.
  • if a member m has rvalue reference type T&&, it is direct-initialized with static_­cast<T&&>(x.m);
  • otherwise
  • if the base class has type T, the base subobject is direct-initialized from static_cast<cv T&>(x) if x is an lvalue, or from static_cast<T&&>(x) otherwise.
  • otherwise, the non-static member m is direct-initialized from x.m

Since [expr.ref] p6 and [expr.sub] p2 have defined the value category

If E1 is an lvalue, then E1.E2 is an lvalue; otherwise E1.E2 is an xvalue.

the result is an lvalue if that operand is an lvalue and an xvalue otherwise.

The explicitly defined type and the value category for x and the member or base thereof will be helpful to select the constructor for the member or base. [class.copy.assign] p12 has the same issue, which should be fixed with a similar approach.

@xmh0511 xmh0511 changed the title [class.copy.ctor] Clarify the valute category of the initializer in the implicit defined function [class.copy.ctor] Clarify the value category of the initializer in the implicit defined function May 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant