blob: ab86d9437f02bd7a52afcb45c7729b70ff39d63e [file] [log] [blame]
Douglas Gregorc5e77d52010-02-19 15:18:45 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Douglas Gregorc5e77d52010-02-19 15:18:45 +00002@interface I1
Douglas Gregor6aa14d82010-04-21 22:36:40 +00003- (int*)method;
Douglas Gregorc5e77d52010-02-19 15:18:45 +00004@end
5
6@implementation I1
Douglas Gregor6aa14d82010-04-21 22:36:40 +00007- (int*)method {
Douglas Gregorc5e77d52010-02-19 15:18:45 +00008 struct x { };
Douglas Gregor2725ca82010-04-21 19:57:20 +00009 [x method]; // expected-error{{receiver type 'x' is not an Objective-C class}}
Douglas Gregor6aa14d82010-04-21 22:36:40 +000010 return 0;
Douglas Gregorc5e77d52010-02-19 15:18:45 +000011}
12@end
Douglas Gregor36262b82010-02-19 16:08:35 +000013
14typedef struct { int x; } ivar;
15
16@interface I2 {
17 id ivar;
18}
Douglas Gregor6aa14d82010-04-21 22:36:40 +000019- (int*)method;
Douglas Gregor36262b82010-02-19 16:08:35 +000020+ (void)method;
21@end
22
Douglas Gregor6aa14d82010-04-21 22:36:40 +000023struct I2_holder {
24 I2_holder();
25
26 I2 *get();
27};
28
29I2 *operator+(I2_holder, int);
30
Douglas Gregor36262b82010-02-19 16:08:35 +000031@implementation I2
Douglas Gregor6aa14d82010-04-21 22:36:40 +000032- (int*)method {
Douglas Gregor36262b82010-02-19 16:08:35 +000033 [ivar method];
Douglas Gregor6aa14d82010-04-21 22:36:40 +000034
35 // Test instance messages that start with a simple-type-specifier.
36 [I2_holder().get() method];
37 [I2_holder().get() + 17 method];
38 return 0;
Douglas Gregor36262b82010-02-19 16:08:35 +000039}
40+ (void)method {
Gabor Greifd5278742010-08-28 10:40:52 +000041 [ivar method]; // expected-error{{receiver type 'ivar' is not an Objective-C class}}
Douglas Gregor36262b82010-02-19 16:08:35 +000042}
43@end
Douglas Gregor6aa14d82010-04-21 22:36:40 +000044
45// Class message sends
46@interface I3
47+ (int*)method;
48@end
49
50@interface I4 : I3
51+ (int*)otherMethod;
52@end
53
54template<typename T>
55struct identity {
56 typedef T type;
57};
58
59@implementation I4
60+ (int *)otherMethod {
61 // Test class messages that use non-trivial simple-type-specifiers
62 // or typename-specifiers.
63 if (false) {
64 if (true)
Douglas Gregor1a15dae2010-06-16 22:31:08 +000065 return [typename identity<I3>::type method]; // expected-warning{{occurs outside of a template}}
Douglas Gregor6aa14d82010-04-21 22:36:40 +000066
67 return [::I3 method];
68 }
69
70 int* ip1 = {[super method]};
71 int* ip2 = {[::I3 method]};
Douglas Gregor1a15dae2010-06-16 22:31:08 +000072 int* ip3 = {[typename identity<I3>::type method]}; // expected-warning{{occurs outside of a template}}
73 int* ip4 = {[typename identity<I2_holder>::type().get() method]}; // expected-warning{{occurs outside of a template}}
Douglas Gregor6aa14d82010-04-21 22:36:40 +000074 int array[5] = {[3] = 2};
75 return [super method];
76}
77@end
Douglas Gregor688fc9b2010-04-21 23:24:10 +000078
79struct String {
80 String(const char *);
81};
82
83struct MutableString : public String { };
84
85// C++-specific parameter types
86@interface I5
Douglas Gregora41a8c52010-04-22 00:20:18 +000087- method:(const String&)str1
88 other:(String&)str2; // expected-note{{passing argument to parameter 'str2' here}}
Douglas Gregor688fc9b2010-04-21 23:24:10 +000089@end
90
91void test_I5(I5 *i5, String s) {
92 [i5 method:"hello" other:s];
Chris Lattner58f9e132010-09-05 00:04:01 +000093 [i5 method:s other:"world"]; // expected-error{{non-const lvalue reference to type 'String' cannot bind to a value of unrelated type 'const char [6]'}}
Douglas Gregor688fc9b2010-04-21 23:24:10 +000094}