-
Notifications
You must be signed in to change notification settings - Fork 522
Description
Bug report
Required Info:
- Operating System:
- Archlinux @ June, 9 [GCC 11.1.0]
- Installation type:
- From source
- Version or commit hash:
- master (7d8b269)
- DDS implementation:
- rmw_fastrtps_cpp
Steps to reproduce issue
Try to run the following code:
#include "rclcpp/rclcpp.hpp"
#include <string>
int main(int argc, char *argv[])
{
rclcpp::init(argc, argv);
rclcpp::Node mynode("name");
mynode.declare_parameter<std::string>("myparam");
rclcpp::shutdown();
}
Expected behavior
Run and exit successfully.
Actual behavior
Compiles but in runtime exits due to an exception. Full output:
terminate called after throwing an instance of 'rclcpp::ParameterTypeException'
what(): expected [string] got [not set]
Aborted (core dumped)
Additional information
This call fails:
mynode.declare_parameter<std::string>("myparam");
(This is not specific to std::string)
Here's my understanding of why this happens: Under the hood, rclcpp declares an uninitialized parameter and tries to return it as a typed object (code here). However, it seems that rclcpp keeps track of uninitialized parameters by assigning not set type to them (code here), even if they are typed. So this boils down to contradictory typing (string type implied by template argument, not set type implied by the node being uninitialized...)
Interestingly the mynode.declare_parameter<T>(param_name) function call is actually included in the tests (code here) and they are passing without errors. The reason that the error doesn't manifest there is that in the same test file, a default value is defined for the parameter (code here). This means the parameter gets initialized (and therefore loses the not set type) before mynode.declare_parameter<T>(param_name) finishes.