[linters] Do not report MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE when the variable has __block attribute

Reviewed By: mbouaziz

Differential Revision: D5964778

fbshipit-source-id: 1807a66
master
Dulma Churchill 7 years ago committed by Facebook Github Bot
parent bb3201a8e8
commit ca23ed5f5f

@ -127,7 +127,7 @@ let mutable_local_vars_advice context an =
&& not (CAst_utils.is_static_local_var decl) && not is_const && not (CAst_utils.is_static_local_var decl) && not is_const
&& not (is_of_whitelisted_type qual_type) && not decl_info.di_is_implicit && not (is_of_whitelisted_type qual_type) && not decl_info.di_is_implicit
&& not context.CLintersContext.in_for_loop_declaration && not context.CLintersContext.in_for_loop_declaration
&& not (CAst_utils.is_std_vector qual_type) && not (CAst_utils.is_std_vector qual_type) && not (CAst_utils.has_block_attribute decl)
in in
if condition then if condition then
Some Some

@ -498,3 +498,12 @@ let is_std_vector qt =
-> false ) -> false )
| None | None
-> false -> false
let has_block_attribute decl =
let open Clang_ast_t in
match decl with
| VarDecl (decl_info, _, _, _)
-> let attributes = decl_info.di_attributes in
List.exists ~f:(fun attr -> match attr with BlocksAttr _ -> true | _ -> false) attributes
| _
-> false

@ -151,3 +151,5 @@ val get_cxx_base_classes : Clang_ast_t.decl -> Clang_ast_t.type_ptr list
val get_cxx_virtual_base_classes : Clang_ast_t.decl -> Clang_ast_t.type_ptr list val get_cxx_virtual_base_classes : Clang_ast_t.decl -> Clang_ast_t.type_ptr list
val is_std_vector : Clang_ast_t.qual_type -> bool val is_std_vector : Clang_ast_t.qual_type -> bool
val has_block_attribute : Clang_ast_t.decl -> bool

@ -25,6 +25,8 @@ struct D {};
} }
std::vector<D*> v; // no error std::vector<D*> v; // no error
__block D* var; // no error
return nil; return nil;
} }
@end @end

Loading…
Cancel
Save