diff options
Diffstat (limited to 'clang/test/Analysis/identical-expressions.cpp')
| -rw-r--r-- | clang/test/Analysis/identical-expressions.cpp | 151 |
1 files changed, 151 insertions, 0 deletions
diff --git a/clang/test/Analysis/identical-expressions.cpp b/clang/test/Analysis/identical-expressions.cpp index 3a331fb8f2f..acb7c8c57b0 100644 --- a/clang/test/Analysis/identical-expressions.cpp +++ b/clang/test/Analysis/identical-expressions.cpp @@ -1043,6 +1043,11 @@ void test_float() { a = a > 5 ? a : a; // expected-warning {{identical expressions on both sides of ':' in conditional expression}} } +const char *test_string() { + float a = 0; + return a > 5 ? "abc" : "abc"; // expected-warning {{identical expressions on both sides of ':' in conditional expression}} +} + void test_unsigned_expr() { unsigned a = 0; unsigned b = 0; @@ -1158,3 +1163,149 @@ void test_signed_nested_cond_expr() { int c = 3; a = a > 5 ? (b > 5 ? 1 : 4) : (b > 5 ? 4 : 4); // expected-warning {{identical expressions on both sides of ':' in conditional expression}} } + +void test_identical_branches1(bool b) { + int i = 0; + if (b) { // expected-warning {{true and false branches are identical}} + ++i; + } else { + ++i; + } +} + +void test_identical_branches2(bool b) { + int i = 0; + if (b) { // expected-warning {{true and false branches are identical}} + ++i; + } else + ++i; +} + +void test_identical_branches3(bool b) { + int i = 0; + if (b) { // no warning + ++i; + } else { + i++; + } +} + +void test_identical_branches4(bool b) { + int i = 0; + if (b) { // expected-warning {{true and false branches are identical}} + } else { + } +} + +void test_identical_branches_break(bool b) { + while (true) { + if (b) // expected-warning {{true and false branches are identical}} + break; + else + break; + } +} + +void test_identical_branches_continue(bool b) { + while (true) { + if (b) // expected-warning {{true and false branches are identical}} + continue; + else + continue; + } +} + +void test_identical_branches_func(bool b) { + if (b) // expected-warning {{true and false branches are identical}} + func(); + else + func(); +} + +void test_identical_branches_func_arguments(bool b) { + if (b) // no-warning + funcParam(1); + else + funcParam(2); +} + +void test_identical_branches_cast1(bool b) { + long v = -7; + if (b) // no-warning + v = (signed int) v; + else + v = (unsigned int) v; +} + +void test_identical_branches_cast2(bool b) { + long v = -7; + if (b) // expected-warning {{true and false branches are identical}} + v = (signed int) v; + else + v = (signed int) v; +} + +int test_identical_branches_return_int(bool b) { + int i = 0; + if (b) { // expected-warning {{true and false branches are identical}} + i++; + return i; + } else { + i++; + return i; + } +} + +int test_identical_branches_return_func(bool b) { + if (b) { // expected-warning {{true and false branches are identical}} + return func(); + } else { + return func(); + } +} + +void test_identical_branches_for(bool b) { + int i; + int j; + if (b) { // expected-warning {{true and false branches are identical}} + for (i = 0, j = 0; i < 10; i++) + j += 4; + } else { + for (i = 0, j = 0; i < 10; i++) + j += 4; + } +} + +void test_identical_branches_while(bool b) { + int i = 10; + if (b) { // expected-warning {{true and false branches are identical}} + while (func()) + i--; + } else { + while (func()) + i--; + } +} + +void test_identical_branches_do_while(bool b) { + int i = 10; + if (b) { // expected-warning {{true and false branches are identical}} + do { + i--; + } while (func()); + } else { + do { + i--; + } while (func()); + } +} + +void test_identical_branches_if(bool b, int i) { + if (b) { // expected-warning {{true and false branches are identical}} + if (i < 5) + i += 10; + } else { + if (i < 5) + i += 10; + } +} |

