From bb059f0daf477ede85aeaca4820ae80b7e3c6a81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20Gr=C3=BCninger?= Date: Sun, 7 Jan 2024 14:06:46 +0100 Subject: [PATCH] Add reference in range-for for non-trivial type Avoid copy-ctor and dtor to get called. Found by Clazy (range-loop-reference) --- include/dap/typeof.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/dap/typeof.h b/include/dap/typeof.h index 803bb8d..43c9289 100644 --- a/include/dap/typeof.h +++ b/include/dap/typeof.h @@ -164,7 +164,7 @@ 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__}) { \ + 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); \ @@ -177,7 +177,7 @@ 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__}) { \ + 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); \