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