Home | History | Annotate | Download | only in CodeGenCXX
      1 // RUN: %clang_cc1 -emit-llvm -o - %s
      2 
      3 extern "C" int printf(...);
      4 
      5 struct F {
      6   F() : iF(1), fF(2.0) {}
      7   int iF;
      8   float fF;
      9 };
     10 
     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 {
     27 public:
     28   A() : f(1.0), d(2.0), Ai(3) {}
     29   float f;
     30   double d;
     31   int Ai;
     32   F Af;
     33 };
     34 
     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 
     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 
     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 
     78 int main()
     79 {
     80   A a1;
     81   TT<I> tt;
     82   I i;
     83   int A::* pa = &A::Ai;
     84   float A::* pf = &A::f;
     85   double A::* pd = &A::d;
     86   tt.pti = &I::x;
     87   printf("%d %d %d\n", &A::Ai, &A::f, &A::d);
     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);
     95   printf("%d, %f, %f  \n", a1.*pa, a1.*pf, a1.*pd);
     96   printf("%d\n", i.*tt.pti);
     97   test_aggr_pdata(a1);
     98   test_aggr_pdata_1(&a1);
     99 }
    100