File: instantiate-stmt.mm

package info (click to toggle)
llvm-toolchain-15 1%3A15.0.6-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,554,644 kB
  • sloc: cpp: 5,922,452; ansic: 1,012,136; asm: 674,362; python: 191,568; objc: 73,855; f90: 42,327; lisp: 31,913; pascal: 11,973; javascript: 10,144; sh: 9,421; perl: 7,447; ml: 5,527; awk: 3,523; makefile: 2,520; xml: 885; cs: 573; fortran: 567
file content (78 lines) | stat: -rw-r--r-- 2,710 bytes parent folder | download | duplicates (21)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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{{the type 'vector' is not a pointer to a fast-enumerable object}}
    eat(element);
  }

  E element;
  for (element in collection) // expected-error{{selector element type 'int' is not a valid object}} \
    // expected-error{{the type 'vector' is not a pointer to a fast-enumerable object}}
    eat(element);

  for (NSString *str in collection) // expected-error{{the type 'vector' is not a pointer to a fast-enumerable object}}
    eat(str);

  NSString *str;
  for (str in collection) // expected-error{{the type 'vector' is not a pointer to a fast-enumerable 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{{incompatible integer to pointer conversion assigning to 'int *' from '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}}