blob: a6f523e2d7dd01b446cd24128027340e3783005e [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -emit-llvm -o - %s
Fariborz Jahaniana6362992009-10-21 18:38:00 +00002
3extern "C" int printf(...);
4
Fariborz Jahanian8bfd31f2009-10-22 22:57:31 +00005struct F {
6 F() : iF(1), fF(2.0) {}
7 int iF;
8 float fF;
9};
10
Fariborz Jahanian39762952009-10-21 21:01:47 +000011struct V {
12 double d;
13 int iV;
14};
15
16struct B : virtual V{
17 double d;
18 int iB;
19};
20
21struct B1 : virtual V{
22 double d;
23 int iB1;
24};
25
26class A : public B, public B1 {
Fariborz Jahaniana6362992009-10-21 18:38:00 +000027public:
Fariborz Jahanianf51dc642009-10-21 23:45:42 +000028 A() : f(1.0), d(2.0), Ai(3) {}
Fariborz Jahaniana6362992009-10-21 18:38:00 +000029 float f;
30 double d;
31 int Ai;
Fariborz Jahanian8bfd31f2009-10-22 22:57:31 +000032 F Af;
Fariborz Jahaniana6362992009-10-21 18:38:00 +000033};
34
Douglas Gregor87c12c42009-11-04 16:49:01 +000035template <typename T> struct TT {
36 int T::t::*pti;
37};
38
39struct I {
40 typedef I t;
41 int x;
42};
43
Fariborz Jahanian8bfd31f2009-10-22 22:57:31 +000044void pr(const F& b) {
45 printf(" %d %f\n", b.iF, b.fF);
46}
47
48void test_aggr_pdata(A& a1) {
49 F A::* af = &A::Af;
50 pr(a1.*af);
51
52 (a1.*af).iF = 100;
53 (a1.*af).fF = 200.00;
54 printf(" %d %f\n", (a1.*af).iF, (a1.*af).fF);
55 pr(a1.*af);
56
57 (a1.*af).iF++;
58 (a1.*af).fF--;
59 --(a1.*af).fF;
60 pr(a1.*af);
61}
62
Fariborz Jahanian52f08bc2009-10-26 21:58:25 +000063void test_aggr_pdata_1(A* pa) {
64 F A::* af = &A::Af;
65 pr(pa->*af);
66
67 (pa->*af).iF = 100;
68 (pa->*af).fF = 200.00;
69 printf(" %d %f\n", (pa->*af).iF, (pa->*af).fF);
70 pr(pa->*af);
71
72 (pa->*af).iF++;
73 (pa->*af).fF--;
74 --(pa->*af).fF;
75 pr(pa->*af);
76}
77
Fariborz Jahaniana6362992009-10-21 18:38:00 +000078int main()
79{
80 A a1;
Douglas Gregor87c12c42009-11-04 16:49:01 +000081 TT<I> tt;
82 I i;
Fariborz Jahaniana6362992009-10-21 18:38:00 +000083 int A::* pa = &A::Ai;
84 float A::* pf = &A::f;
85 double A::* pd = &A::d;
Douglas Gregor87c12c42009-11-04 16:49:01 +000086 tt.pti = &I::x;
Fariborz Jahaniana6362992009-10-21 18:38:00 +000087 printf("%d %d %d\n", &A::Ai, &A::f, &A::d);
Fariborz Jahanian39762952009-10-21 21:01:47 +000088 printf("%d\n", &A::B::iB);
89 printf("%d\n", &A::B1::iB1);
90 printf("%d\n", &A::f);
91 printf("%d\n", &A::B::iV);
92 printf("%d\n", &A::B1::iV);
93 printf("%d\n", &A::B::V::iV);
94 printf("%d\n", &A::B1::V::iV);
Fariborz Jahanianf51dc642009-10-21 23:45:42 +000095 printf("%d, %f, %f \n", a1.*pa, a1.*pf, a1.*pd);
Douglas Gregor87c12c42009-11-04 16:49:01 +000096 printf("%d\n", i.*tt.pti);
Fariborz Jahanian8bfd31f2009-10-22 22:57:31 +000097 test_aggr_pdata(a1);
Fariborz Jahanian52f08bc2009-10-26 21:58:25 +000098 test_aggr_pdata_1(&a1);
Fariborz Jahaniana6362992009-10-21 18:38:00 +000099}