Skip to content

Move t instead of copying the value#330

Closed
venkat-murty wants to merge 1 commit into
boostorg:developfrom
venkat-murty:develop
Closed

Move t instead of copying the value#330
venkat-murty wants to merge 1 commit into
boostorg:developfrom
venkat-murty:develop

Conversation

@venkat-murty

Copy link
Copy Markdown

std::optional<T> does not compile when T has a move operator and the copy operator is deleted.

gennaroprota added a commit that referenced this pull request Jul 20, 2026
`load_impl` read the value into a local and copy-assigned it to the
optional. A move-only value type then failed to compile: `optional`'s
perfect-forwarding assignment is removed by SFINAE when the value is not
copy-assignable, leaving no viable `operator=`.

So, move the local into the optional instead.

The one-line fix was proposed by Venkat Murty in PR #330; this extends
it with `boost::move` and a regression test.
@gennaroprota

Copy link
Copy Markdown
Collaborator

Thanks. Modified a bit into PR #348, with a regression test.

gennaroprota added a commit that referenced this pull request Jul 20, 2026
`load_impl` read the value into a local and copy-assigned it to the
optional. A move-only type then failed to compile: `optional`'s
perfect-forwarding assignment is removed by SFINAE when the value is not
copy-assignable, leaving no viable `operator=`.

So, move the local into the optional instead.

The one-line fix was proposed by Venkat Murty in PR #330; this extends
it with `boost::move` and a regression test.
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

Successfully merging this pull request may close these issues.

2 participants