diff --git a/infer/src/clang/cPredicates.ml b/infer/src/clang/cPredicates.ml index fbec15548..0e44b981a 100644 --- a/infer/src/clang/cPredicates.ml +++ b/infer/src/clang/cPredicates.ml @@ -531,6 +531,8 @@ let is_qual_type_const an = ei.Clang_ast_t.ei_qual_type.qt_is_const | _ -> false ) + | Ctl_parser_types.Decl (Clang_ast_t.VarDecl (_, _, qt, _)) -> + qt.qt_is_const | _ -> false diff --git a/infer/tests/codetoanalyze/objc/linters-for-test-only/al_definitions/linters_example.al b/infer/tests/codetoanalyze/objc/linters-for-test-only/al_definitions/linters_example.al index 5ebece7fa..1f9cb770c 100644 --- a/infer/tests/codetoanalyze/objc/linters-for-test-only/al_definitions/linters_example.al +++ b/infer/tests/codetoanalyze/objc/linters-for-test-only/al_definitions/linters_example.al @@ -809,3 +809,11 @@ DEFINE-CHECKER TEST_IS_RECEIVER_SUPER = { SET message = "This node is a method call to 'super'."; }; + +DEFINE-CHECKER CONST_NAMING = { + SET report_when = WHEN + is_qual_type_const() + HOLDS-IN-NODE VarDecl; + + SET message = "That's a const"; +}; diff --git a/infer/tests/codetoanalyze/objc/linters-for-test-only/const.m b/infer/tests/codetoanalyze/objc/linters-for-test-only/const.m new file mode 100644 index 000000000..aa5eb6da0 --- /dev/null +++ b/infer/tests/codetoanalyze/objc/linters-for-test-only/const.m @@ -0,0 +1,11 @@ +/* + * 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. + */ +static int* const kSome1 = 0; +const float kSome2 = 12.f; +static int* kSome3 = 0; + +void main() {} diff --git a/infer/tests/codetoanalyze/objc/linters-for-test-only/issues.exp b/infer/tests/codetoanalyze/objc/linters-for-test-only/issues.exp index 4ea50dffa..b3894f1d3 100644 --- a/infer/tests/codetoanalyze/objc/linters-for-test-only/issues.exp +++ b/infer/tests/codetoanalyze/objc/linters-for-test-only/issues.exp @@ -204,6 +204,14 @@ codetoanalyze/objc/linters-for-test-only/InContextOfMethodsTest.m, objc_block_1, codetoanalyze/objc/linters-for-test-only/InContextOfMethodsTest.m, objc_block_2, 19, TEST_IN_BLOCK_CONTEXT, no_bucket, WARNING, [] codetoanalyze/objc/linters-for-test-only/InSubclassExample.m, HappySadView2_makeBadAction, 33, IN_SUBCLASS_TEST, no_bucket, WARNING, [] codetoanalyze/objc/linters-for-test-only/PrivateAPIChecker.m, TestView_methoddd, 19, TEST_SELECTOR, no_bucket, WARNING, [] +codetoanalyze/objc/linters-for-test-only/const.m, Linters_dummy_method, 1, CONST_NAMING, no_bucket, WARNING, [] +codetoanalyze/objc/linters-for-test-only/const.m, Linters_dummy_method, 1, TEST_VAR_TYPE_CHECK, no_bucket, WARNING, [] +codetoanalyze/objc/linters-for-test-only/const.m, Linters_dummy_method, 2, CONST_NAMING, no_bucket, WARNING, [] +codetoanalyze/objc/linters-for-test-only/const.m, Linters_dummy_method, 3, TEST_VAR_TYPE_CHECK, no_bucket, WARNING, [] +codetoanalyze/objc/linters-for-test-only/const.m, main, 5, ALL_PATH_NO_FILTER_EXAMPLE, no_bucket, WARNING, [] +codetoanalyze/objc/linters-for-test-only/const.m, main, 5, BLACKLIST_PATH_EXAMPLE, no_bucket, WARNING, [] +codetoanalyze/objc/linters-for-test-only/const.m, main, 5, FILTER_BY_ALL_PATH_EXAMPLE, no_bucket, WARNING, [] +codetoanalyze/objc/linters-for-test-only/const.m, main, 5, WHITE_BLACKLIST_PATH_EXAMPLE, no_bucket, WARNING, [] codetoanalyze/objc/linters-for-test-only/enums.m, test, 15, ENUM_CONSTANTS, no_bucket, WARNING, [] codetoanalyze/objc/linters-for-test-only/enums.m, test, 15, ENUM_CONSTANTS_OF_ENUM, no_bucket, WARNING, [] codetoanalyze/objc/linters-for-test-only/enums.m, test_c_style_enum, 21, ENUM_CONSTANTS, no_bucket, WARNING, []