Reviewed By: jvillard Differential Revision: D5632172 fbshipit-source-id: 4ab6ef5master
parent
4c3a36ae4c
commit
336f6f8dff
@ -0,0 +1,21 @@
|
|||||||
|
# Copyright (c) 2016 - present Facebook, Inc.
|
||||||
|
# All rights reserved.
|
||||||
|
#
|
||||||
|
# This source code is licensed under the BSD style license found in the
|
||||||
|
# LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
# of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
|
||||||
|
TESTS_DIR = ../../..
|
||||||
|
|
||||||
|
ANALYZER = linters
|
||||||
|
CLANG_OPTIONS = -x objective-c++ -std=c++11 -fobjc-arc -c
|
||||||
|
INFER_OPTIONS = --cxx --linters-def-file linters_example.al --project-root $(TESTS_DIR) --no-keep-going
|
||||||
|
INFERPRINT_OPTIONS = --issues-tests
|
||||||
|
|
||||||
|
SOURCES = \
|
||||||
|
$(wildcard *.m) \
|
||||||
|
$(wildcard */*.m) \
|
||||||
|
$(wildcard *.mm) \
|
||||||
|
$(wildcard *.c) \
|
||||||
|
|
||||||
|
include $(TESTS_DIR)/clang.make
|
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017 - present Facebook, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the BSD style license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
*/
|
||||||
|
#import <Foundation/NSObject.h>
|
||||||
|
|
||||||
|
#import <string>
|
||||||
|
#import <unordered_map>
|
||||||
|
|
||||||
|
template <typename... T>
|
||||||
|
class MyClassTemplated {};
|
||||||
|
|
||||||
|
typedef MyClassTemplated<> MyClass;
|
||||||
|
|
||||||
|
@interface ReferenceTest : NSObject
|
||||||
|
// bug
|
||||||
|
+ (instancetype)newWithConstAction:(const MyClass&)action;
|
||||||
|
|
||||||
|
// bug
|
||||||
|
+ (instancetype)newWithActionRef:(MyClass&)action;
|
||||||
|
|
||||||
|
// bug
|
||||||
|
+ (instancetype)newWithAction:(MyClass)action;
|
||||||
|
|
||||||
|
// no bug
|
||||||
|
+ (instancetype)newWithTypedAction:(MyClassTemplated<BOOL>)typedAction;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation ReferenceTest
|
||||||
|
// bug
|
||||||
|
+ (instancetype)newWithConstAction:(const MyClass&)action {
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
// bug
|
||||||
|
+ (instancetype)newWithActionRef:(MyClass&)action {
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
// bug
|
||||||
|
+ (instancetype)newWithAction:(MyClass&)action {
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This should not produce an error
|
||||||
|
+ (instancetype)newWithTypedAction:(MyClassTemplated<BOOL>)typedAction {
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
@ -0,0 +1,6 @@
|
|||||||
|
codetoanalyze/objcpp/linters-for-test-only/ReferenceTest.mm, ReferenceTest_newWithAction:, 27, TEST_REFERENCE, []
|
||||||
|
codetoanalyze/objcpp/linters-for-test-only/ReferenceTest.mm, ReferenceTest_newWithAction:, 44, TEST_REFERENCE, []
|
||||||
|
codetoanalyze/objcpp/linters-for-test-only/ReferenceTest.mm, ReferenceTest_newWithActionRef:, 24, TEST_REFERENCE, []
|
||||||
|
codetoanalyze/objcpp/linters-for-test-only/ReferenceTest.mm, ReferenceTest_newWithActionRef:, 40, TEST_REFERENCE, []
|
||||||
|
codetoanalyze/objcpp/linters-for-test-only/ReferenceTest.mm, ReferenceTest_newWithConstAction:, 21, TEST_REFERENCE, []
|
||||||
|
codetoanalyze/objcpp/linters-for-test-only/ReferenceTest.mm, ReferenceTest_newWithConstAction:, 36, TEST_REFERENCE, []
|
@ -0,0 +1,9 @@
|
|||||||
|
DEFINE-CHECKER TEST_REFERENCE = {
|
||||||
|
SET report_when =
|
||||||
|
WHEN method_return_type("instancetype")
|
||||||
|
AND HOLDS-NEXT WITH-TRANSITION Parameters
|
||||||
|
(has_type("MyClass") OR has_type("MyClass &"))
|
||||||
|
AND declaration_has_name(REGEXP("^new.*:$"))
|
||||||
|
HOLDS-IN-NODE ObjCMethodDecl;
|
||||||
|
SET message = "Found reference in parameter of method new";
|
||||||
|
};
|
Loading…
Reference in new issue