Skip to content

Commit cdf2274

Browse files
committed
Fixed existing code compile error problem.
Changed macro name from MSGPACK_USE_LEGACY_CONVERT to MSGPACK_DISABLE_LEGACY_CONVERT. msgpack-c shouldn't make compile error on existing codes by default without major version up. So if you want to disable msgpack::object::convert(T*), you need to define MSGPACK_DISABLE_LEGACY_CONVERT macro.
1 parent 134eec7 commit cdf2274

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

include/msgpack/object.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,14 +523,14 @@ inline T& object::convert(T& v) const
523523
return v;
524524
}
525525

526-
#if defined(MSGPACK_USE_LEGACY_CONVERT)
526+
#if !defined(MSGPACK_DISABLE_LEGACY_CONVERT)
527527
template <typename T>
528528
inline T* object::convert(T* v) const
529529
{
530530
convert(*v);
531531
return v;
532532
}
533-
#endif // defined(MSGPACK_USE_LEGACY_CONVERT)
533+
#endif // !defined(MSGPACK_DISABLE_LEGACY_CONVERT)
534534

535535
template <typename T>
536536
inline bool object::convert_if_not_nil(T& v) const

include/msgpack/object_fwd.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ struct object {
172172
T& convert(T& v) const;
173173

174174

175-
#if defined(MSGPACK_USE_LEGACY_CONVERT)
175+
#if !defined(MSGPACK_DISABLE_LEGACY_CONVERT)
176176
/// Convert the object (obsolete)
177177
/**
178178
* If the object can't be converted to T, msgpack::type_error would be thrown.
@@ -182,7 +182,7 @@ struct object {
182182
*/
183183
template <typename T>
184184
T* convert(T* v) const;
185-
#endif // defined(MSGPACK_USE_LEGACY_CONVERT)
185+
#endif // !defined(MSGPACK_DISABLE_LEGACY_CONVERT)
186186

187187
/// Convert the object if not nil
188188
/**

test/convert.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,20 @@ TEST(convert, return_value_ref)
8484
EXPECT_EQ(i, j);
8585
}
8686

87+
#if !defined(MSGPACK_DISABLE_LEGACY_CONVERT)
88+
89+
TEST(convert, return_value_ptr)
90+
{
91+
msgpack::zone z;
92+
msgpack::object obj(1, z);
93+
94+
int i;
95+
EXPECT_EQ(obj.convert(&i), &i);
96+
EXPECT_EQ(1, i);
97+
}
98+
99+
#endif // !defined(MSGPACK_DISABLE_LEGACY_CONVERT)
100+
87101
TEST(convert, if_not_nil_nil)
88102
{
89103
msgpack::object obj;

0 commit comments

Comments
 (0)