Changeset 36dfdac for tests/raii


Ignore:
Timestamp:
Dec 11, 2024, 7:53:36 PM (7 days ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
master
Children:
bad15f7
Parents:
5d3d281
Message:

Enable partial autogen for types declared inside functions.

Done by giving pass cores finer grained error-recovery points, which causes Resolver's existing error-recovery logic to kick in for autogens within function bodies.

Location:
tests/raii
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tests/raii/.expect/partial.txt

    r5d3d281 r36dfdac  
     1====== Top-level declarations ======
    12test1
    23custom ctor
     
    1516custom ctor
    1617custom dtor
     18====== Function-nested declarations ======
     19test1
     20custom ctor
     21test2
     22custom ctor
     23custom dtor
     24custom dtor
     25test3
     26test4
     27custom ctor
     28custom dtor
     29test5
     30custom ctor
     31custom dtor
     32test6
     33custom ctor
     34custom dtor
  • tests/raii/partial.cfa

    r5d3d281 r36dfdac  
    77#define BAD(...)
    88#endif
     9
     10void 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
    979
    1080// Declaring your own empty ctor leaves an autogen dtor usable
     
    67137
    68138int main() {
     139    printf("====== Top-level declarations ======\n");
    69140    test1();
    70141    test2();
     
    73144    test5();
    74145    test6();
     146    printf("====== Function-nested declarations ======\n");
     147    testAllNested();
    75148}
Note: See TracChangeset for help on using the changeset viewer.