diff --git a/infer/src/clang/ctl_parser_types.ml b/infer/src/clang/ctl_parser_types.ml index d4ba058c1..edc26a31f 100644 --- a/infer/src/clang/ctl_parser_types.ml +++ b/infer/src/clang/ctl_parser_types.ml @@ -498,8 +498,8 @@ and c_type_equal c_type abs_ctype = typename_equal pointer ae | TypedefType (_, tdi), TypeName ae -> typename_equal tdi.tti_decl_ptr ae - | TypedefType (ti, _), ObjCGenProt _ -> ( - match ti.ti_desugared_type with Some dt -> check_type_ptr dt abs_ctype | None -> false ) + | ElaboratedType ti, TypeName _ + | TypedefType (ti, _), ObjCGenProt _ | AttributedType (ti, _), Pointer _ -> ( match ti.ti_desugared_type with Some dt -> check_type_ptr dt abs_ctype | None -> false ) | _, _ -> diff --git a/infer/tests/codetoanalyze/cpp/linters/extracopy.al b/infer/tests/codetoanalyze/cpp/linters/extracopy.al index 335f7253b..91df0036c 100644 --- a/infer/tests/codetoanalyze/cpp/linters/extracopy.al +++ b/infer/tests/codetoanalyze/cpp/linters/extracopy.al @@ -24,3 +24,14 @@ DEFINE-CHECKER EXTRA_COPY = { //}; }; + +DEFINE-CHECKER NAMESPACE_STRING = { + + SET report_when = + WHEN has_type("REGEXP('string')") + HOLDS-IN-NODE VarDecl; + + SET message = "Found type strings with namespace"; + SET mode = "ON"; + +}; diff --git a/infer/tests/codetoanalyze/cpp/linters/issues.exp b/infer/tests/codetoanalyze/cpp/linters/issues.exp index ce0ea43f5..4d48b4834 100644 --- a/infer/tests/codetoanalyze/cpp/linters/issues.exp +++ b/infer/tests/codetoanalyze/cpp/linters/issues.exp @@ -1,2 +1,3 @@ -codetoanalyze/cpp/linters/extracopy.cpp, test_a, 33, EXTRA_COPY, no_bucket, WARNING, [] -codetoanalyze/cpp/linters/extracopy.cpp, test_map, 43, EXTRA_COPY, no_bucket, WARNING, [] +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, [] diff --git a/infer/tests/codetoanalyze/cpp/linters/type_namespace.cpp b/infer/tests/codetoanalyze/cpp/linters/type_namespace.cpp new file mode 100644 index 000000000..29b9fca57 --- /dev/null +++ b/infer/tests/codetoanalyze/cpp/linters/type_namespace.cpp @@ -0,0 +1,11 @@ +/* + * 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 + +using namespace std; + +void test() { std::string s1 = "a"; }