diff --git a/include/fixed_containers/reflection.hpp b/include/fixed_containers/reflection.hpp index 9db39c09..eddffc1c 100644 --- a/include/fixed_containers/reflection.hpp +++ b/include/fixed_containers/reflection.hpp @@ -242,7 +242,7 @@ constexpr void for_each_field(T&& instance, Func&& func) { constexpr const auto& FIELD_NAMES = field_names_of(); struct_decomposition::to_parameter_pack( - std::forward(instance), + instance, [&func](Args&&... args) -> bool { variadic_templates::for_each_entry( diff --git a/test/reflection_test.cpp b/test/reflection_test.cpp index 8f9f559f..c3ce3a52 100644 --- a/test/reflection_test.cpp +++ b/test/reflection_test.cpp @@ -610,6 +610,20 @@ TEST(Reflection, ForEachFieldEmptyStruct) static_assert(COUNTER == 0); } +TEST(Reflection, RValue) +{ + constexpr auto RESULT = []() + { + std::size_t counter = 0; + reflection::for_each_field(FieldCount100{}, + [&](const std::string_view& /*name*/, const T&) + { counter++; }); + return counter; + }(); + + static_assert(100 == RESULT); +} + TEST(Reflection, MockFailingAddressOfOperator) { MockFailingAddressOfOperator instance{};