Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
diehard2 opened this issue Nov 18, 2024 · 1 comment
Open

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

diehard2 opened this issue Nov 18, 2024 · 1 comment

Comments

@diehard2
Copy link

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);
  }
}
@gummif
Copy link
Member

gummif commented Nov 19, 2024

You have a view into a moved from container, so I would say that is UB.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants