diff --git a/include/dap/typeof.h b/include/dap/typeof.h index 43c9289..d679d8d 100644 --- a/include/dap/typeof.h +++ b/include/dap/typeof.h @@ -164,10 +164,12 @@ M member_type(M T::*); bool TypeOf::deserializeFields(const Deserializer* fd, void* obj) { \ using StructTy = STRUCT; \ (void)sizeof(StructTy); /* avoid unused 'using' warning */ \ - for (auto& field : std::initializer_list{__VA_ARGS__}) { \ - if (!fd->field(field.name, [&](Deserializer* d) { \ - auto ptr = reinterpret_cast(obj) + field.offset; \ - return field.type->deserialize(d, ptr); \ + const std::initializer_list fields{__VA_ARGS__}; \ + for (const auto& field : fields) { \ + const auto ptr = reinterpret_cast(obj) + field.offset; \ + const auto type = field.type; \ + if (!fd->field(field.name, [ptr, type](Deserializer* d) { \ + return type->deserialize(d, ptr); \ })) { \ return false; \ } \ @@ -177,10 +179,12 @@ M member_type(M T::*); bool TypeOf::serializeFields(FieldSerializer* fs, const void* obj) {\ using StructTy = STRUCT; \ (void)sizeof(StructTy); /* avoid unused 'using' warning */ \ - for (auto& field : std::initializer_list{__VA_ARGS__}) { \ - if (!fs->field(field.name, [&](Serializer* s) { \ - auto ptr = reinterpret_cast(obj) + field.offset; \ - return field.type->serialize(s, ptr); \ + const std::initializer_list fields{__VA_ARGS__}; \ + for (const auto& field : fields) { \ + const auto ptr = reinterpret_cast(obj) + field.offset; \ + const auto type = field.type; \ + if (!fs->field(field.name, [ptr, type](Serializer* s) { \ + return type->serialize(s, ptr); \ })) { \ return false; \ } \