// RUN: %clang_cc1 -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -verify -fblocks %s @interface A @end @class NSString; template struct is_same { static const bool value = false; }; template struct is_same { static const bool value = true; }; // Instantiation for reference/pointer types that will get lifetime // adjustments. template struct X0 { typedef T* pointer; // okay: ends up being strong. typedef T& reference; // okay: ends up being strong }; void test_X0() { X0 x0id; X0 x0a; X0<__strong A*> x0sa; id __strong *ptr; id __strong val; X0<__strong id>::pointer &ptr_ref = ptr; X0<__strong id>::reference ref = val; } int check_infer_strong[is_same::value? 1 : -1]; // Check template argument deduction (e.g., for specialization) using // lifetime qualifiers. template struct is_pointer_strong { static const bool value = false; }; template struct is_pointer_strong<__strong T*> { static const bool value = true; }; int check_ptr_strong1[is_pointer_strong<__strong id*>::value? 1 : -1]; int check_ptr_strong2[is_pointer_strong<__weak id*>::value? -1 : 1]; int check_ptr_strong3[is_pointer_strong<__autoreleasing id*>::value? -1 : 1]; int check_ptr_strong4[is_pointer_strong<__unsafe_unretained id*>::value? -1 : 1]; int check_ptr_strong5[is_pointer_strong::value? -1 : 1]; // Check substitution into lifetime-qualified dependent types. template struct make_strong_pointer { typedef __strong T *type; }; template struct make_strong_pointer<__weak T> { typedef __strong T *type; }; template struct make_strong_pointer<__autoreleasing T> { typedef __strong T *type; }; template struct make_strong_pointer<__unsafe_unretained T> { typedef __strong T *type; }; // Adding qualifiers int check_make_strong1[is_same::type, __strong id *>::value ? 1 : -1]; int check_make_strong2[is_same::type, A* __strong *>::value ? 1 : -1]; // Adding redundant qualifiers int check_make_strong3[is_same::type, __strong id *>::value ? 1 : -1]; int check_make_strong4[is_same::type, A* __strong *>::value ? 1 : -1]; // Adding nonsensical qualifiers. int check_make_strong5[is_same::type, int *>::value ? 1 : -1]; int check_make_strong6[is_same::type, __strong id *>::value ? 1 : -1]; template struct make_weak { typedef __weak T type; }; int check_make_weak0[is_same::type, __weak id>::value? 1 : -1]; int check_make_weak1[is_same::type, __weak id>::value? 1 : -1]; int check_make_weak2[is_same::type, __weak id>::value? 1 : -1]; template struct make_weak_fail { typedef T T_type; typedef __weak T_type type; // expected-error{{the type 'T_type' (aka '__weak id') is already explicitly ownership-qualified}} \ // expected-error{{the type 'T_type' (aka '__strong id') is already explicitly ownership-qualified}} }; int check_make_weak_fail0[is_same::type, __weak id>::value? 1 : -1]; // expected-note{{in instantiation of template class 'make_weak_fail<__weak id>' requested here}} int check_make_weak_fail1[is_same::type, __weak id>::value? -1 : 1]; // expected-note{{in instantiation of template class 'make_weak_fail' requested here}} // Check template argument deduction from function templates. template struct identity { }; template identity accept_strong_ptr(__strong T*); template identity accept_strong_ref(__strong T&); template identity accept_any_ptr(T*); template identity accept_any_ref(T&); void test_func_deduction_id() { __strong id *sip; __weak id *wip; __autoreleasing id *aip; __unsafe_unretained id *uip; identity res1 = accept_strong_ptr(sip); identity<__strong id> res2 = accept_any_ptr(sip); __strong id si; __weak id wi; __autoreleasing id ai; __unsafe_unretained id ui; identity res3 = accept_strong_ref(si); identity<__strong id> res4 = accept_any_ref(si); identity<__weak id> res5 = accept_any_ref(wi); identity<__autoreleasing id> res6 = accept_any_ref(ai); identity<__unsafe_unretained id> res7 = accept_any_ref(ui); } void test_func_deduction_A() { __strong A * *sip; __weak A * *wip; __autoreleasing A * *aip; __unsafe_unretained A * *uip; identity res1 = accept_strong_ptr(sip); identity<__strong A *> res2 = accept_any_ptr(sip); __strong A * si; __weak A * wi; __autoreleasing A * ai; __unsafe_unretained A * ui; identity res3 = accept_strong_ref(si); identity<__strong A *> res4 = accept_any_ref(si); identity<__weak A *> res5 = accept_any_ref(wi); identity<__autoreleasing A *> res6 = accept_any_ref(ai); identity<__unsafe_unretained A *> res7 = accept_any_ref(ui); } // Test partial ordering (qualified vs. non-qualified). template struct classify_pointer_pointer { static const unsigned value = 0; }; template struct classify_pointer_pointer { static const unsigned value = 1; }; template struct classify_pointer_pointer<__strong T*> { static const unsigned value = 2; }; template struct classify_pointer_pointer<__weak T*> { static const unsigned value = 3; }; template struct classify_pointer_pointer { static const unsigned value = 4; }; template struct classify_pointer_pointer<__strong T&> { static const unsigned value = 5; }; template struct classify_pointer_pointer<__weak T&> { static const unsigned value = 6; }; int classify_ptr1[classify_pointer_pointer::value == 0? 1 : -1]; int classify_ptr2[classify_pointer_pointer::value == 1? 1 : -1]; int classify_ptr3[classify_pointer_pointer::value == 2? 1 : -1]; int classify_ptr4[classify_pointer_pointer::value == 3? 1 : -1]; int classify_ptr5[classify_pointer_pointer::value == 4? 1 : -1]; int classify_ptr6[classify_pointer_pointer::value == 5? 1 : -1]; int classify_ptr7[classify_pointer_pointer::value == 6? 1 : -1]; int classify_ptr8[classify_pointer_pointer::value == 4? 1 : -1]; int classify_ptr9[classify_pointer_pointer::value == 4? 1 : -1]; int classify_ptr10[classify_pointer_pointer::value == 1? 1 : -1]; int classify_ptr11[classify_pointer_pointer::value == 1? 1 : -1]; int classify_ptr12[classify_pointer_pointer::value == 1? 1 : -1]; int classify_ptr13[classify_pointer_pointer::value == 2? 1 : -1]; int classify_ptr14[classify_pointer_pointer::value == 3? 1 : -1]; int classify_ptr15[classify_pointer_pointer::value == 4? 1 : -1]; int classify_ptr16[classify_pointer_pointer::value == 5? 1 : -1]; int classify_ptr17[classify_pointer_pointer::value == 6? 1 : -1]; int classify_ptr18[classify_pointer_pointer::value == 4? 1 : -1]; int classify_ptr19[classify_pointer_pointer::value == 4? 1 : -1]; int classify_ptr20[classify_pointer_pointer::value == 1? 1 : -1]; int classify_ptr21[classify_pointer_pointer::value == 1? 1 : -1]; template int& qual_vs_unqual_ptr(__strong T*); template double& qual_vs_unqual_ptr(__weak T*); template float& qual_vs_unqual_ptr(T*); template int& qual_vs_unqual_ref(__strong T&); template double& qual_vs_unqual_ref(__weak T&); template float& qual_vs_unqual_ref(T&); void test_qual_vs_unqual_id() { __strong id *sip; __weak id *wip; __autoreleasing id *aip; __unsafe_unretained id *uip; int &ir1 = qual_vs_unqual_ptr(sip); double &dr1 = qual_vs_unqual_ptr(wip); float &fr1 = qual_vs_unqual_ptr(aip); float &fr2 = qual_vs_unqual_ptr(uip); int &ir2 = qual_vs_unqual_ref(*sip); double &dr2 = qual_vs_unqual_ref(*wip); float &fr3 = qual_vs_unqual_ref(*aip); float &fr4 = qual_vs_unqual_ref(*uip); } void test_qual_vs_unqual_a() { __strong A * *sap; __weak A * *wap; __autoreleasing A * *aap; __unsafe_unretained A * *uap; int &ir1 = qual_vs_unqual_ptr(sap); double &dr1 = qual_vs_unqual_ptr(wap); float &fr1 = qual_vs_unqual_ptr(aap); float &fr2 = qual_vs_unqual_ptr(uap); int &ir2 = qual_vs_unqual_ref(*sap); double &dr2 = qual_vs_unqual_ref(*wap); float &fr3 = qual_vs_unqual_ref(*aap); float &fr4 = qual_vs_unqual_ref(*uap); } namespace rdar9828157 { // Template argument deduction involving lifetime qualifiers and // non-lifetime types. class A { }; template float& f(T&); template int& f(__strong T&); template double& f(__weak T&); void test_f(A* ap) { float &fr = (f)(ap); } } namespace rdar10862386 { // More deduction with lifetime qualifiers. template int testing(const T &) { return 1; } void test() { testing(1); testing("hi"); testing(@"hi"); testing(@"hi"); } } namespace rdar12367446 { template class A; template class A {}; void test() { A value; } } namespace rdar14467941 { template int &takePtr(const T &); template float &takePtr(T * const &); void testTakePtr(A *a) { float &fr1 = takePtr(a); float &fr2 = takePtr(a); } } namespace rdar15713945 { template int &f(__strong T &); template float &f(__weak T &); template double &f(__unsafe_unretained T &); template char &f(T &); void foo() { __strong NSString * const strong = 0; int &ir = (f)(strong); __weak NSString * const weak = 0; float &fr = (f)(weak); __unsafe_unretained NSString * const unsafe = 0; double &dr = (f)(unsafe); } }