Anders Carlsson | e9b801f | 2011-02-22 01:52:06 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -fobjc-exceptions %s |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 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 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 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 | } |
Douglas Gregor | d1377b2 | 2010-04-22 21:44:01 +0000 | [diff] [blame] | 22 | |
Douglas Gregor | 8fdc13a | 2010-04-22 22:01:21 +0000 | [diff] [blame] | 23 | template void synchronized_test(NSException *); |
| 24 | template void synchronized_test(int); // expected-note{{in instantiation of}} |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 25 | |
| 26 | // fast enumeration |
| 27 | @interface NSArray |
Fariborz Jahanian | ea16110 | 2010-08-12 22:25:42 +0000 | [diff] [blame] | 28 | - (unsigned int)countByEnumeratingWithState: (struct __objcFastEnumerationState *)state objects: (id *)items count:(unsigned int)stackcount; |
Douglas Gregor | c3203e7 | 2010-04-22 23:10:45 +0000 | [diff] [blame] | 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{{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 | |
| 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}} |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 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 | } |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 69 | @catch (T obj) { // expected-error{{@catch parameter is not a pointer to an interface type}} |
| 70 | id x = obj; |
| 71 | } @finally { |
Douglas Gregor | 4dfdd1b | 2010-04-22 23:59:56 +0000 | [diff] [blame] | 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}} |
Douglas Gregor | be270a0 | 2010-04-26 17:57:08 +0000 | [diff] [blame] | 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}} |