1 // RUN: %check_clang_tidy %s bugprone-macro-parentheses %t 2 3 #define BAD1 -1 4 // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: macro replacement list should be enclosed in parentheses [bugprone-macro-parentheses] 5 #define BAD2 1+2 6 // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: macro replacement list should be enclosed in parentheses [bugprone-macro-parentheses] 7 #define BAD3(A) (A+1) 8 // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: macro argument should be enclosed in parentheses [bugprone-macro-parentheses] 9 #define BAD4(x) ((unsigned char)(x & 0xff)) 10 // CHECK-MESSAGES: :[[@LINE-1]]:44: warning: macro argument should be enclosed in parentheses [bugprone-macro-parentheses] 11 #define BAD5(X) A*B=(C*)X+2 12 // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: macro argument should be enclosed in parentheses [bugprone-macro-parentheses] 13 14 #define GOOD1 1 15 #define GOOD2 (1+2) 16 #define GOOD3(A) #A 17 #define GOOD4(A,B) A ## B 18 #define GOOD5(T) ((T*)0) 19 #define GOOD6(B) "A" B "C" 20 #define GOOD7(b) A b 21 #define GOOD8(a) a B 22 #define GOOD9(type) (type(123)) 23 #define GOOD10(car, ...) car 24 #define GOOD11 a[b+c] 25 #define GOOD12(x) a[x] 26 #define GOOD13(x) a.x 27 #define GOOD14(x) a->x 28 #define GOOD15(x) ({ int a = x; a+4; }) 29 #define GOOD16(x) a_ ## x, b_ ## x = c_ ## x - 1, 30 #define GOOD17 case 123: x=4+5; break; 31 #define GOOD18(x) ;x; 32 #define GOOD19 ;-2; 33 #define GOOD20 void* 34 #define GOOD21(a) case Fred::a: 35 #define GOOD22(a) if (verbose) return a; 36 #define GOOD23(type) (type::Field) 37 #define GOOD24(t) std::set<t> s 38 #define GOOD25(t) std::set<t,t,t> s 39 #define GOOD26(x) (a->*x) 40 #define GOOD27(x) (a.*x) 41 #define GOOD28(x) namespace x {int b;} 42 #define GOOD29(...) std::cout << __VA_ARGS__; 43 #define GOOD30(args...) std::cout << args; 44 #define GOOD31(X) A*X=2 45 #define GOOD32(X) std::vector<X> 46 #define GOOD33(x) if (!a__##x) a_##x = &f(#x) 47 48 // These are allowed for now.. 49 #define MAYBE1 *12.34 50 #define MAYBE2 <<3 51