1 | // RUN: %check_clang_tidy %s objc-missing-hash %t |
2 | |
3 | typedef _Bool BOOL; |
4 | #define YES 1 |
5 | #define NO 0 |
6 | typedef unsigned int NSUInteger; |
7 | typedef void *id; |
8 | |
9 | @interface NSObject |
10 | - (NSUInteger)hash; |
11 | - (BOOL)isEqual:(id)object; |
12 | @end |
13 | |
14 | @interface MissingHash : NSObject |
15 | @end |
16 | |
17 | @implementation MissingHash |
18 | // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: 'MissingHash' implements -isEqual: without implementing -hash [objc-missing-hash] |
19 | |
20 | - (BOOL)isEqual:(id)object { |
21 | return YES; |
22 | } |
23 | |
24 | @end |
25 | |
26 | @interface HasHash : NSObject |
27 | @end |
28 | |
29 | @implementation HasHash |
30 | |
31 | - (NSUInteger)hash { |
32 | return 0; |
33 | } |
34 | |
35 | - (BOOL)isEqual:(id)object { |
36 | return YES; |
37 | } |
38 | |
39 | @end |
40 | |
41 | @interface NSArray : NSObject |
42 | @end |
43 | |
44 | @interface MayHaveInheritedHash : NSArray |
45 | @end |
46 | |
47 | @implementation MayHaveInheritedHash |
48 | |
49 | - (BOOL)isEqual:(id)object { |
50 | return YES; |
51 | } |
52 | |
53 | @end |
54 | |
55 | @interface AnotherRootClass |
56 | @end |
57 | |
58 | @interface NotDerivedFromNSObject : AnotherRootClass |
59 | @end |
60 | |
61 | @implementation NotDerivedFromNSObject |
62 | |
63 | - (BOOL)isEqual:(id)object { |
64 | return NO; |
65 | } |
66 | |
67 | @end |
68 | |
69 | |