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// <rdar://problem/12031870>: don't warn about this 15extern "C" A* MakeA(); 16 17// Ensure that deduction works with lifetime qualifiers. 18void deduction(id obj) { 19 auto a = [[A alloc] init]; 20 __strong A** aPtr = &a; 21 22 auto a2([[A alloc] init]); 23 __strong A** aPtr2 = &a2; 24 25 __strong id *idp = new auto(obj); 26 27 __strong id array[17]; 28 for (auto x : array) { // expected-warning{{'auto' deduced as 'id' in declaration of 'x'}} 29 __strong id *xPtr = &x; 30 } 31 32 @try { 33 } @catch (auto e) { // expected-error {{'auto' not allowed in exception declaration}} 34 } 35} 36 37// rdar://problem/11068137 38void test1a() { 39 __autoreleasing id p; // expected-note 2 {{'p' declared here}} 40 (void) [&p] {}; 41 (void) [p] {}; // expected-error {{cannot capture __autoreleasing variable in a lambda by copy}} 42 (void) [=] { (void) p; }; // expected-error {{cannot capture __autoreleasing variable in a lambda by copy}} 43} 44void test1b() { 45 __autoreleasing id v; 46 __autoreleasing id &p = v; // expected-note 2 {{'p' declared here}} 47 (void) [&p] {}; 48 (void) [p] {}; // expected-error {{cannot capture __autoreleasing variable in a lambda by copy}} 49 (void) [=] { (void) p; }; // expected-error {{cannot capture __autoreleasing variable in a lambda by copy}} 50} 51void test1c() { 52 __autoreleasing id v; // expected-note {{'v' declared here}} 53 __autoreleasing id &p = v; 54 (void) ^{ (void) p; }; 55 (void) ^{ (void) v; }; // expected-error {{cannot capture __autoreleasing variable in a block}} 56} 57 58 59// <rdar://problem/11319689> 60// warn when initializing an 'auto' variable with an 'id' initializer expression 61 62void testAutoId(id obj) { 63 auto x = obj; // expected-warning{{'auto' deduced as 'id' in declaration of 'x'}} 64} 65 66@interface Array 67+ (instancetype)new; 68- (id)objectAtIndex:(int)index; 69@end 70 71// ...but don't warn if it's coming from a template parameter. 72template<typename T, int N> 73void autoTemplateFunction(T param, id obj, Array *arr) { 74 auto x = param; // no-warning 75 auto y = obj; // expected-warning{{'auto' deduced as 'id' in declaration of 'y'}} 76 auto z = [arr objectAtIndex:N]; // expected-warning{{'auto' deduced as 'id' in declaration of 'z'}} 77} 78 79void testAutoIdTemplate(id obj) { 80 autoTemplateFunction<id, 2>(obj, obj, [Array new]); // no-warning 81} 82 83// rdar://12229679 84@interface NSObject @end 85typedef __builtin_va_list va_list; 86@interface MyClass : NSObject 87@end 88 89@implementation MyClass 90+ (void)fooMethod:(id)firstArg, ... { 91 va_list args; 92 93 __builtin_va_arg(args, id); 94} 95@end 96 97namespace rdar12078752 { 98 void f() { 99 NSObject* o =0; 100 __autoreleasing decltype(o) o2 = o; 101 __autoreleasing auto o3 = o; 102 } 103} 104