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 | // Declaring your own empty ctor leaves an autogen dtor usable |
---|
11 | struct thing1 {}; |
---|
12 | void ?{}( thing1 & this ) { printf( "custom ctor\n"); } |
---|
13 | void test1() { |
---|
14 | printf("test1\n"); |
---|
15 | thing1 x; |
---|
16 | } |
---|
17 | |
---|
18 | // Declaring your own empty ctor and dtor leaves an autogen copy ctor usable |
---|
19 | struct thing2 {}; |
---|
20 | void ?{}( thing2 & this ) { printf( "custom ctor\n"); } |
---|
21 | void ^?{}( thing2 & this ) { printf( "custom dtor\n"); } |
---|
22 | void test2() { |
---|
23 | printf("test2\n"); |
---|
24 | thing2 x; |
---|
25 | thing2 y = x; |
---|
26 | } |
---|
27 | |
---|
28 | // Deleting the autogen copy ctor also deletes the autogen empty ctor |
---|
29 | struct thing3 {}; |
---|
30 | void ?{}( thing3 &, thing3 ) = void; |
---|
31 | void test3() { |
---|
32 | printf("test3\n"); |
---|
33 | BAD( thing3 x; ) // Unique best alternative includes deleted identifier |
---|
34 | } |
---|
35 | |
---|
36 | struct thing456 {}; |
---|
37 | void ?{}( thing456 & this ) { printf( "custom ctor\n"); } |
---|
38 | void ?{}( thing456 &, thing456 ) = void; |
---|
39 | thing456 & ?=?( thing456 &, thing456 ) = void; |
---|
40 | void ^?{}( thing456 & this ) { printf( "custom dtor\n"); } |
---|
41 | |
---|
42 | struct wrapper1 { thing456 x; }; |
---|
43 | struct wrapper2 { wrapper1 x; }; |
---|
44 | |
---|
45 | // Deleting some autogens and declaring your own for the others leaves yours usable |
---|
46 | // and the deleted ones cleanly deleted |
---|
47 | void test4() { |
---|
48 | printf("test4\n"); |
---|
49 | thing456 x; |
---|
50 | BAD( thing456 y = x; ) // Unique best alternative includes deleted identifier |
---|
51 | } |
---|
52 | |
---|
53 | // Wrapping v4 leaves yours usable via autogen |
---|
54 | // and the autogen-lifts of your deleted ones are not usable |
---|
55 | void test5() { |
---|
56 | printf("test5\n"); |
---|
57 | wrapper1 x; |
---|
58 | BAD( wrapper1 y = x; ) // Unique best alternative includes deleted identifier |
---|
59 | } |
---|
60 | |
---|
61 | // Wrapping again works similarly |
---|
62 | void test6() { |
---|
63 | printf("test6\n"); |
---|
64 | wrapper2 x; |
---|
65 | BAD( wrapper2 y = x; ) // Unique best alternative includes deleted identifier |
---|
66 | } |
---|
67 | |
---|
68 | int main() { |
---|
69 | test1(); |
---|
70 | test2(); |
---|
71 | test3(); |
---|
72 | test4(); |
---|
73 | test5(); |
---|
74 | test6(); |
---|
75 | } |
---|