blob: fa552076fb92af14d8629e3b9b988dc39198d945 [file] [log] [blame]
John McCall993f43f2013-05-06 21:39:12 +00001// RUN: %clang_cc1 -verify -o - %s
2
3__attribute__((objc_root_class))
4@interface Root @end
Daniel Dunbarfcf3de32009-06-05 06:03:19 +00005
6// Test reference binding.
7
8typedef struct {
9 int f0;
10 int f1;
11} T;
12
John McCall993f43f2013-05-06 21:39:12 +000013@interface A : Root
Daniel Dunbarfcf3de32009-06-05 06:03:19 +000014@property (assign) T p0;
Fariborz Jahanian14086762011-03-28 23:47:18 +000015@property (assign) T& p1;
Daniel Dunbarfcf3de32009-06-05 06:03:19 +000016@end
17
18int f0(const T& t) {
19 return t.f0;
20}
21
22int f1(A *a) {
23 return f0(a.p0);
24}
25
26int f2(A *a) {
Fariborz Jahanian14086762011-03-28 23:47:18 +000027 return f0(a.p1);
Daniel Dunbarfcf3de32009-06-05 06:03:19 +000028}
29
Douglas Gregor8f70ddb2010-07-29 16:05:45 +000030// PR7740
31@class NSString;
32
33void f3(id);
34void f4(NSString &tmpstr) {
35 f3(&tmpstr);
36}
Douglas Gregor569c3162010-08-07 11:51:51 +000037
38// PR7741
39@protocol P1 @end
40@protocol P2 @end
41@protocol P3 @end
42@interface foo<P1> {} @end
Fariborz Jahanianb7bc34a2011-04-08 18:25:29 +000043@interface bar : foo <P1, P2, P3> {} @end
Douglas Gregor569c3162010-08-07 11:51:51 +000044typedef bar baz;
Douglas Gregoraaa37132010-08-07 11:56:45 +000045
46struct ToBar {
47 operator bar&() const;
48};
49
Douglas Gregor569c3162010-08-07 11:51:51 +000050void f5(foo&);
51void f5b(foo<P1>&);
52void f5c(foo<P2>&);
53void f5d(foo<P3>&);
54void f6(baz* x) {
55 f5(*x);
56 f5b(*x);
57 f5c(*x);
58 f5d(*x);
Douglas Gregoraaa37132010-08-07 11:56:45 +000059 (void)((foo&)*x);
60 f5(ToBar());
61 f5b(ToBar());
62 f5c(ToBar());
63 f5d(ToBar());
64 (void)((foo&)ToBar());
Douglas Gregor569c3162010-08-07 11:51:51 +000065}
John McCall993f43f2013-05-06 21:39:12 +000066
67// rdar://13794269
68@interface B : Root @end
69@implementation B {
70 unsigned bf : 4; // expected-note {{declared here}}
71}
72
73- (void) foo {
74 unsigned &i = bf; // expected-error {{non-const reference cannot bind to bit-field 'bf'}}
75}
76@end