blob: ff72858afd3f25c71c3f49efe9f606a336158e0f [file] [log] [blame]
Anders Carlssone9b801f2011-02-22 01:52:06 +00001// RUN: %clang_cc1 -fsyntax-only -verify -fobjc-exceptions %s
Douglas Gregord1377b22010-04-22 21:44:01 +00002
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
Fariborz Jahanianea161102010-08-12 22:25:42 +000028- (unsigned int)countByEnumeratingWithState: (struct __objcFastEnumerationState *)state objects: (id *)items count:(unsigned int)stackcount;
Douglas Gregorc3203e72010-04-22 23:10:45 +000029@end
30
31@interface NSString
32@end
33
34struct vector {};
35
36template<typename T> void eat(T);
37
38template<typename E, typename T>
39void 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{{collection expression type 'vector' is not a valid 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{{collection expression type 'vector' is not a valid object}}
48 eat(element);
49
50 for (NSString *str in collection) // expected-error{{collection expression type 'vector' is not a valid object}}
51 eat(str);
52
53 NSString *str;
54 for (str in collection) // expected-error{{collection expression type 'vector' is not a valid object}}
55 eat(str);
56}
57
58template void fast_enumeration_test<NSString *>(NSArray*);
59template void fast_enumeration_test<int>(NSArray*); // expected-note{{in instantiation of}}
60template void fast_enumeration_test<NSString *>(vector); // expected-note{{in instantiation of}}
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +000061
62// @try/@catch/@finally
63
64template<typename T, typename U>
65void try_catch_finally_test(U value) {
66 @try {
67 value = 1; // expected-error{{assigning to 'int *' from incompatible type 'int'}}
68 }
Douglas Gregorbe270a02010-04-26 17:57:08 +000069 @catch (T obj) { // expected-error{{@catch parameter is not a pointer to an interface type}}
70 id x = obj;
71 } @finally {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +000072 value = 0;
73 }
74}
75
76template void try_catch_finally_test<NSString *>(int);
77template void try_catch_finally_test<NSString *>(int*); // expected-note{{in instantiation of}}
Douglas Gregorbe270a02010-04-26 17:57:08 +000078template void try_catch_finally_test<NSString>(int); // expected-note{{in instantiation of function template specialization 'try_catch_finally_test<NSString, int>' requested here}}