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