1 // RUN: %clang_analyze_cc1 -std=c++14 -analyzer-checker=optin.osx.OSObjectCStyleCast %s -verify
2 #include "os_object_base.h"
4 struct OSArray
: public OSObject
{
15 unsigned warn_on_explicit_downcast(OSObject
* obj
) {
16 OSArray
*a
= (OSArray
*) obj
; // expected-warning{{C-style cast of an OSObject is prone to type confusion attacks; use 'OSRequiredCast' if the object is definitely of type 'OSArray', or 'OSDynamicCast' followed by a null check if unsure}}
20 void no_warn_on_upcast(OSArray
*arr
) {
21 OSObject
*obj
= (OSObject
*) arr
;
26 unsigned no_warn_on_dynamic_cast(OSObject
*obj
) {
27 OSArray
*a
= OSDynamicCast(OSArray
, obj
);
31 __SIZE_TYPE__
no_warn_on_primitive_conversion(OSArray
*arr
) {
32 return (__SIZE_TYPE__
) arr
;
35 unsigned no_warn_on_other_type_cast(A
*a
) {
40 unsigned no_warn_alloc_class_with_name() {
41 OSArray
*a
= (OSArray
*)OSMetaClass::allocClassWithName("OSArray"); // no warning
45 unsigned warn_alloc_class_with_name() {
46 OSArray
*a
= (OSArray
*)OSMetaClass::allocClassWithName("OSObject"); // expected-warning{{C-style cast of an OSObject is prone to type confusion attacks; use 'OSRequiredCast' if the object is definitely of type 'OSArray', or 'OSDynamicCast' followed by a null check if unsure}}