File: warn-superclass-method-mismatch.m

package info (click to toggle)
llvm-toolchain-11 1%3A11.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 995,808 kB
  • sloc: cpp: 4,767,656; ansic: 760,916; asm: 477,436; python: 170,940; objc: 69,804; lisp: 29,914; sh: 23,855; f90: 18,173; pascal: 7,551; perl: 7,471; ml: 5,603; awk: 3,489; makefile: 2,573; xml: 915; cs: 573; fortran: 503; javascript: 452
file content (50 lines) | stat: -rw-r--r-- 2,203 bytes parent folder | download | duplicates (38)
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
// RUN: %clang_cc1  -fsyntax-only -Wsuper-class-method-mismatch -verify %s

@interface Root
-(void) method_r: (char)ch : (float*)f1 : (int*) x; // expected-note {{previous declaration is here}}
@end

@class Sub;

@interface Base : Root
-(void) method: (int*) x; // expected-note {{previous declaration is here}}
-(void) method1: (Base*) x; // expected-note {{previous declaration is here}}
-(void) method2: (Sub*) x; // expected-note{{passing argument to parameter 'x' here}}
+ method3: (int)x1 : (Base *)x2 : (float)x3; // expected-note {{previous declaration is here}}
+ mathod4: (id)x1;
- method5: (int) x : (double) d; // expected-note {{previous declaration is here}}
- method6: (int) x : (float) d; // expected-note {{previous declaration is here}}
@end

struct A {
  int x,y,z;
};

@interface Sub : Base
-(void) method: (struct A*) a;	// expected-warning {{method parameter type 'struct A *' does not match super class method parameter type 'int *'}}
-(void) method1: (Sub*) x;	// expected-warning {{method parameter type 'Sub *' does not match super class method parameter type 'Base *'}}
-(void) method2: (Base*) x;	// no need to warn. At call point we warn if need be.
+ method3: (int)x1 : (Sub *)x2 : (float)x3;	// expected-warning {{method parameter type 'Sub *' does not match super class method parameter type 'Base *'}}
+ mathod4: (Base*)x1;
-(void) method_r: (char)ch : (float*)f1 : (Sub*) x; // expected-warning {{method parameter type 'Sub *' does not match super class method parameter type 'int *'}}
- method5: (int) x : (float) d; // expected-warning {{method parameter type 'float' does not match super class method parameter type 'double'}}
- method6: (int) x : (double) d; // expected-warning {{method parameter type 'double' does not match super class method parameter type 'float'}}
@end

void f(Base *base, Sub *sub) {
  int x;
  [base method:&x];  // warn. if base is actually 'Sub' it will use -[Sub method] with wrong arguments
  
  Base *b;
  [base method1:b]; // if base is actuall 'Sub'  it will use [Sub method1] with wrong argument.

  [base method2:b];  // expected-warning {{}}

  Sub *s;
  [base method2:s]; // if base is actually 'Sub' OK. Either way OK.
  
}