This is an automated email from the ASF dual-hosted git repository.
chaokunyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fory.git
The following commit(s) were added to refs/heads/main by this push:
new 29d512686 fix(c++): fix fory c++ compile warnings (#3188)
29d512686 is described below
commit 29d512686d2976a00ee2cc0e7c9b5a938f9167b3
Author: Shawn Yang <[email protected]>
AuthorDate: Wed Jan 21 21:03:03 2026 +0800
fix(c++): fix fory c++ compile warnings (#3188)
## Why?
## What does this PR do?
## Related issues
#2906
## Does this PR introduce any user-facing change?
- [ ] Does this PR introduce any public API change?
- [ ] Does this PR introduce any binary protocol compatibility change?
## Benchmark
---
cpp/fory/meta/field_info.h | 11 ++-
cpp/fory/serialization/basic_serializer.h | 87 +++++++++----------
cpp/fory/serialization/collection_serializer.h | 1 -
cpp/fory/serialization/enum_serializer.h | 5 +-
cpp/fory/serialization/skip.cc | 4 +-
.../serialization/smart_ptr_serializer_test.cc | 12 +--
cpp/fory/serialization/smart_ptr_serializers.h | 5 --
cpp/fory/serialization/string_serializer.h | 31 +++----
cpp/fory/serialization/struct_serializer.h | 97 ++--------------------
cpp/fory/serialization/type_resolver.h | 6 +-
cpp/fory/serialization/unsigned_serializer.h | 84 ++++++++-----------
cpp/fory/serialization/weak_ptr_serializer_test.cc | 7 --
12 files changed, 114 insertions(+), 236 deletions(-)
diff --git a/cpp/fory/meta/field_info.h b/cpp/fory/meta/field_info.h
index 0a4985baa..ec7dcd3a9 100644
--- a/cpp/fory/meta/field_info.h
+++ b/cpp/fory/meta/field_info.h
@@ -82,6 +82,15 @@ template <typename FieldInfo> constexpr bool
IsValidFieldInfo() {
static_assert(
\
fory::meta::IsValidFieldInfo<ForyFieldInfoImpl<type>>(),
\
"duplicated fields in FORY_FIELD_INFO arguments are detected");
\
+ static_assert(ForyFieldInfoImpl<type>::Name.data() != nullptr,
\
+ "ForyFieldInfoImpl name must be available");
\
+ static_assert(ForyFieldInfoImpl<type>::Names.size() ==
\
+ ForyFieldInfoImpl<type>::Size,
\
+ "ForyFieldInfoImpl names size mismatch");
\
inline constexpr auto ForyFieldInfo(const type &) noexcept {
\
return ForyFieldInfoImpl<type>{};
\
- };
+ }
\
+ static_assert(
\
+ static_cast<ForyFieldInfoImpl<type> (*)(const type &) noexcept>(
\
+ &ForyFieldInfo) != nullptr,
\
+ "ForyFieldInfo must be declared");
diff --git a/cpp/fory/serialization/basic_serializer.h
b/cpp/fory/serialization/basic_serializer.h
index 6aa3c45c7..fa4484ecd 100644
--- a/cpp/fory/serialization/basic_serializer.h
+++ b/cpp/fory/serialization/basic_serializer.h
@@ -58,7 +58,7 @@ template <> struct Serializer<bool> {
}
static inline void write(bool value, WriteContext &ctx, RefMode ref_mode,
- bool write_type, bool has_generics = false) {
+ bool write_type, bool = false) {
write_not_null_ref_flag(ctx, ref_mode);
if (write_type) {
ctx.write_varuint32(static_cast<uint32_t>(type_id));
@@ -70,8 +70,7 @@ template <> struct Serializer<bool> {
ctx.write_uint8(value ? 1 : 0);
}
- static inline void write_data_generic(bool value, WriteContext &ctx,
- bool has_generics) {
+ static inline void write_data_generic(bool value, WriteContext &ctx, bool) {
write_data(value, ctx);
}
@@ -100,12 +99,12 @@ template <> struct Serializer<bool> {
return value != 0;
}
- static inline bool read_data_generic(ReadContext &ctx, bool has_generics) {
+ static inline bool read_data_generic(ReadContext &ctx, bool) {
return read_data(ctx);
}
static inline bool read_with_type_info(ReadContext &ctx, RefMode ref_mode,
- const TypeInfo &type_info) {
+ const TypeInfo &) {
return read(ctx, ref_mode, false);
}
};
@@ -130,7 +129,7 @@ template <> struct Serializer<int8_t> {
}
static inline void write(int8_t value, WriteContext &ctx, RefMode ref_mode,
- bool write_type, bool has_generics = false) {
+ bool write_type, bool = false) {
write_not_null_ref_flag(ctx, ref_mode);
if (write_type) {
ctx.write_varuint32(static_cast<uint32_t>(type_id));
@@ -142,8 +141,7 @@ template <> struct Serializer<int8_t> {
ctx.write_int8(value);
}
- static inline void write_data_generic(int8_t value, WriteContext &ctx,
- bool has_generics) {
+ static inline void write_data_generic(int8_t value, WriteContext &ctx, bool)
{
write_data(value, ctx);
}
@@ -171,12 +169,12 @@ template <> struct Serializer<int8_t> {
return ctx.read_int8(ctx.error());
}
- static inline int8_t read_data_generic(ReadContext &ctx, bool has_generics) {
+ static inline int8_t read_data_generic(ReadContext &ctx, bool) {
return read_data(ctx);
}
static inline int8_t read_with_type_info(ReadContext &ctx, RefMode ref_mode,
- const TypeInfo &type_info) {
+ const TypeInfo &) {
return read(ctx, ref_mode, false);
}
};
@@ -201,7 +199,7 @@ template <> struct Serializer<int16_t> {
}
static inline void write(int16_t value, WriteContext &ctx, RefMode ref_mode,
- bool write_type, bool has_generics = false) {
+ bool write_type, bool = false) {
write_not_null_ref_flag(ctx, ref_mode);
if (write_type) {
ctx.write_varuint32(static_cast<uint32_t>(type_id));
@@ -214,7 +212,7 @@ template <> struct Serializer<int16_t> {
}
static inline void write_data_generic(int16_t value, WriteContext &ctx,
- bool has_generics) {
+ bool) {
write_data(value, ctx);
}
@@ -242,12 +240,12 @@ template <> struct Serializer<int16_t> {
return ctx.read_int16(ctx.error());
}
- static inline int16_t read_data_generic(ReadContext &ctx, bool has_generics)
{
+ static inline int16_t read_data_generic(ReadContext &ctx, bool) {
return read_data(ctx);
}
static inline int16_t read_with_type_info(ReadContext &ctx, RefMode ref_mode,
- const TypeInfo &type_info) {
+ const TypeInfo &) {
return read(ctx, ref_mode, false);
}
};
@@ -272,7 +270,7 @@ template <> struct Serializer<int32_t> {
}
static inline void write(int32_t value, WriteContext &ctx, RefMode ref_mode,
- bool write_type, bool has_generics = false) {
+ bool write_type, bool = false) {
write_not_null_ref_flag(ctx, ref_mode);
if (write_type) {
ctx.write_varuint32(static_cast<uint32_t>(type_id));
@@ -285,7 +283,7 @@ template <> struct Serializer<int32_t> {
}
static inline void write_data_generic(int32_t value, WriteContext &ctx,
- bool has_generics) {
+ bool) {
write_data(value, ctx);
}
@@ -313,12 +311,12 @@ template <> struct Serializer<int32_t> {
return ctx.read_varint32(ctx.error());
}
- static inline int32_t read_data_generic(ReadContext &ctx, bool has_generics)
{
+ static inline int32_t read_data_generic(ReadContext &ctx, bool) {
return read_data(ctx);
}
static inline int32_t read_with_type_info(ReadContext &ctx, RefMode ref_mode,
- const TypeInfo &type_info) {
+ const TypeInfo &) {
return read(ctx, ref_mode, false);
}
};
@@ -343,7 +341,7 @@ template <> struct Serializer<int64_t> {
}
static inline void write(int64_t value, WriteContext &ctx, RefMode ref_mode,
- bool write_type, bool has_generics = false) {
+ bool write_type, bool = false) {
write_not_null_ref_flag(ctx, ref_mode);
if (write_type) {
ctx.write_varuint32(static_cast<uint32_t>(type_id));
@@ -356,7 +354,7 @@ template <> struct Serializer<int64_t> {
}
static inline void write_data_generic(int64_t value, WriteContext &ctx,
- bool has_generics) {
+ bool) {
write_data(value, ctx);
}
@@ -384,12 +382,12 @@ template <> struct Serializer<int64_t> {
return ctx.read_varint64(ctx.error());
}
- static inline int64_t read_data_generic(ReadContext &ctx, bool has_generics)
{
+ static inline int64_t read_data_generic(ReadContext &ctx, bool) {
return read_data(ctx);
}
static inline int64_t read_with_type_info(ReadContext &ctx, RefMode ref_mode,
- const TypeInfo &type_info) {
+ const TypeInfo &) {
return read(ctx, ref_mode, false);
}
};
@@ -414,7 +412,7 @@ template <> struct Serializer<float> {
}
static inline void write(float value, WriteContext &ctx, RefMode ref_mode,
- bool write_type, bool has_generics = false) {
+ bool write_type, bool = false) {
write_not_null_ref_flag(ctx, ref_mode);
if (write_type) {
ctx.write_varuint32(static_cast<uint32_t>(type_id));
@@ -426,8 +424,7 @@ template <> struct Serializer<float> {
ctx.write_bytes(&value, sizeof(float));
}
- static inline void write_data_generic(float value, WriteContext &ctx,
- bool has_generics) {
+ static inline void write_data_generic(float value, WriteContext &ctx, bool) {
write_data(value, ctx);
}
@@ -454,12 +451,12 @@ template <> struct Serializer<float> {
return ctx.read_float(ctx.error());
}
- static inline float read_data_generic(ReadContext &ctx, bool has_generics) {
+ static inline float read_data_generic(ReadContext &ctx, bool) {
return read_data(ctx);
}
static inline float read_with_type_info(ReadContext &ctx, RefMode ref_mode,
- const TypeInfo &type_info) {
+ const TypeInfo &) {
return read(ctx, ref_mode, false);
}
};
@@ -484,7 +481,7 @@ template <> struct Serializer<double> {
}
static inline void write(double value, WriteContext &ctx, RefMode ref_mode,
- bool write_type, bool has_generics = false) {
+ bool write_type, bool = false) {
write_not_null_ref_flag(ctx, ref_mode);
if (write_type) {
ctx.write_varuint32(static_cast<uint32_t>(type_id));
@@ -496,8 +493,7 @@ template <> struct Serializer<double> {
ctx.write_bytes(&value, sizeof(double));
}
- static inline void write_data_generic(double value, WriteContext &ctx,
- bool has_generics) {
+ static inline void write_data_generic(double value, WriteContext &ctx, bool)
{
write_data(value, ctx);
}
@@ -525,12 +521,12 @@ template <> struct Serializer<double> {
return ctx.read_double(ctx.error());
}
- static inline double read_data_generic(ReadContext &ctx, bool has_generics) {
+ static inline double read_data_generic(ReadContext &ctx, bool) {
return read_data(ctx);
}
static inline double read_with_type_info(ReadContext &ctx, RefMode ref_mode,
- const TypeInfo &type_info) {
+ const TypeInfo &) {
return read(ctx, ref_mode, false);
}
};
@@ -559,7 +555,7 @@ template <> struct Serializer<char> {
}
static inline void write(char value, WriteContext &ctx, RefMode ref_mode,
- bool write_type, bool has_generics = false) {
+ bool write_type, bool = false) {
write_not_null_ref_flag(ctx, ref_mode);
if (write_type) {
ctx.write_varuint32(static_cast<uint32_t>(type_id));
@@ -571,8 +567,7 @@ template <> struct Serializer<char> {
ctx.write_int8(static_cast<int8_t>(value));
}
- static inline void write_data_generic(char value, WriteContext &ctx,
- bool has_generics) {
+ static inline void write_data_generic(char value, WriteContext &ctx, bool) {
write_data(value, ctx);
}
@@ -599,12 +594,12 @@ template <> struct Serializer<char> {
return static_cast<char>(ctx.read_int8(ctx.error()));
}
- static inline char read_data_generic(ReadContext &ctx, bool has_generics) {
+ static inline char read_data_generic(ReadContext &ctx, bool) {
return read_data(ctx);
}
static inline char read_with_type_info(ReadContext &ctx, RefMode ref_mode,
- const TypeInfo &type_info) {
+ const TypeInfo &) {
return read(ctx, ref_mode, false);
}
};
@@ -629,7 +624,7 @@ template <> struct Serializer<char16_t> {
}
static inline void write(char16_t value, WriteContext &ctx, RefMode ref_mode,
- bool write_type, bool has_generics = false) {
+ bool write_type, bool = false) {
write_not_null_ref_flag(ctx, ref_mode);
if (write_type) {
ctx.write_varuint32(static_cast<uint32_t>(type_id));
@@ -642,7 +637,7 @@ template <> struct Serializer<char16_t> {
}
static inline void write_data_generic(char16_t value, WriteContext &ctx,
- bool has_generics) {
+ bool) {
write_data(value, ctx);
}
@@ -673,13 +668,12 @@ template <> struct Serializer<char16_t> {
return value;
}
- static inline char16_t read_data_generic(ReadContext &ctx,
- bool has_generics) {
+ static inline char16_t read_data_generic(ReadContext &ctx, bool) {
return read_data(ctx);
}
static inline char16_t read_with_type_info(ReadContext &ctx, RefMode
ref_mode,
- const TypeInfo &type_info) {
+ const TypeInfo &) {
return read(ctx, ref_mode, false);
}
};
@@ -704,7 +698,7 @@ template <> struct Serializer<char32_t> {
}
static inline void write(char32_t value, WriteContext &ctx, RefMode ref_mode,
- bool write_type, bool has_generics = false) {
+ bool write_type, bool = false) {
write_not_null_ref_flag(ctx, ref_mode);
if (write_type) {
ctx.write_varuint32(static_cast<uint32_t>(type_id));
@@ -717,7 +711,7 @@ template <> struct Serializer<char32_t> {
}
static inline void write_data_generic(char32_t value, WriteContext &ctx,
- bool has_generics) {
+ bool) {
write_data(value, ctx);
}
@@ -748,13 +742,12 @@ template <> struct Serializer<char32_t> {
return value;
}
- static inline char32_t read_data_generic(ReadContext &ctx,
- bool has_generics) {
+ static inline char32_t read_data_generic(ReadContext &ctx, bool) {
return read_data(ctx);
}
static inline char32_t read_with_type_info(ReadContext &ctx, RefMode
ref_mode,
- const TypeInfo &type_info) {
+ const TypeInfo &) {
return read(ctx, ref_mode, false);
}
};
diff --git a/cpp/fory/serialization/collection_serializer.h
b/cpp/fory/serialization/collection_serializer.h
index 1000fdb31..7c3abf2d3 100644
--- a/cpp/fory/serialization/collection_serializer.h
+++ b/cpp/fory/serialization/collection_serializer.h
@@ -393,7 +393,6 @@ inline Container read_collection_data_slow(ReadContext
&ctx, uint32_t length) {
}
constexpr bool elem_is_polymorphic = is_polymorphic_v<T>;
- constexpr bool elem_is_shared_ref = is_shared_ref_v<T>;
uint8_t bitmap = ctx.read_uint8(ctx.error());
if (FORY_PREDICT_FALSE(ctx.has_error())) {
diff --git a/cpp/fory/serialization/enum_serializer.h
b/cpp/fory/serialization/enum_serializer.h
index fe431c59d..81b9349db 100644
--- a/cpp/fory/serialization/enum_serializer.h
+++ b/cpp/fory/serialization/enum_serializer.h
@@ -81,8 +81,7 @@ struct Serializer<E, std::enable_if_t<std::is_enum_v<E>>> {
ctx.write_varuint32(static_cast<uint32_t>(ordinal));
}
- static inline void write_data_generic(E value, WriteContext &ctx,
- bool has_generics) {
+ static inline void write_data_generic(E value, WriteContext &ctx, bool) {
write_data(value, ctx);
}
@@ -124,7 +123,7 @@ struct Serializer<E, std::enable_if_t<std::is_enum_v<E>>> {
}
static inline E read_with_type_info(ReadContext &ctx, RefMode ref_mode,
- const TypeInfo &type_info) {
+ const TypeInfo &) {
return read(ctx, ref_mode, false);
}
};
diff --git a/cpp/fory/serialization/skip.cc b/cpp/fory/serialization/skip.cc
index 7bc17fe0b..58d1423de 100644
--- a/cpp/fory/serialization/skip.cc
+++ b/cpp/fory/serialization/skip.cc
@@ -196,7 +196,7 @@ void skip_map(ReadContext &ctx, const FieldType
&field_type) {
}
}
-void skip_struct(ReadContext &ctx, const FieldType &field_type) {
+void skip_struct(ReadContext &ctx, const FieldType &) {
// Struct fields in compatible mode are serialized with type_id and
// optionally meta_index, followed by field values. We use the loaded
// TypeMeta to skip all fields for the remote struct.
@@ -269,7 +269,7 @@ void skip_struct(ReadContext &ctx, const FieldType
&field_type) {
}
}
-void skip_ext(ReadContext &ctx, const FieldType &field_type) {
+void skip_ext(ReadContext &ctx, const FieldType &) {
// EXT fields in compatible mode are serialized with type_id followed by
// ext data. For named ext, meta_index is also written after type_id.
// We read the type_id, look up the registered ext harness, and call its
diff --git a/cpp/fory/serialization/smart_ptr_serializer_test.cc
b/cpp/fory/serialization/smart_ptr_serializer_test.cc
index b4151c6e9..d69eaff97 100644
--- a/cpp/fory/serialization/smart_ptr_serializer_test.cc
+++ b/cpp/fory/serialization/smart_ptr_serializer_test.cc
@@ -337,16 +337,6 @@ struct NestedContainer {
};
FORY_STRUCT(NestedContainer, value, nested);
-inline bool operator==(const NestedContainer &a, const NestedContainer &b) {
- if (a.value != b.value)
- return false;
- if (static_cast<bool>(a.nested) != static_cast<bool>(b.nested))
- return false;
- if (a.nested && b.nested)
- return *a.nested == *b.nested;
- return true;
-}
-
// Holder struct to wrap nested container in a polymorphic shared_ptr
struct NestedContainerHolder {
std::shared_ptr<NestedContainer> ptr;
@@ -514,4 +504,4 @@ TEST(SmartPtrSerializerTest, NonDynamicFieldNullValue) {
} // namespace
} // namespace serialization
-} // namespace fory
\ No newline at end of file
+} // namespace fory
diff --git a/cpp/fory/serialization/smart_ptr_serializers.h
b/cpp/fory/serialization/smart_ptr_serializers.h
index 30e3df016..6a4dbb7ba 100644
--- a/cpp/fory/serialization/smart_ptr_serializers.h
+++ b/cpp/fory/serialization/smart_ptr_serializers.h
@@ -132,11 +132,6 @@ template <typename T> struct Serializer<std::optional<T>> {
static inline std::optional<T> read(ReadContext &ctx, RefMode ref_mode,
bool read_type) {
constexpr bool inner_is_nullable = is_nullable_v<T>;
-
- std::cerr << "[optional::read] T=" << typeid(T).name()
- << ", ref_mode=" << static_cast<int>(ref_mode)
- << ", buffer_pos=" << ctx.buffer().reader_index() << std::endl;
-
if (ref_mode == RefMode::None) {
T value = Serializer<T>::read(ctx, RefMode::None, read_type);
if (ctx.has_error()) {
diff --git a/cpp/fory/serialization/string_serializer.h
b/cpp/fory/serialization/string_serializer.h
index 5bf161be0..2dc5a298f 100644
--- a/cpp/fory/serialization/string_serializer.h
+++ b/cpp/fory/serialization/string_serializer.h
@@ -251,8 +251,7 @@ template <> struct Serializer<std::string> {
}
static inline void write(const std::string &value, WriteContext &ctx,
- RefMode ref_mode, bool write_type,
- bool has_generics = false) {
+ RefMode ref_mode, bool write_type, bool = false) {
write_not_null_ref_flag(ctx, ref_mode);
if (write_type) {
ctx.write_varuint32(static_cast<uint32_t>(type_id));
@@ -265,7 +264,7 @@ template <> struct Serializer<std::string> {
}
static inline void write_data_generic(const std::string &value,
- WriteContext &ctx, bool has_generics) {
+ WriteContext &ctx, bool) {
write_data(value, ctx);
}
@@ -293,14 +292,12 @@ template <> struct Serializer<std::string> {
return detail::read_string_data(ctx);
}
- static inline std::string read_data_generic(ReadContext &ctx,
- bool has_generics) {
+ static inline std::string read_data_generic(ReadContext &ctx, bool) {
return read_data(ctx);
}
- static inline std::string read_with_type_info(ReadContext &ctx,
- RefMode ref_mode,
- const TypeInfo &type_info) {
+ static inline std::string
+ read_with_type_info(ReadContext &ctx, RefMode ref_mode, const TypeInfo &) {
return read(ctx, ref_mode, false);
}
};
@@ -320,8 +317,7 @@ template <> struct Serializer<std::string_view> {
}
static inline void write(std::string_view value, WriteContext &ctx,
- RefMode ref_mode, bool write_type,
- bool has_generics = false) {
+ RefMode ref_mode, bool write_type, bool = false) {
write_not_null_ref_flag(ctx, ref_mode);
if (write_type) {
ctx.write_varuint32(static_cast<uint32_t>(type_id));
@@ -334,7 +330,7 @@ template <> struct Serializer<std::string_view> {
}
static inline void write_data_generic(std::string_view value,
- WriteContext &ctx, bool has_generics) {
+ WriteContext &ctx, bool) {
write_data(value, ctx);
}
};
@@ -363,8 +359,7 @@ template <> struct Serializer<std::u16string> {
}
static inline void write(const std::u16string &value, WriteContext &ctx,
- RefMode ref_mode, bool write_type,
- bool has_generics = false) {
+ RefMode ref_mode, bool write_type, bool = false) {
write_not_null_ref_flag(ctx, ref_mode);
if (write_type) {
ctx.write_varuint32(static_cast<uint32_t>(type_id));
@@ -378,7 +373,7 @@ template <> struct Serializer<std::u16string> {
}
static inline void write_data_generic(const std::u16string &value,
- WriteContext &ctx, bool has_generics) {
+ WriteContext &ctx, bool) {
write_data(value, ctx);
}
@@ -406,14 +401,12 @@ template <> struct Serializer<std::u16string> {
return detail::read_u16string_data(ctx);
}
- static inline std::u16string read_data_generic(ReadContext &ctx,
- bool has_generics) {
+ static inline std::u16string read_data_generic(ReadContext &ctx, bool) {
return read_data(ctx);
}
- static inline std::u16string read_with_type_info(ReadContext &ctx,
- RefMode ref_mode,
- const TypeInfo &type_info) {
+ static inline std::u16string
+ read_with_type_info(ReadContext &ctx, RefMode ref_mode, const TypeInfo &) {
return read(ctx, ref_mode, false);
}
};
diff --git a/cpp/fory/serialization/struct_serializer.h
b/cpp/fory/serialization/struct_serializer.h
index e0fa60065..6203b59c8 100644
--- a/cpp/fory/serialization/struct_serializer.h
+++ b/cpp/fory/serialization/struct_serializer.h
@@ -40,10 +40,6 @@
#include <utility>
#include <vector>
-#ifdef ENABLE_FORY_DEBUG_OUTPUT
-#include <iostream>
-#endif
-
namespace fory {
namespace serialization {
@@ -119,13 +115,19 @@ struct SerializationMeta<
}
\
inline constexpr std::true_type ForyStructMarker(const Type &) noexcept {
\
return {};
\
- }
+ }
\
+ static_assert(static_cast<std::true_type (*)(const Type &) noexcept>(
\
+ &ForyStructMarker) != nullptr,
\
+ "ForyStructMarker must be declared");
#define FORY_STRUCT_WITH_FIELDS(Type, ...)
\
FORY_FIELD_INFO(Type, __VA_ARGS__)
\
inline constexpr std::true_type ForyStructMarker(const Type &) noexcept {
\
return {};
\
- }
+ }
\
+ static_assert(static_cast<std::true_type (*)(const Type &) noexcept>(
\
+ &ForyStructMarker) != nullptr,
\
+ "ForyStructMarker must be declared");
#define FORY_STRUCT_1(Type, ...) FORY_STRUCT_TYPE_ONLY(Type)
#define FORY_STRUCT_0(Type, ...) FORY_STRUCT_WITH_FIELDS(Type, __VA_ARGS__)
@@ -2073,18 +2075,6 @@ void read_single_field_by_index(T &obj, ReadContext
&ctx) {
// Per xlang protocol: non-nullable fields skip ref flag entirely
constexpr RefMode field_ref_mode =
make_ref_mode(is_nullable || field_type_is_nullable, track_ref);
-
-#ifdef ENABLE_FORY_DEBUG_OUTPUT
- const auto debug_names = decltype(field_info)::Names;
- std::cerr << "[xlang][field] T=" << typeid(T).name() << ", index=" << Index
- << ", name=" << debug_names[Index]
- << ", field_type_is_nullable=" << field_type_is_nullable
- << ", is_nullable=" << is_nullable
- << ", ref_mode=" << static_cast<int>(field_ref_mode)
- << ", read_type=" << read_type
- << ", reader_index=" << ctx.buffer().reader_index() << std::endl;
-#endif
-
// OPTIMIZATION: For raw primitive fields (not wrappers like optional,
// shared_ptr) that don't need ref metadata, bypass Serializer<T>::read
// and use direct buffer reads with Error&.
@@ -2092,13 +2082,6 @@ void read_single_field_by_index(T &obj, ReadContext
&ctx) {
if constexpr (is_raw_prim && is_primitive_field && !field_type_is_nullable) {
auto read_value = [&ctx]() -> FieldType {
if constexpr (is_configurable_int_v<FieldType>) {
-#ifdef ENABLE_FORY_DEBUG_OUTPUT
- constexpr auto enc = field_int_encoding<FieldType, T, Index>();
- std::cerr << "[xlang][encoding] T=" << typeid(T).name()
- << ", Index=" << Index << ", enc=" << static_cast<int>(enc)
- << ", reader_index=" << ctx.buffer().reader_index()
- << std::endl;
-#endif
return read_configurable_int<FieldType, T, Index>(ctx);
}
return read_primitive_field_direct<FieldType>(ctx, ctx.error());
@@ -2126,19 +2109,8 @@ void read_single_field_by_index(T &obj, ReadContext
&ctx) {
if constexpr (is_encoded_optional_uint) {
constexpr auto enc =
::fory::detail::GetFieldConfigEntry<T, Index>::encoding;
-#ifdef ENABLE_FORY_DEBUG_OUTPUT
- std::cerr << "[DEBUG] is_encoded_optional_uint: Index=" << Index
- << ", enc=" << static_cast<int>(enc)
- << ", reader_index=" << ctx.buffer().reader_index()
- << std::endl;
-#endif
// Read nullable flag
int8_t flag = ctx.read_int8(ctx.error());
-#ifdef ENABLE_FORY_DEBUG_OUTPUT
- std::cerr << "[DEBUG] After read flag: flag=" << static_cast<int>(flag)
- << ", reader_index=" << ctx.buffer().reader_index()
- << std::endl;
-#endif
if (FORY_PREDICT_FALSE(ctx.has_error())) {
return;
}
@@ -2160,11 +2132,6 @@ void read_single_field_by_index(T &obj, ReadContext
&ctx) {
value = static_cast<uint32_t>(ctx.read_int32(ctx.error()));
}
} else if constexpr (std::is_same_v<InnerType, uint64_t>) {
-#ifdef ENABLE_FORY_DEBUG_OUTPUT
- std::cerr << "[DEBUG] Reading uint64 with enc=" <<
static_cast<int>(enc)
- << ", reader_index=" << ctx.buffer().reader_index()
- << std::endl;
-#endif
if constexpr (enc == Encoding::Varint) {
value = ctx.read_varuint64(ctx.error());
} else if constexpr (enc == Encoding::Tagged) {
@@ -2172,11 +2139,6 @@ void read_single_field_by_index(T &obj, ReadContext
&ctx) {
} else {
value = ctx.read_uint64(ctx.error());
}
-#ifdef ENABLE_FORY_DEBUG_OUTPUT
- std::cerr << "[DEBUG] After read uint64: value=" << value
- << ", reader_index=" << ctx.buffer().reader_index()
- << ", has_error=" << ctx.has_error() << std::endl;
-#endif
}
if constexpr (is_fory_field_v<RawFieldType>) {
(obj.*field_ptr).value = std::optional<InnerType>(value);
@@ -2186,18 +2148,7 @@ void read_single_field_by_index(T &obj, ReadContext
&ctx) {
} else if constexpr (is_encoded_optional_int) {
constexpr auto enc =
::fory::detail::GetFieldConfigEntry<T, Index>::encoding;
-#ifdef ENABLE_FORY_DEBUG_OUTPUT
- std::cerr << "[DEBUG] is_encoded_optional_int: Index=" << Index
- << ", enc=" << static_cast<int>(enc)
- << ", reader_index=" << ctx.buffer().reader_index()
- << std::endl;
-#endif
int8_t flag = ctx.read_int8(ctx.error());
-#ifdef ENABLE_FORY_DEBUG_OUTPUT
- std::cerr << "[DEBUG] After read flag: flag=" << static_cast<int>(flag)
- << ", reader_index=" << ctx.buffer().reader_index()
- << std::endl;
-#endif
if (FORY_PREDICT_FALSE(ctx.has_error())) {
return;
}
@@ -2292,16 +2243,6 @@ void read_single_field_by_index_compatible(T &obj,
ReadContext &ctx,
// In compatible mode, trust the remote field metadata (remote_ref_mode)
// to tell us whether a ref/null flag was written before the value payload.
-
-#ifdef ENABLE_FORY_DEBUG_OUTPUT
- const auto debug_names = decltype(field_info)::Names;
- std::cerr << "[compatible][read_field] Index=" << Index
- << ", name=" << debug_names[Index]
- << ", FieldType=" << typeid(FieldType).name()
- << ", remote_ref_mode=" << static_cast<int>(remote_ref_mode)
- << ", buffer pos=" << ctx.buffer().reader_index() << std::endl;
-#endif
-
// In compatible mode, handle primitive fields specially to use remote
// encoding. This is critical for schema evolution where encoding differs
// between sender/receiver.
@@ -2715,11 +2656,6 @@ void read_struct_fields_compatible(T &obj, ReadContext
&ctx,
const TypeMeta *remote_type_meta,
std::index_sequence<Indices...>) {
const auto &remote_fields = remote_type_meta->get_field_infos();
-
- std::cerr << "[compatible] Starting to read " << remote_fields.size()
- << " remote fields, buffer pos=" << ctx.buffer().reader_index()
- << std::endl;
-
// Iterate through remote fields in their serialization order
for (size_t remote_idx = 0; remote_idx < remote_fields.size(); ++remote_idx)
{
const auto &remote_field = remote_fields[remote_idx];
@@ -2729,15 +2665,6 @@ void read_struct_fields_compatible(T &obj, ReadContext
&ctx,
// This is computed from nullable and ref_tracking flags in the remote
// field's header during FieldInfo::from_bytes.
RefMode remote_ref_mode = remote_field.field_type.ref_mode;
-
- std::cerr << "[compatible] remote_idx=" << remote_idx
- << ", field=" << remote_field.field_name
- << ", type_id=" << remote_field.field_type.type_id
- << ", nullable=" << remote_field.field_type.nullable
- << ", ref_mode=" << static_cast<int>(remote_ref_mode)
- << ", field_id=" << field_id
- << ", buffer pos=" << ctx.buffer().reader_index() << std::endl;
-
if (field_id == -1) {
// Field unknown locally — skip its value
skip_field_value(ctx, remote_field.field_type, remote_ref_mode);
@@ -2907,12 +2834,6 @@ struct Serializer<T,
std::enable_if_t<is_fory_serializable_v<T>>> {
if (FORY_PREDICT_FALSE(ctx.has_error())) {
return T{};
}
-#ifdef ENABLE_FORY_DEBUG_OUTPUT
- std::cerr << "[xlang][struct] T=" << typeid(T).name()
- << ", read_ref_flag=" << static_cast<int>(ref_flag)
- << ", reader_index=" << ctx.buffer().reader_index()
- << std::endl;
-#endif
} else {
ref_flag = static_cast<int8_t>(RefFlag::NotNullValue);
}
@@ -3051,8 +2972,6 @@ struct Serializer<T,
std::enable_if_t<is_fory_serializable_v<T>>> {
}
static T read_compatible(ReadContext &ctx, const TypeInfo *remote_type_info)
{
- std::cerr << "[read_compatible] Entering for type " << typeid(T).name()
- << ", buffer_pos=" << ctx.buffer().reader_index() << std::endl;
// Read and verify struct version if enabled (matches write_data behavior)
if (ctx.check_struct_version()) {
int32_t read_version = ctx.buffer().ReadInt32(ctx.error());
diff --git a/cpp/fory/serialization/type_resolver.h
b/cpp/fory/serialization/type_resolver.h
index 463374e85..c1398d2ec 100644
--- a/cpp/fory/serialization/type_resolver.h
+++ b/cpp/fory/serialization/type_resolver.h
@@ -314,7 +314,7 @@ template <typename T> FieldType build_field_type(bool
nullable = false) {
template <typename T>
struct FieldTypeBuilder<T, std::enable_if_t<is_optional_v<decay_t<T>>>> {
using Inner = typename decay_t<T>::value_type;
- static FieldType build(bool nullable) {
+ static FieldType build(bool) {
FieldType inner = FieldTypeBuilder<Inner>::build(true);
inner.nullable = true;
return inner;
@@ -324,7 +324,7 @@ struct FieldTypeBuilder<T,
std::enable_if_t<is_optional_v<decay_t<T>>>> {
template <typename T>
struct FieldTypeBuilder<T, std::enable_if_t<is_shared_ptr_v<decay_t<T>>>> {
using Inner = typename decay_t<T>::element_type;
- static FieldType build(bool nullable) {
+ static FieldType build(bool) {
FieldType inner = FieldTypeBuilder<Inner>::build(true);
inner.nullable = true;
return inner;
@@ -334,7 +334,7 @@ struct FieldTypeBuilder<T,
std::enable_if_t<is_shared_ptr_v<decay_t<T>>>> {
template <typename T>
struct FieldTypeBuilder<T, std::enable_if_t<is_unique_ptr_v<decay_t<T>>>> {
using Inner = typename decay_t<T>::element_type;
- static FieldType build(bool nullable) {
+ static FieldType build(bool) {
FieldType inner = FieldTypeBuilder<Inner>::build(true);
inner.nullable = true;
return inner;
diff --git a/cpp/fory/serialization/unsigned_serializer.h
b/cpp/fory/serialization/unsigned_serializer.h
index 1079afc68..9402c39ec 100644
--- a/cpp/fory/serialization/unsigned_serializer.h
+++ b/cpp/fory/serialization/unsigned_serializer.h
@@ -53,7 +53,7 @@ template <> struct Serializer<uint8_t> {
}
static inline void write(uint8_t value, WriteContext &ctx, RefMode ref_mode,
- bool write_type, bool has_generics = false) {
+ bool write_type, bool = false) {
write_not_null_ref_flag(ctx, ref_mode);
if (write_type) {
write_type_info(ctx);
@@ -66,7 +66,7 @@ template <> struct Serializer<uint8_t> {
}
static inline void write_data_generic(uint8_t value, WriteContext &ctx,
- bool has_generics) {
+ bool) {
write_data(value, ctx);
}
@@ -90,12 +90,12 @@ template <> struct Serializer<uint8_t> {
return ctx.read_uint8(ctx.error());
}
- static inline uint8_t read_data_generic(ReadContext &ctx, bool has_generics)
{
+ static inline uint8_t read_data_generic(ReadContext &ctx, bool) {
return read_data(ctx);
}
static inline uint8_t read_with_type_info(ReadContext &ctx, RefMode ref_mode,
- const TypeInfo &type_info) {
+ const TypeInfo &) {
return read(ctx, ref_mode, false);
}
};
@@ -117,7 +117,7 @@ template <> struct Serializer<uint16_t> {
}
static inline void write(uint16_t value, WriteContext &ctx, RefMode ref_mode,
- bool write_type, bool has_generics = false) {
+ bool write_type, bool = false) {
write_not_null_ref_flag(ctx, ref_mode);
if (write_type) {
write_type_info(ctx);
@@ -130,7 +130,7 @@ template <> struct Serializer<uint16_t> {
}
static inline void write_data_generic(uint16_t value, WriteContext &ctx,
- bool has_generics) {
+ bool) {
write_data(value, ctx);
}
@@ -154,13 +154,12 @@ template <> struct Serializer<uint16_t> {
return ctx.read_uint16(ctx.error());
}
- static inline uint16_t read_data_generic(ReadContext &ctx,
- bool has_generics) {
+ static inline uint16_t read_data_generic(ReadContext &ctx, bool) {
return read_data(ctx);
}
static inline uint16_t read_with_type_info(ReadContext &ctx, RefMode
ref_mode,
- const TypeInfo &type_info) {
+ const TypeInfo &) {
return read(ctx, ref_mode, false);
}
};
@@ -182,7 +181,7 @@ template <> struct Serializer<uint32_t> {
}
static inline void write(uint32_t value, WriteContext &ctx, RefMode ref_mode,
- bool write_type, bool has_generics = false) {
+ bool write_type, bool = false) {
write_not_null_ref_flag(ctx, ref_mode);
if (write_type) {
write_type_info(ctx);
@@ -195,7 +194,7 @@ template <> struct Serializer<uint32_t> {
}
static inline void write_data_generic(uint32_t value, WriteContext &ctx,
- bool has_generics) {
+ bool) {
write_data(value, ctx);
}
@@ -219,13 +218,12 @@ template <> struct Serializer<uint32_t> {
return ctx.read_uint32(ctx.error());
}
- static inline uint32_t read_data_generic(ReadContext &ctx,
- bool has_generics) {
+ static inline uint32_t read_data_generic(ReadContext &ctx, bool) {
return read_data(ctx);
}
static inline uint32_t read_with_type_info(ReadContext &ctx, RefMode
ref_mode,
- const TypeInfo &type_info) {
+ const TypeInfo &) {
return read(ctx, ref_mode, false);
}
};
@@ -247,7 +245,7 @@ template <> struct Serializer<uint64_t> {
}
static inline void write(uint64_t value, WriteContext &ctx, RefMode ref_mode,
- bool write_type, bool has_generics = false) {
+ bool write_type, bool = false) {
write_not_null_ref_flag(ctx, ref_mode);
if (write_type) {
write_type_info(ctx);
@@ -260,7 +258,7 @@ template <> struct Serializer<uint64_t> {
}
static inline void write_data_generic(uint64_t value, WriteContext &ctx,
- bool has_generics) {
+ bool) {
write_data(value, ctx);
}
@@ -284,13 +282,12 @@ template <> struct Serializer<uint64_t> {
return ctx.read_uint64(ctx.error());
}
- static inline uint64_t read_data_generic(ReadContext &ctx,
- bool has_generics) {
+ static inline uint64_t read_data_generic(ReadContext &ctx, bool) {
return read_data(ctx);
}
static inline uint64_t read_with_type_info(ReadContext &ctx, RefMode
ref_mode,
- const TypeInfo &type_info) {
+ const TypeInfo &) {
return read(ctx, ref_mode, false);
}
};
@@ -341,7 +338,7 @@ template <size_t N> struct Serializer<std::array<uint8_t,
N>> {
}
static inline void write_data_generic(const std::array<uint8_t, N> &arr,
- WriteContext &ctx, bool has_generics) {
+ WriteContext &ctx, bool) {
write_data(arr, ctx);
}
@@ -378,8 +375,7 @@ template <size_t N> struct Serializer<std::array<uint8_t,
N>> {
}
static inline std::array<uint8_t, N>
- read_with_type_info(ReadContext &ctx, RefMode ref_mode,
- const TypeInfo &type_info) {
+ read_with_type_info(ReadContext &ctx, RefMode ref_mode, const TypeInfo &) {
return read(ctx, ref_mode, false);
}
};
@@ -425,7 +421,7 @@ template <size_t N> struct Serializer<std::array<uint16_t,
N>> {
}
static inline void write_data_generic(const std::array<uint16_t, N> &arr,
- WriteContext &ctx, bool has_generics) {
+ WriteContext &ctx, bool) {
write_data(arr, ctx);
}
@@ -462,8 +458,7 @@ template <size_t N> struct Serializer<std::array<uint16_t,
N>> {
}
static inline std::array<uint16_t, N>
- read_with_type_info(ReadContext &ctx, RefMode ref_mode,
- const TypeInfo &type_info) {
+ read_with_type_info(ReadContext &ctx, RefMode ref_mode, const TypeInfo &) {
return read(ctx, ref_mode, false);
}
};
@@ -509,7 +504,7 @@ template <size_t N> struct Serializer<std::array<uint32_t,
N>> {
}
static inline void write_data_generic(const std::array<uint32_t, N> &arr,
- WriteContext &ctx, bool has_generics) {
+ WriteContext &ctx, bool) {
write_data(arr, ctx);
}
@@ -546,8 +541,7 @@ template <size_t N> struct Serializer<std::array<uint32_t,
N>> {
}
static inline std::array<uint32_t, N>
- read_with_type_info(ReadContext &ctx, RefMode ref_mode,
- const TypeInfo &type_info) {
+ read_with_type_info(ReadContext &ctx, RefMode ref_mode, const TypeInfo &) {
return read(ctx, ref_mode, false);
}
};
@@ -593,7 +587,7 @@ template <size_t N> struct Serializer<std::array<uint64_t,
N>> {
}
static inline void write_data_generic(const std::array<uint64_t, N> &arr,
- WriteContext &ctx, bool has_generics) {
+ WriteContext &ctx, bool) {
write_data(arr, ctx);
}
@@ -630,8 +624,7 @@ template <size_t N> struct Serializer<std::array<uint64_t,
N>> {
}
static inline std::array<uint64_t, N>
- read_with_type_info(ReadContext &ctx, RefMode ref_mode,
- const TypeInfo &type_info) {
+ read_with_type_info(ReadContext &ctx, RefMode ref_mode, const TypeInfo &) {
return read(ctx, ref_mode, false);
}
};
@@ -683,7 +676,7 @@ template <> struct Serializer<std::vector<uint8_t>> {
}
static inline void write_data_generic(const std::vector<uint8_t> &vec,
- WriteContext &ctx, bool has_generics) {
+ WriteContext &ctx, bool) {
write_data(vec, ctx);
}
@@ -717,14 +710,12 @@ template <> struct Serializer<std::vector<uint8_t>> {
return vec;
}
- static inline std::vector<uint8_t> read_data_generic(ReadContext &ctx,
- bool has_generics) {
+ static inline std::vector<uint8_t> read_data_generic(ReadContext &ctx, bool)
{
return read_data(ctx);
}
static inline std::vector<uint8_t>
- read_with_type_info(ReadContext &ctx, RefMode ref_mode,
- const TypeInfo &type_info) {
+ read_with_type_info(ReadContext &ctx, RefMode ref_mode, const TypeInfo &) {
return read(ctx, ref_mode, false);
}
};
@@ -772,7 +763,7 @@ template <> struct Serializer<std::vector<uint16_t>> {
}
static inline void write_data_generic(const std::vector<uint16_t> &vec,
- WriteContext &ctx, bool has_generics) {
+ WriteContext &ctx, bool) {
write_data(vec, ctx);
}
@@ -808,13 +799,12 @@ template <> struct Serializer<std::vector<uint16_t>> {
}
static inline std::vector<uint16_t> read_data_generic(ReadContext &ctx,
- bool has_generics) {
+ bool) {
return read_data(ctx);
}
static inline std::vector<uint16_t>
- read_with_type_info(ReadContext &ctx, RefMode ref_mode,
- const TypeInfo &type_info) {
+ read_with_type_info(ReadContext &ctx, RefMode ref_mode, const TypeInfo &) {
return read(ctx, ref_mode, false);
}
};
@@ -862,7 +852,7 @@ template <> struct Serializer<std::vector<uint32_t>> {
}
static inline void write_data_generic(const std::vector<uint32_t> &vec,
- WriteContext &ctx, bool has_generics) {
+ WriteContext &ctx, bool) {
write_data(vec, ctx);
}
@@ -898,13 +888,12 @@ template <> struct Serializer<std::vector<uint32_t>> {
}
static inline std::vector<uint32_t> read_data_generic(ReadContext &ctx,
- bool has_generics) {
+ bool) {
return read_data(ctx);
}
static inline std::vector<uint32_t>
- read_with_type_info(ReadContext &ctx, RefMode ref_mode,
- const TypeInfo &type_info) {
+ read_with_type_info(ReadContext &ctx, RefMode ref_mode, const TypeInfo &) {
return read(ctx, ref_mode, false);
}
};
@@ -952,7 +941,7 @@ template <> struct Serializer<std::vector<uint64_t>> {
}
static inline void write_data_generic(const std::vector<uint64_t> &vec,
- WriteContext &ctx, bool has_generics) {
+ WriteContext &ctx, bool) {
write_data(vec, ctx);
}
@@ -988,13 +977,12 @@ template <> struct Serializer<std::vector<uint64_t>> {
}
static inline std::vector<uint64_t> read_data_generic(ReadContext &ctx,
- bool has_generics) {
+ bool) {
return read_data(ctx);
}
static inline std::vector<uint64_t>
- read_with_type_info(ReadContext &ctx, RefMode ref_mode,
- const TypeInfo &type_info) {
+ read_with_type_info(ReadContext &ctx, RefMode ref_mode, const TypeInfo &) {
return read(ctx, ref_mode, false);
}
};
diff --git a/cpp/fory/serialization/weak_ptr_serializer_test.cc
b/cpp/fory/serialization/weak_ptr_serializer_test.cc
index 112cfc38d..4da9d5300 100644
--- a/cpp/fory/serialization/weak_ptr_serializer_test.cc
+++ b/cpp/fory/serialization/weak_ptr_serializer_test.cc
@@ -167,13 +167,6 @@ struct NodeWithParent {
};
FORY_STRUCT(NodeWithParent, value, parent, children);
-struct MultipleWeakRefs {
- SharedWeak<SimpleStruct> weak1;
- SharedWeak<SimpleStruct> weak2;
- SharedWeak<SimpleStruct> weak3;
-};
-FORY_STRUCT(MultipleWeakRefs, weak1, weak2, weak3);
-
// ============================================================================
// Serialization Tests
// ============================================================================
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]