diff options
Diffstat (limited to 'test/SemaObjCXX')
35 files changed, 683 insertions, 48 deletions
diff --git a/test/SemaObjCXX/NSString-type.mm b/test/SemaObjCXX/NSString-type.mm new file mode 100644 index 000000000000..10338667b78b --- /dev/null +++ b/test/SemaObjCXX/NSString-type.mm @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -x objective-c++ -triple x86_64-apple-darwin10 -fblocks -fsyntax-only -verify %s +// rdar://10907410 + +void test(id pid, Class pclass) { + void (^block)(void) = @"help"; // expected-error {{cannot initialize a variable of type 'void (^)()' with an rvalue of type 'NSString *'}} + void (^block1)(void) = pid; + void (^block2)(void) = @"help"; // expected-error {{cannot initialize a variable of type 'void (^)()' with an rvalue of type 'NSString *'}} + void (^block3)(void) = @"help"; // expected-error {{cannot initialize a variable of type 'void (^)()' with an rvalue of type 'NSString *'}} +} + diff --git a/test/SemaObjCXX/arc-0x.mm b/test/SemaObjCXX/arc-0x.mm index be9f1dc2e28c..28eec51775bd 100644 --- a/test/SemaObjCXX/arc-0x.mm +++ b/test/SemaObjCXX/arc-0x.mm @@ -30,3 +30,24 @@ void deduction(id obj) { } @catch (auto e) { // expected-error {{'auto' not allowed in exception declaration}} } } + +// rdar://problem/11068137 +void test1a() { + __autoreleasing id p; // expected-note 2 {{'p' declared here}} + (void) [&p] {}; + (void) [p] {}; // expected-error {{cannot capture __autoreleasing variable in a lambda by copy}} + (void) [=] { (void) p; }; // expected-error {{cannot capture __autoreleasing variable in a lambda by copy}} +} +void test1b() { + __autoreleasing id v; + __autoreleasing id &p = v; // expected-note 2 {{'p' declared here}} + (void) [&p] {}; + (void) [p] {}; // expected-error {{cannot capture __autoreleasing variable in a lambda by copy}} + (void) [=] { (void) p; }; // expected-error {{cannot capture __autoreleasing variable in a lambda by copy}} +} +void test1c() { + __autoreleasing id v; // expected-note {{'v' declared here}} + __autoreleasing id &p = v; + (void) ^{ (void) p; }; + (void) ^{ (void) v; }; // expected-error {{cannot capture __autoreleasing variable in a block}} +} diff --git a/test/SemaObjCXX/arc-overloading.mm b/test/SemaObjCXX/arc-overloading.mm index dad5d0f7051f..a74941721172 100644 --- a/test/SemaObjCXX/arc-overloading.mm +++ b/test/SemaObjCXX/arc-overloading.mm @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -verify -fblocks %s +// RUN: %clang_cc1 -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -verify -fblocks -Wno-objc-root-class %s // Simple ownership conversions + diagnostics. int &f0(id __strong const *); // expected-note{{candidate function not viable: 1st argument ('__weak id *') has __weak ownership, but parameter has __strong ownership}} diff --git a/test/SemaObjCXX/arc-ppe.mm b/test/SemaObjCXX/arc-ppe.mm new file mode 100644 index 000000000000..c9ff81110ddb --- /dev/null +++ b/test/SemaObjCXX/arc-ppe.mm @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -fobjc-arc %s + +// Make sure the ARC auto-deduction of id* in unevaluated contexts +// works correctly in cases where we can't immediately tell whether the +// context is unevaluated. + +namespace std { + class type_info; +} + +int& NP(void*); +void test1() { (void)typeid(NP((void*)(id*)0)); } + +class Poly { virtual ~Poly(); }; +Poly& P(void*); +void test2() { (void)typeid(P((void*)(id*)0)); } // expected-error {{pointer to non-const type 'id'}} diff --git a/test/SemaObjCXX/arc-templates.mm b/test/SemaObjCXX/arc-templates.mm index 931b21f5d47a..9eca84648f6a 100644 --- a/test/SemaObjCXX/arc-templates.mm +++ b/test/SemaObjCXX/arc-templates.mm @@ -97,8 +97,8 @@ int check_make_weak2[is_same<make_weak<__autoreleasing id>::type, __weak id>::va template<typename T> struct make_weak_fail { typedef T T_type; - typedef __weak T_type type; // expected-error{{the type 'T_type' (aka '__weak id') already has retainment attributes set on it}} \ - // expected-error{{the type 'T_type' (aka '__strong id') already has retainment attributes set on it}} + 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<make_weak_fail<__weak id>::type, __weak id>::value? 1 : -1]; // expected-note{{in instantiation of template class 'make_weak_fail<__weak id>' requested here}} diff --git a/test/SemaObjCXX/arc-type-conversion.mm b/test/SemaObjCXX/arc-type-conversion.mm index 48d1e4833b4c..fd42513d5ff4 100644 --- a/test/SemaObjCXX/arc-type-conversion.mm +++ b/test/SemaObjCXX/arc-type-conversion.mm @@ -12,10 +12,7 @@ void * cvt(id arg) // expected-note{{candidate function not viable: cannot conve (void)(__autoreleasing id**)voidp_val; (void)(void*)voidp_val; (void)(void**)arg; // expected-error {{cast of an Objective-C pointer to 'void **' is disallowed}} - cvt((void*)arg); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'void *' requires a bridged cast}} \ - // expected-error {{no matching function for call to 'cvt'}} \ - // expected-note{{use __bridge to convert directly (no change in ownership)}} \ - // expected-note{{use __bridge_retained to make an ARC object available as a +1 'void *'}} + cvt((void*)arg); // expected-error {{no matching function for call to 'cvt'}} cvt(0); (void)(__strong id**)(0); diff --git a/test/SemaObjCXX/arc-type-traits.mm b/test/SemaObjCXX/arc-type-traits.mm index b876018e2574..9877870f9447 100644 --- a/test/SemaObjCXX/arc-type-traits.mm +++ b/test/SemaObjCXX/arc-type-traits.mm @@ -53,16 +53,16 @@ TRAIT_IS_TRUE(__has_trivial_destructor, __autoreleasing id); TRAIT_IS_TRUE(__has_trivial_destructor, __unsafe_unretained id); // __is_literal -TRAIT_IS_FALSE(__is_literal, __strong id); -TRAIT_IS_FALSE(__is_literal, __weak id); -TRAIT_IS_FALSE(__is_literal, __autoreleasing id); -TRAIT_IS_FALSE(__is_literal, __unsafe_unretained id); +TRAIT_IS_TRUE(__is_literal, __strong id); +TRAIT_IS_TRUE(__is_literal, __weak id); +TRAIT_IS_TRUE(__is_literal, __autoreleasing id); +TRAIT_IS_TRUE(__is_literal, __unsafe_unretained id); // __is_literal_type -TRAIT_IS_FALSE(__is_literal_type, __strong id); -TRAIT_IS_FALSE(__is_literal_type, __weak id); -TRAIT_IS_FALSE(__is_literal_type, __autoreleasing id); -TRAIT_IS_FALSE(__is_literal_type, __unsafe_unretained id); +TRAIT_IS_TRUE(__is_literal_type, __strong id); +TRAIT_IS_TRUE(__is_literal_type, __weak id); +TRAIT_IS_TRUE(__is_literal_type, __autoreleasing id); +TRAIT_IS_TRUE(__is_literal_type, __unsafe_unretained id); // __is_pod TRAIT_IS_FALSE(__is_pod, __strong id); diff --git a/test/SemaObjCXX/arc-unavailable-for-weakref.mm b/test/SemaObjCXX/arc-unavailable-for-weakref.mm index 24593ce5e4ed..2a80aebaf8e5 100644 --- a/test/SemaObjCXX/arc-unavailable-for-weakref.mm +++ b/test/SemaObjCXX/arc-unavailable-for-weakref.mm @@ -15,7 +15,8 @@ int main() { id obj; ns1 = (__weak sub *)obj; // expected-error {{assignment of a weak-unavailable object to a __weak object}} \ - // expected-error {{class is incompatible with __weak references}} + // expected-error {{class is incompatible with __weak references}} \ + // expected-error {{explicit ownership qualifier on cast result has no effect}} } // rdar://9732636 @@ -30,7 +31,8 @@ NOWEAK * Test1() { weak1 = strong1; // expected-error {{assignment of a weak-unavailable object to a __weak object}} __weak id weak2 = strong1; // expected-error {{assignment of a weak-unavailable object to a __weak object}} - return (__weak id)strong1; // expected-error {{cast of weak-unavailable object of type 'NOWEAK *' to a __weak object of type '__weak id'}} + return (__weak id)strong1; // expected-error {{cast of weak-unavailable object of type 'NOWEAK *' to a __weak object of type '__weak id'}} \ + // expected-error {{explicit ownership qualifier on cast result has no effect}} } @protocol P @end @@ -42,6 +44,7 @@ NOWEAK<P, P1> * Test2() { weak1 = strong1; // expected-error {{assignment of a weak-unavailable object to a __weak object}} __weak id<P> weak2 = strong1; // expected-error {{assignment of a weak-unavailable object to a __weak object}} - return (__weak id<P, P1>)strong1; // expected-error {{cast of weak-unavailable object of type 'NOWEAK<P,P1> *' to a __weak object of type '__weak id<P,P1>'}} + return (__weak id<P, P1>)strong1; // expected-error {{cast of weak-unavailable object of type 'NOWEAK<P,P1> *' to a __weak object of type '__weak id<P,P1>'}} \ + // expected-error {{explicit ownership qualifier on cast result has no effect}} } diff --git a/test/SemaObjCXX/arc-unbridged-cast.mm b/test/SemaObjCXX/arc-unbridged-cast.mm new file mode 100644 index 000000000000..0b3ba07eef3e --- /dev/null +++ b/test/SemaObjCXX/arc-unbridged-cast.mm @@ -0,0 +1,110 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -verify %s + +typedef const struct __CFString * CFStringRef; +typedef const void * CFTypeRef; +extern "C" CFTypeRef CFBridgingRetain(id X); +extern "C" id CFBridgingRelease(CFTypeRef); + + +@interface Object +@property CFStringRef property; +- (CFStringRef) implicitProperty; +- (CFStringRef) newString; +- (CFStringRef) makeString; +@end + +extern Object *object; + +// rdar://9744349 +id test0(void) { + id p1 = (id)[object property]; + id p2 = (__bridge_transfer id)[object property]; + id p3 = (__bridge id)[object property]; + return (id) object.property; +} + +// rdar://10140692 +CFStringRef unauditedString(void); +CFStringRef plusOneString(void) __attribute__((cf_returns_retained)); + +#pragma clang arc_cf_code_audited begin +CFStringRef auditedString(void); +CFStringRef auditedCreateString(void); +#pragma clang arc_cf_code_audited end + +void test1(int cond) { + id x; + x = (id) auditedString(); + x = (id) (cond ? auditedString() : (void*) 0); + x = (id) (cond ? (void*) 0 : auditedString()); + x = (id) (cond ? (CFStringRef) @"help" : auditedString()); + + x = (id) unauditedString(); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}} + x = (id) (cond ? unauditedString() : (void*) 0); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}} + x = (id) (cond ? (void*) 0 : unauditedString()); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}} + x = (id) (cond ? (CFStringRef) @"help" : unauditedString()); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}} + + x = (id) auditedCreateString(); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}} + x = (id) (cond ? auditedCreateString() : (void*) 0); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}} + x = (id) (cond ? (void*) 0 : auditedCreateString()); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}} + x = (id) (cond ? (CFStringRef) @"help" : auditedCreateString()); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}} + + x = (id) [object property]; + x = (id) (cond ? [object property] : (void*) 0); + x = (id) (cond ? (void*) 0 : [object property]); + x = (id) (cond ? (CFStringRef) @"help" : [object property]); + + x = (id) object.property; + x = (id) (cond ? object.property : (void*) 0); + x = (id) (cond ? (void*) 0 : object.property); + x = (id) (cond ? (CFStringRef) @"help" : object.property); + + x = (id) object.implicitProperty; + x = (id) (cond ? object.implicitProperty : (void*) 0); + x = (id) (cond ? (void*) 0 : object.implicitProperty); + x = (id) (cond ? (CFStringRef) @"help" : object.implicitProperty); + + x = (id) [object makeString]; + x = (id) (cond ? [object makeString] : (void*) 0); + x = (id) (cond ? (void*) 0 : [object makeString]); + x = (id) (cond ? (CFStringRef) @"help" : [object makeString]); + + x = (id) [object newString]; + x = (id) (cond ? [object newString] : (void*) 0); + x = (id) (cond ? (void*) 0 : [object newString]); + x = (id) (cond ? (CFStringRef) @"help" : [object newString]); // a bit questionable +} + +// rdar://problem/10246264 +@interface CFTaker +- (void) takeOrdinary: (CFStringRef) arg; +- (void) takeVariadic: (int) n, ...; +- (void) takeConsumed: (CFStringRef __attribute__((cf_consumed))) arg; +@end +void testCFTaker(CFTaker *taker, id string) { + [taker takeOrdinary: (CFStringRef) string]; + [taker takeVariadic: 1, (CFStringRef) string]; + [taker takeConsumed: (CFStringRef) string]; // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}} +} + +void takeCFOrdinaryUnaudited(CFStringRef arg); +void takeCFVariadicUnaudited(int n, ...); +void takeCFConsumedUnaudited(CFStringRef __attribute__((cf_consumed)) arg); +#pragma clang arc_cf_code_audited begin +void takeCFOrdinaryAudited(CFStringRef arg); +void takeCFVariadicAudited(int n, ...); +void takeCFConsumedAudited(CFStringRef __attribute__((cf_consumed)) arg); +#pragma clang arc_cf_code_audited end + +void testTakerFunctions(id string) { + takeCFOrdinaryUnaudited((CFStringRef) string); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}} + takeCFVariadicUnaudited(1, (CFStringRef) string); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}} + takeCFConsumedUnaudited((CFStringRef) string); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}} + + void (*taker)(CFStringRef) = 0; + taker((CFStringRef) string); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}} + + takeCFOrdinaryAudited((CFStringRef) string); + takeCFVariadicAudited(1, (CFStringRef) string); + takeCFConsumedAudited((CFStringRef) string); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}} +} diff --git a/test/SemaObjCXX/blocks.mm b/test/SemaObjCXX/blocks.mm index c91fd103e133..09d614d37287 100644 --- a/test/SemaObjCXX/blocks.mm +++ b/test/SemaObjCXX/blocks.mm @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -fblocks %s +// RUN: %clang_cc1 -fsyntax-only -verify -fblocks -Wno-objc-root-class %s @protocol NSObject; void bar(id(^)(void)); diff --git a/test/SemaObjCXX/composite-objc-pointertype.mm b/test/SemaObjCXX/composite-objc-pointertype.mm index 0d9a93897656..684f633f71cc 100644 --- a/test/SemaObjCXX/composite-objc-pointertype.mm +++ b/test/SemaObjCXX/composite-objc-pointertype.mm @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s @interface Foo @end diff --git a/test/SemaObjCXX/cstyle-block-pointer-cast.mm b/test/SemaObjCXX/cstyle-block-pointer-cast.mm index 72f5283dea37..0f982bae62a7 100644 --- a/test/SemaObjCXX/cstyle-block-pointer-cast.mm +++ b/test/SemaObjCXX/cstyle-block-pointer-cast.mm @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -fblocks %s +// RUN: %clang_cc1 -fsyntax-only -verify -fblocks -Wno-objc-root-class %s // radar 7562285 typedef int (^blocktype)(int a, int b); diff --git a/test/SemaObjCXX/cxxoperator-selector.mm b/test/SemaObjCXX/cxxoperator-selector.mm index 6dd36a8c100e..f1aecab23a9d 100644 --- a/test/SemaObjCXX/cxxoperator-selector.mm +++ b/test/SemaObjCXX/cxxoperator-selector.mm @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s // rdar:// 8328250 @class NSDate; diff --git a/test/SemaObjCXX/debugger-cast-result-to-id.mm b/test/SemaObjCXX/debugger-cast-result-to-id.mm new file mode 100644 index 000000000000..cd7aa7b6ac0b --- /dev/null +++ b/test/SemaObjCXX/debugger-cast-result-to-id.mm @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -fdebugger-support -fdebugger-cast-result-to-id -funknown-anytype -fsyntax-only -verify %s + +// rdar://problem/9416370 +namespace test0 { + void test(id x) { + if ([x foo]) {} // expected-error {{no known method '-foo'; cast the message send to the method's return type}} + [x foo]; + } +} + +// rdar://10988847 +@class NSString; // expected-note {{forward declaration of class here}} +namespace test1 { + void rdar10988847() { + id s = [NSString stringWithUTF8String:"foo"]; // expected-warning {{receiver 'NSString' is a forward class and corresponding @interface may not exist}} + } +} diff --git a/test/SemaObjCXX/fragile-abi-object-assign.m b/test/SemaObjCXX/fragile-abi-object-assign.m new file mode 100644 index 000000000000..5bb3ac6f6f50 --- /dev/null +++ b/test/SemaObjCXX/fragile-abi-object-assign.m @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -x objective-c++ -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-fragile-abi -verify -Wno-objc-root-class %s +// rdar://10731065 + +@interface MyView {} +@end + +@implementation MyViewTemplate // expected-warning {{cannot find interface declaration for 'MyViewTemplate'}} +- (id) createRealObject { + id realObj; + *(MyView *) realObj = *(MyView *) self; // expected-error {{cannot assign to class object}} +} +@end + diff --git a/test/SemaObjCXX/goto.mm b/test/SemaObjCXX/goto.mm index 67df1f4c3240..55bde99da29f 100644 --- a/test/SemaObjCXX/goto.mm +++ b/test/SemaObjCXX/goto.mm @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s // PR9495 struct NonPOD { NonPOD(); ~NonPOD(); }; diff --git a/test/SemaObjCXX/instantiate-expr.mm b/test/SemaObjCXX/instantiate-expr.mm index 08be5f7b9110..75a5b7eaf855 100644 --- a/test/SemaObjCXX/instantiate-expr.mm +++ b/test/SemaObjCXX/instantiate-expr.mm @@ -20,10 +20,11 @@ template<unsigned N, typename T, typename U, typename V> void f(U value, V value2) { get_an_A(N)->ivar = value; // expected-error{{assigning to 'int' from incompatible type 'int *'}} get_an_A(N).prop = value2; // expected-error{{assigning to 'int' from incompatible type 'double *'}} - T c = get_an_id(N)->isa; // expected-error{{cannot initialize a variable of type 'int' with an lvalue of type 'Class'}} + T c = get_an_id(N)->isa; // expected-error{{cannot initialize a variable of type 'int' with an lvalue of type 'Class'}} \ + // expected-warning 5 {{direct access to objective-c's isa is deprecated in favor of object_setClass() and object_getClass()}} } -template void f<6, Class>(int, int); +template void f<6, Class>(int, int); // expected-note{{in instantiation of}} template void f<7, Class>(int*, int); // expected-note{{in instantiation of}} template void f<8, Class>(int, double*); // expected-note{{in instantiation of}} template void f<9, int>(int, int); // expected-note{{in instantiation of}} @@ -44,10 +45,11 @@ template void f2(A*, int, double*); // expected-note{{instantiation of}} // an isa. template<typename T, typename U> void f3(U ptr) { - T c = ptr->isa; // expected-error{{cannot initialize a variable of type 'int' with an lvalue of type 'Class'}} + T c = ptr->isa; // expected-error{{cannot initialize a variable of type 'int' with an lvalue of type 'Class'}} \ + // expected-warning 2 {{direct access to objective-c's isa is deprecated in favor of object_setClass() and object_getClass()}} } -template void f3<Class>(id); +template void f3<Class>(id); // expected-note{{in instantiation of}} template void f3<int>(id); // expected-note{{instantiation of}} // Implicit setter/getter diff --git a/test/SemaObjCXX/instantiate-method-return.mm b/test/SemaObjCXX/instantiate-method-return.mm index b8ba4af09222..2a3ae3231280 100644 --- a/test/SemaObjCXX/instantiate-method-return.mm +++ b/test/SemaObjCXX/instantiate-method-return.mm @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s // PR7386 @class NSObject; diff --git a/test/SemaObjCXX/ivar-construct.mm b/test/SemaObjCXX/ivar-construct.mm index da066e965971..535d2a0217ff 100644 --- a/test/SemaObjCXX/ivar-construct.mm +++ b/test/SemaObjCXX/ivar-construct.mm @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s struct Y { Y(); diff --git a/test/SemaObjCXX/ivar-lookup.mm b/test/SemaObjCXX/ivar-lookup.mm index bb26f48f13d5..fc99c15fd379 100644 --- a/test/SemaObjCXX/ivar-lookup.mm +++ b/test/SemaObjCXX/ivar-lookup.mm @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s @interface Ivar - (float*)method; @end diff --git a/test/SemaObjCXX/literals.mm b/test/SemaObjCXX/literals.mm new file mode 100644 index 000000000000..eed67652d2ab --- /dev/null +++ b/test/SemaObjCXX/literals.mm @@ -0,0 +1,187 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x -fblocks %s + +// rdar://11231426 +typedef bool BOOL; + +void y(BOOL (^foo)()); + +void x() { + y(^{ + return __objc_yes; + }); +} + +@protocol NSCopying +- copy; +@end + +@interface NSObject +@end + +@interface NSNumber : NSObject <NSCopying> +-copy; +@end + +@interface NSNumber (NSNumberCreation) ++ (NSNumber *)numberWithChar:(char)value; ++ (NSNumber *)numberWithUnsignedChar:(unsigned char)value; ++ (NSNumber *)numberWithShort:(short)value; ++ (NSNumber *)numberWithUnsignedShort:(unsigned short)value; ++ (NSNumber *)numberWithInt:(int)value; ++ (NSNumber *)numberWithUnsignedInt:(unsigned int)value; ++ (NSNumber *)numberWithLong:(long)value; ++ (NSNumber *)numberWithUnsignedLong:(unsigned long)value; ++ (NSNumber *)numberWithLongLong:(long long)value; ++ (NSNumber *)numberWithUnsignedLongLong:(unsigned long long)value; ++ (NSNumber *)numberWithFloat:(float)value; ++ (NSNumber *)numberWithDouble:(double)value; ++ (NSNumber *)numberWithBool:(BOOL)value; +@end + +@interface NSArray : NSObject <NSCopying> +-copy; +@end + +@interface NSArray (NSArrayCreation) ++ (id)arrayWithObjects:(const id [])objects count:(unsigned long)cnt; +@end + +@interface NSDictionary ++ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id<NSCopying> [])keys count:(unsigned long)cnt; +@end + +template<typename T> +struct ConvertibleTo { + operator T(); +}; + +template<typename T> +struct ExplicitlyConvertibleTo { + explicit operator T(); +}; + +template<typename T> +class PrivateConvertibleTo { +private: + operator T(); // expected-note{{declared private here}} +}; + +template<typename T> ConvertibleTo<T> makeConvertible(); + +struct X { + ConvertibleTo<id> x; + ConvertibleTo<id> get(); +}; + +template<typename T> T test_numeric_instantiation() { + return @-17.42; +} + +template id test_numeric_instantiation(); + +void test_convertibility(ConvertibleTo<NSArray*> toArray, + ConvertibleTo<id> toId, + ConvertibleTo<int (^)(int)> toBlock, + ConvertibleTo<int> toInt, + ExplicitlyConvertibleTo<NSArray *> toArrayExplicit) { + id array = @[ + toArray, + toId, + toBlock, + toInt // expected-error{{collection element of type 'ConvertibleTo<int>' is not an Objective-C object}} + ]; + id array2 = @[ toArrayExplicit ]; // expected-error{{collection element of type 'ExplicitlyConvertibleTo<NSArray *>' is not an Objective-C object}} + + id array3 = @[ + makeConvertible<id>(), + makeConvertible<id>, // expected-error{{collection element of type 'ConvertibleTo<id> ()' is not an Objective-C object}} + ]; + + X x; + id array4 = @[ x.x ]; + id array5 = @[ x.get ]; // expected-error{{reference to non-static member function must be called}} + id array6 = @[ PrivateConvertibleTo<NSArray*>() ]; // expected-error{{operator NSArray *' is a private member of 'PrivateConvertibleTo<NSArray *>'}} +} + +template<typename T> +void test_array_literals(T t) { + id arr = @[ @17, t ]; // expected-error{{collection element of type 'int' is not an Objective-C object}} +} + +template void test_array_literals(id); +template void test_array_literals(NSArray*); +template void test_array_literals(int); // expected-note{{in instantiation of function template specialization 'test_array_literals<int>' requested here}} + +template<typename T, typename U> +void test_dictionary_literals(T t, U u) { + NSObject *object; + id dict = @{ + @17 : t, // expected-error{{collection element of type 'int' is not an Objective-C object}} + u : @42 // expected-error{{collection element of type 'int' is not an Objective-C object}} + }; + + id dict2 = @{ + object : @"object" // expected-error{{cannot initialize a parameter of type 'const id<NSCopying>' with an rvalue of type 'NSObject *'}} + }; +} + +template void test_dictionary_literals(id, NSArray*); +template void test_dictionary_literals(NSArray*, id); +template void test_dictionary_literals(int, id); // expected-note{{in instantiation of function template specialization 'test_dictionary_literals<int, id>' requested here}} +template void test_dictionary_literals(id, int); // expected-note{{in instantiation of function template specialization 'test_dictionary_literals<id, int>' requested here}} + +template<typename ...Args> +void test_bad_variadic_array_literal(Args ...args) { + id arr1 = @[ args ]; // expected-error{{initializer contains unexpanded parameter pack 'args'}} +} + +template<typename ...Args> +void test_variadic_array_literal(Args ...args) { + id arr1 = @[ args... ]; // expected-error{{collection element of type 'int' is not an Objective-C object}} +} +template void test_variadic_array_literal(id); +template void test_variadic_array_literal(id, NSArray*); +template void test_variadic_array_literal(id, int, NSArray*); // expected-note{{in instantiation of function template specialization 'test_variadic_array_literal<id, int, NSArray *>' requested here}} + +template<typename ...Args> +void test_bad_variadic_dictionary_literal(Args ...args) { + id dict = @{ args : @17 }; // expected-error{{initializer contains unexpanded parameter pack 'args'}} +} + +// Test array literal pack expansions. +template<typename T, typename U> +struct pair { + T first; + U second; +}; + +template<typename T, typename ...Ts, typename ... Us> +void test_variadic_dictionary_expansion(T t, pair<Ts, Us>... key_values) { + id dict = @{ + t : key_values.second ..., // expected-error{{collection element of type 'int' is not an Objective-C object}} + key_values.first : key_values.second ..., // expected-error{{collection element of type 'float' is not an Objective-C object}} + key_values.second : t ... + }; +} + +template void test_variadic_dictionary_expansion(id, + pair<NSNumber*, id>, + pair<id, ConvertibleTo<id>>); +template void test_variadic_dictionary_expansion(NSNumber *, // expected-note{{in instantiation of function template specialization}} + pair<NSNumber*, int>, + pair<id, ConvertibleTo<id>>); +template void test_variadic_dictionary_expansion(NSNumber *, // expected-note{{in instantiation of function template specialization}} + pair<NSNumber*, id>, + pair<float, ConvertibleTo<id>>); + +// Test parsing +struct key { + static id value; +}; + +id key; +id value; + +void test_dictionary_colon() { + id dict = @{ key : value }; +} diff --git a/test/SemaObjCXX/message.mm b/test/SemaObjCXX/message.mm index 51a15d5773ba..5ac2f40db849 100644 --- a/test/SemaObjCXX/message.mm +++ b/test/SemaObjCXX/message.mm @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -fobjc-fragile-abi -verify %s +// RUN: %clang_cc1 -fsyntax-only -fobjc-fragile-abi -verify -Wno-objc-root-class %s @interface I1 - (int*)method; @end diff --git a/test/SemaObjCXX/objc-container-subscripting.mm b/test/SemaObjCXX/objc-container-subscripting.mm new file mode 100644 index 000000000000..c835cbe53c61 --- /dev/null +++ b/test/SemaObjCXX/objc-container-subscripting.mm @@ -0,0 +1,138 @@ +// RUN: %clang_cc1 -fblocks -triple x86_64-apple-darwin11 -fsyntax-only -std=c++11 -verify %s + +@class NSArray; + +@interface NSMutableDictionary +- (id)objectForKeyedSubscript:(id)key; +- (void)setObject:(id)object forKeyedSubscript:(id)key; // expected-note {{passing argument to parameter 'object' here}} +@end + +template<typename T, typename U, typename O> +void test_dictionary_subscripts(T base, U key, O obj) { + base[key] = obj; // expected-error {{expected method to write array element not found on object of type 'NSMutableDictionary *'}} \ + // expected-error {{cannot initialize a parameter of type 'id' with an lvalue of type 'int'}} + obj = base[key]; // expected-error {{expected method to read array element not found on object of type 'NSMutableDictionary *'}} \ + // expected-error {{assigning to 'int' from incompatible type 'id'}} + +} + +template void test_dictionary_subscripts(NSMutableDictionary*, id, NSArray *ns); + +template void test_dictionary_subscripts(NSMutableDictionary*, NSArray *ns, id); + +template void test_dictionary_subscripts(NSMutableDictionary*, int, id); // expected-note {{in instantiation of function template specialization 'test_dictionary_subscripts<NSMutableDictionary *, int, id>' requested here}} + +template void test_dictionary_subscripts(NSMutableDictionary*, id, int); // expected-note {{in instantiation of function template specialization 'test_dictionary_subscripts<NSMutableDictionary *, id, int>' requested here}} + + +@interface NSMutableArray +- (id)objectAtIndexedSubscript:(int)index; +- (void)setObject:(id)object atIndexedSubscript:(int)index; +@end + +template<typename T, typename U, typename O> +void test_array_subscripts(T base, U index, O obj) { + base[index] = obj; // expected-error {{indexing expression is invalid because subscript type 'double' is not an integral or objective-C pointer type}} + obj = base[index]; // expected-error {{indexing expression is invalid because subscript type 'double' is not an integral or objective-C pointer type}} +} + +template void test_array_subscripts(NSMutableArray *, int, id); +template void test_array_subscripts(NSMutableArray *, short, id); +enum E { e }; + +template void test_array_subscripts(NSMutableArray *, E, id); + +template void test_array_subscripts(NSMutableArray *, double, id); // expected-note {{in instantiation of function template specialization 'test_array_subscripts<NSMutableArray *, double, id>' requested here}} + +template<typename T> +struct ConvertibleTo { + operator T(); +}; + +template<typename T> +struct ExplicitlyConvertibleTo { + explicit operator T(); +}; + +template<typename T> ConvertibleTo<T> makeConvertible(); + +struct X { + ConvertibleTo<id> x; + ConvertibleTo<id> get(); +}; + +NSMutableArray *test_array_convertibility(ConvertibleTo<NSMutableArray*> toArray, + ConvertibleTo<id> toId, + ConvertibleTo<int (^)(int)> toBlock, + ConvertibleTo<int> toInt, + ExplicitlyConvertibleTo<NSMutableArray *> toArrayExplicit) { + id array; + + array[1] = toArray; + + array[4] = array[1]; + + toArrayExplicit[2] = toId; // expected-error {{type 'ExplicitlyConvertibleTo<NSMutableArray *>' does not provide a subscript operator}} + + return array[toInt]; + +} + +id test_dict_convertibility(ConvertibleTo<NSMutableDictionary*> toDict, + ConvertibleTo<id> toId, + ConvertibleTo<int (^)(int)> toBlock, + ConvertibleTo<int> toInt, + ExplicitlyConvertibleTo<NSMutableDictionary *> toDictExplicit) { + + + NSMutableDictionary *Dict; + id Id; + Dict[toId] = toBlock; + + Dict[toBlock] = toBlock; + + Dict[toBlock] = Dict[toId] = Dict[toBlock]; + + Id = toDictExplicit[toId] = Id; // expected-error {{no viable overloaded operator[] for type 'ExplicitlyConvertibleTo<NSMutableDictionary *>'}} + + return Dict[toBlock]; +} + + +template<typename ...Args> +void test_bad_variadic_array_subscripting(Args ...args) { + id arr1; + arr1[3] = args; // expected-error {{expression contains unexpanded parameter pack 'args'}} +} + +template<typename ...Args> +void test_variadic_array_subscripting(Args ...args) { + id arr[] = {args[3]...}; // which means: {a[3], b[3], c[3]}; +} + +template void test_variadic_array_subscripting(id arg1, NSMutableArray* arg2, id arg3); + +@class Key; + +template<typename Index, typename ...Args> +void test_variadic_dictionary_subscripting(Index I, Args ...args) { + id arr[] = {args[I]...}; // which means: {a[3], b[3], c[3]}; +} + +template void test_variadic_dictionary_subscripting(Key *key, id arg1, NSMutableDictionary* arg2, id arg3); + +template<int N> +id get(NSMutableArray *array) { + return array[N]; // array[N] should be a value- and instantiation-dependent ObjCSubscriptRefExpr +} + +struct WeirdIndex { + operator int(); // expected-note {{type conversion function declared here}} + operator id(); // expected-note {{type conversion function declared here}} +}; + +id FUNC(WeirdIndex w) { + NSMutableArray *array; + return array[w]; // expected-error {{indexing expression is invalid because subscript type 'WeirdIndex' has multiple type conversion functions}} +} + diff --git a/test/SemaObjCXX/objc-decls-inside-namespace.mm b/test/SemaObjCXX/objc-decls-inside-namespace.mm index f68078b6779d..070207195f37 100644 --- a/test/SemaObjCXX/objc-decls-inside-namespace.mm +++ b/test/SemaObjCXX/objc-decls-inside-namespace.mm @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s namespace C { diff --git a/test/SemaObjCXX/objc-extern-c.mm b/test/SemaObjCXX/objc-extern-c.mm new file mode 100644 index 000000000000..6bd37610ae43 --- /dev/null +++ b/test/SemaObjCXX/objc-extern-c.mm @@ -0,0 +1,30 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +@protocol P // expected-note {{previous}} +-(void)meth1; +@end + +@interface I // expected-note {{previous}} +@end + +@interface I2 +@end +@interface I2(C) // expected-note {{previous}} +@end + +extern "C" { +@protocol P // expected-warning {{duplicate protocol definition of 'P' is ignored}} +-(void)meth2; +@end + +@interface I // expected-error {{duplicate}} +@end + +@interface I2(C) // expected-warning {{duplicate}} +@end +} + +void test(id<P> p) { + [p meth1]; + [p meth2]; // expected-warning {{not found}} +} diff --git a/test/SemaObjCXX/objc-pointer-conv.mm b/test/SemaObjCXX/objc-pointer-conv.mm index 6f59de179472..611b7bc009ae 100644 --- a/test/SemaObjCXX/objc-pointer-conv.mm +++ b/test/SemaObjCXX/objc-pointer-conv.mm @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s typedef const void * VoidStar; diff --git a/test/SemaObjCXX/overload.mm b/test/SemaObjCXX/overload.mm index ea5f0e593284..6f24c59e3a73 100644 --- a/test/SemaObjCXX/overload.mm +++ b/test/SemaObjCXX/overload.mm @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s @interface Foo @end @@ -171,3 +171,9 @@ namespace rdar9327203 { int &fr = (f)(x, 0); } } + +namespace class_id { + // it's okay to overload Class with id. + void f(Class) { } + void f(id) { } +} diff --git a/test/SemaObjCXX/propert-dot-error.mm b/test/SemaObjCXX/propert-dot-error.mm index 747efeb536b4..2237411aaf0c 100644 --- a/test/SemaObjCXX/propert-dot-error.mm +++ b/test/SemaObjCXX/propert-dot-error.mm @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s // rdar: // 8379892 struct X { @@ -20,7 +20,7 @@ struct X { @end void f(A* a) { - a.x = X(); // expected-error {{setter method is needed to assign to object using property assignment syntax}} + a.x = X(); // expected-error {{no setter method 'setX:' for assignment to property}} } struct Y : X { }; diff --git a/test/SemaObjCXX/properties.mm b/test/SemaObjCXX/properties.mm index f148b3395d93..3c6b13858686 100644 --- a/test/SemaObjCXX/properties.mm +++ b/test/SemaObjCXX/properties.mm @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -Wno-objc-root-class %s struct X { void f() const; @@ -19,6 +19,90 @@ struct X { - (void)setx:(const X&)other { x_ = other; } - (void)method { self.x.f(); -} +} +@end + +// rdar://problem/10444030 +@interface Test2 +- (void) setY: (int) y; +- (int) z; +@end +void test2(Test2 *a) { + auto y = a.y; // expected-error {{expected getter method not found on object of type 'Test2 *'}} + auto z = a.z; +} + +// rdar://problem/10672108 +@interface Test3 +- (int) length; @end +void test3(Test3 *t) { + char vla[t.length] = {}; // expected-error {{variable-sized object may not be initialized}} + char *heaparray = new char[t.length]; +} +// <rdar://problem/10672501> +namespace std { + template<typename T> void count(); +} + +@interface Test4 +- (X&) prop; +@end + +void test4(Test4 *t) { + (void)const_cast<const X&>(t.prop); + (void)dynamic_cast<X&>(t.prop); + (void)reinterpret_cast<int&>(t.prop); +} + +@interface Test5 { +@public + int count; +} +@property int count; +@end + +void test5(Test5* t5) { + if (t5.count < 2) { } + if (t5->count < 2) { } +} + + +@interface Test6 ++ (Class)class; +- (Class)class; +@end + +void test6(Test6 *t6) { + Class x = t6.class; + Class x2 = Test6.class; +} + +template<typename T> +void test6_template(T *t6) { + Class x = t6.class; +} + +template void test6_template(Test6*); + +// rdar://problem/10965735 +struct Test7PointerMaker { + operator char *() const; +}; +@interface Test7 +- (char*) implicit_property; +- (char) bad_implicit_property; +- (Test7PointerMaker) implicit_struct_property; +@property int *explicit_property; +@property int bad_explicit_property; +@property Test7PointerMaker explicit_struct_property; +@end +void test7(Test7 *ptr) { + delete ptr.implicit_property; + delete ptr.bad_implicit_property; // expected-error {{cannot delete expression of type 'char'}} + delete ptr.explicit_property; + delete ptr.bad_explicit_property; // expected-error {{cannot delete expression of type 'int'}} + delete ptr.implicit_struct_property; + delete ptr.explicit_struct_property; +} diff --git a/test/SemaObjCXX/property-reference.mm b/test/SemaObjCXX/property-reference.mm index 236dba61fc2d..18f06045a340 100644 --- a/test/SemaObjCXX/property-reference.mm +++ b/test/SemaObjCXX/property-reference.mm @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -x objective-c++ -triple x86_64-apple-darwin10 -fsyntax-only -verify %s +// RUN: %clang_cc1 -x objective-c++ -triple x86_64-apple-darwin10 -fsyntax-only -verify -Wno-objc-root-class %s // rdar://9070460 class TCPPObject @@ -8,7 +8,7 @@ public: TCPPObject(); ~TCPPObject(); - TCPPObject& operator=(const TCPPObject& inObj)const ; + TCPPObject& operator=(const TCPPObject& inObj)const ; // expected-note {{'operator=' declared here}} void* Data(); @@ -29,7 +29,7 @@ typedef const TCPPObject& CREF_TCPPObject; @implementation TNSObject @synthesize cppObjectNonAtomic; -@synthesize cppObjectAtomic; // expected-warning{{atomic property of type 'CREF_TCPPObject' (aka 'const TCPPObject &') synthesizing setter using non-trivial assignment operator}} +@synthesize cppObjectAtomic; // expected-error{{atomic property of reference type 'CREF_TCPPObject' (aka 'const TCPPObject &') cannot have non-trivial assignment operator}} @dynamic cppObjectDynamic; - (const TCPPObject&) cppObjectNonAtomic diff --git a/test/SemaObjCXX/property-synthesis-error.mm b/test/SemaObjCXX/property-synthesis-error.mm index 5ba4b70a2b69..4b726d8ca64a 100644 --- a/test/SemaObjCXX/property-synthesis-error.mm +++ b/test/SemaObjCXX/property-synthesis-error.mm @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s // rdar: //8550657 @interface NSArray @end @@ -38,7 +38,7 @@ public: TCPPObject(const TCPPObject& inObj); TCPPObject(); ~TCPPObject(); - TCPPObject& operator=(const TCPPObject& inObj); + TCPPObject& operator=(const TCPPObject& inObj); // expected-note {{'operator=' declared here}} private: void* fData; }; @@ -67,7 +67,7 @@ private: @implementation MyDocument -@synthesize cppObject = _cppObject; // expected-warning {{atomic property of type 'const TCPPObject &' synthesizing setter using non-trivial assignment operator}} +@synthesize cppObject = _cppObject; // expected-error {{atomic property of reference type 'const TCPPObject &' cannot have non-trivial assignment operator}} @synthesize ncppObject = _ncppObject; @synthesize tcppObject = _tcppObject; diff --git a/test/SemaObjCXX/unknown-anytype.mm b/test/SemaObjCXX/unknown-anytype.mm index 163dddee708f..b28b1355efcd 100644 --- a/test/SemaObjCXX/unknown-anytype.mm +++ b/test/SemaObjCXX/unknown-anytype.mm @@ -3,6 +3,7 @@ // rdar://problem/9416370 namespace test0 { void test(id x) { + if ([x foo]) {} // expected-error {{no known method '-foo'; cast the message send to the method's return type}} [x foo]; // expected-error {{no known method '-foo'; cast the message send to the method's return type}} } } diff --git a/test/SemaObjCXX/vararg-non-pod.mm b/test/SemaObjCXX/vararg-non-pod.mm index 7e5c4c6c97a0..5a6281d71cb2 100644 --- a/test/SemaObjCXX/vararg-non-pod.mm +++ b/test/SemaObjCXX/vararg-non-pod.mm @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s -Wnon-pod-varargs +// RUN: %clang_cc1 -fsyntax-only -verify %s -Wno-error=non-pod-varargs extern char version[]; diff --git a/test/SemaObjCXX/void_to_obj.mm b/test/SemaObjCXX/void_to_obj.mm index 7dca9faa8544..97151fd7fa49 100644 --- a/test/SemaObjCXX/void_to_obj.mm +++ b/test/SemaObjCXX/void_to_obj.mm @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s // <rdar://problem/6463729> @class XX; diff --git a/test/SemaObjCXX/warn-strict-selector-match.mm b/test/SemaObjCXX/warn-strict-selector-match.mm index 6d315db27cba..330b10b471b0 100644 --- a/test/SemaObjCXX/warn-strict-selector-match.mm +++ b/test/SemaObjCXX/warn-strict-selector-match.mm @@ -13,6 +13,6 @@ void foo(void) { id r; - [r meth1:r]; // expected-warning {{multiple methods named 'meth1:' found [-Wstrict-selector-match]}} - [r window]; // expected-warning {{multiple methods named 'window' found [-Wstrict-selector-match]}} + [r meth1:r]; // expected-warning {{multiple methods named 'meth1:' found}} + [r window]; // expected-warning {{multiple methods named 'window' found}} } |