[class.copy.elision] p3 The return type in the first bullet should be restricted
Nobody has claimed this yet.
- Dominant language
- TeX
- Stars
- 221
- Forks
- 813
- Avg merge
- 16h 4m
- Merged PRs (30d)
- 36
Description
An implicitly movable entity is a variable of automatic storage duration that is either a non-volatile object or an rvalue reference to a non-volatile object type. In the following copy-initialization contexts, a move operation is first considered before attempting a copy operation:
- If the expression in a return ([stmt.return]) or co_return ([stmt.return.coroutine]) statement is a (possibly parenthesized) id-expression that names an implicitly movable entity declared in the body or parameter-declaration-clause of the innermost enclosing function or lambda-expression, or
- [...]
overload resolution to select the constructor for the copy or the return_value overload to call is first performed as if the expression or operand were an rvalue. If the first overload resolution fails or was not performed, overload resolution is performed again, considering the expression or operand as an lvalue.
Consider this example
struct A{
A(){}
A(A const&){
std::cout<<"copy\n";
}
A(A&&){
std::cout<<"move\n";
}
};
A& fun(A x){
return x;
}
A a;
A b = fun(a);
According to the rule, id-expression x in the return statement does name an implicitly movable entity. However, that rule indeed does not apply to this example. Shouldn't we restrict that the return type, in either case, shall be (possible cv-qualified) class type?
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 with the quoted wording in [class.copy.elision] and test it against the provided A, fun, and initialization example. Compare the first-bullet rule with return statements whose return type is a reference or class type, then check related wording for consistency. Done means the draft clearly specifies the intended applicability without leaving the example ambiguous.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- documentation
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100