Skip to content

Commit f7bb88f

Browse files
authored
Use parantheses around logging macro parameter (#1820)
* Use parantheses around logging macro parameter This allows the macro to expand "correctly", i.e. macro argument expression is fully evaluated before use. Signed-off-by: Abrar Rahman Protyasha <aprotyas@u.rochester.edu> * Remove redundant parantheses around macro param `decltype(X)` already provides sufficient "scoping" to the macro parameter `X`. Signed-off-by: Abrar Rahman Protyasha <aprotyas@u.rochester.edu> * Add test case for expressions as logging param Signed-off-by: Abrar Rahman Protyasha <aprotyas@u.rochester.edu>
1 parent 0781ea5 commit f7bb88f

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

rclcpp/resource/logging.hpp.em

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def get_rclcpp_suffix_from_features(features):
149149
@[ if params]@
150150
@(''.join([' ' + p + ', \\\n' for p in params if p != stream_arg]))@
151151
@[ end if]@
152-
logger.get_name(), \
152+
(logger).get_name(), \
153153
@[ if 'stream' not in feature_combination]@
154154
__VA_ARGS__); \
155155
@[ else]@

rclcpp/test/rclcpp/test_logging.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,12 @@ TEST_F(TestLoggingMacros, test_throttle) {
229229
}
230230
}
231231

232+
TEST_F(TestLoggingMacros, test_parameter_expression) {
233+
RCLCPP_DEBUG_STREAM(*&g_logger, "message");
234+
EXPECT_EQ(1u, g_log_calls);
235+
EXPECT_EQ("message", g_last_log_event.message);
236+
}
237+
232238
bool log_function(rclcpp::Logger logger)
233239
{
234240
RCLCPP_INFO(logger, "successful log");

0 commit comments

Comments
 (0)