| 1 |
// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-runtime-has-weak -fobjc-arc -verify %s |
| 2 |
// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin11 -fsyntax-only -verify -DNOARC %s |
| 3 |
#ifdef NOARC |
| 4 |
// expected-no-diagnostics |
| 5 |
#endif |
| 6 |
|
| 7 |
int testObjCComparisonRules(void *v, id x, id y) { |
| 8 |
return v == x; |
| 9 |
#ifndef NOARC |
| 10 |
// 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 |
#endif |
| 14 |
return v >= x; |
| 15 |
#ifndef NOARC |
| 16 |
// 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 |
#endif |
| 20 |
return v == (id)(void *)0; // OK |
| 21 |
return v == nullptr; // OK |
| 22 |
return v == (void *)0; |
| 23 |
return x == y; |
| 24 |
} |
| 25 |
|
| 26 |
@class A; |
| 27 |
|
| 28 |
int testMixedQualComparisonRules(void *v, const void *cv, A *a, const A *ca) { |
| 29 |
return cv == ca; |
| 30 |
#ifndef NOARC |
| 31 |
// 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 |
#endif |
| 35 |
// FIXME: The "to" type in this diagnostic is wrong; we should convert to "const void *". |
| 36 |
return v == ca; |
| 37 |
#ifndef NOARC |
| 38 |
// 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 |
#endif |
| 42 |
return cv == a; |
| 43 |
#ifndef NOARC |
| 44 |
// 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 |
#endif |
| 48 |
|
| 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 NOARC |
| 56 |
int 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 |
#endif |