Debian Codegraph @

clang/test/FixIt/fixit-objc.m

raw
1 // RUN: %clang_cc1 -pedantic -verify %s
2 // RUN: cp %s %t
3 // RUN: not %clang_cc1 -pedantic -fixit -x objective-c %t
4 // RUN: %clang_cc1 -pedantic -Werror -x objective-c %t
5
6 /* This is a test of the various code modification hints that are
7 provided as part of warning or extension diagnostics. All of the
8 warnings will be fixed by -fixit, and the resulting file should
9 compile cleanly with -Werror -pedantic. */
10
11 @protocol X;
12
13 void foo(void) {
14 <X> *P; // expected-warning{{protocol has no object type specified; defaults to qualified 'id'}}
15 }
16
17 @class A;
18 @class NSString;
19
20 @interface Test
21 - (void)test:(NSString *)string;
22
23 @property (copy) NSString *property;
24 @end
25
26 void g(NSString *a);
27 void h(id a);
28
29 void f(Test *t) {
30 NSString *a = "Foo"; // expected-error {{string literal must be prefixed by '@'}}
31 id b = "Foo"; // expected-error {{string literal must be prefixed by '@'}}
32 g("Foo"); // expected-error {{string literal must be prefixed by '@'}}
33 h("Foo"); // expected-error {{string literal must be prefixed by '@'}}
34 h(("Foo")); // expected-error {{string literal must be prefixed by '@'}}
35 [t test:"Foo"]; // expected-error {{string literal must be prefixed by '@'}}
36 t.property = "Foo"; // expected-error {{string literal must be prefixed by '@'}}
37
38 [t test:@"Foo"]]; // expected-error{{extraneous ']' before ';'}}
39 g(@"Foo")); // expected-error{{extraneous ')' before ';'}}
40 }
41
42 @interface Radar7861841 {
43 @public
44 int x;
45 }
46
47 @property (assign) int y;
48 @end
49
50 int f0(Radar7861841 *a) { return a.x; } // expected-error {{property 'x' not found on object of type 'Radar7861841 *'; did you mean to access instance variable 'x'}}
51
52 int f1(Radar7861841 *a) { return a->y; } // expected-error {{property 'y' found on object of type 'Radar7861841 *'; did you mean to access it with the "." operator?}}
53
54
55 #define nil ((void*)0)
56 #define NULL ((void*)0)
57
58 void sentinel(int x, ...) __attribute__((sentinel)); // expected-note{{function has been explicitly marked sentinel here}}
59
60 @interface Sentinel
61 - (void)sentinel:(int)x, ... __attribute__((sentinel)); // expected-note{{method has been explicitly marked sentinel here}}
62 @end
63
64 void sentinel_test(Sentinel *a) {
65 sentinel(1, 2, 3); // expected-warning{{missing sentinel in function call}}
66 [a sentinel:1, 2, 3]; // expected-warning{{missing sentinel in method dispatch}}
67 }
68
69 @interface A
70 @property (class) int c;
71 @end
72
73 int test(A *a) {
74 return a.c; // expected-error {{property 'c' is a class property; did you mean to access it with class 'A'}}
75 }