1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441
|
/* Check Class <protocol> types */
/* Author: David Ayers <d.ayers@inode.at> */
/* { dg-do compile } */
#include <objc/objc.h>
#include "../objc-obj-c++-shared/runtime.h"
@protocol MyProto1
+(void)doItClass1;
-(void)doItInstance1;
@end
@protocol MyProto2
+(void)doItClass2;
-(void)doItInstance2;
@end
@interface MyClass1 <MyProto1>
{
Class isa;
}
@end
@implementation MyClass1
+(void)doItClass1{}
-(void)doItInstance1{}
@end
@interface MyClass2 : MyClass1 <MyProto2>
@end
@implementation MyClass2
+(void)doItClass2{}
-(void)doItInstance2{}
@end
@interface MyClass3
{
Class isa;
}
@end
@interface MyClass4 : MyClass3 <MyProto1>
@end
/*----------------------------------------*/
Class cls = 0;
Class <MyProto1> clsP1 = 0;
Class <MyProto2> clsP2 = 0;
void
testSimple(void)
{
[cls doItClass1];
[cls doItInstance1];
[cls doItClass2];
[cls doItInstance2];
[clsP1 doItClass1];
[clsP1 doItInstance1]; /* { dg-warning "instead of" } */
[clsP1 doItClass2]; /* { dg-warning "not found in protocol" } */
[clsP1 doItInstance2]; /* { dg-warning "not found in protocol" } */
[clsP2 doItClass1]; /* { dg-warning "not found in protocol" } */
[clsP2 doItInstance1]; /* { dg-warning "not found in protocol" } */
[clsP2 doItClass2];
[clsP2 doItInstance2]; /* { dg-warning "instead of" } */
[MyClass1 doItClass1];
[MyClass1 doItInstance1];
[MyClass1 doItClass2]; /* { dg-warning "may not respond to" } */
[MyClass1 doItInstance2]; /* { dg-warning "may not respond to" } */
[MyClass2 doItClass1];
[MyClass2 doItInstance1];
[MyClass2 doItClass2];
[MyClass2 doItInstance2]; /* { dg-warning "may not respond to" } */
[MyClass3 doItClass1]; /* { dg-warning "may not respond to" } */
[MyClass3 doItInstance1]; /* { dg-warning "may not respond to" } */
[MyClass4 doItClass1];
[MyClass4 doItInstance1]; /* { dg-warning "may not respond to" } */
}
/*----------------------------------------*/
/* Protocols declared by categories */
@protocol MyProto3
+(void)doItClass3;
-(void)doItInstance3;
@end
@protocol MyProto4
+(void)doItClass4;
-(void)doItInstance4;
@end
@interface MyClass1 (Category1) <MyProto3>
@end
@interface MyClass2 (Category2) <MyProto4>
@end
void
testCategory(void)
{
[cls doItClass3];
[cls doItInstance3];
[cls doItClass4];
[cls doItInstance4];
[MyClass1 doItClass3];
[MyClass1 doItInstance3];
[MyClass1 doItClass4]; /* { dg-warning "may not respond" } */
[MyClass1 doItInstance4]; /* { dg-warning "may not respond" } */
[MyClass2 doItClass3];
[MyClass2 doItInstance3];
[MyClass2 doItClass4];
[MyClass2 doItInstance4]; /* { dg-warning "may not respond" } */
}
/*----------------------------------------*/
/* Inherited protocols declared by categories */
@protocol MyProto5 <MyProto1>
+(void)doItClass5;
-(void)doItInstance5;
@end
@protocol MyProto6 <MyProto2>
+(void)doItClass6;
-(void)doItInstance6;
@end
@interface MyClass1 (Category3) <MyProto5>
@end
@interface MyClass2 (Category4) <MyProto6>
@end
Class <MyProto5> clsP5 = 0;
Class <MyProto6> clsP6 = 0;
void
testCategoryInherited(void)
{
[cls doItClass5];
[cls doItInstance5];
[cls doItClass6];
[cls doItInstance6];
[clsP5 doItClass1];
[clsP5 doItInstance1]; /* { dg-warning "instead of" } */
[clsP5 doItClass2]; /* { dg-warning "not found in protocol" } */
[clsP5 doItInstance2]; /* { dg-warning "not found in protocol" } */
[clsP6 doItClass1]; /* { dg-warning "not found in protocol" } */
[clsP6 doItInstance1]; /* { dg-warning "not found in protocol" } */
[clsP6 doItClass2];
[clsP6 doItInstance2]; /* { dg-warning "instead of" } */
[MyClass1 doItClass5];
[MyClass1 doItInstance5];
[MyClass1 doItClass6]; /* { dg-warning "may not respond" } */
[MyClass1 doItInstance6]; /* { dg-warning "may not respond" } */
[MyClass2 doItClass5];
[MyClass2 doItInstance5];
[MyClass2 doItClass6];
[MyClass2 doItInstance6]; /* { dg-warning "may not respond" } */
}
/*----------------------------------------*/
/* Forward declared root protocols */
@protocol FwProto;
@interface MyClass1 (Forward) <FwProto> /* { dg-warning "definition of protocol .FwProto. not found" } */
@end
Class <FwProto> clsP7 = 0;
void
testForwardeDeclared1(void)
{
[cls doItClass7]; /* { dg-warning "no .\\+doItClass7. method found" } */
[cls doItInstance7]; /* { dg-warning "no .\\+doItInstance7. method found" } */
[clsP7 doItClass7]; /* { dg-warning "not found in protocol" } */
/* { dg-warning "no .\\+doItClass7. method found" "" { target *-*-* } .-1 } */
[clsP7 doItInstance7]; /* { dg-warning "not found in protocol" } */
/* { dg-warning "no .\\+doItInstance7. method found" "" { target *-*-* } .-1 } */
[MyClass1 doItClass7]; /* { dg-warning "may not respond" } */
[MyClass1 doItInstance7]; /* { dg-warning "may not respond" } */
[MyClass2 doItClass7]; /* { dg-warning "may not respond" } */
[MyClass2 doItInstance7]; /* { dg-warning "may not respond" } */
}
@protocol FwProto
+(void)doItClass7;
-(void)doItInstance7;
@end
void
testForwardeDeclared2(void)
{
[cls doItClass7];
[cls doItInstance7];
[clsP7 doItClass7];
[clsP7 doItInstance7]; /* { dg-warning "instead of" } */
[MyClass1 doItClass7];
[MyClass1 doItInstance7];
[MyClass2 doItClass7];
[MyClass2 doItInstance7];
}
/*----------------------------------------*/
/* Inherited non root protocols */
@protocol MyProto8
+(void)doItClass8;
-(void)doItInstance8;
@end
@protocol MyProto9 <MyProto8>
+(void)doItClass9;
-(void)doItInstance9;
@end
@interface MyClass1 (InheritedNonRoot) <MyProto9>
@end
Class <MyProto8> clsP8 = 0;
Class <MyProto9> clsP9 = 0;
void
testInheritedNonRoot(void)
{
[cls doItClass8];
[cls doItInstance8];
[cls doItClass9];
[cls doItInstance9];
[clsP8 doItClass8];
[clsP8 doItInstance8]; /* { dg-warning "instead of" } */
[clsP8 doItClass9]; /* { dg-warning "not found in protocol" } */
[clsP8 doItInstance9]; /* { dg-warning "not found in protocol" } */
[clsP9 doItClass8];
[clsP9 doItInstance8]; /* { dg-warning "instead of" } */
[clsP9 doItClass9];
[clsP9 doItInstance9]; /* { dg-warning "instead of" } */
[MyClass1 doItClass8];
[MyClass1 doItInstance8];
[MyClass1 doItClass9];
[MyClass1 doItInstance9];
[MyClass2 doItClass8];
[MyClass2 doItInstance8];
[MyClass2 doItClass9];
[MyClass2 doItInstance9];
}
/*----------------------------------------*/
/* Prototype mismatch */
@protocol MyOtherProto1
+(id)doItClass1;
-(id)doItInstance1;
@end
@interface MyOtherClass1 <MyOtherProto1>
@end
Class <MyOtherProto1> oclsP1;
void
testPrototypeMismatch(void)
{
id tmp1 = [oclsP1 doItClass1];
id tmp2 = [oclsP1 doItInstance1]; /* { dg-warning "instead of" } */
[clsP1 doItClass1];
[clsP1 doItInstance1]; /* { dg-warning "instead of" } */
}
id obj = nil;
id <MyProto1> objP1 = nil;
id <MyProto2> objP2 = nil;
id <MyProto5> objP5 = nil;
int num = 0;
void *ptr = 0;
MyClass1 *mc1 = nil;
void
testComptypes(void)
{
{ /* id <protocol>, id <protocol> */
objP1 == objP2; /* { dg-warning "lacks a cast" } */
objP2 == objP1; /* { dg-warning "lacks a cast" } */
objP1 == objP5;
objP5 == objP1;
}
{ /* id <protocol>, SomeClass * */
mc1 == objP1;
objP1 == mc1;
mc1 == objP2; /* { dg-warning "lacks a cast" } */
objP2 == mc1; /* { dg-warning "lacks a cast" } */
}
{ /* id <protocol>, id */
obj == objP1;
objP1 == obj;
}
{ /* id <protocol>, Class */
cls == objP1; /* { dg-warning "lacks a cast" } */
objP1 == cls; /* { dg-warning "lacks a cast" } */
}
{ /* id <protocol>, non-ObjC */
num == objP1; /* { dg-error "between pointer" } */
objP1 == num; /* { dg-error "between pointer" } */
ptr == objP1;
objP1 == ptr;
}
{ /* Class <protocol>, Class <protocol> */
clsP1 == clsP2; /* { dg-warning "lacks a cast" } */
clsP2 == clsP1; /* { dg-warning "lacks a cast" } */
clsP1 == clsP5;
clsP5 == clsP1;
}
{ /* Class <protocol>, SomeClass * */
mc1 == clsP1; /* { dg-warning "lacks a cast" } */
clsP1 == mc1; /* { dg-warning "lacks a cast" } */
}
{ /* Class <protocol>, id */
obj == clsP1;
clsP1 == obj;
}
{ /* Class <protocol>, Class */
cls == clsP1;
clsP1 == cls;
}
{ /* Class <protocol>, non-ObjC */
num == clsP1; /* { dg-error "between pointer" } */
clsP1 == num; /* { dg-error "between pointer" } */
ptr == clsP1;
clsP1 == ptr;
}
{ /* Class <protocol>, id <protocol> */
clsP1 == objP1; /* { dg-warning "lacks a cast" } */
objP1 == clsP1; /* { dg-warning "lacks a cast" } */
}
{ /* id <protocol>, id <protocol> */
objP1 = objP2; /* { dg-warning "does not conform" } */
objP2 = objP1; /* { dg-warning "does not conform" } */
objP1 = objP5;
objP5 = objP1; /* { dg-warning "does not conform" } */
}
{ /* id <protocol>, SomeClass * */
mc1 = objP1;
objP1 = mc1;
mc1 = objP2; /* { dg-warning "does not conform" } */
objP2 = mc1; /* { dg-warning "does not implement" } */
}
{ /* id <protocol>, id */
obj = objP1;
objP1 = obj;
}
{ /* id <protocol>, Class */
cls = objP1; /* { dg-warning "distinct Objective\\-C type" } */
objP1 = cls; /* { dg-warning "distinct Objective\\-C type" } */
}
{ /* id <protocol>, non-ObjC */
num = objP1; /* { dg-error "invalid conversion" } */
objP1 = num; /* { dg-error "invalid conversion" } */
ptr = objP1;
objP1 = ptr; /* { dg-error "invalid conversion" } */
}
{ /* Class <protocol>, Class <protocol> */
clsP1 = clsP2; /* { dg-warning "does not conform" } */
clsP2 = clsP1; /* { dg-warning "does not conform" } */
clsP1 = clsP5;
clsP5 = clsP1; /* { dg-warning "does not conform" } */
}
{ /* Class <protocol>, SomeClass * */
/* These combinations should always elicit a warning. */
mc1 = clsP1; /* { dg-warning "distinct Objective\\-C type" } */
clsP1 = mc1; /* { dg-warning "distinct Objective\\-C type" } */
mc1 = clsP2; /* { dg-warning "distinct Objective\\-C type" } */
clsP2 = mc1; /* { dg-warning "distinct Objective\\-C type" } */
}
{ /* Class <protocol>, id */
obj = clsP1;
clsP1 = obj;
}
{ /* Class <protocol>, Class */
cls = clsP1;
clsP1 = cls;
}
{ /* Class <protocol>, non-ObjC */
num = clsP1; /* { dg-error "invalid conversion" } */
clsP1 = num; /* { dg-error "invalid conversion" } */
ptr = clsP1;
clsP1 = ptr; /* { dg-error "invalid conversion" } */
}
{ /* Class <protocol>, id <protocol> */
clsP1 = objP1; /* { dg-warning "distinct Objective\\-C type" } */
objP1 = clsP1; /* { dg-warning "distinct Objective\\-C type" } */
}
}
int main ()
{
testSimple();
testCategory();
testCategoryInherited();
return(0);
}
/* { dg-warning "Messages without a matching method signature" "" { target *-*-* } 0 } */
/* { dg-warning "will be assumed to return .id. and accept" "" { target *-*-* } 0 } */
/* { dg-warning ".\.\.\.. as arguments" "" { target *-*-* } 0 } */
|