<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/73453>73453</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Function should call copy constructor if return is a lvalue expr and move constructor is not available.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
changkhothuychung
</td>
</tr>
</table>
<pre>
Is this example considered a bug? https://godbolt.org/z/TETeK9n5c
According to https://timsong-cpp.github.io/cppwp/n4659/class.copy.elision#3
`
In the following copy-initialization contexts, a move operation might be used instead of a copy operation:
[(3.1)](https://timsong-cpp.github.io/cppwp/n4659/class.copy.elision#3.1)
If the [expression](https://timsong-cpp.github.io/cppwp/n4659/expr.comma#nt:expression) in a [return statement](https://timsong-cpp.github.io/cppwp/n4659/stmt.return) is a (possibly parenthesized) [id-expression](https://timsong-cpp.github.io/cppwp/n4659/expr.prim.id#nt:id-expression) that names an object with automatic storage duration declared in the body or [parameter-declaration-clause](https://timsong-cpp.github.io/cppwp/n4659/dcl.fct#nt:parameter-declaration-clause) of the innermost enclosing function or [lambda-expression](https://timsong-cpp.github.io/cppwp/n4659/expr.prim.lambda#nt:lambda-expression), or
[(3.2)](https://timsong-cpp.github.io/cppwp/n4659/class.copy.elision#3.2)
if the operand of a [throw-expression](https://timsong-cpp.github.io/cppwp/n4659/expr.throw#nt:throw-expression) is the name of a non-volatile automatic object (other than a function or catch-clause parameter) whose scope does not extend beyond the end of the innermost enclosing [try-block](https://timsong-cpp.github.io/cppwp/n4659/except#nt:try-block) (if there is one),
overload resolution to select the constructor for the copy is first performed as if the object were designated by an rvalue. If the first overload resolution fails or was not performed, or if the type of the first parameter of the selected constructor is not an rvalue reference to the object's type (possibly cv-qualified), overload resolution is performed again, considering the object as an lvalue. [ Note: This two-stage overload resolution must be performed regardless of whether copy elision will occur. It determines the constructor to be called if elision is not performed, and the selected constructor must be accessible even if the call is elided. — end note ]
`
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VkFz4jgT_TXi0oULZEzgwCH5MlRNfVV7mj8gS21bO7LaK7UhzK_fkmwIM8PuJdlLAkZ-3f36vVarGG3rEQ-iehHV60KN3FE46E759ntH3I0X3Y2-XdRkLoevEbizEfBN9YND0OSjNRjQgIJ6bEV5hI55iKJ8FvIo5LElU5PjgkIr5PGHkMdvX77h__e-0mL1KlbP099nrSkY61tg-gWBbR_Jt0s9DEVruRvrwpKQRz0M50HIo99sq3367lSMhabhUqCz0ZIXsizhPorYrqYPXz1wh9CQc3ROUdNrS-stW-XsD8WWfCqO8Y2jkP8DBT2dEGjAMP3Y27ZjqBHGiAasj4zKADWgMtb7yVTHfQrVi5C7slgLuRfVq5C7z6x2gp1KbHKJonrBtyFgzEc-EDChFJr6XglZehbl8x2u3IP1oFK0gDwGD5EVY4-ePxIzcs_FBJhDxBRC7gaK0dbuAoMK6LnDaH-gSSdE9WLN8hMLHoLtC2uuJf8MLvfAnWLwqscIygPVf6JmOFvuQI1MvWKrITIF1SKYcdaOQe1UyLLJPUrWAgop-0EF1SNjWE6H8gtL7dQY8SPFGO2KRvO1jn8NI_dJxykx6z2GniIDeu0oJqc0o9e5iilhp_raqE-nfIK9pvt7ELlPrqTwyFryv7GWvFnLTuxki_vZ9KJ64S7Q-TOZyIBXDn5DnwyREkn6m7Lw5JcncoqtwzsFzroUckfcYUiqTW69b6VWrLtZAXCTRwpy7igiRE0DgiGM4IkB3xi9gRov5E1OAicm_kk2iZ9wWdaO9PePEaNxuOn4HTKZX-6mzgRMzJDHSSb3GqETBkfKQMBIbszVM0FElwhKyacrjcOomQI0FOZnwyVBNjZEhgFDQ6FPd16EqxZm56fYBtOVqhgN1Jc0FsJJuRELmEfyhPIok0ZZF1M3zmqi-RZqUvs1Gl8GvJI953Tt2PXxVBGan-qxE-otJQjYYECvMZHwXoeQT3EKcj9t9Wn516icbWwetjmlB0XYeM9Qq6xP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