-
Notifications
You must be signed in to change notification settings - Fork 715
fix: use assignment to implement optional<> move assignment #10815
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
base: master
Are you sure you want to change the base?
fix: use assignment to implement optional<> move assignment #10815
Conversation
36bedbf to
8ebec37
Compare
|
changelog-none |
|
Mathlib CI status (docs):
|
|
Reference manual CI status:
|
8ebec37 to
7785558
Compare
| m_value.~T(); | ||
| m_some = true; | ||
| new (&m_value) T(std::move(other)); | ||
| optional& operator=(T && other) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one was unecessarily noexcept, std::optional does not mark it as such.
7785558 to
a8bfe15
Compare
Kha
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please merge master so that we can also run the new fsanitize job on this?
…ptional-assignment
|
changelog-skip |
|
changelog-no |
This PR ensures that when reassigning an already-assigned
optional, the underlying move or copy assignment operator is used rather than destructing and constructing. This matchesstd::optional.This also fixes an exception safety bug where
o1 = o2foroptional<T>would leaveo1in an invalid state if the copy constructor forTthrows.As a reminder, we can't use the upstream
std::optionaluntil C++17.