blob: 5e14a99b9bdb827c9ccbe300c5fd5b37182363eb [file] [log] [blame]
Douglas Gregord1377b22010-04-22 21:44:01 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
2
3@interface NSException
4@end
5
6// @throw
7template<typename T>
8void throw_test(T value) {
9 @throw value; // expected-error{{@throw requires an Objective-C object type ('int' invalid)}}
10}
11
12template void throw_test(NSException *);
13template void throw_test(int); // expected-note{{in instantiation of}}
14
Douglas Gregor8fdc13a2010-04-22 22:01:21 +000015// @synchronized
16template<typename T>
17void synchronized_test(T value) {
18 @synchronized (value) { // expected-error{{@synchronized requires an Objective-C object type ('int' invalid)}}
19 value = 0;
20 }
21}
Douglas Gregord1377b22010-04-22 21:44:01 +000022
Douglas Gregor8fdc13a2010-04-22 22:01:21 +000023template void synchronized_test(NSException *);
24template void synchronized_test(int); // expected-note{{in instantiation of}}
Douglas Gregorc3203e72010-04-22 23:10:45 +000025
26// fast enumeration
27@interface NSArray
28@end
29
30@interface NSString
31@end
32
33struct vector {};
34
35template<typename T> void eat(T);
36
37template<typename E, typename T>
38void fast_enumeration_test(T collection) {
39 for (E element in collection) { // expected-error{{selector element type 'int' is not a valid object}} \
40 // expected-error{{collection expression type 'vector' is not a valid object}}
41 eat(element);
42 }
43
44 E element;
45 for (element in collection) // expected-error{{selector element type 'int' is not a valid object}} \
46 // expected-error{{collection expression type 'vector' is not a valid object}}
47 eat(element);
48
49 for (NSString *str in collection) // expected-error{{collection expression type 'vector' is not a valid object}}
50 eat(str);
51
52 NSString *str;
53 for (str in collection) // expected-error{{collection expression type 'vector' is not a valid object}}
54 eat(str);
55}
56
57template void fast_enumeration_test<NSString *>(NSArray*);
58template void fast_enumeration_test<int>(NSArray*); // expected-note{{in instantiation of}}
59template void fast_enumeration_test<NSString *>(vector); // expected-note{{in instantiation of}}
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +000060
61// @try/@catch/@finally
62
63template<typename T, typename U>
64void try_catch_finally_test(U value) {
65 @try {
66 value = 1; // expected-error{{assigning to 'int *' from incompatible type 'int'}}
67 }
68 // FIXME: Add @catch
69 @finally {
70 value = 0;
71 }
72}
73
74template void try_catch_finally_test<NSString *>(int);
75template void try_catch_finally_test<NSString *>(int*); // expected-note{{in instantiation of}}