OSDN Git Service

2008-01-15 Douglas Gregor <doug.gregor@gmail.com>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.dg / cpp0x / not_special.C
1 // I, Howard Hinnant, hereby place this code in the public domain.
2
3 // Test that move constructor and move assignement are not special.
4 //   That is, their presence should not inhibit compiler generated
5 //   copy ctor or assignment.  Rather they should overload with the
6 //   compiler generated special members.
7
8 // { dg-do run }
9 // { dg-options "-std=c++0x" }
10
11 #include <assert.h>
12
13 template <bool> struct sa;
14 template <> struct sa<true> {};
15
16 struct one   {char x[1];};
17 struct two   {char x[2];};
18
19 int copy = 0;
20 int assign = 0;
21
22 struct base
23 {
24     base() {}
25     base(const base&) {++copy;}
26     base& operator=(const base&) {++assign; return *this;}
27 };
28
29 struct derived
30     : base
31 {
32     derived() {}
33     derived(derived&&) {}
34     derived& operator=(derived&&) {return *this;}
35 };
36
37 int test1()
38 {
39     derived d;
40     derived d2(static_cast<derived&&>(d));  // should not call base::(const base&)
41     assert(copy == 0);
42     derived d3(d);                          // should     call base::(const base&)
43     assert(copy == 1);
44     d2 = static_cast<derived&&>(d);         // should not call base::operator=
45     assert(assign == 0);
46     d3 = d;                                 // should     call base::operator=
47     assert(assign == 1);
48     return 0;
49 }
50
51 int main()
52 {
53     return test1();
54 }