mirror of
https://github.com/TartanLlama/optional.git
synced 2025-08-01 02:44:27 +02:00
[ constructors ] prevent empty optional access
optional types being taken in were forwarding their values without checking, resulting in segfaults on optional<U> -> optional<T> conversions. This fixes those problems in the constructors.
This commit is contained in:
committed by
GitHub
parent
5d3d6c399a
commit
1de2f2a49c
@@ -1190,7 +1190,9 @@ public:
|
||||
class U, detail::enable_from_other<T, U, const U &> * = nullptr,
|
||||
detail::enable_if_t<std::is_convertible<const U &, T>::value> * = nullptr>
|
||||
optional(const optional<U> &rhs) {
|
||||
this->construct(*rhs);
|
||||
if (rhs.has_value()) {
|
||||
this->construct(*rhs);
|
||||
}
|
||||
}
|
||||
|
||||
/// \exclude
|
||||
@@ -1198,7 +1200,9 @@ public:
|
||||
detail::enable_if_t<!std::is_convertible<const U &, T>::value> * =
|
||||
nullptr>
|
||||
explicit optional(const optional<U> &rhs) {
|
||||
this->construct(*rhs);
|
||||
if (rhs.has_value()) {
|
||||
this->construct(*rhs);
|
||||
}
|
||||
}
|
||||
|
||||
/// Converting move constructor.
|
||||
@@ -1207,7 +1211,9 @@ public:
|
||||
class U, detail::enable_from_other<T, U, U &&> * = nullptr,
|
||||
detail::enable_if_t<std::is_convertible<U &&, T>::value> * = nullptr>
|
||||
optional(optional<U> &&rhs) {
|
||||
this->construct(std::move(*rhs));
|
||||
if (rhs.has_value()) {
|
||||
this->construct(std::move(*rhs));
|
||||
}
|
||||
}
|
||||
|
||||
/// \exclude
|
||||
@@ -1215,7 +1221,9 @@ public:
|
||||
class U, detail::enable_from_other<T, U, U &&> * = nullptr,
|
||||
detail::enable_if_t<!std::is_convertible<U &&, T>::value> * = nullptr>
|
||||
explicit optional(optional<U> &&rhs) {
|
||||
this->construct(std::move(*rhs));
|
||||
if (rhs.has_value()) {
|
||||
this->construct(std::move(*rhs));
|
||||
}
|
||||
}
|
||||
|
||||
/// Destroys the stored value if there is one.
|
||||
|
Reference in New Issue
Block a user