Discussion:
[capnproto] Can't move unique pointer to MallocMessageBuilder
k***@gmail.com
2018-01-09 06:57:38 UTC
Permalink
I'm trying to figure out how to move a MallocMessageBuilder. I thought that
if I created a std::unique_ptr to it, then I could move that pointer, but
it is failing at runtime because the rvalue constructor is deleted.

Am I doing something wrong with my move?

Pseudo-code:
void my_func(std::unique_ptr<::capnp::MallocMessageBuilder> builder) {
my_class.builder = std::move(builder);
}
auto builder = std::unique_ptr<::capnp::MallocMessageBuilder>();
// ... initialize the builder ...
my_func(std::move(builder));

Is there a way to move a MallocMessageBuilder without just using a raw
pointer? It fails at runtime in the std::move call in my function.

Thanks!
--
You received this message because you are subscribed to the Google Groups "Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to capnproto+***@googlegroups.com.
Visit this group at https://groups.google.com/group/capnproto.
'Kenton Varda' via Cap'n Proto
2018-01-09 17:40:30 UTC
Permalink
Hi Kevin,

Moving a unique_ptr doesn't touch the pointed-to type at all, so the
problem here couldn't possibly have anything to do with
MallocMessageBuilder. I don't see anything obviously wrong with the code
you provided, so the bug must be elsewhere in your code. It is possible
that my_class is an invalid reference? What do you mean when you say that
std::move() "fails"? I honestly can't think of any way that std::move()
could fail at runtime, since it only casts one reference type to another.

-Kenton
Post by k***@gmail.com
I'm trying to figure out how to move a MallocMessageBuilder. I thought
that if I created a std::unique_ptr to it, then I could move that pointer,
but it is failing at runtime because the rvalue constructor is deleted.
Am I doing something wrong with my move?
void my_func(std::unique_ptr<::capnp::MallocMessageBuilder> builder) {
my_class.builder = std::move(builder);
}
auto builder = std::unique_ptr<::capnp::MallocMessageBuilder>();
// ... initialize the builder ...
my_func(std::move(builder));
Is there a way to move a MallocMessageBuilder without just using a raw
pointer? It fails at runtime in the std::move call in my function.
Thanks!
--
You received this message because you are subscribed to the Google Groups
"Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/capnproto.
--
You received this message because you are subscribed to the Google Groups "Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to capnproto+***@googlegroups.com.
Visit this group at https://groups.google.com/group/capnproto.
Kevin Greene
2018-01-09 17:47:36 UTC
Permalink
You’re right, that doesn’t make any sense.

Turned out to be related to the fact that it was being called in a
constructor, and some unrelated things weren’t initialized yet. I had just
gotten confused by the backtrace output.

Sorry for the noise.
Post by 'Kenton Varda' via Cap'n Proto
Hi Kevin,
Moving a unique_ptr doesn't touch the pointed-to type at all, so the
problem here couldn't possibly have anything to do with
MallocMessageBuilder. I don't see anything obviously wrong with the code
you provided, so the bug must be elsewhere in your code. It is possible
that my_class is an invalid reference? What do you mean when you say that
std::move() "fails"? I honestly can't think of any way that std::move()
could fail at runtime, since it only casts one reference type to another.
-Kenton
Post by k***@gmail.com
I'm trying to figure out how to move a MallocMessageBuilder. I thought
that if I created a std::unique_ptr to it, then I could move that pointer,
but it is failing at runtime because the rvalue constructor is deleted.
Am I doing something wrong with my move?
void my_func(std::unique_ptr<::capnp::MallocMessageBuilder> builder) {
my_class.builder = std::move(builder);
}
auto builder = std::unique_ptr<::capnp::MallocMessageBuilder>();
// ... initialize the builder ...
my_func(std::move(builder));
Is there a way to move a MallocMessageBuilder without just using a raw
pointer? It fails at runtime in the std::move call in my function.
Thanks!
--
Post by k***@gmail.com
You received this message because you are subscribed to the Google Groups
"Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/capnproto.
--
You received this message because you are subscribed to the Google Groups "Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to capnproto+***@googlegroups.com.
Visit this group at https://groups.google.com/group/capnproto.
Loading...