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

Build fails for a message pair containing at least one field of type bool[] #445

Open
mendes-jose opened this issue Feb 26, 2025 · 1 comment

Comments

@mendes-jose
Copy link

mendes-jose commented Feb 26, 2025

⚠ Relates to #391, #393

Description

While trying to create a bridge for a message pair containing fields of type bool[], the build of ros1_bridge fails.

The compilation error message:

--- stderr: ros1_bridge
/root/bridge_ws/build/ros1_bridge/generated/sick_safetyscanners2_interfaces__msg__OutputPaths__factories.cpp: In instantiation of ‘void ros1_bridge::streamPrimitiveVector(ros::serialization::OStream&, const VEC_PRIMITIVE_T&) [with VEC_PRIMITIVE_T = std::vector<bool, std::allocator<bool> >]’:
/root/bridge_ws/build/ros1_bridge/generated/sick_safetyscanners2_interfaces__msg__OutputPaths__factories.cpp:208:48:   required from here
/root/bridge_ws/build/ros1_bridge/generated/sick_safetyscanners2_interfaces__msg__OutputPaths__factories.cpp:170:36: error: lvalue required as unary ‘&’ operand
  170 |   memcpy(stream.advance(data_len), &vec.front(), data_len);
/root/bridge_ws/build/ros1_bridge/generated/sick_safetyscanners2_interfaces__msg__OutputPaths__factories.cpp: In instantiation of ‘void ros1_bridge::streamPrimitiveVector(ros::serialization::IStream&, VEC_PRIMITIVE_T&) [with VEC_PRIMITIVE_T = std::vector<bool, std::allocator<bool> >]’:
/root/bridge_ws/build/ros1_bridge/generated/sick_safetyscanners2_interfaces__msg__OutputPaths__factories.cpp:245:48:   required from here
/root/bridge_ws/build/ros1_bridge/generated/sick_safetyscanners2_interfaces__msg__OutputPaths__factories.cpp:187:10: error: taking address of rvalue [-fpermissive]
  187 |   memcpy(&vec.front(), stream.advance(data_len), data_len);
/root/bridge_ws/build/ros1_bridge/generated/sick_safetyscanners2_interfaces__msg__OutputPaths__factories.cpp:187:9: warning: ‘void* memcpy(void*, const void*, size_t)’ writing to an object of type ‘std::vector<bool, std::allocator<bool> >::reference’ {aka ‘struct std::_Bit_reference’} with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
  187 |   memcpy(&vec.front(), stream.advance(data_len), data_len);
      |   ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/9/vector:68,
                 from /usr/include/c++/9/functional:62,
                 from /root/bridge_ws/src/ros1_bridge/include/ros1_bridge/factory.hpp:18,
                 from /root/bridge_ws/build/ros1_bridge/generated/sick_safetyscanners2_interfaces_factories.hpp:6,
                 from /root/bridge_ws/build/ros1_bridge/generated/sick_safetyscanners2_interfaces__msg__OutputPaths__factories.cpp:3:
/usr/include/c++/9/bits/stl_bvector.h:72:10: note: ‘std::vector<bool, std::allocator<bool> >::reference’ {aka ‘struct std::_Bit_reference’} declared here
   72 |   struct _Bit_reference
      |          ^~~~~~~~~~~~~~
make[2]: *** [CMakeFiles/ros1_bridge.dir/build.make:5431: CMakeFiles/ros1_bridge.dir/generated/sick_safetyscanners2_interfaces__msg__OutputPaths__factories.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [CMakeFiles/Makefile2:292: CMakeFiles/ros1_bridge.dir/all] Error 2
make: *** [Makefile:141: all] Error 2
---
Failed   <<< ros1_bridge [11min 49s, exited with code 2]

Steps to reproduce

Simply define a ROS1 message and a ROS2 message with the same package name, same message name, same fields and make sure at least one of the field is of type bool[].

Try to compile ros1_bridge.

Possible reasons for the error

I'm assuming this error has something to do with the fact that a bool in ROS1 is actually a uint8_t and that in ROS2 it is a actual bool.

That plus the fact that std::vector<bool> is a special type of vector, optimized for size (std::_Bit_reference)

Steps to solve?

If somebody can help with ideas on what would be the best way to solve this. I'm assuming that we would have to have some kind of explicit template specialization somewhere to cope with the types bool[].

I'm willing to work on the issue, but some instructions on where to start would be much appreciated

@mendes-jose mendes-jose changed the title Build fails for a message pair containing at least a field with type bool[] Build fails for a message pair containing at least one field of type bool[] Feb 26, 2025
@mendes-jose
Copy link
Author

mendes-jose commented Feb 26, 2025

A tested solution to this issue is proposed in this PR here: #446

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

1 participant