summaryrefslogtreecommitdiff
path: root/clang/test/SemaObjCXX/instantiate-stmt.mm
diff options
context:
space:
mode:
authorZancanaro; Carlo <czan8762@plang3.cs.usyd.edu.au>2012-09-24 09:58:17 +1000
committerZancanaro; Carlo <czan8762@plang3.cs.usyd.edu.au>2012-09-24 09:58:17 +1000
commit222e2a7620e6520ffaf4fc4e69d79c18da31542e (patch)
tree7bfbc05bfa3b41c8f9d2e56d53a0bc3e310df239 /clang/test/SemaObjCXX/instantiate-stmt.mm
parent3d206f03985b50beacae843d880bccdc91a9f424 (diff)
Add the clang library to the repo (with some of my changes, too).
Diffstat (limited to 'clang/test/SemaObjCXX/instantiate-stmt.mm')
-rw-r--r--clang/test/SemaObjCXX/instantiate-stmt.mm78
1 files changed, 78 insertions, 0 deletions
diff --git a/clang/test/SemaObjCXX/instantiate-stmt.mm b/clang/test/SemaObjCXX/instantiate-stmt.mm
new file mode 100644
index 0000000..ff72858
--- /dev/null
+++ b/clang/test/SemaObjCXX/instantiate-stmt.mm
@@ -0,0 +1,78 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -fobjc-exceptions %s
+
+@interface NSException
+@end
+
+// @throw
+template<typename T>
+void throw_test(T value) {
+ @throw value; // expected-error{{@throw requires an Objective-C object type ('int' invalid)}}
+}
+
+template void throw_test(NSException *);
+template void throw_test(int); // expected-note{{in instantiation of}}
+
+// @synchronized
+template<typename T>
+void synchronized_test(T value) {
+ @synchronized (value) { // expected-error{{@synchronized requires an Objective-C object type ('int' invalid)}}
+ value = 0;
+ }
+}
+
+template void synchronized_test(NSException *);
+template void synchronized_test(int); // expected-note{{in instantiation of}}
+
+// fast enumeration
+@interface NSArray
+- (unsigned int)countByEnumeratingWithState: (struct __objcFastEnumerationState *)state objects: (id *)items count:(unsigned int)stackcount;
+@end
+
+@interface NSString
+@end
+
+struct vector {};
+
+template<typename T> void eat(T);
+
+template<typename E, typename T>
+void fast_enumeration_test(T collection) {
+ for (E element in collection) { // expected-error{{selector element type 'int' is not a valid object}} \
+ // expected-error{{collection expression type 'vector' is not a valid object}}
+ eat(element);
+ }
+
+ E element;
+ for (element in collection) // expected-error{{selector element type 'int' is not a valid object}} \
+ // expected-error{{collection expression type 'vector' is not a valid object}}
+ eat(element);
+
+ for (NSString *str in collection) // expected-error{{collection expression type 'vector' is not a valid object}}
+ eat(str);
+
+ NSString *str;
+ for (str in collection) // expected-error{{collection expression type 'vector' is not a valid object}}
+ eat(str);
+}
+
+template void fast_enumeration_test<NSString *>(NSArray*);
+template void fast_enumeration_test<int>(NSArray*); // expected-note{{in instantiation of}}
+template void fast_enumeration_test<NSString *>(vector); // expected-note{{in instantiation of}}
+
+// @try/@catch/@finally
+
+template<typename T, typename U>
+void try_catch_finally_test(U value) {
+ @try {
+ value = 1; // expected-error{{assigning to 'int *' from incompatible type 'int'}}
+ }
+ @catch (T obj) { // expected-error{{@catch parameter is not a pointer to an interface type}}
+ id x = obj;
+ } @finally {
+ value = 0;
+ }
+}
+
+template void try_catch_finally_test<NSString *>(int);
+template void try_catch_finally_test<NSString *>(int*); // expected-note{{in instantiation of}}
+template void try_catch_finally_test<NSString>(int); // expected-note{{in instantiation of function template specialization 'try_catch_finally_test<NSString, int>' requested here}}