Skip to content

Commit a5e33d5

Browse files
committed
Fix macro argument parentheses for clang-tidy compliance
Add proper parentheses around macro arguments in ADA_ASSERT_EQUAL, ADA_ASSERT_TRUE, and ADA_ASSUME macros to prevent operator precedence issues and comply with clang-tidy's bugprone-macro-parentheses check. This is a safety improvement that prevents potential bugs when macro arguments contain expressions with lower-precedence operators. Fixes: - ADA_ASSERT_EQUAL: Wrap LHS and RHS in comparisons and output - ADA_ASSERT_TRUE: Wrap COND in negation check - ADA_ASSUME: Wrap COND in both MSVC and GCC/Clang versions
1 parent 644b574 commit a5e33d5

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

include/ada/common_defs.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,14 @@ namespace ada {
203203
} while (0);
204204
#define ADA_ASSERT_EQUAL(LHS, RHS, MESSAGE) \
205205
do { \
206-
if (LHS != RHS) { \
207-
std::cerr << "Mismatch: '" << LHS << "' - '" << RHS << "'" << std::endl; \
206+
if ((LHS) != (RHS)) { \
207+
std::cerr << "Mismatch: '" << (LHS) << "' - '" << (RHS) << "'" << std::endl; \
208208
ADA_FAIL(MESSAGE); \
209209
} \
210210
} while (0);
211211
#define ADA_ASSERT_TRUE(COND) \
212212
do { \
213-
if (!(COND)) { \
213+
if (!((COND))) { \
214214
std::cerr << "Assert at line " << __LINE__ << " of file " << __FILE__ \
215215
<< std::endl; \
216216
ADA_FAIL(ADA_STR(COND)); \
@@ -223,11 +223,11 @@ namespace ada {
223223
#endif
224224

225225
#ifdef ADA_VISUAL_STUDIO
226-
#define ADA_ASSUME(COND) __assume(COND)
226+
#define ADA_ASSUME(COND) __assume((COND))
227227
#else
228228
#define ADA_ASSUME(COND) \
229229
do { \
230-
if (!(COND)) { \
230+
if (!((COND))) { \
231231
__builtin_unreachable(); \
232232
} \
233233
} while (0)

0 commit comments

Comments
 (0)