xref: /minix3/external/bsd/llvm/dist/clang/test/SemaObjCXX/arc-unavailable-for-weakref.mm (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc// RUN: %clang_cc1 -x objective-c++ -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -verify %s
2*f4a2713aSLionel Sambuc// rdar://9693477
3*f4a2713aSLionel Sambuc
4*f4a2713aSLionel Sambuc__attribute__((objc_arc_weak_reference_unavailable))
5*f4a2713aSLionel Sambuc@interface NSOptOut1072  // expected-note {{class is declared here}}
6*f4a2713aSLionel Sambuc@end
7*f4a2713aSLionel Sambuc
8*f4a2713aSLionel Sambuc@interface sub : NSOptOut1072 @end // expected-note 2 {{class is declared here}}
9*f4a2713aSLionel Sambuc
10*f4a2713aSLionel Sambucint main() {
11*f4a2713aSLionel Sambuc  __weak sub *w2; // expected-error {{class is incompatible with __weak references}}
12*f4a2713aSLionel Sambuc
13*f4a2713aSLionel Sambuc  __weak NSOptOut1072 *ns1; // expected-error {{class is incompatible with __weak references}}
14*f4a2713aSLionel Sambuc
15*f4a2713aSLionel Sambuc  id obj;
16*f4a2713aSLionel Sambuc
17*f4a2713aSLionel Sambuc  ns1 = (__weak sub *)obj; // expected-error {{assignment of a weak-unavailable object to a __weak object}} \
18*f4a2713aSLionel Sambuc                           // expected-error {{class is incompatible with __weak references}} \
19*f4a2713aSLionel Sambuc                           // expected-error {{explicit ownership qualifier on cast result has no effect}}
20*f4a2713aSLionel Sambuc}
21*f4a2713aSLionel Sambuc
22*f4a2713aSLionel Sambuc// rdar://9732636
23*f4a2713aSLionel Sambuc__attribute__((objc_arc_weak_reference_unavailable))
24*f4a2713aSLionel Sambuc@interface NOWEAK
25*f4a2713aSLionel Sambuc+ (id) new;
26*f4a2713aSLionel Sambuc@end
27*f4a2713aSLionel Sambuc
28*f4a2713aSLionel SambucNOWEAK * Test1() {
29*f4a2713aSLionel Sambuc  NOWEAK * strong1 = [NOWEAK new];
30*f4a2713aSLionel Sambuc  __weak id weak1;
31*f4a2713aSLionel Sambuc  weak1 = strong1; // expected-error {{assignment of a weak-unavailable object to a __weak object}}
32*f4a2713aSLionel Sambuc
33*f4a2713aSLionel Sambuc  __weak id weak2 = strong1; // expected-error {{assignment of a weak-unavailable object to a __weak object}}
34*f4a2713aSLionel Sambuc  return (__weak id)strong1; // expected-error {{cast of weak-unavailable object of type 'NOWEAK *' to a __weak object of type '__weak id'}} \
35*f4a2713aSLionel Sambuc                             // expected-error {{explicit ownership qualifier on cast result has no effect}}
36*f4a2713aSLionel Sambuc}
37*f4a2713aSLionel Sambuc
38*f4a2713aSLionel Sambuc@protocol P @end
39*f4a2713aSLionel Sambuc@protocol P1 @end
40*f4a2713aSLionel Sambuc
41*f4a2713aSLionel SambucNOWEAK<P, P1> * Test2() {
42*f4a2713aSLionel Sambuc  NOWEAK<P, P1> * strong1 = 0;
43*f4a2713aSLionel Sambuc  __weak id<P> weak1;
44*f4a2713aSLionel Sambuc  weak1 = strong1; // expected-error {{assignment of a weak-unavailable object to a __weak object}}
45*f4a2713aSLionel Sambuc
46*f4a2713aSLionel Sambuc  __weak id<P> weak2 = strong1; // expected-error {{assignment of a weak-unavailable object to a __weak object}}
47*f4a2713aSLionel Sambuc  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>'}} \
48*f4a2713aSLionel Sambuc                                    // expected-error {{explicit ownership qualifier on cast result has no effect}}
49*f4a2713aSLionel Sambuc}
50*f4a2713aSLionel Sambuc
51