RCLCPP logging macros not a single expression
I just discovered after a lot of confusion that the RCLCPP_
logging macros do not expand to a single expression and therefore cannot be used in brace-less if
clauses and for
loops. For example, this doesn't compile for me because the compiler sees an unexpected else
:
if (true)
RCLCPP_INFO(node->get_logger(), "true");
else
RCLCPP_INFO(node->get_logger(), "false");
Is this expected?
Edit: added the mistakenly elided semi-colons from the original question
"Expected" I don't know, but yes, all
RCLCPP_*
macros are two-liners: see here.Might be an oversight: perhaps they should be wrapped in
do { } while(0);
constructs?There was some discussion about this last fall here. I suspect that
;
's might help you in the above example, but, otherwise, ROS 2 linters require curly braces on all if statements, so it's understandable as to how this was not caught earlier.