68 lines · plain
1// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-runtime-has-weak -fobjc-arc -verify %s2// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin11 -fsyntax-only -verify -DNOARC %s3#ifdef NOARC4// expected-no-diagnostics5#endif6 7int testObjCComparisonRules(void *v, id x, id y) {8 return v == x;9#ifndef NOARC10// expected-error@-2 {{implicit conversion of Objective-C pointer type 'id' to C pointer type 'void *' requires a bridged cast}}11// expected-note@-3 {{use __bridge to convert directly (no change in ownership)}}12// expected-note@-4 {{use __bridge_retained to make an ARC object available as a +1 'void *'}}13#endif14 return v >= x;15#ifndef NOARC16// expected-error@-2 {{implicit conversion of Objective-C pointer type 'id' to C pointer type 'void *' requires a bridged cast}}17// expected-note@-3 {{use __bridge to convert directly (no change in ownership)}}18// expected-note@-4 {{use __bridge_retained to make an ARC object available as a +1 'void *'}}19#endif20 return v == (id)(void *)0; // OK21 return v == nullptr; // OK22 return v == (void *)0;23 return x == y;24}25 26@class A;27 28int testMixedQualComparisonRules(void *v, const void *cv, A *a, const A *ca) {29 return cv == ca;30#ifndef NOARC31// expected-error@-2 {{implicit conversion of Objective-C pointer type 'const A *' to C pointer type 'const void *' requires a bridged cast}}32// expected-note@-3 {{use __bridge to convert directly (no change in ownership)}}33// expected-note@-4 {{use __bridge_retained to make an ARC object available as a +1 'const void *'}}34#endif35 // FIXME: The "to" type in this diagnostic is wrong; we should convert to "const void *".36 return v == ca;37#ifndef NOARC38// expected-error@-2 {{implicit conversion of Objective-C pointer type 'const A *' to C pointer type 'void *' requires a bridged cast}}39// expected-note@-3 {{use __bridge to convert directly (no change in ownership)}}40// expected-note@-4 {{use __bridge_retained to make an ARC object available as a +1 'void *'}}41#endif42 return cv == a;43#ifndef NOARC44// expected-error@-2 {{implicit conversion of Objective-C pointer type 'A *' to C pointer type 'const void *' requires a bridged cast}}45// expected-note@-3 {{use __bridge to convert directly (no change in ownership)}}46// expected-note@-4 {{use __bridge_retained to make an ARC object available as a +1 'const void *'}}47#endif48 49 // FIXME: Shouldn't these be rejected in ARC mode too?50 return ca == cv;51 return a == cv;52 return ca == v;53}54 55#ifndef NOARC56int testDoublePtr(void *pv, void **ppv, A *__strong* pspa, A *__weak* pwpa, A *__strong** ppspa) {57 return pv == pspa;58 return pspa == pv;59 return pv == pspa;60 return pv == pwpa;61 return pspa == pwpa; // expected-error {{comparison of distinct pointer types}}62 return ppv == pspa; // expected-error {{comparison of distinct pointer types}}63 return pspa == ppv; // expected-error {{comparison of distinct pointer types}}64 return pv == ppspa;65 return ppv == ppspa; // expected-error{{comparison of distinct pointer types}}66}67#endif68