From b0564dfd976c7f86184f09616df083d5a0c35816 Mon Sep 17 00:00:00 2001 From: Gerson Fernando Budke Date: Thu, 11 Aug 2022 15:29:56 +0200 Subject: [PATCH] zephyr/ztest_assert.h: Fix implicit to bool conversion The current zassert macro uses implicit conversion to boolean which has implication on analysis tools like clang-tidy-14. This add an aditional step to create a boolean value for the evaluation instead use the string direct which allows run analysis tool without this warning/error. Signed-off-by: Gerson Fernando Budke --- subsys/testsuite/ztest/include/zephyr/ztest_assert.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/subsys/testsuite/ztest/include/zephyr/ztest_assert.h b/subsys/testsuite/ztest/include/zephyr/ztest_assert.h index 0773d3abccd..482f70e5027 100644 --- a/subsys/testsuite/ztest/include/zephyr/ztest_assert.h +++ b/subsys/testsuite/ztest/include/zephyr/ztest_assert.h @@ -132,8 +132,10 @@ static inline bool z_zassume(bool cond, const char *default_msg, const char *fil */ #define zassert(cond, default_msg, msg, ...) \ do { \ - bool _ret = z_zassert(cond, msg ? ("(" default_msg ")") : (default_msg), __FILE__, \ - __LINE__, __func__, msg ? msg : "", ##__VA_ARGS__); \ + bool _msg = (msg != NULL); \ + bool _ret = z_zassert(cond, _msg ? ("(" default_msg ")") : (default_msg), __FILE__,\ + __LINE__, __func__, _msg ? msg : "", ##__VA_ARGS__); \ + (void)_msg; \ if (!_ret) { \ /* If kernel but without multithreading return. */ \ COND_CODE_1(KERNEL, (COND_CODE_1(CONFIG_MULTITHREADING, (), (return;))), \ @@ -161,8 +163,10 @@ static inline bool z_zassume(bool cond, const char *default_msg, const char *fil */ #define zassume(cond, default_msg, msg, ...) \ do { \ - bool _ret = z_zassume(cond, msg ? ("(" default_msg ")") : (default_msg), __FILE__, \ - __LINE__, __func__, msg ? msg : "", ##__VA_ARGS__); \ + bool _msg = (msg != NULL); \ + bool _ret = z_zassume(cond, _msg ? ("(" default_msg ")") : (default_msg), __FILE__,\ + __LINE__, __func__, _msg ? msg : "", ##__VA_ARGS__); \ + (void)_msg; \ if (!_ret) { \ /* If kernel but without multithreading return. */ \ COND_CODE_1(KERNEL, (COND_CODE_1(CONFIG_MULTITHREADING, (), (return;))), \