You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Change signature of tf2::fromMsg() and tf2::toMsg() to prevent linking errors. #242
Make all overloads of fromMsg() and toMsg() template specializations (with template<>)
Feature description
As pointed out in ros/geometry2#430, the fromMsg() and toMsg() Methods are traditional overloads (same function name, different arguments) and not a specialization of the templated forward declarations in <tf2/convert.h>. So, sometimes the compiler chooses the wrong functions which results in linking errors like (from ros/geometry2#430):
I already made a PR on the ROS1 version (ros/geometry2#433) which declares all fromMsg() and toMsg() as template specializations. The conversion between two non-geometry-msgs types is done explicitly, the mappings are generated with the help of a python script. Implicitly mapping these types together does not work with template specializations.
Downstream projects will break, because tf2::toMsg() now has two parameters in my implementation. Otherwise, the second type couldn't be deduced as the return value does not take part in template parameter deduction. On the other hand, all calls to tf2::fromMsg() and tf2::convert() will be fine.
We've tried to do something like this in the past, and it led to a lot of downstream breakage (as you might imagine). This doesn't automatically disqualify it, but I'd like to use that experience to know what we are getting ourselves into.
Looking at Fix tf2::convert for non-msgs types ros/geometry2#433, I have to say that the API is strictly worse. Having to first define the message and then pass it as a ref parameter to toMsg is pretty ugly, and we'll get a lot of complaints from downstream consumers. Is there anything else we can do here to make the API nicer, even if we have to (further) break it?
create a templated struct which will contain a message type member for each non-message type
make this the default argument for the second template parameter of toMsg()
move the actual conversion between message and non-message types into static struct member functions
With this approach, missing #includes are caught at compile-time (because the struct converter is empty).
The API is left unchanged, but the ABI will break (due to name mangling). Deprecating the non-templated functions does not work, as their precendence at overload resolution is higher than the (new) templated ones.
I'm happy to dig a bit deeper and to adapt my previous PR (ros/geometry2#433) if you agree to this approach.
Activity
clalancette commentedon Jun 10, 2020
There are a few problems with this proposal:
toMsgis pretty ugly, and we'll get a lot of complaints from downstream consumers. Is there anything else we can do here to make the API nicer, even if we have to (further) break it?gleichdick commentedon Nov 24, 2020
The following idea came to my mind:
toMsg()With this approach, missing
#includesare caught at compile-time (because the structconverteris empty).The API is left unchanged, but the ABI will break (due to name mangling). Deprecating the non-templated functions does not work, as their precendence at overload resolution is higher than the (new) templated ones.
I'm happy to dig a bit deeper and to adapt my previous PR (ros/geometry2#433) if you agree to this approach.
Example:
gleichdick commentedon Jan 11, 2021
For the records, the new PR for ROS1: ros/geometry2#491
Workaround ros2/geometry2#242