Skip to content

Commit 88ada98

Browse files
authored
Merge pull request #347 from gummif/gfa/aliasing-warning
Problem: Strict aliasing warning in tests
2 parents 3b1038d + 57d3681 commit 88ada98

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

tests/socket_ref.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,12 @@ TEST_CASE("socket_ref swap", "[socket_ref]")
9595
swap(sr1, sr2);
9696
}
9797

98-
TEST_CASE("socket_ref reinterpret as void*", "[socket_ref]")
98+
TEST_CASE("socket_ref type punning", "[socket_ref]")
9999
{
100100
struct SVP
101101
{
102102
void *p;
103-
};
103+
} svp;
104104
struct SSR
105105
{
106106
zmq::socket_ref sr;
@@ -109,7 +109,9 @@ TEST_CASE("socket_ref reinterpret as void*", "[socket_ref]")
109109
zmq::context_t context;
110110
zmq::socket_t socket(context, zmq::socket_type::router);
111111
CHECK(socket.handle() != nullptr);
112-
reinterpret_cast<SVP *>(&ssr)->p = socket.handle();
112+
svp.p = socket.handle();
113+
// static_cast to silence incorrect warning
114+
std::memcpy(static_cast<void*>(&ssr), &svp, sizeof(ssr));
113115
CHECK(ssr.sr == socket);
114116
}
115117

0 commit comments

Comments
 (0)