40 lines · cpp
1// RUN: %clang_analyze_cc1 -analyzer-checker=core.DivideZero -verify %s2 3int div0LogicalOpInTernary(bool b1) {4 int y = (b1 || b1) ? 0 : 1;5 return 1 / y; // expected-warning {{Division by zero}}6}7 8int div0LogicalAndArith(bool b1, int x) {9 int y = (b1 || (x < 3)) ? 0 : 1;10 return 1 / y; // expected-warning {{Division by zero}}11}12 13int div0NestedLogicalOp(bool b1) {14 int y = (b1 && b1 || b1 && b1) ? 0 : 1;15 return 1 / y; // expected-warning {{Division by zero}}16}17 18int div0TernaryInTernary(bool b) {19 int y = ((b || b) ? false : true) ? 0 : 1;20 return 1 / y; // expected-warning {{Division by zero}}21}22 23int div0LogicalOpParensInTernary(bool b1) {24 int y = ((((b1)) || ((b1)))) ? 0 : 1;25 return 1 / y; // expected-warning {{Division by zero}}26}27 28int div0LogicalOpInsideStExpr(bool b1) {29 int y = ({1; (b1 || b1);}) ? 0 : 1;30 // expected-warning@-1 {{expression result unused}}31 return 1 / y; // expected-warning {{Division by zero}}32}33 34int div0StExprInsideLogicalOp(bool b1) {35 int y = (({1; b1;}) || ({1; b1;})) ? 0 : 1;36 // expected-warning@-1 {{expression result unused}}37 // expected-warning@-2 {{expression result unused}}38 return 1 / y; // expected-warning {{Division by zero}}39}40