Skip to content

Commit 961bb4f

Browse files
authored
Merge pull request #313 from gummif/gfa/socket-ctor
Problem: socket_t can not be default constructed
2 parents 132f7b0 + 4ceabb3 commit 961bb4f

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

tests/socket.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,27 @@ static_assert(std::is_nothrow_swappable<zmq::socket_t>::value,
99
"socket_t should be nothrow swappable");
1010
#endif
1111

12+
TEST_CASE("socket default ctor", "[socket]")
13+
{
14+
zmq::socket_t socket;
15+
}
16+
1217
TEST_CASE("socket create destroy", "[socket]")
1318
{
1419
zmq::context_t context;
1520
zmq::socket_t socket(context, ZMQ_ROUTER);
1621
}
1722

1823
#ifdef ZMQ_CPP11
24+
TEST_CASE("socket create assign", "[socket]")
25+
{
26+
zmq::context_t context;
27+
zmq::socket_t socket(context, ZMQ_ROUTER);
28+
CHECK(static_cast<void*>(socket));
29+
socket = {};
30+
CHECK(!static_cast<void*>(socket));
31+
}
32+
1933
TEST_CASE("socket create by enum and destroy", "[socket]")
2034
{
2135
zmq::context_t context;

zmq.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,12 @@ class socket_t
646646
friend class monitor_t;
647647

648648
public:
649+
socket_t() ZMQ_NOTHROW
650+
: ptr(ZMQ_NULLPTR)
651+
, ctxptr(ZMQ_NULLPTR)
652+
{
653+
}
654+
649655
socket_t(context_t &context_, int type_)
650656
: ptr(zmq_socket(static_cast<void*>(context_), type_))
651657
, ctxptr(static_cast<void*>(context_))

0 commit comments

Comments
 (0)