1 // RUN: %clang_analyze_cc1 -analyzer-checker=optin.osx.OSObjectCStyleCast %s -verify 2 #include "os_object_base.h" 3 4 struct OSArray : public OSObject { 5 unsigned getCount(); 6 }; 7 8 struct A { 9 int x; 10 }; 11 struct B : public A { 12 unsigned getCount(); 13 }; 14 15 unsigned warn_on_explicit_downcast(OSObject * obj) { 16 OSArray *a = (OSArray *) obj; // expected-warning{{C-style cast of OSObject. Use OSDynamicCast instead}} 17 return a->getCount(); 18 } 19 20 void no_warn_on_upcast(OSArray *arr) { 21 OSObject *obj = (OSObject *) arr; 22 obj->retain(); 23 obj->release(); 24 } 25 26 unsigned no_warn_on_dynamic_cast(OSObject *obj) { 27 OSArray *a = OSDynamicCast(OSArray, obj); 28 return a->getCount(); 29 } 30 31 __SIZE_TYPE__ no_warn_on_primitive_conversion(OSArray *arr) { 32 return (__SIZE_TYPE__) arr; 33 } 34 35 unsigned no_warn_on_other_type_cast(A *a) { 36 B *b = (B *) a; 37 return b->getCount(); 38 } 39 40