• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fobjc-arc -verify -fblocks -fobjc-exceptions %s
2
3// "Move" semantics, trivial version.
4void move_it(__strong id &&from) {
5  id to = static_cast<__strong id&&>(from);
6}
7
8// Deduction with 'auto'.
9@interface A
10+ alloc;
11- init;
12@end
13
14// Ensure that deduction works with lifetime qualifiers.
15void deduction(id obj) {
16  auto a = [[A alloc] init];
17  __strong A** aPtr = &a;
18
19  auto a2([[A alloc] init]);
20  __strong A** aPtr2 = &a2;
21
22  __strong id *idp = new auto(obj);
23
24  __strong id array[17];
25  for (auto x : array) {
26    __strong id *xPtr = &x;
27  }
28
29  @try {
30  } @catch (auto e) { // expected-error {{'auto' not allowed in exception declaration}}
31  }
32}
33
34// rdar://problem/11068137
35void test1a() {
36  __autoreleasing id p; // expected-note 2 {{'p' declared here}}
37  (void) [&p] {};
38  (void) [p] {}; // expected-error {{cannot capture __autoreleasing variable in a lambda by copy}}
39  (void) [=] { (void) p; }; // expected-error {{cannot capture __autoreleasing variable in a lambda by copy}}
40}
41void test1b() {
42  __autoreleasing id v;
43  __autoreleasing id &p = v; // expected-note 2 {{'p' declared here}}
44  (void) [&p] {};
45  (void) [p] {}; // expected-error {{cannot capture __autoreleasing variable in a lambda by copy}}
46  (void) [=] { (void) p; }; // expected-error {{cannot capture __autoreleasing variable in a lambda by copy}}
47}
48void test1c() {
49  __autoreleasing id v; // expected-note {{'v' declared here}}
50  __autoreleasing id &p = v;
51  (void) ^{ (void) p; };
52  (void) ^{ (void) v; }; // expected-error {{cannot capture __autoreleasing variable in a block}}
53}
54