Fix the clang-wpa example.
[clang.git] / test / SemaObjCXX / message.mm
blob4f7f8bca5eb1974631d1f21d51e1b0e8fead4044
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2 @interface I1
3 - (int*)method;
4 @end
6 @implementation I1
7 - (int*)method {
8   struct x { };
9   [x method]; // expected-error{{receiver type 'x' is not an Objective-C class}}
10   return 0;
12 @end
14 typedef struct { int x; } ivar;
16 @interface I2 {
17   id ivar;
19 - (int*)method;
20 + (void)method;
21 @end
23 struct I2_holder {
24   I2_holder();
26   I2 *get();
29 I2 *operator+(I2_holder, int);
31 @implementation I2
32 - (int*)method {
33   [ivar method];
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;
40 + (void)method {
41   [ivar method]; // expected-error{{receiver type 'ivar' is not an Objective-C class}}
43 @end
45 // Class message sends
46 @interface I3
47 + (int*)method;
48 @end
50 @interface I4 : I3
51 + (int*)otherMethod;
52 @end
54 template<typename T>
55 struct identity {
56   typedef T type;
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)
65       return [typename identity<I3>::type method]; // expected-warning{{occurs outside of a template}}
67     return [::I3 method];
68   }
70   int* ip1 = {[super method]};
71   int* ip2 = {[::I3 method]};
72   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}}
74   int array[5] = {[3] = 2};
75   return [super method];
77 @end
79 struct String {
80   String(const char *);
83 struct MutableString : public String { };
85 // C++-specific parameter types
86 @interface I5
87 - method:(const String&)str1 
88    other:(String&)str2; // expected-note{{passing argument to parameter 'str2' here}}
89 @end
91 void test_I5(I5 *i5, String s) {
92   [i5 method:"hello" other:s];
93   [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]'}}
96 // <rdar://problem/8483253>
97 @interface A
99 struct X { };
101 + (A *)create:(void (*)(void *x, X r, void *data))callback
102               callbackData:(void *)callback_data;
104 @end
107 void foo(void)
109   void *fun;
110   void *ptr;
111   X r;
112   A *im = [A create:(void (*)(void *cgl_ctx, X r, void *data)) fun
113              callbackData:ptr];
116 // <rdar://problem/8807070>
117 template<typename T> struct X1; // expected-note{{template is declared here}}
119 @interface B
120 + (X1<int>)blah;
121 + (X1<float>&)blarg;
122 @end
124 void f() {
125   [B blah]; // expected-error{{implicit instantiation of undefined template 'X1<int>'}}
126   [B blarg];