25 lines · cpp
1// RUN: %check_clang_tidy %s readability-avoid-nested-conditional-operator %t2 3int 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 operators5// CHECK-MESSAGES: :[[@LINE-2]]:25: note: parent conditional operator here6 7int 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 operators9// CHECK-MESSAGES: :[[@LINE-2]]:18: note: parent conditional operator here10 11int 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 operators13// CHECK-MESSAGES: :[[@LINE-2]]:19: note: parent conditional operator here14int 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 operators16// CHECK-MESSAGES: :[[@LINE-2]]:20: note: parent conditional operator here17 18int 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 operators20// CHECK-MESSAGES: :[[@LINE-2]]:24: note: parent conditional operator here21 22#define CONDITIONAL_EXPR (true ? 1 : 2)23// not diag for macro since it will not reduce readability24int NestWithMacro = true ? CONDITIONAL_EXPR : 2;25