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