annotate clang/test/SemaObjCXX/literals.mm @ 222:81f6424ef0e3 llvm-original

LLVM original branch
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 18 Jul 2021 22:10:01 +0900
parents 1d019706d866
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x -fblocks %s
anatofuz
parents:
diff changeset
2
anatofuz
parents:
diff changeset
3 // rdar://11231426
anatofuz
parents:
diff changeset
4 typedef signed char BOOL;
anatofuz
parents:
diff changeset
5
anatofuz
parents:
diff changeset
6 void y(BOOL (^foo)());
anatofuz
parents:
diff changeset
7
anatofuz
parents:
diff changeset
8 void x() {
anatofuz
parents:
diff changeset
9 y(^{
anatofuz
parents:
diff changeset
10 return __objc_yes;
anatofuz
parents:
diff changeset
11 });
anatofuz
parents:
diff changeset
12 }
anatofuz
parents:
diff changeset
13
anatofuz
parents:
diff changeset
14 @protocol NSCopying
anatofuz
parents:
diff changeset
15 - copy;
anatofuz
parents:
diff changeset
16 @end
anatofuz
parents:
diff changeset
17
anatofuz
parents:
diff changeset
18 @interface NSObject
anatofuz
parents:
diff changeset
19 @end
anatofuz
parents:
diff changeset
20
anatofuz
parents:
diff changeset
21 @interface NSNumber : NSObject <NSCopying>
anatofuz
parents:
diff changeset
22 -copy;
anatofuz
parents:
diff changeset
23 @end
anatofuz
parents:
diff changeset
24
anatofuz
parents:
diff changeset
25 @interface NSNumber (NSNumberCreation)
anatofuz
parents:
diff changeset
26 + (NSNumber *)numberWithChar:(char)value;
anatofuz
parents:
diff changeset
27 + (NSNumber *)numberWithUnsignedChar:(unsigned char)value;
anatofuz
parents:
diff changeset
28 + (NSNumber *)numberWithShort:(short)value;
anatofuz
parents:
diff changeset
29 + (NSNumber *)numberWithUnsignedShort:(unsigned short)value;
anatofuz
parents:
diff changeset
30 + (NSNumber *)numberWithInt:(int)value;
anatofuz
parents:
diff changeset
31 + (NSNumber *)numberWithUnsignedInt:(unsigned int)value;
anatofuz
parents:
diff changeset
32 + (NSNumber *)numberWithLong:(long)value;
anatofuz
parents:
diff changeset
33 + (NSNumber *)numberWithUnsignedLong:(unsigned long)value;
anatofuz
parents:
diff changeset
34 + (NSNumber *)numberWithLongLong:(long long)value;
anatofuz
parents:
diff changeset
35 + (NSNumber *)numberWithUnsignedLongLong:(unsigned long long)value;
anatofuz
parents:
diff changeset
36 + (NSNumber *)numberWithFloat:(float)value;
anatofuz
parents:
diff changeset
37 + (NSNumber *)numberWithDouble:(double)value;
anatofuz
parents:
diff changeset
38 + (NSNumber *)numberWithBool:(BOOL)value;
anatofuz
parents:
diff changeset
39 @end
anatofuz
parents:
diff changeset
40
anatofuz
parents:
diff changeset
41 @interface NSArray : NSObject <NSCopying>
anatofuz
parents:
diff changeset
42 -copy;
anatofuz
parents:
diff changeset
43 @end
anatofuz
parents:
diff changeset
44
anatofuz
parents:
diff changeset
45 @interface NSArray (NSArrayCreation)
anatofuz
parents:
diff changeset
46 + (id)arrayWithObjects:(const id [])objects count:(unsigned long)cnt;
anatofuz
parents:
diff changeset
47 @end
anatofuz
parents:
diff changeset
48
anatofuz
parents:
diff changeset
49 @interface NSDictionary
anatofuz
parents:
diff changeset
50 + (id)dictionaryWithObjects:(const id [])objects forKeys:(const id<NSCopying> [])keys count:(unsigned long)cnt;
anatofuz
parents:
diff changeset
51 @end
anatofuz
parents:
diff changeset
52
anatofuz
parents:
diff changeset
53 @interface NSString
anatofuz
parents:
diff changeset
54 @end
anatofuz
parents:
diff changeset
55
anatofuz
parents:
diff changeset
56 template<typename T>
anatofuz
parents:
diff changeset
57 struct ConvertibleTo {
anatofuz
parents:
diff changeset
58 operator T();
anatofuz
parents:
diff changeset
59 };
anatofuz
parents:
diff changeset
60
anatofuz
parents:
diff changeset
61 template<typename T>
anatofuz
parents:
diff changeset
62 struct ExplicitlyConvertibleTo {
anatofuz
parents:
diff changeset
63 explicit operator T();
anatofuz
parents:
diff changeset
64 };
anatofuz
parents:
diff changeset
65
anatofuz
parents:
diff changeset
66 template<typename T>
anatofuz
parents:
diff changeset
67 class PrivateConvertibleTo {
anatofuz
parents:
diff changeset
68 private:
anatofuz
parents:
diff changeset
69 operator T(); // expected-note{{declared private here}}
anatofuz
parents:
diff changeset
70 };
anatofuz
parents:
diff changeset
71
anatofuz
parents:
diff changeset
72 template<typename T> ConvertibleTo<T> makeConvertible();
anatofuz
parents:
diff changeset
73
anatofuz
parents:
diff changeset
74 struct X {
anatofuz
parents:
diff changeset
75 ConvertibleTo<id> x;
anatofuz
parents:
diff changeset
76 ConvertibleTo<id> get();
anatofuz
parents:
diff changeset
77 };
anatofuz
parents:
diff changeset
78
anatofuz
parents:
diff changeset
79 template<typename T> T test_numeric_instantiation() {
anatofuz
parents:
diff changeset
80 return @-17.42;
anatofuz
parents:
diff changeset
81 }
anatofuz
parents:
diff changeset
82
anatofuz
parents:
diff changeset
83 template id test_numeric_instantiation();
anatofuz
parents:
diff changeset
84
anatofuz
parents:
diff changeset
85 void test_convertibility(ConvertibleTo<NSArray*> toArray,
anatofuz
parents:
diff changeset
86 ConvertibleTo<id> toId,
anatofuz
parents:
diff changeset
87 ConvertibleTo<int (^)(int)> toBlock,
anatofuz
parents:
diff changeset
88 ConvertibleTo<int> toInt,
anatofuz
parents:
diff changeset
89 ExplicitlyConvertibleTo<NSArray *> toArrayExplicit) {
anatofuz
parents:
diff changeset
90 id array = @[
anatofuz
parents:
diff changeset
91 toArray,
anatofuz
parents:
diff changeset
92 toId,
anatofuz
parents:
diff changeset
93 toBlock,
anatofuz
parents:
diff changeset
94 toInt // expected-error{{collection element of type 'ConvertibleTo<int>' is not an Objective-C object}}
anatofuz
parents:
diff changeset
95 ];
anatofuz
parents:
diff changeset
96 id array2 = @[ toArrayExplicit ]; // expected-error{{collection element of type 'ExplicitlyConvertibleTo<NSArray *>' is not an Objective-C object}}
anatofuz
parents:
diff changeset
97
anatofuz
parents:
diff changeset
98 id array3 = @[
anatofuz
parents:
diff changeset
99 makeConvertible<id>(),
anatofuz
parents:
diff changeset
100 makeConvertible<id>, // expected-error{{collection element of type 'ConvertibleTo<id> ()' is not an Objective-C object}}
anatofuz
parents:
diff changeset
101 ];
anatofuz
parents:
diff changeset
102
anatofuz
parents:
diff changeset
103 X x;
anatofuz
parents:
diff changeset
104 id array4 = @[ x.x ];
anatofuz
parents:
diff changeset
105 id array5 = @[ x.get ]; // expected-error{{reference to non-static member function must be called}}
anatofuz
parents:
diff changeset
106 id array6 = @[ PrivateConvertibleTo<NSArray*>() ]; // expected-error{{operator NSArray *' is a private member of 'PrivateConvertibleTo<NSArray *>'}}
anatofuz
parents:
diff changeset
107 }
anatofuz
parents:
diff changeset
108
anatofuz
parents:
diff changeset
109 template<typename T>
anatofuz
parents:
diff changeset
110 void test_array_literals(T t) {
anatofuz
parents:
diff changeset
111 id arr = @[ @17, t ]; // expected-error{{collection element of type 'int' is not an Objective-C object}}
anatofuz
parents:
diff changeset
112 }
anatofuz
parents:
diff changeset
113
anatofuz
parents:
diff changeset
114 template void test_array_literals(id);
anatofuz
parents:
diff changeset
115 template void test_array_literals(NSArray*);
anatofuz
parents:
diff changeset
116 template void test_array_literals(int); // expected-note{{in instantiation of function template specialization 'test_array_literals<int>' requested here}}
anatofuz
parents:
diff changeset
117
anatofuz
parents:
diff changeset
118 template<typename T, typename U>
anatofuz
parents:
diff changeset
119 void test_dictionary_literals(T t, U u) {
anatofuz
parents:
diff changeset
120 NSObject *object;
anatofuz
parents:
diff changeset
121 id dict = @{
anatofuz
parents:
diff changeset
122 @17 : t, // expected-error{{collection element of type 'int' is not an Objective-C object}}
anatofuz
parents:
diff changeset
123 u : @42 // expected-error{{collection element of type 'int' is not an Objective-C object}}
anatofuz
parents:
diff changeset
124 };
anatofuz
parents:
diff changeset
125
anatofuz
parents:
diff changeset
126 id dict2 = @{
anatofuz
parents:
diff changeset
127 object : @"object" // expected-error{{cannot initialize a parameter of type 'const id<NSCopying>' with an rvalue of type 'NSObject *'}}
anatofuz
parents:
diff changeset
128 };
anatofuz
parents:
diff changeset
129 }
anatofuz
parents:
diff changeset
130
anatofuz
parents:
diff changeset
131 template void test_dictionary_literals(id, NSArray*);
anatofuz
parents:
diff changeset
132 template void test_dictionary_literals(NSArray*, id);
anatofuz
parents:
diff changeset
133 template void test_dictionary_literals(int, id); // expected-note{{in instantiation of function template specialization 'test_dictionary_literals<int, id>' requested here}}
anatofuz
parents:
diff changeset
134 template void test_dictionary_literals(id, int); // expected-note{{in instantiation of function template specialization 'test_dictionary_literals<id, int>' requested here}}
anatofuz
parents:
diff changeset
135
anatofuz
parents:
diff changeset
136 template<typename ...Args>
anatofuz
parents:
diff changeset
137 void test_bad_variadic_array_literal(Args ...args) {
anatofuz
parents:
diff changeset
138 id arr1 = @[ args ]; // expected-error{{initializer contains unexpanded parameter pack 'args'}}
anatofuz
parents:
diff changeset
139 }
anatofuz
parents:
diff changeset
140
anatofuz
parents:
diff changeset
141 template<typename ...Args>
anatofuz
parents:
diff changeset
142 void test_variadic_array_literal(Args ...args) {
anatofuz
parents:
diff changeset
143 id arr1 = @[ args... ]; // expected-error{{collection element of type 'int' is not an Objective-C object}}
anatofuz
parents:
diff changeset
144 }
anatofuz
parents:
diff changeset
145 template void test_variadic_array_literal(id);
anatofuz
parents:
diff changeset
146 template void test_variadic_array_literal(id, NSArray*);
anatofuz
parents:
diff changeset
147 template void test_variadic_array_literal(id, int, NSArray*); // expected-note{{in instantiation of function template specialization 'test_variadic_array_literal<id, int, NSArray *>' requested here}}
anatofuz
parents:
diff changeset
148
anatofuz
parents:
diff changeset
149 template<typename ...Args>
anatofuz
parents:
diff changeset
150 void test_bad_variadic_dictionary_literal(Args ...args) {
anatofuz
parents:
diff changeset
151 id dict = @{ args : @17 }; // expected-error{{initializer contains unexpanded parameter pack 'args'}}
anatofuz
parents:
diff changeset
152 }
anatofuz
parents:
diff changeset
153
anatofuz
parents:
diff changeset
154 // Test array literal pack expansions.
anatofuz
parents:
diff changeset
155 template<typename T, typename U>
anatofuz
parents:
diff changeset
156 struct pair {
anatofuz
parents:
diff changeset
157 T first;
anatofuz
parents:
diff changeset
158 U second;
anatofuz
parents:
diff changeset
159 };
anatofuz
parents:
diff changeset
160
anatofuz
parents:
diff changeset
161 template<typename T, typename ...Ts, typename ... Us>
anatofuz
parents:
diff changeset
162 void test_variadic_dictionary_expansion(T t, pair<Ts, Us>... key_values) {
anatofuz
parents:
diff changeset
163 id dict = @{
anatofuz
parents:
diff changeset
164 t : key_values.second ..., // expected-error{{collection element of type 'int' is not an Objective-C object}}
anatofuz
parents:
diff changeset
165 key_values.first : key_values.second ..., // expected-error{{collection element of type 'float' is not an Objective-C object}}
anatofuz
parents:
diff changeset
166 key_values.second : t ...
anatofuz
parents:
diff changeset
167 };
anatofuz
parents:
diff changeset
168 }
anatofuz
parents:
diff changeset
169
anatofuz
parents:
diff changeset
170 template void test_variadic_dictionary_expansion(id,
anatofuz
parents:
diff changeset
171 pair<NSNumber*, id>,
anatofuz
parents:
diff changeset
172 pair<id, ConvertibleTo<id>>);
anatofuz
parents:
diff changeset
173 template void test_variadic_dictionary_expansion(NSNumber *, // expected-note{{in instantiation of function template specialization}}
anatofuz
parents:
diff changeset
174 pair<NSNumber*, int>,
anatofuz
parents:
diff changeset
175 pair<id, ConvertibleTo<id>>);
anatofuz
parents:
diff changeset
176 template void test_variadic_dictionary_expansion(NSNumber *, // expected-note{{in instantiation of function template specialization}}
anatofuz
parents:
diff changeset
177 pair<NSNumber*, id>,
anatofuz
parents:
diff changeset
178 pair<float, ConvertibleTo<id>>);
anatofuz
parents:
diff changeset
179
anatofuz
parents:
diff changeset
180 // Test parsing
anatofuz
parents:
diff changeset
181 struct key {
anatofuz
parents:
diff changeset
182 static id value;
anatofuz
parents:
diff changeset
183 };
anatofuz
parents:
diff changeset
184
anatofuz
parents:
diff changeset
185 id key;
anatofuz
parents:
diff changeset
186 id value;
anatofuz
parents:
diff changeset
187
anatofuz
parents:
diff changeset
188 void test_dictionary_colon() {
anatofuz
parents:
diff changeset
189 id dict = @{ key : value };
anatofuz
parents:
diff changeset
190 }
anatofuz
parents:
diff changeset
191
anatofuz
parents:
diff changeset
192 void testConstExpr() {
anatofuz
parents:
diff changeset
193 constexpr NSString *t0 = @"abc";
anatofuz
parents:
diff changeset
194 constexpr NSString *t1 = @("abc");
anatofuz
parents:
diff changeset
195 }