CFDateGC.m revision 88739bff1d856e7087f9b60bd7c2ec292856ee6b
1// RUN: clang -checker-cfref -verify -fobjc-gc %s 2 3//===----------------------------------------------------------------------===// 4// The following code is reduced using delta-debugging from 5// Foundation.h and CoreFoundation.h (Mac OS X). 6// 7// It includes the basic definitions for the test cases below. 8// Not directly including [Core]Foundation.h directly makes this test case 9// both svelt and portable to non-Mac platforms. 10//===----------------------------------------------------------------------===// 11 12typedef const void * CFTypeRef; 13typedef const struct __CFAllocator * CFAllocatorRef; 14typedef double CFTimeInterval; 15typedef CFTimeInterval CFAbsoluteTime; 16typedef const struct __CFDate * CFDateRef; 17extern CFDateRef CFDateCreate(CFAllocatorRef allocator, CFAbsoluteTime at); 18typedef signed char BOOL; 19typedef unsigned int NSUInteger; 20typedef struct _NSZone NSZone; 21static __inline__ __attribute__((always_inline)) id NSMakeCollectable(CFTypeRef cf) {} 22@protocol NSObject - (BOOL)isEqual:(id)object; - (oneway void)release; @end 23extern id NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone); 24 25//===----------------------------------------------------------------------===// 26// Test cases. 27//===----------------------------------------------------------------------===// 28 29CFAbsoluteTime f1() { 30 CFAbsoluteTime t = CFAbsoluteTimeGetCurrent(); 31 CFDateRef date = CFDateCreate(0, t); 32 CFRetain(date); 33 [NSMakeCollectable(date) release]; 34 CFDateGetAbsoluteTime(date); // no-warning 35 CFRelease(date); 36 t = CFDateGetAbsoluteTime(date); // expected-warning{{Reference-counted object is used after it is released.}} 37 return t; 38} 39 40