New is_cxx_method_overriding predicate

Reviewed By: jvillard

Differential Revision: D13222367

fbshipit-source-id: 8b20575b7
master
David Lively 6 years ago committed by Facebook Github Bot
parent e59d9632b1
commit 33eabe6bfd

@ -1412,6 +1412,14 @@ let is_cxx_copy_constructor an =
false false
let is_cxx_method_overriding an =
match an with
| Ctl_parser_types.Decl (Clang_ast_t.CXXMethodDecl (_, _, _, _, mdi)) ->
not (List.is_empty mdi.xmdi_overriden_methods)
| _ ->
false
let is_init_expr_cxx11_constant an = let is_init_expr_cxx11_constant an =
let open Clang_ast_t in let open Clang_ast_t in
match an with match an with

@ -487,6 +487,12 @@ val is_method_called_by_superclass : Ctl_parser_types.ast_node -> bool
val is_cxx_copy_constructor : Ctl_parser_types.ast_node -> bool val is_cxx_copy_constructor : Ctl_parser_types.ast_node -> bool
(** true if the current node is a C++ copy constructor *) (** true if the current node is a C++ copy constructor *)
val is_cxx_method_overriding : Ctl_parser_types.ast_node -> bool
(**
* Checks if the current node is a CXXMethodDecl node and is overriding a
* method in a superclass.
*)
val is_init_expr_cxx11_constant : Ctl_parser_types.ast_node -> bool val is_init_expr_cxx11_constant : Ctl_parser_types.ast_node -> bool
(** true if the current node is classified as C++11 constant expression by the AST. It works only for VarDecl init expr *) (** true if the current node is classified as C++11 constant expression by the AST. It works only for VarDecl init expr *)

@ -1153,6 +1153,8 @@ let rec eval_Atomic pred_name_ args an lcxt =
CPredicates.is_method_called_by_superclass an CPredicates.is_method_called_by_superclass an
| "is_cxx_copy_constructor", [], an -> | "is_cxx_copy_constructor", [], an ->
CPredicates.is_cxx_copy_constructor an CPredicates.is_cxx_copy_constructor an
| "is_cxx_method_overriding", [], an ->
CPredicates.is_cxx_method_overriding an
| "is_init_expr_cxx11_constant", [], an -> | "is_init_expr_cxx11_constant", [], an ->
CPredicates.is_init_expr_cxx11_constant an CPredicates.is_init_expr_cxx11_constant an
| "cxx_construct_expr_has_no_parameters", [], an -> | "cxx_construct_expr_has_no_parameters", [], an ->

@ -1,2 +1,4 @@
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, 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_constructor.cpp, g, 17, FIND_CXX_COPY_CONSTRUCTOR, 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, []

@ -27,3 +27,7 @@ SET message = "Found static local var";
}; };
DEFINE-CHECKER FIND_CXX_METHOD_OVERRIDES = {
SET report_when = is_cxx_method_overriding;
SET message = "%decl_name% overrides";
};

@ -0,0 +1,18 @@
/*
* 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.
*/
struct A {
virtual void foo();
virtual void bar();
void bazoo();
};
struct B : public A {
void foo() override;
void bar(int i);
void bar() /* override */;
void bazoo();
};
Loading…
Cancel
Save