[cfe-commits] r153069 - /cfe/trunk/test/Analysis/retain-release.mm

Ted Kremenek kremenek at apple.com
Mon Mar 19 17:10:36 PDT 2012


Author: kremenek
Date: Mon Mar 19 19:10:35 2012
New Revision: 153069

URL: http://llvm.org/viewvc/llvm-project?rev=153069&view=rev
Log:
Add test case for <rdar://problem/10553686>, which illustrates RetainCount checker working with inlined C++ template functions.

Modified:
    cfe/trunk/test/Analysis/retain-release.mm

Modified: cfe/trunk/test/Analysis/retain-release.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/retain-release.mm?rev=153069&r1=153068&r2=153069&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/retain-release.mm (original)
+++ cfe/trunk/test/Analysis/retain-release.mm Mon Mar 19 19:10:35 2012
@@ -321,3 +321,29 @@
   NSString *token = (NSString*) Scopy();
   [token release]; // expected-warning {{object that is not owned}}
 }
+
+//===----------------------------------------------------------------------===//
+// Test handling of template functions used to do magic with
+// tracked retained pointers.
+//===----------------------------------------------------------------------===//
+
+template <typename T, typename U> T static_objc_cast(U* value)
+{
+  // ...debugging code omitted...
+  return static_cast<T>(value);
+}
+
+int rdar10553686(void)
+{
+  NSObject* bar = static_objc_cast<NSObject*>([[NSObject alloc] init]);
+  [bar release];
+  return 0;
+}
+int rdar10553686_positive(void)
+{
+  NSObject* bar = static_objc_cast<NSObject*>([[NSObject alloc] init]); // expected-warning {{Potential leak}}
+  [bar release];
+  [bar retain];
+  return 0;
+}
+





More information about the cfe-commits mailing list