1// RUN: %check_clang_tidy -check-suffixes=,MACROS %s readability-simplify-boolean-expr %t
2
3// Ignore expressions in macros.
4// RUN: %check_clang_tidy %s readability-simplify-boolean-expr %t \
5// RUN: -- -config="{CheckOptions: {readability-simplify-boolean-expr.IgnoreMacros: true}}" \
6// RUN: --
7
8#define NEGATE(expr) !(expr)
9#define NOT_AND_NOT(a, b) (!a && !b)
10
11bool without_macro(bool a, bool b) {
12 return !(!a && b);
13 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: boolean expression can be simplified by DeMorgan's theorem
14 // CHECK-FIXES: return a || !b;
15}
16
17void macro(bool a, bool b) {
18 NEGATE(!a && b);
19 // CHECK-MESSAGES-MACROS: :[[@LINE-1]]:5: warning: boolean expression can be simplified by DeMorgan's theorem
20 // CHECK-FIXES: NEGATE(!a && b);
21 !NOT_AND_NOT(a, b);
22 // CHECK-MESSAGES-MACROS: :[[@LINE-1]]:5: warning: boolean expression can be simplified by DeMorgan's theorem
23 // CHECK-FIXES: !NOT_AND_NOT(a, b);
24 !(NEGATE(a) && b);
25 // CHECK-MESSAGES-MACROS: :[[@LINE-1]]:5: warning: boolean expression can be simplified by DeMorgan's theorem
26 // CHECK-FIXES: !(NEGATE(a) && b);
27 !(a && NEGATE(b));
28 // CHECK-MESSAGES-MACROS: :[[@LINE-1]]:5: warning: boolean expression can be simplified by DeMorgan's theorem
29 // CHECK-FIXES: !(a && NEGATE(b));
30}
31

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of clang-tools-extra/test/clang-tidy/checkers/readability/simplify-boolean-expr-macros.cpp