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