use do { .. } while(0) around content of logging macros (#681)

Signed-off-by: Dirk Thomas <dirk-thomas@users.noreply.github.com>
This commit is contained in:
Dirk Thomas 2019-04-03 06:16:57 -07:00 committed by GitHub
parent 1f2904f980
commit 8783cdcf96
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -71,6 +71,9 @@ def is_supported_feature_combination(feature_combination):
#else #else
@[ for feature_combination in [fc for fc in feature_combinations if is_supported_feature_combination(fc)]]@ @[ for feature_combination in [fc for fc in feature_combinations if is_supported_feature_combination(fc)]]@
@{suffix = get_suffix_from_features(feature_combination)}@ @{suffix = get_suffix_from_features(feature_combination)}@
// The RCLCPP_@(severity)@(suffix) macro is surrounded by do { .. } while (0)
// to implement the standard C macro idiom to make the macro safe in all
// contexts; see http://c-faq.com/cpp/multistmt.html for more information.
/** /**
* \def RCLCPP_@(severity)@(suffix) * \def RCLCPP_@(severity)@(suffix)
* Log a message with severity @(severity)@ * Log a message with severity @(severity)@
@ -90,6 +93,7 @@ def is_supported_feature_combination(feature_combination):
* It also accepts a single argument of type std::string. * It also accepts a single argument of type std::string.
*/ */
#define RCLCPP_@(severity)@(suffix)(logger, @(''.join([p + ', ' for p in get_macro_parameters(feature_combination).keys()]))...) \ #define RCLCPP_@(severity)@(suffix)(logger, @(''.join([p + ', ' for p in get_macro_parameters(feature_combination).keys()]))...) \
do { \
static_assert( \ static_assert( \
::std::is_same<typename std::remove_reference<decltype(logger)>::type, \ ::std::is_same<typename std::remove_reference<decltype(logger)>::type, \
typename ::rclcpp::Logger>::value, \ typename ::rclcpp::Logger>::value, \
@ -101,7 +105,8 @@ def is_supported_feature_combination(feature_combination):
@[ end if]@ @[ end if]@
logger.get_name(), \ logger.get_name(), \
rclcpp::get_c_string(RCLCPP_FIRST_ARG(__VA_ARGS__, "")), \ rclcpp::get_c_string(RCLCPP_FIRST_ARG(__VA_ARGS__, "")), \
RCLCPP_ALL_BUT_FIRST_ARGS(__VA_ARGS__,"")) RCLCPP_ALL_BUT_FIRST_ARGS(__VA_ARGS__,"")); \
} while (0)
@[ end for]@ @[ end for]@
#endif #endif