diff --git a/include/rfl/parsing/Parser_optional.hpp b/include/rfl/parsing/Parser_optional.hpp index 029a897b..d4b7af17 100644 --- a/include/rfl/parsing/Parser_optional.hpp +++ b/include/rfl/parsing/Parser_optional.hpp @@ -38,7 +38,7 @@ struct Parser, ProcessorsType> { if (_r.is_empty(_var)) { return std::optional(); } - const auto to_opt = [](auto&& _t) { return std::make_optional(_t); }; + const auto to_opt = [](auto&& _t) { return std::make_optional(std::forward(_t)); }; return Parser, ProcessorsType>::read(_r, _var) .transform(to_opt); diff --git a/tests/generic/test_optional.cpp b/tests/generic/test_optional.cpp new file mode 100644 index 00000000..838adbd9 --- /dev/null +++ b/tests/generic/test_optional.cpp @@ -0,0 +1,17 @@ +#include +#include +#include + +namespace test_optional { + +struct Person { + std::string name; + std::optional> spouse; +}; + +TEST(generic, test_optional) { + rfl::Generic generic; + // This failed to compile due to optional copying rather than moving + rfl::from_generic(generic); +} +} // namespace test_map