From 9de6bbac1539850ecc2b87ea12624b8d8b5b02ff Mon Sep 17 00:00:00 2001 From: willvale <66674079+willvale@users.noreply.github.com> Date: Sat, 8 Nov 2025 20:09:50 +1300 Subject: [PATCH] Fix optional::emplace(), which wasn't marking the newly-constructed value as present. Replace unchecked access to _value with checked access for the various operators. --- shared/public/system.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/shared/public/system.h b/shared/public/system.h index 5047a971..d1b70816 100644 --- a/shared/public/system.h +++ b/shared/public/system.h @@ -269,13 +269,13 @@ class optional { } - const T& operator*() const { return _value; } + const T& operator*() const { return value(); } - T& operator*() { return _value; } + T& operator*() { return value(); } - const T* operator->() const { return &_value; } + const T* operator->() const { return &value(); } - T* operator->() { return &_value; } + T* operator->() { return &value(); } constexpr bool has_value() const { return _has_value; } @@ -302,8 +302,12 @@ class optional template T& emplace(Args... args) { - _value.~T(); - return *(new (&_value) T(args...)); + if (_has_value) + _value.~T(); + + new (&_value) T(args...); + _has_value = true; + return _value; } private: