Douglas Gregor | 9ba23b4 | 2010-09-07 15:23:11 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -pedantic -verify %s |
Nick Lewycky | ba5f6ec | 2010-04-24 01:30:46 +0000 | [diff] [blame] | 2 | // RUN: cp %s %t |
Douglas Gregor | 9ba23b4 | 2010-09-07 15:23:11 +0000 | [diff] [blame] | 3 | // RUN: not %clang_cc1 -pedantic -fixit -x objective-c %t |
| 4 | // RUN: %clang_cc1 -pedantic -Werror -x objective-c %t |
Anders Carlsson | b76cd3d | 2009-11-10 04:46:30 +0000 | [diff] [blame] | 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. */ |
Chris Lattner | 75e3606 | 2009-04-03 18:38:42 +0000 | [diff] [blame] | 10 | |
| 11 | @protocol X; |
| 12 | |
| 13 | void foo() { |
Douglas Gregor | 9ba23b4 | 2010-09-07 15:23:11 +0000 | [diff] [blame] | 14 | <X> *P; // expected-warning{{protocol qualifiers without 'id' is archaic}} |
Chris Lattner | 75e3606 | 2009-04-03 18:38:42 +0000 | [diff] [blame] | 15 | } |
Anders Carlsson | b76cd3d | 2009-11-10 04:46:30 +0000 | [diff] [blame] | 16 | |
| 17 | @class A; |
| 18 | @class NSString; |
| 19 | |
| 20 | @interface Test |
Douglas Gregor | 9ba23b4 | 2010-09-07 15:23:11 +0000 | [diff] [blame] | 21 | - (void)test:(NSString *)string; // expected-note{{passing argument to parameter 'string' here}} |
Anders Carlsson | b76cd3d | 2009-11-10 04:46:30 +0000 | [diff] [blame] | 22 | |
| 23 | @property (copy) NSString *property; |
| 24 | @end |
| 25 | |
Douglas Gregor | 9ba23b4 | 2010-09-07 15:23:11 +0000 | [diff] [blame] | 26 | void g(NSString *a); // expected-note{{passing argument to parameter 'a' here}} |
| 27 | void h(id a); // expected-note 2{{passing argument to parameter 'a' here}} |
Anders Carlsson | b76cd3d | 2009-11-10 04:46:30 +0000 | [diff] [blame] | 28 | |
| 29 | void f(Test *t) { |
Douglas Gregor | 9ba23b4 | 2010-09-07 15:23:11 +0000 | [diff] [blame] | 30 | NSString *a = "Foo"; // expected-warning {{incompatible pointer types initializing 'NSString *' with an expression of type 'char [4]'}} |
| 31 | id b = "Foo"; // expected-warning {{incompatible pointer types initializing 'id' with an expression of type 'char [4]'}} |
| 32 | g("Foo"); // expected-warning{{incompatible pointer types passing 'char [4]' to parameter of type 'NSString *'}} |
| 33 | h("Foo"); // expected-warning{{incompatible pointer types passing 'char [4]' to parameter of type 'id'}} |
| 34 | h(("Foo")); // expected-warning{{incompatible pointer types passing 'char [4]' to parameter of type 'id'}} |
| 35 | [t test:"Foo"]; // expected-warning{{incompatible pointer types sending 'char [4]' to parameter of type 'NSString *'}} |
| 36 | t.property = "Foo"; // expected-warning{{incompatible pointer types assigning to 'NSString *' from 'char [4]'}} |
| 37 | |
| 38 | // <rdar://problem/6896493> |
| 39 | [t test:@"Foo"]]; // expected-error{{extraneous ']' before ';'}} |
| 40 | g(@"Foo")); // expected-error{{extraneous ')' before ';'}} |
Anders Carlsson | b76cd3d | 2009-11-10 04:46:30 +0000 | [diff] [blame] | 41 | } |
Fariborz Jahanian | 6326e05 | 2011-06-28 00:00:52 +0000 | [diff] [blame] | 42 | |
| 43 | // rdar://7861841 |
| 44 | @interface Radar7861841 { |
| 45 | @public |
| 46 | int x; |
| 47 | } |
| 48 | |
| 49 | @property (assign) int y; |
| 50 | @end |
| 51 | |
| 52 | int f0(Radar7861841 *a) { return a.x; } // expected-error {{property 'x' not found on object of type 'Radar7861841 *'; did you mean to access ivar 'x'}} |
| 53 | |
| 54 | 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?}} |
| 55 | |
Douglas Gregor | f78c4e5 | 2011-07-30 08:57:03 +0000 | [diff] [blame] | 56 | |
| 57 | #define nil ((void*)0) |
| 58 | #define NULL ((void*)0) |
| 59 | |
| 60 | void 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 | |
| 66 | void 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 | } |