Merged revisions 208012,208018-208019,208021,208023-208030,208033,208037,208040-20804...
[official-gcc.git] / main / gcc / testsuite / g++.dg / cpp0x / not_special.C
blob22054ea058ee1d8f8225f8815d407e989efbd1b9
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 cause compiler declared
5 //   copy ctor or assignment to be deleted.
7 // { dg-do compile { target c++11 } }
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                  // { dg-message "declares a move" }
28     : base
30     derived() {}
31     derived(derived&&) {}
32     derived& operator=(derived&&) {return *this;}
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 "deleted" }
41     assert(copy == 1);
42     d2 = static_cast<derived&&>(d);         // should not call base::operator=
43     assert(assign == 0);
44     d3 = d;                     // { dg-error "deleted" }
45     assert(assign == 1);
46     return 0;
49 int main()
51     return test1();