--- a/include/sol/optional_implementation.hpp +++ b/include/sol/optional_implementation.hpp @@ -2191,8 +2191,10 @@ namespace sol { static_assert(std::is_constructible::value, "T must be constructible with Args"); *this = nullopt; - this->construct(std::forward(args)...); - return value(); + // Reference specialization stores a pointer; set it directly. + // construct() only exists in the non-reference specialization. + m_value = std::addressof(std::forward(args)...); + return *m_value; } /// Swaps this optional with the other.