George Karpenkov | cf40ba8 | 2018-08-09 19:03:12 +0000 | [diff] [blame] | 1 | // RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.cplusplus.UninitializedObject -std=c++11 -fblocks -verify %s |
| 2 | |
| 3 | typedef void (^myBlock) (); |
| 4 | |
| 5 | struct StructWithBlock { |
| 6 | int a; |
Kristof Umann | 015b059 | 2018-08-13 18:43:08 +0000 | [diff] [blame] | 7 | myBlock z; // expected-note{{uninitialized pointer 'this->z'}} |
George Karpenkov | cf40ba8 | 2018-08-09 19:03:12 +0000 | [diff] [blame] | 8 | |
| 9 | StructWithBlock() : a(0), z(^{}) {} |
| 10 | |
| 11 | // Miss initialization of field `z`. |
| 12 | StructWithBlock(int pA) : a(pA) {} // expected-warning{{1 uninitialized field at the end of the constructor call}} |
| 13 | |
| 14 | }; |
| 15 | |
| 16 | void warnOnUninitializedBlock() { |
| 17 | StructWithBlock a(10); |
| 18 | } |
| 19 | |
| 20 | void noWarningWhenInitialized() { |
| 21 | StructWithBlock a; |
| 22 | } |
George Karpenkov | e3b1d96 | 2018-08-13 23:32:15 +0000 | [diff] [blame^] | 23 | |
| 24 | struct StructWithId { |
| 25 | int a; |
| 26 | id z; // expected-note{{uninitialized pointer 'this->z'}} |
| 27 | StructWithId() : a(0) {} // expected-warning{{1 uninitialized field at the end of the constructor call}} |
| 28 | }; |
| 29 | |
| 30 | void warnOnUninitializedId() { |
| 31 | StructWithId s; |
| 32 | } |