[LLVMbugs] [Bug 11425] New: False "potential leak" positive in static analyzer with a typesafe cast function

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Nov 22 20:46:52 PST 2011


             Bug #: 11425
           Summary: False "potential leak" positive in static analyzer
                    with a typesafe cast function
           Product: clang
           Version: unspecified
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Static Analyzer
        AssignedTo: kremenek at apple.com
        ReportedBy: nicolasweber at gmx.de
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

$ cat test.mm
#import <Foundation/Foundation.h>

template<class T>
class scoped_nsobject {
  scoped_nsobject(T* t) : t_(t) {}
  virtual ~scoped_nsobject() { [t_ release]; }

  operator T*() { return t_; }
  T* t_;

#define CF_TO_NS_CAST_DEFN(TypeCF, TypeNS) \
TypeNS* CFToNSCast(TypeCF##Ref cf_val) { \
  TypeNS* ns_val = \
      const_cast<TypeNS*>(reinterpret_cast<const TypeNS*>(cf_val)); \
  return ns_val; \

CF_TO_NS_CAST_DEFN(CFDictionary, NSDictionary);

int main() {
  ProcessSerialNumber psn = { 0, kCurrentProcess };
  scoped_nsobject<NSDictionary> process_info(
      // works:

$ scan-build  clang++ test.mm -framework Foundation -framework

scan-build: Using 'clang' from path:
test.mm:31:18: warning: Potential leak of an object allocated on line 31
1 warning generated.
scan-build: 1 bugs found.

With a c-style cast, the warning goes away.

Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.

More information about the llvm-bugs mailing list