Skip to content

Commit

Permalink
Add reference in range-for for non-trivial type
Browse files Browse the repository at this point in the history
Avoid copy-ctor and dtor to get called.
Found by Clazy (range-loop-reference)
  • Loading branch information
gruenich committed Jan 7, 2024
1 parent ae76a38 commit b56df74
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/dap/typeof.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ M member_type(M T::*);
bool TypeOf<STRUCT>::deserializeFields(const Deserializer* fd, void* obj) { \
using StructTy = STRUCT; \
(void)sizeof(StructTy); /* avoid unused 'using' warning */ \
for (auto field : std::initializer_list<Field>{__VA_ARGS__}) { \
for (auto& field : std::initializer_list<Field>{__VA_ARGS__}) { \
if (!fd->field(field.name, [&](Deserializer* d) { \
auto ptr = reinterpret_cast<uint8_t*>(obj) + field.offset; \
return field.type->deserialize(d, ptr); \
Expand All @@ -177,7 +177,7 @@ M member_type(M T::*);
bool TypeOf<STRUCT>::serializeFields(FieldSerializer* fs, const void* obj) {\
using StructTy = STRUCT; \
(void)sizeof(StructTy); /* avoid unused 'using' warning */ \
for (auto field : std::initializer_list<Field>{__VA_ARGS__}) { \
for (auto& field : std::initializer_list<Field>{__VA_ARGS__}) { \
if (!fs->field(field.name, [&](Serializer* s) { \
auto ptr = reinterpret_cast<const uint8_t*>(obj) + field.offset; \
return field.type->serialize(s, ptr); \
Expand Down

0 comments on commit b56df74

Please sign in to comment.