diff --git a/infer/src/clang/ComponentKit.ml b/infer/src/clang/ComponentKit.ml index 42c96b10f..2e4296d8f 100644 --- a/infer/src/clang/ComponentKit.ml +++ b/infer/src/clang/ComponentKit.ml @@ -77,15 +77,21 @@ let mutable_local_vars_advice context decl = let rec get_referenced_type (qual_type: Clang_ast_t.qual_type) : Clang_ast_t.decl option = let typ_opt = Ast_utils.get_desugared_type qual_type.qt_type_ptr in match (typ_opt : Clang_ast_t.c_type option) with + | Some ObjCInterfaceType (_, decl_ptr) | Some RecordType (_, decl_ptr) -> Ast_utils.get_decl decl_ptr + | Some PointerType (_, inner_qual_type) + | Some ObjCObjectPointerType (_, inner_qual_type) | Some LValueReferenceType (_, inner_qual_type) -> get_referenced_type inner_qual_type | _ -> None in let is_of_whitelisted_type qual_type = - let whitelist = ["CKComponentScope"; "FBTrackingNodeScope"; "FBTrackingCodeScope"] in + let cpp_whitelist = ["CKComponentScope"; "FBTrackingNodeScope"; "FBTrackingCodeScope"] in + let objc_whitelist = ["NSError"] in match get_referenced_type qual_type with | Some CXXRecordDecl (_, ndi, _, _, _, _, _, _) -> - IList.mem string_equal ndi.ni_name whitelist + IList.mem string_equal ndi.ni_name cpp_whitelist + | Some ObjCInterfaceDecl (_, ndi, _, _, _) -> + IList.mem string_equal ndi.ni_name objc_whitelist | _ -> false in match decl with diff --git a/infer/tests/codetoanalyze/objcpp/linters/componentkit/Test.mm b/infer/tests/codetoanalyze/objcpp/linters/componentkit/Test.mm index 98d602e03..eb3f26f81 100644 --- a/infer/tests/codetoanalyze/objcpp/linters/componentkit/Test.mm +++ b/infer/tests/codetoanalyze/objcpp/linters/componentkit/Test.mm @@ -60,9 +60,9 @@ const BOOL f = YES; // no error // Pointer types - NSError* const error = nil; // no error - NSError* const* g = &error; // error - NSError* const* const h = &error; // no error + NSObject* const o1 = nil; // no error + NSObject* const* o2 = &o1; // error + NSObject* const* const o3 = &o1; // no error return [super newWithComponent:[CKLabelComponent newWithLabelAttributes:{ .string = [@[ a, b, c, d ] componentsJoinedByString:@", "], @@ -93,5 +93,12 @@ class BarClass { CKComponentScope& w3 = w1; // no error // const CKComponentScope w4 = {.a = 3}; // Can't, lacks default ctor const CKComponentScope w4(self); // no error + + // Whitelisted Objc class + NSError* const e = nil; // no error + NSError** e1; // no error + NSError const** e2; // no error + NSError* const* e3 = &e; // no error + NSError* const* const e4 = &e; // no error } @end