Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -emit-llvm -o - %s |
Fariborz Jahanian | a636299 | 2009-10-21 18:38:00 +0000 | [diff] [blame] | 2 | |
| 3 | extern "C" int printf(...); |
| 4 | |
Fariborz Jahanian | 8bfd31f | 2009-10-22 22:57:31 +0000 | [diff] [blame] | 5 | struct F { |
| 6 | F() : iF(1), fF(2.0) {} |
| 7 | int iF; |
| 8 | float fF; |
| 9 | }; |
| 10 | |
Fariborz Jahanian | 3976295 | 2009-10-21 21:01:47 +0000 | [diff] [blame] | 11 | struct V { |
| 12 | double d; |
| 13 | int iV; |
| 14 | }; |
| 15 | |
| 16 | struct B : virtual V{ |
| 17 | double d; |
| 18 | int iB; |
| 19 | }; |
| 20 | |
| 21 | struct B1 : virtual V{ |
| 22 | double d; |
| 23 | int iB1; |
| 24 | }; |
| 25 | |
| 26 | class A : public B, public B1 { |
Fariborz Jahanian | a636299 | 2009-10-21 18:38:00 +0000 | [diff] [blame] | 27 | public: |
Fariborz Jahanian | f51dc64 | 2009-10-21 23:45:42 +0000 | [diff] [blame] | 28 | A() : f(1.0), d(2.0), Ai(3) {} |
Fariborz Jahanian | a636299 | 2009-10-21 18:38:00 +0000 | [diff] [blame] | 29 | float f; |
| 30 | double d; |
| 31 | int Ai; |
Fariborz Jahanian | 8bfd31f | 2009-10-22 22:57:31 +0000 | [diff] [blame] | 32 | F Af; |
Fariborz Jahanian | a636299 | 2009-10-21 18:38:00 +0000 | [diff] [blame] | 33 | }; |
| 34 | |
Douglas Gregor | 87c12c4 | 2009-11-04 16:49:01 +0000 | [diff] [blame] | 35 | template <typename T> struct TT { |
| 36 | int T::t::*pti; |
| 37 | }; |
| 38 | |
| 39 | struct I { |
| 40 | typedef I t; |
| 41 | int x; |
| 42 | }; |
| 43 | |
Fariborz Jahanian | 8bfd31f | 2009-10-22 22:57:31 +0000 | [diff] [blame] | 44 | void pr(const F& b) { |
| 45 | printf(" %d %f\n", b.iF, b.fF); |
| 46 | } |
| 47 | |
| 48 | void 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 Jahanian | 52f08bc | 2009-10-26 21:58:25 +0000 | [diff] [blame] | 63 | void 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 Jahanian | a636299 | 2009-10-21 18:38:00 +0000 | [diff] [blame] | 78 | int main() |
| 79 | { |
| 80 | A a1; |
Douglas Gregor | 87c12c4 | 2009-11-04 16:49:01 +0000 | [diff] [blame] | 81 | TT<I> tt; |
| 82 | I i; |
Fariborz Jahanian | a636299 | 2009-10-21 18:38:00 +0000 | [diff] [blame] | 83 | int A::* pa = &A::Ai; |
| 84 | float A::* pf = &A::f; |
| 85 | double A::* pd = &A::d; |
Douglas Gregor | 87c12c4 | 2009-11-04 16:49:01 +0000 | [diff] [blame] | 86 | tt.pti = &I::x; |
Fariborz Jahanian | a636299 | 2009-10-21 18:38:00 +0000 | [diff] [blame] | 87 | printf("%d %d %d\n", &A::Ai, &A::f, &A::d); |
Fariborz Jahanian | 3976295 | 2009-10-21 21:01:47 +0000 | [diff] [blame] | 88 | 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 Jahanian | f51dc64 | 2009-10-21 23:45:42 +0000 | [diff] [blame] | 95 | printf("%d, %f, %f \n", a1.*pa, a1.*pf, a1.*pd); |
Douglas Gregor | 87c12c4 | 2009-11-04 16:49:01 +0000 | [diff] [blame] | 96 | printf("%d\n", i.*tt.pti); |
Fariborz Jahanian | 8bfd31f | 2009-10-22 22:57:31 +0000 | [diff] [blame] | 97 | test_aggr_pdata(a1); |
Fariborz Jahanian | 52f08bc | 2009-10-26 21:58:25 +0000 | [diff] [blame] | 98 | test_aggr_pdata_1(&a1); |
Fariborz Jahanian | a636299 | 2009-10-21 18:38:00 +0000 | [diff] [blame] | 99 | } |