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 authored and ben-clayton committed Jan 8, 2024
1 parent ae76a38 commit bb059f0
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 bb059f0

Please sign in to comment.