diff options
Diffstat (limited to 'clang/test')
| -rw-r--r-- | clang/test/Analysis/osobject-retain-release.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/clang/test/Analysis/osobject-retain-release.cpp b/clang/test/Analysis/osobject-retain-release.cpp index ca5dfbf707c..81cf2a1f210 100644 --- a/clang/test/Analysis/osobject-retain-release.cpp +++ b/clang/test/Analysis/osobject-retain-release.cpp @@ -23,6 +23,9 @@ struct OSObject { static OSObject *getObject(); static OSObject *GetObject(); + + static void * operator new(unsigned long size); + static const OSMetaClass * const metaClass; }; @@ -62,6 +65,18 @@ struct OSMetaClassBase { static OSObject *safeMetaCast(const OSObject *inst, const OSMetaClass *meta); }; +unsigned int check_leak_explicit_new() { + OSArray *arr = new OSArray; // expected-note{{Operator new returns an OSObject of type struct OSArray * with a +1 retain count}} + return arr->getCount(); // expected-note{{Object leaked: allocated object of type struct OSArray * is not referenced later in this execution path and has a retain count of +1}} + // expected-warning@-1{{Potential leak of an object of type struct OSArray *}} +} + +unsigned int check_leak_factory() { + OSArray *arr = OSArray::withCapacity(10); // expected-note{{Call to function 'OSArray::withCapacity' returns an OSObject of type struct OSArray * with a +1 retain count}} + return arr->getCount(); // expected-note{{Object leaked: object allocated and stored into 'arr' is not referenced later in this execution path and has a retain count of +1}} + // expected-warning@-1{{Potential leak of an object stored into 'arr'}} +} + void check_get_object() { OSObject::getObject(); } |

