diff --git a/infer/src/clang/ctl_parser_types.ml b/infer/src/clang/ctl_parser_types.ml index 982f044e1..8c91501f0 100644 --- a/infer/src/clang/ctl_parser_types.ml +++ b/infer/src/clang/ctl_parser_types.ml @@ -80,30 +80,39 @@ let rec ast_node_name an = "" -let rec ast_node_cxx_fully_qualified_name an = - let fully_qualified_name qual_name = "::" ^ String.concat ~sep:"::" (List.rev qual_name) in +let decl_cxx_fully_qualified_name (decl : Clang_ast_t.decl) = + match Clang_ast_proj.get_var_decl_tuple decl with + | Some (_, ndi, _, {vdi_is_global= false}) -> + ndi.ni_name + | _ -> ( + match Clang_ast_proj.get_named_decl_tuple decl with + | Some (_, ndi) -> + "::" ^ String.concat ~sep:"::" (List.rev ndi.ni_qual_name) + | None -> + "" ) + + +let ast_node_cxx_fully_qualified_name an = let open Clang_ast_t in match an with - | Decl dec -> ( - match Clang_ast_proj.get_var_decl_tuple dec with - | Some (_, ndi, _, {vdi_is_global= false}) -> - ndi.ni_name - | Some (_, ndi, _, _) -> - fully_qualified_name ndi.ni_qual_name - | None -> ( - match Clang_ast_proj.get_named_decl_tuple dec with - | Some (_, ndi) -> - fully_qualified_name ndi.ni_qual_name - | None -> - "" ) ) + | Decl decl -> + decl_cxx_fully_qualified_name decl | Stmt (DeclRefExpr (_, _, _, {drti_decl_ref= Some dr})) -> ( match CAst_utils.get_decl dr.dr_decl_pointer with | Some decl -> - ast_node_cxx_fully_qualified_name (Decl decl) + decl_cxx_fully_qualified_name decl + | None -> + "" ) + | Stmt stmt -> ( + match Clang_ast_proj.get_cxx_construct_expr_tuple stmt with + | Some (_, _, _, xcei) -> ( + match CAst_utils.get_decl xcei.xcei_decl_ref.dr_decl_pointer with + | Some decl -> + decl_cxx_fully_qualified_name decl + | None -> + "" ) | None -> "" ) - | _ -> - "" let ast_node_kind node = diff --git a/infer/tests/codetoanalyze/cpp/linters-for-test-only/issues.exp b/infer/tests/codetoanalyze/cpp/linters-for-test-only/issues.exp index 9d7059508..9682c1adf 100644 --- a/infer/tests/codetoanalyze/cpp/linters-for-test-only/issues.exp +++ b/infer/tests/codetoanalyze/cpp/linters-for-test-only/issues.exp @@ -1,12 +1,15 @@ codetoanalyze/cpp/linters-for-test-only/test_constructor.cpp, f, 12, FIND_STATIC_LOCAL_VAR, no_bucket, WARNING, [] codetoanalyze/cpp/linters-for-test-only/test_constructor.cpp, g, 17, FIND_CXX_COPY_CONSTRUCTOR, no_bucket, WARNING, [] -codetoanalyze/cpp/linters-for-test-only/test_fully_qualified_names.cpp, Foo::Bar_f, 26, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, [] -codetoanalyze/cpp/linters-for-test-only/test_fully_qualified_names.cpp, Foo::Bar_f, 28, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, [] -codetoanalyze/cpp/linters-for-test-only/test_fully_qualified_names.cpp, Foo::Bar_f, 29, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, [] -codetoanalyze/cpp/linters-for-test-only/test_fully_qualified_names.cpp, Linters_dummy_method, 22, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, [] -codetoanalyze/cpp/linters-for-test-only/test_fully_qualified_names.cpp, Linters_dummy_method, 24, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, [] +codetoanalyze/cpp/linters-for-test-only/test_fully_qualified_names.cpp, Foo::Bar_Bar, 26, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, [] +codetoanalyze/cpp/linters-for-test-only/test_fully_qualified_names.cpp, Foo::Bar_f, 30, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, [] +codetoanalyze/cpp/linters-for-test-only/test_fully_qualified_names.cpp, Foo::Bar_f, 32, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, [] +codetoanalyze/cpp/linters-for-test-only/test_fully_qualified_names.cpp, Foo::Bar_f, 33, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, [] +codetoanalyze/cpp/linters-for-test-only/test_fully_qualified_names.cpp, Foo::Bar_fooey, 36, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, [] +codetoanalyze/cpp/linters-for-test-only/test_fully_qualified_names.cpp, Foo::Bar_fooey, 36, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, [] +codetoanalyze/cpp/linters-for-test-only/test_fully_qualified_names.cpp, Linters_dummy_method, 23, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, [] codetoanalyze/cpp/linters-for-test-only/test_fully_qualified_names.cpp, Linters_dummy_method, 25, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, [] -codetoanalyze/cpp/linters-for-test-only/test_fully_qualified_names.cpp, Linters_dummy_method, 33, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, [] +codetoanalyze/cpp/linters-for-test-only/test_fully_qualified_names.cpp, Linters_dummy_method, 28, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, [] +codetoanalyze/cpp/linters-for-test-only/test_fully_qualified_names.cpp, Linters_dummy_method, 39, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, [] codetoanalyze/cpp/linters-for-test-only/test_included.h, Bazoo_fibble, 11, FIND_CXX_METHODS_FROM_HEADER_FILE, no_bucket, WARNING, [] codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, B_bar, 16, FIND_CXX_METHOD_OVERRIDES, no_bucket, WARNING, [] codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, B_foo, 14, FIND_CXX_METHOD_OVERRIDES, no_bucket, WARNING, [] diff --git a/infer/tests/codetoanalyze/cpp/linters-for-test-only/test_fully_qualified_names.cpp b/infer/tests/codetoanalyze/cpp/linters-for-test-only/test_fully_qualified_names.cpp index c62d55adc..bf26f108c 100644 --- a/infer/tests/codetoanalyze/cpp/linters-for-test-only/test_fully_qualified_names.cpp +++ b/infer/tests/codetoanalyze/cpp/linters-for-test-only/test_fully_qualified_names.cpp @@ -12,6 +12,7 @@ namespace { int globalVarInAnonNs; struct Baz { + Baz(int x) : fld_(x) {} int fld_; }; @@ -21,14 +22,19 @@ namespace Foo { int globalVarInFoo; -class Bar : public Baz { +struct Bar : public Baz { + Bar(int x, int y) : Baz(x), barFld_(y) {} + static int classVar; + int f(const Baz& baz) { label: return baz.fld_ + fld_ + barFld_ + classVar + globalVarInTopNs + globalVarInAnonNs + globalVarInFoo; } + static int fooey(int x) { return Bar(x, x + 1).f(Baz(x)); } + private: int barFld_; };