1// I, Howard Hinnant, hereby place this code in the public domain.
2
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.
6
7// { dg-do compile { target c++11 } }
8
9#include <assert.h>
10
11template <bool> struct sa;
12template <> struct sa<true> {};
13
14struct one   {char x[1];};
15struct two   {char x[2];};
16
17int copy = 0;
18int assign = 0;
19
20struct base
21{
22    base() {}
23    base(const base&) {++copy;}
24    base& operator=(const base&) {++assign; return *this;}
25};
26
27struct derived			// { dg-message "declares a move" }
28    : base
29{
30    derived() {}
31    derived(derived&&) {}
32    derived& operator=(derived&&) {return *this;}
33};
34
35int test1()
36{
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;
47}
48
49int main()
50{
51    return test1();
52}
53