Skip to content

std::move of zmq::message_t not behaving as expected #644

@diehard2

Description

@diehard2

I'm trying to pin a message_t in a way I can use it later for zero copy and I'm having a bear of a time doing it. In the below test the first one passes and the second one fails. I would have expected them both to pass since the underlying data isn't being memcpy'd anywhere. I can go with the first message, but its a bit unexpected to me that the first one fails.

TEST(ZMQTests, BUG)
{
  {
    zmq::multipart_t test;
    test.pushstr("echo2");

    zmq::multipart_t message;
    std::string_view view;

    zmq::message_t foo = test.pop();
    view = {static_cast<char*>(foo.data()), foo.size()};
    message = std::move(foo);

    EXPECT_EQ(std::string("echo2"), view);
  }
  {
    zmq::multipart_t test;
    test.pushstr("echo2");

    zmq::message_t message;
    std::string_view view;

    zmq::message_t foo = test.pop();
    view = {static_cast<char*>(foo.data()), foo.size()};
    message = std::move(foo);

    EXPECT_EQ(std::string("echo2"), view);
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions