74 lines · cpp
1// RUN: %check_clang_tidy %s readability-redundant-parentheses %t2 3void parenExpr() {4 1 + 1;5 (1 + 1);6 ((1 + 1));7 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: redundant parentheses around expression [readability-redundant-parentheses]8 // CHECK-FIXES: (1 + 1);9 (((1 + 1)));10 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: redundant parentheses around expression [readability-redundant-parentheses]11 // CHECK-MESSAGES: :[[@LINE-2]]:4: warning: redundant parentheses around expression [readability-redundant-parentheses]12 // CHECK-FIXES: (1 + 1);13 ((((1 + 1))));14 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: redundant parentheses around expression [readability-redundant-parentheses]15 // CHECK-MESSAGES: :[[@LINE-2]]:4: warning: redundant parentheses around expression [readability-redundant-parentheses]16 // CHECK-MESSAGES: :[[@LINE-3]]:5: warning: redundant parentheses around expression [readability-redundant-parentheses]17 // CHECK-FIXES: (1 + 1);18}19 20#define EXP (1 + 1)21#define PAREN(e) (e)22void parenExprWithMacro() {23 EXP; // 124 (EXP); // 225 ((EXP)); // 326 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: redundant parentheses around expression [readability-redundant-parentheses]27 // CHECK-FIXES: (EXP); // 328 PAREN((1));29}30 31void constant() {32 (1);33 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: redundant parentheses around expression [readability-redundant-parentheses]34 // CHECK-FIXES: 1;35 (1.0);36 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: redundant parentheses around expression [readability-redundant-parentheses]37 // CHECK-FIXES: 1.0;38 (true);39 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: redundant parentheses around expression [readability-redundant-parentheses]40 // CHECK-FIXES: true;41 (',');42 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: redundant parentheses around expression [readability-redundant-parentheses]43 // CHECK-FIXES: ',';44 ("v4");45 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: redundant parentheses around expression [readability-redundant-parentheses]46 // CHECK-FIXES: "v4";47 (nullptr);48 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: redundant parentheses around expression [readability-redundant-parentheses]49 // CHECK-FIXES: nullptr;50}51 52void declRefExpr(int a) {53 (a);54 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: redundant parentheses around expression [readability-redundant-parentheses]55 // CHECK-FIXES: a;56}57 58void exceptions() {59 sizeof(1);60 alignof(2);61 alignof((3));62 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: redundant parentheses around expression [readability-redundant-parentheses]63 // CHECK-FIXES: alignof(3);64}65 66namespace std {67 template<class T> T max(T, T);68 template<class T> T min(T, T);69} // namespace std70void ignoreStdMaxMin() {71 (std::max)(1,2);72 (std::min)(1,2);73}74