[class.copy.ctor] Clarify the value category of the initializer in the implicit defined function
Nobody has claimed this yet.
- Dominant language
- TeX
- Stars
- 221
- Forks
- 813
- Avg merge
- 16h 4m
- Merged PRs (30d)
- 36
Description
[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 https://github.com/cplusplus/draft/issues/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 Cof the copy constructor or, for the move constructor, if the parameterPis of typervalue reference to type C, an xvaluestatic_cast<C&&>(P). Each base or non-static data member is copied/moved in the manner appropriate to its type:
- if the member
mis an array, letx.mdesignate the member, each i element is direct-initialized from x.m[i] designating the i element ofx.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) ifxis an lvalue, or from static_cast<T&&>(x) otherwise.- otherwise, the non-static member
mis direct-initialized fromx.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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating [class.copy.ctor] p14 and the corresponding [class.copy.assign] wording in the draft, then compare the value-category rules in [expr.ref] and [expr.sub] with issue 4917. Done means the copy and move wording explicitly describes the relevant types and value categories consistently for bases, members, and arrays.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, tex
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100