diff options
author | Carlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au> | 2012-10-15 17:10:06 +1100 |
---|---|---|
committer | Carlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au> | 2012-10-15 17:10:06 +1100 |
commit | be1de4be954c80875ad4108e0a33e8e131b2f2c0 (patch) | |
tree | 1fbbecf276bf7c7bdcbb4dd446099d6d90eaa516 /clang/test/CodeGenCXX/ptr-to-datamember.cpp | |
parent | c4626a62754862d20b41e8a46a3574264ea80e6d (diff) | |
parent | f1bd2e48c5324d3f7cda4090c87f8a5b6f463ce2 (diff) |
Merge branch 'master' of ssh://bitbucket.org/czan/honours
Diffstat (limited to 'clang/test/CodeGenCXX/ptr-to-datamember.cpp')
-rw-r--r-- | clang/test/CodeGenCXX/ptr-to-datamember.cpp | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/clang/test/CodeGenCXX/ptr-to-datamember.cpp b/clang/test/CodeGenCXX/ptr-to-datamember.cpp new file mode 100644 index 0000000..a6f523e --- /dev/null +++ b/clang/test/CodeGenCXX/ptr-to-datamember.cpp @@ -0,0 +1,99 @@ +// RUN: %clang_cc1 -emit-llvm -o - %s + +extern "C" int printf(...); + +struct F { + F() : iF(1), fF(2.0) {} + int iF; + float fF; +}; + +struct V { + double d; + int iV; +}; + +struct B : virtual V{ + double d; + int iB; +}; + +struct B1 : virtual V{ + double d; + int iB1; +}; + +class A : public B, public B1 { +public: + A() : f(1.0), d(2.0), Ai(3) {} + float f; + double d; + int Ai; + F Af; +}; + +template <typename T> struct TT { + int T::t::*pti; +}; + +struct I { + typedef I t; + int x; +}; + +void pr(const F& b) { + printf(" %d %f\n", b.iF, b.fF); +} + +void test_aggr_pdata(A& a1) { + F A::* af = &A::Af; + pr(a1.*af); + + (a1.*af).iF = 100; + (a1.*af).fF = 200.00; + printf(" %d %f\n", (a1.*af).iF, (a1.*af).fF); + pr(a1.*af); + + (a1.*af).iF++; + (a1.*af).fF--; + --(a1.*af).fF; + pr(a1.*af); +} + +void test_aggr_pdata_1(A* pa) { + F A::* af = &A::Af; + pr(pa->*af); + + (pa->*af).iF = 100; + (pa->*af).fF = 200.00; + printf(" %d %f\n", (pa->*af).iF, (pa->*af).fF); + pr(pa->*af); + + (pa->*af).iF++; + (pa->*af).fF--; + --(pa->*af).fF; + pr(pa->*af); +} + +int main() +{ + A a1; + TT<I> tt; + I i; + int A::* pa = &A::Ai; + float A::* pf = &A::f; + double A::* pd = &A::d; + tt.pti = &I::x; + printf("%d %d %d\n", &A::Ai, &A::f, &A::d); + printf("%d\n", &A::B::iB); + printf("%d\n", &A::B1::iB1); + printf("%d\n", &A::f); + printf("%d\n", &A::B::iV); + printf("%d\n", &A::B1::iV); + printf("%d\n", &A::B::V::iV); + printf("%d\n", &A::B1::V::iV); + printf("%d, %f, %f \n", a1.*pa, a1.*pf, a1.*pd); + printf("%d\n", i.*tt.pti); + test_aggr_pdata(a1); + test_aggr_pdata_1(&a1); +} |