Merged trunk at revision 161680 into branch.
[official-gcc.git] / gcc / testsuite / g++.dg / cpp0x / not_special.C
blob6d73bd086caaea9f2a2f66b0aafc9f4118718dfb
1 // I, Howard Hinnant, hereby place this code in the public domain.
3 // Test that move constructor and move assignement are special.
4 //   That is, their presence should inhibit compiler generated
5 //   copy ctor or assignment.
7 // { dg-options "-std=c++0x" }
9 #include <assert.h>
11 template <bool> struct sa;
12 template <> struct sa<true> {};
14 struct one   {char x[1];};
15 struct two   {char x[2];};
17 int copy = 0;
18 int assign = 0;
20 struct base
22     base() {}
23     base(const base&) {++copy;}
24     base& operator=(const base&) {++assign; return *this;}
27 struct derived
28     : base
30     derived() {}
31     derived(derived&&) {}                         // { dg-error "argument 1" }
32     derived& operator=(derived&&) {return *this;} // { dg-error "argument 1" }
35 int test1()
37     derived d;
38     derived d2(static_cast<derived&&>(d));  // should not call base::(const base&)
39     assert(copy == 0);
40     derived d3(d);              // { dg-error "lvalue" }
41     assert(copy == 1);
42     d2 = static_cast<derived&&>(d);         // should not call base::operator=
43     assert(assign == 0);
44     d3 = d;                     // { dg-error "lvalue" }
45     assert(assign == 1);
46     return 0;
49 int main()
51     return test1();