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: 8 C(int x): x(x) {} // expected-note{{The value 0 is assigned to field 'x'}} 9 ~C() { x = 1 / x; } // expected-warning{{Division by zero}} 10 // expected-note@-1{{Division by zero}} 11 }; 12 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: 26 C(int x): x(x) {} // expected-note{{The value 0 is assigned to field 'x'}} 27 void nop() const {} 28 ~C() { x = 1 / x; } // expected-warning{{Division by zero}} 29 // expected-note@-1{{Division by zero}} 30 }; 31 32 void test(int coin) { 33 // We'd divide by zero in the temporary destructor that goes after the 34 // elidable copy-constructor from C(0) to the lifetime-extended temporary. 35 // So in fact this example has nothing to do with lifetime extension. 36 // Actually, it would probably be better to elide the constructor, and 37 // put the note for the destructor call at the closing brace after nop. 38 const C &c = coin ? C(1) : C(0); // expected-note {{Assuming 'coin' is 0}} 39 // expected-note@-1{{'?' condition is false}} 40 // expected-note@-2{{Passing the value 0 via 1st parameter 'x'}} 41 // expected-note@-3{{Calling constructor for 'C'}} 42 // expected-note@-4{{Returning from constructor for 'C'}} 43 // expected-note@-5{{Calling '~C'}} 44 c.nop(); 45 } 46 } // end namespace test_lifetime_extended_temporary 47 48 namespace test_bug_after_dtor { 49 int glob; 50 51 class C { 52 public: 53 C() { glob += 1; } 54 ~C() { glob -= 2; } // expected-note{{The value 0 is assigned to 'glob'}} 55 }; 56 57 void test() { 58 glob = 1; 59 C(); // expected-note {{Calling '~C'}} 60 // expected-note@-1{{Returning from '~C'}} 61 glob = 1 / glob; // expected-warning{{Division by zero}} 62 // expected-note@-1{{Division by zero}} 63 } 64 } // end namespace test_bug_after_dtor 65