diff --git a/infer/src/clang/ComponentKit.ml b/infer/src/clang/ComponentKit.ml index c55009ec2..1ab9744dd 100644 --- a/infer/src/clang/ComponentKit.ml +++ b/infer/src/clang/ComponentKit.ml @@ -127,6 +127,7 @@ let mutable_local_vars_advice context an = && 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 context.CLintersContext.in_for_loop_declaration + && not (CAst_utils.is_std_vector qual_type) in if condition then Some diff --git a/infer/src/clang/cAst_utils.ml b/infer/src/clang/cAst_utils.ml index 4a3f30191..46b64519b 100644 --- a/infer/src/clang/cAst_utils.ml +++ b/infer/src/clang/cAst_utils.ml @@ -486,3 +486,15 @@ let get_cxx_virtual_base_classes decl = -> cxx_record_info.xrdi_transitive_vbases | _ -> [] + +let is_std_vector qt = + match get_decl_from_typ_ptr qt.Clang_ast_t.qt_type_ptr with + | Some decl -> ( + match Clang_ast_proj.get_named_decl_tuple decl with + | Some (_, qual_name) + -> String.equal qual_name.ni_name "vector" + && List.mem ~equal:String.equal qual_name.ni_qual_name "std" + | None + -> false ) + | None + -> false diff --git a/infer/src/clang/cAst_utils.mli b/infer/src/clang/cAst_utils.mli index 6430bf66f..2eaa13ee4 100644 --- a/infer/src/clang/cAst_utils.mli +++ b/infer/src/clang/cAst_utils.mli @@ -149,3 +149,5 @@ val get_record_fields : Clang_ast_t.decl -> Clang_ast_t.decl list 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 is_std_vector : Clang_ast_t.qual_type -> bool diff --git a/infer/tests/build_systems/ck_imports/issues.exp b/infer/tests/build_systems/ck_imports/issues.exp index a752eed47..efd83579a 100644 --- a/infer/tests/build_systems/ck_imports/issues.exp +++ b/infer/tests/build_systems/ck_imports/issues.exp @@ -1 +1 @@ -TestIgnoreImports.mm, SomeClass_new, 18, MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE, [] +TestIgnoreImports.mm, SomeClass_new, 22, MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE, [] diff --git a/infer/tests/build_systems/codetoanalyze/componentkit/TestIgnoreImports.mm b/infer/tests/build_systems/codetoanalyze/componentkit/TestIgnoreImports.mm index a141f888a..aed07158e 100644 --- a/infer/tests/build_systems/codetoanalyze/componentkit/TestIgnoreImports.mm +++ b/infer/tests/build_systems/codetoanalyze/componentkit/TestIgnoreImports.mm @@ -11,14 +11,20 @@ #include "../../../codetoanalyze/objcpp/linters/componentkit/FakeComponentKitHeader.h" +#include + +struct D {}; + @interface SomeClass : CKCompositeComponent @end @implementation SomeClass + (instancetype) new { int i; // error - for (int i = 0; i < 10; i++) { + for (int i = 0; i < 10; i++) { // no error } + + std::vector v; // no error return nil; } @end