mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-03-20 13:33:51 +01:00
cpp: Fix convert.enum_member test (issue #50).
The patch add serialization operator for the given enum to avoid the use of a cast which leads to strict-aliasing warnings and the test to fail. Solution suggested by qehgt.
This commit is contained in:
parent
e511c32a36
commit
509f27eee1
@ -34,6 +34,25 @@
|
|||||||
msgpack::type::make_define(__VA_ARGS__).msgpack_object(o, z); \
|
msgpack::type::make_define(__VA_ARGS__).msgpack_object(o, z); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MSGPACK_ADD_ENUM must be used in the global namespace.
|
||||||
|
#define MSGPACK_ADD_ENUM(enum) \
|
||||||
|
namespace msgpack { \
|
||||||
|
template <> \
|
||||||
|
inline enum& operator>> (object o, enum& v) \
|
||||||
|
{ \
|
||||||
|
int tmp; \
|
||||||
|
o >> tmp; \
|
||||||
|
v = static_cast<enum>(tmp); \
|
||||||
|
return v; \
|
||||||
|
} \
|
||||||
|
template <> \
|
||||||
|
void operator<< (object::with_zone& o, const enum& v) \
|
||||||
|
{ \
|
||||||
|
int tmp = static_cast<enum>(v); \
|
||||||
|
o << tmp; \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
namespace msgpack {
|
namespace msgpack {
|
||||||
namespace type {
|
namespace type {
|
||||||
|
|
||||||
|
@ -55,9 +55,11 @@ public:
|
|||||||
|
|
||||||
flags_t flag;
|
flags_t flag;
|
||||||
|
|
||||||
MSGPACK_DEFINE((int&)flag);
|
MSGPACK_DEFINE(flag);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
MSGPACK_ADD_ENUM(enum_member::flags_t);
|
||||||
|
|
||||||
TEST(convert, enum_member)
|
TEST(convert, enum_member)
|
||||||
{
|
{
|
||||||
enum_member src;
|
enum_member src;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user