From d390a6f08a142da0bcd0a833ee3ec3431d053aae Mon Sep 17 00:00:00 2001 From: David Lively Date: Tue, 22 Jan 2019 05:29:45 -0800 Subject: [PATCH] [CType_decl] Add missing case to `get_record_typename` Reviewed By: ddino Differential Revision: D13736334 fbshipit-source-id: c088d1aa8 --- infer/src/clang/CType_decl.ml | 3 ++- .../cpp/linters-for-test-only/issues.exp | 9 +++++++++ .../linters-for-test-only/linters_example.al | 2 +- .../test_partial_spec_template.cpp | 19 +++++++++++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 infer/tests/codetoanalyze/cpp/linters-for-test-only/test_partial_spec_template.cpp diff --git a/infer/src/clang/CType_decl.ml b/infer/src/clang/CType_decl.ml index 17e70a31c..97d4c9717 100644 --- a/infer/src/clang/CType_decl.ml +++ b/infer/src/clang/CType_decl.ml @@ -457,6 +457,7 @@ and get_record_typename ?tenv decl = | CXXRecordDecl (_, name_info, _, _, _, `TTK_Union, _, _), _ -> Typ.CUnion (CAst_utils.get_qualified_name ~linters_mode name_info) | CXXRecordDecl (_, name_info, _, _, _, _, _, _), _ + | ClassTemplatePartialSpecializationDecl (_, name_info, _, _, _, _, _, _, _, _), _ | ClassTemplateSpecializationDecl (_, name_info, _, _, _, _, _, _, _, _), _ -> (* we use Typ.CppClass for C++ because we expect Typ.CppClass from *) (* types that have methods. And in C++ struct/class/union can have methods *) @@ -475,7 +476,7 @@ and get_record_typename ?tenv decl = | None -> assert false ) | _ -> - assert false + Logging.die InternalError "Unhandled decl: %s." (Clang_ast_proj.get_decl_kind_string decl) (** fetches list of superclasses for C++ classes *) 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 7b61a32d9..3fcdedecf 100644 --- a/infer/tests/codetoanalyze/cpp/linters-for-test-only/issues.exp +++ b/infer/tests/codetoanalyze/cpp/linters-for-test-only/issues.exp @@ -10,9 +10,18 @@ codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, Foo::Bar::SvIf_poke, codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, Foo::Bar::SvIf_semifuture_poke, 38, FIND_CXX_METHOD_OVERRIDES, no_bucket, WARNING, [] codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, Foo::Bar::SvIf_semifuture_poke, 38, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, [] codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, Foo::Bar::SvIf_~SvIf, 34, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, [] +codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, Foo::SvIf_async_tm_poke, 25, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, [] +codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, Foo::SvIf_future_poke, 26, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, [] +codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, Foo::SvIf_semifuture_poke, 27, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, [] +codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, Foo::SvIf_~SvIf, 24, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, [] codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, FooBarService_async_tm_poke, 50, FIND_CXX_METHOD_OVERRIDES, no_bucket, WARNING, [] codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, FooBarService_future_poke, 51, FIND_CXX_METHOD_OVERRIDES, no_bucket, WARNING, [] codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, FooBarService_future_poke, 51, FIND_CXX_METHOD_OVERRIDES_MATCHING, no_bucket, WARNING, [] codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, FooBarService_poke, 49, FIND_CXX_METHOD_OVERRIDES, no_bucket, WARNING, [] codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, FooBarService_semifuture_poke, 52, FIND_CXX_METHOD_OVERRIDES, no_bucket, WARNING, [] +codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, Linters_dummy_method, 22, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, [] +codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, Linters_dummy_method, 30, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, [] codetoanalyze/cpp/linters-for-test-only/test_overrides.cpp, Linters_dummy_method, 32, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, [] +codetoanalyze/cpp/linters-for-test-only/test_partial_spec_template.cpp, Foo::is_negative_impl_type-parameter-0-0,_false__check, 16, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, [] +codetoanalyze/cpp/linters-for-test-only/test_partial_spec_template.cpp, Linters_dummy_method, 9, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, [] +codetoanalyze/cpp/linters-for-test-only/test_partial_spec_template.cpp, Linters_dummy_method, 14, FIND_NODES_WITH_CXX_FULL_NAME, no_bucket, WARNING, [] diff --git a/infer/tests/codetoanalyze/cpp/linters-for-test-only/linters_example.al b/infer/tests/codetoanalyze/cpp/linters-for-test-only/linters_example.al index 364af7f62..4044990a4 100644 --- a/infer/tests/codetoanalyze/cpp/linters-for-test-only/linters_example.al +++ b/infer/tests/codetoanalyze/cpp/linters-for-test-only/linters_example.al @@ -39,6 +39,6 @@ DEFINE-CHECKER FIND_CXX_METHOD_OVERRIDES_MATCHING = { }; DEFINE-CHECKER FIND_NODES_WITH_CXX_FULL_NAME = { - SET report_when = has_cxx_fully_qualified_name(REGEXP("::Foo::Bar::")); + SET report_when = has_cxx_fully_qualified_name(REGEXP("::Foo::.*")); SET message = "%cxx_fully_qualified_name% matches"; }; diff --git a/infer/tests/codetoanalyze/cpp/linters-for-test-only/test_partial_spec_template.cpp b/infer/tests/codetoanalyze/cpp/linters-for-test-only/test_partial_spec_template.cpp new file mode 100644 index 000000000..20998e4ad --- /dev/null +++ b/infer/tests/codetoanalyze/cpp/linters-for-test-only/test_partial_spec_template.cpp @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2019-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. + */ +namespace Foo { + +template +struct is_negative_impl { + constexpr static bool check(T x) { return x < 0; } +}; + +template +struct is_negative_impl { + constexpr static bool check(T) { return false; } +}; + +} // namespace Foo