xref: /minix3/external/bsd/llvm/dist/clang/test/SemaObjCXX/references.mm (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc// RUN: %clang_cc1 -verify -o - %s
2*f4a2713aSLionel Sambuc
3*f4a2713aSLionel Sambuc__attribute__((objc_root_class))
4*f4a2713aSLionel Sambuc@interface Root @end
5*f4a2713aSLionel Sambuc
6*f4a2713aSLionel Sambuc// Test reference binding.
7*f4a2713aSLionel Sambuc
8*f4a2713aSLionel Sambuctypedef struct {
9*f4a2713aSLionel Sambuc  int f0;
10*f4a2713aSLionel Sambuc  int f1;
11*f4a2713aSLionel Sambuc} T;
12*f4a2713aSLionel Sambuc
13*f4a2713aSLionel Sambuc@interface A : Root
14*f4a2713aSLionel Sambuc@property (assign) T p0;
15*f4a2713aSLionel Sambuc@property (assign) T& p1;
16*f4a2713aSLionel Sambuc@end
17*f4a2713aSLionel Sambuc
18*f4a2713aSLionel Sambucint f0(const T& t) {
19*f4a2713aSLionel Sambuc  return t.f0;
20*f4a2713aSLionel Sambuc}
21*f4a2713aSLionel Sambuc
22*f4a2713aSLionel Sambucint f1(A *a) {
23*f4a2713aSLionel Sambuc  return f0(a.p0);
24*f4a2713aSLionel Sambuc}
25*f4a2713aSLionel Sambuc
26*f4a2713aSLionel Sambucint f2(A *a) {
27*f4a2713aSLionel Sambuc  return f0(a.p1);
28*f4a2713aSLionel Sambuc}
29*f4a2713aSLionel Sambuc
30*f4a2713aSLionel Sambuc// PR7740
31*f4a2713aSLionel Sambuc@class NSString;
32*f4a2713aSLionel Sambuc
33*f4a2713aSLionel Sambucvoid f3(id);
34*f4a2713aSLionel Sambucvoid f4(NSString &tmpstr) {
35*f4a2713aSLionel Sambuc  f3(&tmpstr);
36*f4a2713aSLionel Sambuc}
37*f4a2713aSLionel Sambuc
38*f4a2713aSLionel Sambuc// PR7741
39*f4a2713aSLionel Sambuc@protocol P1 @end
40*f4a2713aSLionel Sambuc@protocol P2 @end
41*f4a2713aSLionel Sambuc@protocol P3 @end
42*f4a2713aSLionel Sambuc@interface foo<P1> {} @end
43*f4a2713aSLionel Sambuc@interface bar : foo <P1, P2, P3> {} @end
44*f4a2713aSLionel Sambuctypedef bar baz;
45*f4a2713aSLionel Sambuc
46*f4a2713aSLionel Sambucstruct ToBar {
47*f4a2713aSLionel Sambuc  operator bar&() const;
48*f4a2713aSLionel Sambuc};
49*f4a2713aSLionel Sambuc
50*f4a2713aSLionel Sambucvoid f5(foo&);
51*f4a2713aSLionel Sambucvoid f5b(foo<P1>&);
52*f4a2713aSLionel Sambucvoid f5c(foo<P2>&);
53*f4a2713aSLionel Sambucvoid f5d(foo<P3>&);
54*f4a2713aSLionel Sambucvoid f6(baz* x) {
55*f4a2713aSLionel Sambuc  f5(*x);
56*f4a2713aSLionel Sambuc  f5b(*x);
57*f4a2713aSLionel Sambuc  f5c(*x);
58*f4a2713aSLionel Sambuc  f5d(*x);
59*f4a2713aSLionel Sambuc  (void)((foo&)*x);
60*f4a2713aSLionel Sambuc  f5(ToBar());
61*f4a2713aSLionel Sambuc  f5b(ToBar());
62*f4a2713aSLionel Sambuc  f5c(ToBar());
63*f4a2713aSLionel Sambuc  f5d(ToBar());
64*f4a2713aSLionel Sambuc  (void)((foo&)ToBar());
65*f4a2713aSLionel Sambuc}
66*f4a2713aSLionel Sambuc
67*f4a2713aSLionel Sambuc// rdar://13794269
68*f4a2713aSLionel Sambuc@interface B : Root @end
69*f4a2713aSLionel Sambuc@implementation B {
70*f4a2713aSLionel Sambuc  unsigned bf : 4; // expected-note {{declared here}}
71*f4a2713aSLionel Sambuc}
72*f4a2713aSLionel Sambuc
73*f4a2713aSLionel Sambuc- (void) foo {
74*f4a2713aSLionel Sambuc  unsigned &i = bf; // expected-error {{non-const reference cannot bind to bit-field 'bf'}}
75*f4a2713aSLionel Sambuc}
76*f4a2713aSLionel Sambuc@end
77