1 | // Partial autogen means that some lifecycle functions are possible to generate, and needed, while |
---|
2 | // others are impossible to generate, but unneeded. |
---|
3 | |
---|
4 | #ifdef ERR1 |
---|
5 | #define BAD(...) __VA_ARGS__ |
---|
6 | #else |
---|
7 | #define BAD(...) |
---|
8 | #endif |
---|
9 | |
---|
10 | void testAllNested() { |
---|
11 | |
---|
12 | // Declaring your own empty ctor leaves an autogen dtor usable |
---|
13 | struct thing1 {}; |
---|
14 | void ?{}( thing1 & this ) { printf( "custom ctor\n"); } |
---|
15 | void test1() { |
---|
16 | printf("test1\n"); |
---|
17 | thing1 x; |
---|
18 | } |
---|
19 | |
---|
20 | // Declaring your own empty ctor and dtor leaves an autogen copy ctor usable |
---|
21 | struct thing2 {}; |
---|
22 | void ?{}( thing2 & this ) { printf( "custom ctor\n"); } |
---|
23 | void ^?{}( thing2 & this ) { printf( "custom dtor\n"); } |
---|
24 | void test2() { |
---|
25 | printf("test2\n"); |
---|
26 | thing2 x; |
---|
27 | thing2 y = x; |
---|
28 | } |
---|
29 | |
---|
30 | // Deleting the autogen copy ctor also deletes the autogen empty ctor |
---|
31 | struct thing3 {}; |
---|
32 | void ?{}( thing3 &, thing3 ) = void; |
---|
33 | void test3() { |
---|
34 | printf("test3\n"); |
---|
35 | BAD( thing3 x; ) // Unique best alternative includes deleted identifier |
---|
36 | } |
---|
37 | |
---|
38 | struct thing456 {}; |
---|
39 | void ?{}( thing456 & this ) { printf( "custom ctor\n"); } |
---|
40 | void ?{}( thing456 &, thing456 ) = void; |
---|
41 | thing456 & ?=?( thing456 &, thing456 ) = void; |
---|
42 | void ^?{}( thing456 & this ) { printf( "custom dtor\n"); } |
---|
43 | |
---|
44 | struct wrapper1 { thing456 x; }; |
---|
45 | struct wrapper2 { wrapper1 x; }; |
---|
46 | |
---|
47 | // Deleting some autogens and declaring your own for the others leaves yours usable |
---|
48 | // and the deleted ones cleanly deleted |
---|
49 | void test4() { |
---|
50 | printf("test4\n"); |
---|
51 | thing456 x; |
---|
52 | BAD( thing456 y = x; ) // Unique best alternative includes deleted identifier |
---|
53 | } |
---|
54 | |
---|
55 | // Wrapping v4 leaves yours usable via autogen |
---|
56 | // and the autogen-lifts of your deleted ones are not usable |
---|
57 | void test5() { |
---|
58 | printf("test5\n"); |
---|
59 | wrapper1 x; |
---|
60 | BAD( wrapper1 y = x; ) // Unique best alternative includes deleted identifier |
---|
61 | } |
---|
62 | |
---|
63 | // Wrapping again works similarly |
---|
64 | void test6() { |
---|
65 | printf("test6\n"); |
---|
66 | wrapper2 x; |
---|
67 | BAD( wrapper2 y = x; ) // Unique best alternative includes deleted identifier |
---|
68 | } |
---|
69 | |
---|
70 | test1(); |
---|
71 | test2(); |
---|
72 | test3(); |
---|
73 | test4(); |
---|
74 | test5(); |
---|
75 | test6(); |
---|
76 | } |
---|
77 | |
---|
78 | // ===== Repeat, now as top-level declarations |
---|
79 | |
---|
80 | // Declaring your own empty ctor leaves an autogen dtor usable |
---|
81 | struct thing1 {}; |
---|
82 | void ?{}( thing1 & this ) { printf( "custom ctor\n"); } |
---|
83 | void test1() { |
---|
84 | printf("test1\n"); |
---|
85 | thing1 x; |
---|
86 | } |
---|
87 | |
---|
88 | // Declaring your own empty ctor and dtor leaves an autogen copy ctor usable |
---|
89 | struct thing2 {}; |
---|
90 | void ?{}( thing2 & this ) { printf( "custom ctor\n"); } |
---|
91 | void ^?{}( thing2 & this ) { printf( "custom dtor\n"); } |
---|
92 | void test2() { |
---|
93 | printf("test2\n"); |
---|
94 | thing2 x; |
---|
95 | thing2 y = x; |
---|
96 | } |
---|
97 | |
---|
98 | // Deleting the autogen copy ctor also deletes the autogen empty ctor |
---|
99 | struct thing3 {}; |
---|
100 | void ?{}( thing3 &, thing3 ) = void; |
---|
101 | void test3() { |
---|
102 | printf("test3\n"); |
---|
103 | BAD( thing3 x; ) // Unique best alternative includes deleted identifier |
---|
104 | } |
---|
105 | |
---|
106 | struct thing456 {}; |
---|
107 | void ?{}( thing456 & this ) { printf( "custom ctor\n"); } |
---|
108 | void ?{}( thing456 &, thing456 ) = void; |
---|
109 | thing456 & ?=?( thing456 &, thing456 ) = void; |
---|
110 | void ^?{}( thing456 & this ) { printf( "custom dtor\n"); } |
---|
111 | |
---|
112 | struct wrapper1 { thing456 x; }; |
---|
113 | struct wrapper2 { wrapper1 x; }; |
---|
114 | |
---|
115 | // Deleting some autogens and declaring your own for the others leaves yours usable |
---|
116 | // and the deleted ones cleanly deleted |
---|
117 | void test4() { |
---|
118 | printf("test4\n"); |
---|
119 | thing456 x; |
---|
120 | BAD( thing456 y = x; ) // Unique best alternative includes deleted identifier |
---|
121 | } |
---|
122 | |
---|
123 | // Wrapping v4 leaves yours usable via autogen |
---|
124 | // and the autogen-lifts of your deleted ones are not usable |
---|
125 | void test5() { |
---|
126 | printf("test5\n"); |
---|
127 | wrapper1 x; |
---|
128 | BAD( wrapper1 y = x; ) // Unique best alternative includes deleted identifier |
---|
129 | } |
---|
130 | |
---|
131 | // Wrapping again works similarly |
---|
132 | void test6() { |
---|
133 | printf("test6\n"); |
---|
134 | wrapper2 x; |
---|
135 | BAD( wrapper2 y = x; ) // Unique best alternative includes deleted identifier |
---|
136 | } |
---|
137 | |
---|
138 | int main() { |
---|
139 | printf("====== Top-level declarations ======\n"); |
---|
140 | test1(); |
---|
141 | test2(); |
---|
142 | test3(); |
---|
143 | test4(); |
---|
144 | test5(); |
---|
145 | test6(); |
---|
146 | printf("====== Function-nested declarations ======\n"); |
---|
147 | testAllNested(); |
---|
148 | } |
---|