OSDN Git Service

PR c++/9335
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.dg / template / repo9.C
1 // PR c++/36364
2 // { dg-options "-frepo" }
3 // { dg-final { cleanup-repo-files } }
4 // { dg-require-host-local "" }
5 // { dg-skip-if "dkms are not final links" { vxworks_kernel } }
6
7 template <typename C> struct A
8 {
9   static void assign (C &c1, const C &c2) { c1 = c2; }
10 };
11
12 template <typename C, typename T> struct B
13 {
14   struct D
15   {
16     static const C terminal;
17     static unsigned long stor[];
18     static D &empty_rep ()
19     {
20       void *p = reinterpret_cast <void *>(&stor);
21       return *reinterpret_cast <D *>(p);
22     }
23     void test (unsigned long n)
24     {
25       T::assign (this->refdata ()[n], terminal);
26     }
27     C *refdata () throw ()
28     {
29       return reinterpret_cast <C *>(this + 1);
30     }
31   };
32   C *dataplus;
33   C *data () const { return dataplus; }
34   D *rep () const { return &((reinterpret_cast < D * >(data ()))[-1]); }
35   static D & empty_rep () { return D::empty_rep (); }
36   B () : dataplus (empty_rep ().refdata ()) { }
37   ~B () { }
38   void push_back (C c) { rep ()->test (10); }
39 };
40
41 template <typename C, typename T> const C B <C, T>::D::terminal = C ();
42 template <typename C, typename T> unsigned long B <C, T>::D::stor[64];
43
44 int
45 main ()
46 {
47   B <char, A <char> > s;
48   s.push_back ('a');
49 }