Fixed has_type for iterator type

Reviewed By: jvillard

Differential Revision: D9179987

fbshipit-source-id: 362ea3836
master
Dino Distefano 6 years ago committed by Facebook Github Bot
parent a566424853
commit 4065b76663

@ -498,7 +498,27 @@ and c_type_equal c_type abs_ctype =
typename_equal pointer ae
| TypedefType (_, tdi), TypeName ae ->
typename_equal tdi.tti_decl_ptr ae
| NoneType ti, TypeName _
| ComplexType ti, TypeName _
| DependentSizedExtVectorType ti, TypeName _
| VectorType ti, TypeName _
| ExtVectorType ti, TypeName _
| UnresolvedUsingType ti, TypeName _
| TypeOfExprType ti, TypeName _
| TypeOfType ti, TypeName _
| UnaryTransformType ti, TypeName _
| TemplateTypeParmType ti, TypeName _
| SubstTemplateTypeParmType ti, TypeName _
| SubstTemplateTypeParmPackType ti, TypeName _
| DeducedTemplateSpecializationType ti, TypeName _
| InjectedClassNameType ti, TypeName _
| DependentNameType ti, TypeName _
| DependentTemplateSpecializationType ti, TypeName _
| ObjCTypeParamType ti, TypeName _
| PackExpansionType ti, TypeName _
| PipeType ti, TypeName _
| ElaboratedType ti, TypeName _
| AutoType ti, TypeName _
| TypedefType (ti, _), ObjCGenProt _
| AttributedType (ti, _), Pointer _ -> (
match ti.ti_desugared_type with Some dt -> check_type_ptr dt abs_ctype | None -> false )

@ -35,3 +35,14 @@ DEFINE-CHECKER NAMESPACE_STRING = {
SET mode = "ON";
};
DEFINE-CHECKER ITERATOR = {
SET report_when =
WHEN has_type("REGEXP('iterator')")
HOLDS-IN-NODE VarDecl;
SET message = "Found type iterator";
SET mode = "ON";
};

@ -1,3 +1,6 @@
codetoanalyze/cpp/linters/extracopy.cpp, test_a, 27, EXTRA_COPY, no_bucket, WARNING, []
codetoanalyze/cpp/linters/extracopy.cpp, test_map, 37, EXTRA_COPY, no_bucket, WARNING, []
codetoanalyze/cpp/linters/type_namespace.cpp, test, 6, NAMESPACE_STRING, no_bucket, WARNING, []
codetoanalyze/cpp/linters/iter.cpp, test, 11, ITERATOR, no_bucket, WARNING, []
codetoanalyze/cpp/linters/iter.cpp, test, 12, EXTRA_COPY, no_bucket, WARNING, []
codetoanalyze/cpp/linters/iter.cpp, test, 12, ITERATOR, no_bucket, WARNING, []
codetoanalyze/cpp/linters/type_namespace.cpp, test, 11, NAMESPACE_STRING, no_bucket, WARNING, []

@ -0,0 +1,13 @@
/*
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <map>
void test() {
std::map<int, int> m;
auto itr1 = m.begin();
auto itr2 = itr1;
}
Loading…
Cancel
Save