source: tests/raii/partial.cfa @ 5d3d281

Last change on this file since 5d3d281 was 64f3b9f, checked in by Michael Brooks <mlbrooks@…>, 7 days ago

Fix support for partial autogen.

Partial autogen means that some lifecycle functions are possible to generate, and needed, while others are impossible to generate, but unneeded. It is a valid situation that a user can implicitly request.

Previous handling of "impossible to generate" left the function in a zombie state, where it could show up as an alternative later. This zombie state is problematic handling caused by a compiler bug. Without the fix, the added test fails by creating zombie states.

This change is also a prerequsite for an upcoming change to avoid gcc warnings by not emitting autogen forward declarations.

  • Property mode set to 100644
File size: 2.0 KB
Line 
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
11struct thing1 {};
12void ?{}( thing1 & this ) {  printf( "custom ctor\n"); }
13void test1() {
14    printf("test1\n");
15    thing1 x;
16}
17
18// Declaring your own empty ctor and dtor leaves an autogen copy ctor usable
19struct thing2 {};
20void  ?{}( thing2 & this ) {  printf( "custom ctor\n"); }
21void ^?{}( thing2 & this ) {  printf( "custom dtor\n"); }
22void 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
29struct thing3 {};
30void  ?{}( thing3 &, thing3 ) = void;
31void test3() {
32    printf("test3\n");
33    BAD( thing3 x; )  // Unique best alternative includes deleted identifier
34}
35
36struct thing456 {};
37void    ?{}( thing456 & this ) {  printf( "custom ctor\n"); }
38void    ?{}( thing456 &, thing456 ) = void;
39thing456 & ?=?( thing456 &, thing456 ) = void;
40void   ^?{}( thing456 & this ) {  printf( "custom dtor\n"); }
41
42struct wrapper1 { thing456 x; };
43struct 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
47void 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
55void 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
62void test6() {
63    printf("test6\n");
64    wrapper2 x;
65    BAD(  wrapper2 y = x;  )  //  Unique best alternative includes deleted identifier
66}
67
68int main() {
69    test1();
70    test2();
71    test3();
72    test4();
73    test5();
74    test6();
75}
Note: See TracBrowser for help on using the repository browser.