57 lines · cpp
1// RUN: %check_clang_tidy %s bugprone-macro-parentheses %t2 3#define BAD1 -14// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: macro replacement list should be enclosed in parentheses [bugprone-macro-parentheses]5#define BAD2 1+26// 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+212// CHECK-MESSAGES: :[[@LINE-1]]:35: warning: macro argument should be enclosed in parentheses [bugprone-macro-parentheses]13#define BAD6(x) goto *x;14// CHECK-MESSAGES: :[[@LINE-1]]:33: warning: macro argument should be enclosed in parentheses [bugprone-macro-parentheses]15#define BAD7(x, y) if (x) goto y; else x;16// CHECK-MESSAGES: :[[@LINE-1]]:47: warning: macro argument should be enclosed in parentheses [bugprone-macro-parentheses]17 18#define GOOD1 119#define GOOD2 (1+2)20#define GOOD3(A) #A21#define GOOD4(A,B) A ## B22#define GOOD5(T) ((T*)0)23#define GOOD6(B) "A" B "C"24#define GOOD7(b) A b25#define GOOD8(a) a B26#define GOOD9(type) (type(123))27#define GOOD10(car, ...) car28#define GOOD11 a[b+c]29#define GOOD12(x) a[x]30#define GOOD13(x) a.x31#define GOOD14(x) a->x32#define GOOD15(x) ({ int a = x; a+4; })33#define GOOD16(x) a_ ## x, b_ ## x = c_ ## x - 1,34#define GOOD17 case 123: x=4+5; break;35#define GOOD18(x) ;x;36#define GOOD19 ;-2;37#define GOOD20 void*38#define GOOD21(a) case Fred::a:39#define GOOD22(a) if (verbose) return a;40#define GOOD23(type) (type::Field)41#define GOOD24(t) std::set<t> s42#define GOOD25(t) std::set<t,t,t> s43#define GOOD26(x) (a->*x)44#define GOOD27(x) (a.*x)45#define GOOD28(x) namespace x {int b;}46#define GOOD29(...) std::cout << __VA_ARGS__;47#define GOOD30(args...) std::cout << args;48#define GOOD31(X) A*X=249#define GOOD32(X) std::vector<X>50#define GOOD33(x) if (!a__##x) a_##x = &f(#x)51#define GOOD34(x, y) if (x) goto y;52#define GOOD35(x, y) if (x) goto *(y);53 54// These are allowed for now..55#define MAYBE1 *12.3456#define MAYBE2 <<357