xref: /aosp_15_r20/external/clang/test/SemaObjC/method-conflict-2.m (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li// RUN: %clang_cc1 -Wmethod-signatures -fsyntax-only -verify -Wno-objc-root-class %s
2*67e74705SXin Li// RUN: %clang_cc1 -x objective-c++ -Wmethod-signatures -fsyntax-only -verify -Wno-objc-root-class %s
3*67e74705SXin Li
4*67e74705SXin Li@interface A @end
5*67e74705SXin Li@interface B : A @end
6*67e74705SXin Li
7*67e74705SXin Li@interface Test1 {}
8*67e74705SXin Li- (void) test1:(A*) object; // expected-note {{previous definition is here}}
9*67e74705SXin Li- (void) test2:(B*) object;
10*67e74705SXin Li@end
11*67e74705SXin Li
12*67e74705SXin Li@implementation Test1
13*67e74705SXin Li- (void) test1:(B*) object {} // expected-warning {{conflicting parameter types in implementation of 'test1:': 'A *' vs 'B *'}}
14*67e74705SXin Li- (void) test2:(A*) object {}
15*67e74705SXin Li@end
16*67e74705SXin Li
17*67e74705SXin Li@interface Test2 {}
18*67e74705SXin Li- (void) test1:(id) object; // expected-note {{previous definition is here}}
19*67e74705SXin Li- (void) test2:(A*) object;
20*67e74705SXin Li@end
21*67e74705SXin Li
22*67e74705SXin Li@implementation Test2
23*67e74705SXin Li- (void) test1:(A*) object {} // expected-warning {{conflicting parameter types in implementation of 'test1:': 'id' vs 'A *'}}
24*67e74705SXin Li- (void) test2:(id) object {}
25*67e74705SXin Li@end
26*67e74705SXin Li
27*67e74705SXin Li@interface Test3 {}
28*67e74705SXin Li- (A*) test1;
29*67e74705SXin Li- (B*) test2; // expected-note {{previous definition is here}}
30*67e74705SXin Li@end
31*67e74705SXin Li
32*67e74705SXin Li@implementation Test3
33*67e74705SXin Li- (B*) test1 { return 0; }
34*67e74705SXin Li- (A*) test2 { return 0; } // expected-warning {{conflicting return type in implementation of 'test2': 'B *' vs 'A *'}}
35*67e74705SXin Li@end
36*67e74705SXin Li
37*67e74705SXin Li// The particular case of overriding with an id return is white-listed.
38*67e74705SXin Li@interface Test4 {}
39*67e74705SXin Li- (id) test1;
40*67e74705SXin Li- (A*) test2;
41*67e74705SXin Li@end
42*67e74705SXin Li@implementation Test4
43*67e74705SXin Li- (A*) test1 { return 0; } // id -> A* is rdar://problem/8596987
44*67e74705SXin Li- (id) test2 { return 0; }
45*67e74705SXin Li@end
46*67e74705SXin Li
47*67e74705SXin Li// rdar://12522752
48*67e74705SXin Litypedef int int32_t;
49*67e74705SXin Litypedef long long int64_t;
50*67e74705SXin Li
51*67e74705SXin Li@interface NSObject @end
52*67e74705SXin Li
53*67e74705SXin Li@protocol CKMessage
54*67e74705SXin Li@property (nonatomic,readonly,assign) int64_t sequenceNumber; // expected-note {{previous definition is here}}
55*67e74705SXin Li@end
56*67e74705SXin Li
57*67e74705SXin Li@protocol CKMessage;
58*67e74705SXin Li
59*67e74705SXin Li@interface CKIMMessage : NSObject<CKMessage>
60*67e74705SXin Li@end
61*67e74705SXin Li
62*67e74705SXin Li@implementation CKIMMessage
63*67e74705SXin Li- (int32_t)sequenceNumber { // expected-warning {{conflicting return type in implementation of 'sequenceNumber': 'int64_t' (aka 'long long') vs 'int32_t' (aka 'int')}}
64*67e74705SXin Li  return 0;
65*67e74705SXin Li}
66*67e74705SXin Li@end
67*67e74705SXin Li
68*67e74705SXin Li// rdar://14650159
69*67e74705SXin Li// Tests that property inherited indirectly from a nested protocol
70*67e74705SXin Li// is seen by the method implementation type matching logic before
71*67e74705SXin Li// method in super class is seen. This fixes the warning coming
72*67e74705SXin Li// out of that method mismatch.
73*67e74705SXin Li@interface NSObject (NSDict)
74*67e74705SXin Li- (void)setValue:(id)value;
75*67e74705SXin Li- (id)value;
76*67e74705SXin Li@end
77*67e74705SXin Li
78*67e74705SXin Li@protocol ProtocolWithValue
79*67e74705SXin Li@property (nonatomic) unsigned value;
80*67e74705SXin Li@end
81*67e74705SXin Li
82*67e74705SXin Li@protocol InterveningProtocol <ProtocolWithValue>
83*67e74705SXin Li@end
84*67e74705SXin Li
85*67e74705SXin Li@interface UsesProtocolWithValue : NSObject <ProtocolWithValue>
86*67e74705SXin Li@end
87*67e74705SXin Li
88*67e74705SXin Li@implementation UsesProtocolWithValue
89*67e74705SXin Li@synthesize value=_value;
90*67e74705SXin Li- (unsigned) value
91*67e74705SXin Li{
92*67e74705SXin Li	return _value;
93*67e74705SXin Li}
94*67e74705SXin Li- (void) setValue:(unsigned)value
95*67e74705SXin Li{
96*67e74705SXin Li	_value = value;
97*67e74705SXin Li}
98*67e74705SXin Li@end
99*67e74705SXin Li
100*67e74705SXin Li
101*67e74705SXin Li@interface UsesInterveningProtocol : NSObject <InterveningProtocol>
102*67e74705SXin Li@end
103*67e74705SXin Li
104*67e74705SXin Li@implementation UsesInterveningProtocol
105*67e74705SXin Li
106*67e74705SXin Li@synthesize value=_value;
107*67e74705SXin Li- (unsigned) value
108*67e74705SXin Li{
109*67e74705SXin Li	return _value;
110*67e74705SXin Li}
111*67e74705SXin Li- (void) setValue:(unsigned)value
112*67e74705SXin Li{
113*67e74705SXin Li	_value = value;
114*67e74705SXin Li}
115*67e74705SXin Li@end
116