| 1 |
// RUN: %clang_analyze_cc1 -analyzer-checker=core.DivideZero -std=c++20 -verify %s |
| 2 |
|
| 3 |
namespace GH148875 { |
| 4 |
struct A { |
| 5 |
int x; |
| 6 |
A(int v) : x(v) {} |
| 7 |
}; |
| 8 |
|
| 9 |
struct B { |
| 10 |
int x; |
| 11 |
B() : x(0) {} |
| 12 |
}; |
| 13 |
|
| 14 |
struct C { |
| 15 |
int x, y; |
| 16 |
C(int a, int b) : x(a), y(b) {} |
| 17 |
}; |
| 18 |
|
| 19 |
struct D { |
| 20 |
int x; |
| 21 |
}; |
| 22 |
|
| 23 |
struct E { |
| 24 |
D d; |
| 25 |
E(int a) : d(a) {} |
| 26 |
}; |
| 27 |
|
| 28 |
struct F { |
| 29 |
int x; |
| 30 |
}; |
| 31 |
|
| 32 |
int t1() { |
| 33 |
A a{42}; |
| 34 |
return 1 / (a.x - 42); // expected-warning {{Division by zero}} |
| 35 |
} |
| 36 |
|
| 37 |
int t2() { |
| 38 |
B b{}; |
| 39 |
return 1 / b.x; // expected-warning {{Division by zero}} |
| 40 |
} |
| 41 |
|
| 42 |
int t3() { |
| 43 |
C c1{1, -1}; |
| 44 |
return 1 / (c1.x + c1.y); // expected-warning {{Division by zero}} |
| 45 |
} |
| 46 |
|
| 47 |
int t4() { |
| 48 |
C c2{0, 0}; |
| 49 |
return 1 / (c2.x + c2.y); // expected-warning {{Division by zero}} |
| 50 |
} |
| 51 |
|
| 52 |
int t5() { |
| 53 |
E e{32}; |
| 54 |
return 1 / (e.d.x - 32); // expected-warning {{Division by zero}} |
| 55 |
} |
| 56 |
|
| 57 |
int t6() { |
| 58 |
F f(32); |
| 59 |
return 1 / (f.x - 32); // expected-warning {{Division by zero}} |
| 60 |
} |
| 61 |
} // namespace GH148875 |