blob: 3e9ff605233b8ffcc26884e9eee9e4ed34340c92 [file] [log] [blame]
Douglas Gregor45d6bdf2010-09-07 15:23:11 +00001// RUN: %clang_cc1 -pedantic -verify %s
Nick Lewycky784fad72010-04-24 01:30:46 +00002// RUN: cp %s %t
Douglas Gregor45d6bdf2010-09-07 15:23:11 +00003// RUN: not %clang_cc1 -pedantic -fixit -x objective-c %t
4// RUN: %clang_cc1 -pedantic -Werror -x objective-c %t
Anders Carlssonace5d072009-11-10 04:46:30 +00005
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. */
Chris Lattner3a4e4312009-04-03 18:38:42 +000010
11@protocol X;
12
13void foo() {
Fariborz Jahaniana1b9b3f2013-02-28 23:16:39 +000014 <X> *P; // expected-warning{{protocol has no object type specified; defaults to qualified 'id'}}
Chris Lattner3a4e4312009-04-03 18:38:42 +000015}
Anders Carlssonace5d072009-11-10 04:46:30 +000016
17@class A;
18@class NSString;
19
20@interface Test
Fariborz Jahanian283bf892013-12-18 21:04:43 +000021- (void)test:(NSString *)string;
Anders Carlssonace5d072009-11-10 04:46:30 +000022
23@property (copy) NSString *property;
24@end
25
Fariborz Jahanian283bf892013-12-18 21:04:43 +000026void g(NSString *a);
27void h(id a);
Anders Carlssonace5d072009-11-10 04:46:30 +000028
29void f(Test *t) {
Fariborz Jahanianbd714e92013-12-17 19:33:43 +000030 NSString *a = "Foo"; // expected-error {{string literal must be prefixed by '@'}}
Fariborz Jahanian283bf892013-12-18 21:04:43 +000031 id b = "Foo"; // expected-error {{string literal must be prefixed by '@'}}
Fariborz Jahanianbd714e92013-12-17 19:33:43 +000032 g("Foo"); // expected-error {{string literal must be prefixed by '@'}}
Fariborz Jahanian283bf892013-12-18 21:04:43 +000033 h("Foo"); // expected-error {{string literal must be prefixed by '@'}}
34 h(("Foo")); // expected-error {{string literal must be prefixed by '@'}}
Fariborz Jahanianbd714e92013-12-17 19:33:43 +000035 [t test:"Foo"]; // expected-error {{string literal must be prefixed by '@'}}
36 t.property = "Foo"; // expected-error {{string literal must be prefixed by '@'}}
Douglas Gregor45d6bdf2010-09-07 15:23:11 +000037
38 // <rdar://problem/6896493>
39 [t test:@"Foo"]]; // expected-error{{extraneous ']' before ';'}}
40 g(@"Foo")); // expected-error{{extraneous ')' before ';'}}
Anders Carlssonace5d072009-11-10 04:46:30 +000041}
Fariborz Jahanianc297cd82011-06-28 00:00:52 +000042
43// rdar://7861841
44@interface Radar7861841 {
45@public
46 int x;
47}
48
49@property (assign) int y;
50@end
51
Fariborz Jahanian14fd8012012-09-24 22:00:36 +000052int 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'}}
Fariborz Jahanianc297cd82011-06-28 00:00:52 +000053
54int 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?}}
55
Douglas Gregor5ff4e982011-07-30 08:57:03 +000056
57#define nil ((void*)0)
58#define NULL ((void*)0)
59
60void sentinel(int x, ...) __attribute__((sentinel)); // expected-note{{function has been explicitly marked sentinel here}}
61
62@interface Sentinel
63- (void)sentinel:(int)x, ... __attribute__((sentinel)); // expected-note{{method has been explicitly marked sentinel here}}
64@end
65
66void sentinel_test(Sentinel *a) {
67 sentinel(1, 2, 3); // expected-warning{{missing sentinel in function call}}
68 [a sentinel:1, 2, 3]; // expected-warning{{missing sentinel in method dispatch}}
69}
Manman Ren2b2b1a92016-06-28 23:01:49 +000070
71@interface A
72@property (class) int c;
73@end
74
75int test(A *a) {
76 return a.c; // expected-error {{property 'c' is a class property; did you mean to access it with class 'A'}}
77}