1 | // RUN: %check_clang_tidy %s readability-avoid-nested-conditional-operator %t |
2 | |
3 | int NestInConditional = (true ? true : false) ? 1 : 2; |
4 | // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: conditional operator is used as sub-expression of parent conditional operator, refrain from using nested conditional operators |
5 | // CHECK-MESSAGES: :[[@LINE-2]]:25: note: parent conditional operator here |
6 | |
7 | int NestInTrue = true ? (true ? 1 : 2) : 2; |
8 | // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: conditional operator is used as sub-expression of parent conditional operator, refrain from using nested conditional operators |
9 | // CHECK-MESSAGES: :[[@LINE-2]]:18: note: parent conditional operator here |
10 | |
11 | int NestInFalse = true ? 1 : true ? 1 : 2; |
12 | // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: conditional operator is used as sub-expression of parent conditional operator, refrain from using nested conditional operators |
13 | // CHECK-MESSAGES: :[[@LINE-2]]:19: note: parent conditional operator here |
14 | int NestInFalse2 = true ? 1 : (true ? 1 : 2); |
15 | // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: conditional operator is used as sub-expression of parent conditional operator, refrain from using nested conditional operators |
16 | // CHECK-MESSAGES: :[[@LINE-2]]:20: note: parent conditional operator here |
17 | |
18 | int NestWithParensis = true ? 1 : ((((true ? 1 : 2)))); |
19 | // CHECK-MESSAGES: :[[@LINE-1]]:39: warning: conditional operator is used as sub-expression of parent conditional operator, refrain from using nested conditional operators |
20 | // CHECK-MESSAGES: :[[@LINE-2]]:24: note: parent conditional operator here |
21 | |
22 | #define CONDITIONAL_EXPR (true ? 1 : 2) |
23 | // not diag for macro since it will not reduce readability |
24 | int NestWithMacro = true ? CONDITIONAL_EXPR : 2; |
25 | |