1 | // RUN: %clang_cc1 -fsyntax-only -verify -fobjc-exceptions %s |
2 | |
3 | @interface NSException |
4 | @end |
5 | |
6 | // @throw |
7 | template<typename T> |
8 | void throw_test(T value) { |
9 | @throw value; // expected-error{{@throw requires an Objective-C object type ('int' invalid)}} |
10 | } |
11 | |
12 | template void throw_test(NSException *); |
13 | template void throw_test(int); // expected-note{{in instantiation of}} |
14 | |
15 | // @synchronized |
16 | template<typename T> |
17 | void synchronized_test(T value) { |
18 | @synchronized (value) { // expected-error{{@synchronized requires an Objective-C object type ('int' invalid)}} |
19 | value = 0; |
20 | } |
21 | } |
22 | |
23 | template void synchronized_test(NSException *); |
24 | template void synchronized_test(int); // expected-note{{in instantiation of}} |
25 | |
26 | // fast enumeration |
27 | @interface NSArray |
28 | - (unsigned int)countByEnumeratingWithState: (struct __objcFastEnumerationState *)state objects: (id *)items count:(unsigned int)stackcount; |
29 | @end |
30 | |
31 | @interface NSString |
32 | @end |
33 | |
34 | struct vector {}; |
35 | |
36 | template<typename T> void eat(T); |
37 | |
38 | template<typename E, typename T> |
39 | void fast_enumeration_test(T collection) { |
40 | for (E element in collection) { // expected-error{{selector element type 'int' is not a valid object}} \ |
41 | // expected-error{{the type 'vector' is not a pointer to a fast-enumerable object}} |
42 | eat(element); |
43 | } |
44 | |
45 | E element; |
46 | for (element in collection) // expected-error{{selector element type 'int' is not a valid object}} \ |
47 | // expected-error{{the type 'vector' is not a pointer to a fast-enumerable object}} |
48 | eat(element); |
49 | |
50 | for (NSString *str in collection) // expected-error{{the type 'vector' is not a pointer to a fast-enumerable object}} |
51 | eat(str); |
52 | |
53 | NSString *str; |
54 | for (str in collection) // expected-error{{the type 'vector' is not a pointer to a fast-enumerable object}} |
55 | eat(str); |
56 | } |
57 | |
58 | template void fast_enumeration_test<NSString *>(NSArray*); |
59 | template void fast_enumeration_test<int>(NSArray*); // expected-note{{in instantiation of}} |
60 | template void fast_enumeration_test<NSString *>(vector); // expected-note{{in instantiation of}} |
61 | |
62 | // @try/@catch/@finally |
63 | |
64 | template<typename T, typename U> |
65 | void try_catch_finally_test(U value) { |
66 | @try { |
67 | value = 1; // expected-error{{assigning to 'int *' from incompatible type 'int'}} |
68 | } |
69 | @catch (T obj) { // expected-error{{@catch parameter is not a pointer to an interface type}} |
70 | id x = obj; |
71 | } @finally { |
72 | value = 0; |
73 | } |
74 | } |
75 | |
76 | template void try_catch_finally_test<NSString *>(int); |
77 | template void try_catch_finally_test<NSString *>(int*); // expected-note{{in instantiation of}} |
78 | template void try_catch_finally_test<NSString>(int); // expected-note{{in instantiation of function template specialization 'try_catch_finally_test<NSString, int>' requested here}} |
79 | |