From 5f49573daf3922658be9ab8f571e117a7405bbf1 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 17 May 2023 14:10:58 -0400 Subject: [PATCH] Fix compiler warning and error encountered on some platforms (#106) * typeof: Avoid -Wshadow-uncaptured-local in DAP_IMPLEMENT_STRUCT_TYPEINFO Previously, applications using `DAP_IMPLEMENT_STRUCT_TYPEINFO` may see: ::1: warning: declaration shadows a local variable [-Wshadow-uncaptured-local] DAP_IMPLEMENT_STRUCT_TYPEINFO(), ^ /.../include/dap/typeof.h:199:3: note: expanded from macro 'DAP_IMPLEMENT_STRUCT_TYPEINFO' DAP_IMPLEMENT_STRUCT_FIELD_SERIALIZATION(STRUCT, NAME, __VA_ARGS__) \ ^ /.../include/dap/typeof.h:168:51: note: expanded from macro 'DAP_IMPLEMENT_STRUCT_FIELD_SERIALIZATION' if (!d->field(field.name, [&](Deserializer* d) { \ ^ ::1: note: previous declaration is here /.../include/dap/typeof.h:199:3: note: expanded from macro 'DAP_IMPLEMENT_STRUCT_TYPEINFO' DAP_IMPLEMENT_STRUCT_FIELD_SERIALIZATION(STRUCT, NAME, __VA_ARGS__) \ ^ /.../include/dap/typeof.h:164:62: note: expanded from macro 'DAP_IMPLEMENT_STRUCT_FIELD_SERIALIZATION' bool TypeOf::deserializeFields(const Deserializer* d, void* obj) { \ ^ * io: add missing include for std::string --- include/dap/typeof.h | 8 ++++---- src/io.cpp | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/dap/typeof.h b/include/dap/typeof.h index 1ed0dc7..803bb8d 100644 --- a/include/dap/typeof.h +++ b/include/dap/typeof.h @@ -161,11 +161,11 @@ M member_type(M T::*); // DAP_IMPLEMENT_STRUCT_TYPEINFO_EXT(). // You probably do not want to use this directly. #define DAP_IMPLEMENT_STRUCT_FIELD_SERIALIZATION(STRUCT, NAME, ...) \ - bool TypeOf::deserializeFields(const Deserializer* d, void* obj) { \ + 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 (!d->field(field.name, [&](Deserializer* d) { \ + if (!fd->field(field.name, [&](Deserializer* d) { \ auto ptr = reinterpret_cast(obj) + field.offset; \ return field.type->deserialize(d, ptr); \ })) { \ @@ -174,11 +174,11 @@ M member_type(M T::*); } \ return true; \ } \ - bool TypeOf::serializeFields(FieldSerializer* s, const void* obj) { \ + 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 (!s->field(field.name, [&](Serializer* s) { \ + if (!fs->field(field.name, [&](Serializer* s) { \ auto ptr = reinterpret_cast(obj) + field.offset; \ return field.type->serialize(s, ptr); \ })) { \ diff --git a/src/io.cpp b/src/io.cpp index 3ee972e..b4133e5 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -21,6 +21,7 @@ #include // strlen #include #include +#include namespace {