From 23b86e2f3b06d7026fd307211604a7b720a7e021 Mon Sep 17 00:00:00 2001 From: Nisarg Date: Tue, 1 Dec 2026 20:22:07 +0900 Subject: [PATCH 1/2] Only build RCLCPP_LOG_STREAM_EXPRESSION message when expression is true Signed-off-by: Nisarg --- rclcpp/include/rclcpp/logging.hpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/rclcpp/include/rclcpp/logging.hpp b/rclcpp/include/rclcpp/logging.hpp index 5d4948ee8a..e396c45e91 100644 --- a/rclcpp/include/rclcpp/logging.hpp +++ b/rclcpp/include/rclcpp/logging.hpp @@ -205,13 +205,11 @@ #define RCLCPP_LOG_STREAM_EXPRESSION(severity, logger, expression, stream_arg) \ do { \ RCLCPP_STATIC_ASSERT_LOGGER(logger); \ - std::stringstream rclcpp_stream_ss_; \ - rclcpp_stream_ss_ << stream_arg; \ - RCUTILS_LOG_EXPRESSION_NAMED( \ - severity, \ - expression, \ - (logger).get_name(), \ - "%s", rclcpp_stream_ss_.str().c_str()); \ + if (expression) { \ + std::stringstream rclcpp_stream_ss_; \ + rclcpp_stream_ss_ << stream_arg; \ + RCUTILS_LOG_NAMED(severity, (logger).get_name(), "%s", rclcpp_stream_ss_.str().c_str()); \ + } \ } while (0) /** From 52f0f502b149a439de255325d01f4804cebf0cd1 Mon Sep 17 00:00:00 2001 From: Nisarg Date: Tue, 1 Dec 2026 20:41:05 +0900 Subject: [PATCH 2/2] fix Signed-off-by: Nisarg --- rclcpp/include/rclcpp/logging.hpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/rclcpp/include/rclcpp/logging.hpp b/rclcpp/include/rclcpp/logging.hpp index e396c45e91..61c316f3ea 100644 --- a/rclcpp/include/rclcpp/logging.hpp +++ b/rclcpp/include/rclcpp/logging.hpp @@ -205,11 +205,15 @@ #define RCLCPP_LOG_STREAM_EXPRESSION(severity, logger, expression, stream_arg) \ do { \ RCLCPP_STATIC_ASSERT_LOGGER(logger); \ - if (expression) { \ - std::stringstream rclcpp_stream_ss_; \ - rclcpp_stream_ss_ << stream_arg; \ - RCUTILS_LOG_NAMED(severity, (logger).get_name(), "%s", rclcpp_stream_ss_.str().c_str()); \ - } \ + RCUTILS_LOG_EXPRESSION_NAMED( \ + severity, \ + expression, \ + (logger).get_name(), \ + "%s", ([&]() { \ + std::stringstream rclcpp_stream_ss_; \ + rclcpp_stream_ss_ << stream_arg; \ + return rclcpp_stream_ss_.str(); \ + }()).c_str()); \ } while (0) /**