annotate gcc/testsuite/g++.dg/cpp0x/not_special.C @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 // I, Howard Hinnant, hereby place this code in the public domain.
kono
parents:
diff changeset
2
kono
parents:
diff changeset
3 // Test that move constructor and move assignement are special.
kono
parents:
diff changeset
4 // That is, their presence should cause compiler declared
kono
parents:
diff changeset
5 // copy ctor or assignment to be deleted.
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 // { dg-do compile { target c++11 } }
kono
parents:
diff changeset
8
kono
parents:
diff changeset
9 #include <assert.h>
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11 template <bool> struct sa;
kono
parents:
diff changeset
12 template <> struct sa<true> {};
kono
parents:
diff changeset
13
kono
parents:
diff changeset
14 struct one {char x[1];};
kono
parents:
diff changeset
15 struct two {char x[2];};
kono
parents:
diff changeset
16
kono
parents:
diff changeset
17 int copy = 0;
kono
parents:
diff changeset
18 int assign = 0;
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 struct base
kono
parents:
diff changeset
21 {
kono
parents:
diff changeset
22 base() {}
kono
parents:
diff changeset
23 base(const base&) {++copy;}
kono
parents:
diff changeset
24 base& operator=(const base&) {++assign; return *this;}
kono
parents:
diff changeset
25 };
kono
parents:
diff changeset
26
kono
parents:
diff changeset
27 struct derived // { dg-message "declares a move" }
kono
parents:
diff changeset
28 : base
kono
parents:
diff changeset
29 {
kono
parents:
diff changeset
30 derived() {}
kono
parents:
diff changeset
31 derived(derived&&) {}
kono
parents:
diff changeset
32 derived& operator=(derived&&) {return *this;}
kono
parents:
diff changeset
33 };
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 int test1()
kono
parents:
diff changeset
36 {
kono
parents:
diff changeset
37 derived d;
kono
parents:
diff changeset
38 derived d2(static_cast<derived&&>(d)); // should not call base::(const base&)
kono
parents:
diff changeset
39 assert(copy == 0);
kono
parents:
diff changeset
40 derived d3(d); // { dg-error "deleted" }
kono
parents:
diff changeset
41 assert(copy == 1);
kono
parents:
diff changeset
42 d2 = static_cast<derived&&>(d); // should not call base::operator=
kono
parents:
diff changeset
43 assert(assign == 0);
kono
parents:
diff changeset
44 d3 = d; // { dg-error "deleted" }
kono
parents:
diff changeset
45 assert(assign == 1);
kono
parents:
diff changeset
46 return 0;
kono
parents:
diff changeset
47 }
kono
parents:
diff changeset
48
kono
parents:
diff changeset
49 int main()
kono
parents:
diff changeset
50 {
kono
parents:
diff changeset
51 return test1();
kono
parents:
diff changeset
52 }