From 46693806d126828adb2b41aae566dbc831deb9e5 Mon Sep 17 00:00:00 2001 From: Joel McKenzie <5271452+jmcken8@users.noreply.github.com> Date: Sun, 23 Mar 2025 14:34:56 +0100 Subject: [PATCH] Fix bugging disallowing optionals to hold items without copy constructors (#390) --- include/rfl/parsing/Parser_optional.hpp | 2 +- tests/generic/test_optional.cpp | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 tests/generic/test_optional.cpp 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