1 // RUN: %clang_analyze_cc1 -analyze -analyzer-checker core -analyzer-config cfg-temporary-dtors=true,c++-temp-dtor-inlining=true -analyzer-output=text -verify %s
2
3 namespace test_simple_temporary {
4 class C {
5 int x;
6
7 public:
C(int x)8 C(int x): x(x) {} // expected-note{{The value 0 is assigned to field 'x'}}
~C()9 ~C() { x = 1 / x; } // expected-warning{{Division by zero}}
10 // expected-note@-1{{Division by zero}}
11 };
12
test()13 void test() {
14 C(0); // expected-note {{Passing the value 0 via 1st parameter 'x'}}
15 // expected-note@-1{{Calling constructor for 'C'}}
16 // expected-note@-2{{Returning from constructor for 'C'}}
17 // expected-note@-3{{Calling '~C'}}
18 }
19 } // end namespace test_simple_temporary
20
21 namespace test_lifetime_extended_temporary {
22 class C {
23 int x;
24
25 public:
C(int x)26 C(int x): x(x) {} // expected-note{{The value 0 is assigned to field 'x'}}
nop() const27 void nop() const {}
~C()28 ~C() { x = 1 / x; } // expected-warning{{Division by zero}}
29 // expected-note@-1{{Division by zero}}
30 };
31
test(int coin)32 void test(int coin) {
33 // We'd divide by zero in the automatic destructor for variable 'c'.
34 const C &c = coin ? C(1) : C(0); // expected-note {{Assuming 'coin' is 0}}
35 // expected-note@-1{{'?' condition is false}}
36 // expected-note@-2{{Passing the value 0 via 1st parameter 'x'}}
37 // expected-note@-3{{Calling constructor for 'C'}}
38 // expected-note@-4{{Returning from constructor for 'C'}}
39 c.nop();
40 } // expected-note{{Calling '~C'}}
41 } // end namespace test_lifetime_extended_temporary
42
43 namespace test_bug_after_dtor {
44 int glob;
45
46 class C {
47 public:
C()48 C() { glob += 1; }
~C()49 ~C() { glob -= 2; } // expected-note{{The value 0 is assigned to 'glob'}}
50 };
51
test()52 void test() {
53 glob = 1;
54 C(); // expected-note {{Calling '~C'}}
55 // expected-note@-1{{Returning from '~C'}}
56 glob = 1 / glob; // expected-warning{{Division by zero}}
57 // expected-note@-1{{Division by zero}}
58 }
59 } // end namespace test_bug_after_dtor
60