Changeset 6c7fe7b


Ignore:
Timestamp:
Jun 30, 2023, 4:50:01 PM (12 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
c5e2a84
Parents:
d7874052
Message:

change from printf to sout

Location:
tests/raii
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tests/raii/.expect/memberCtors-ERR1.txt

    rd7874052 r6c7fe7b  
    1 raii/memberCtors.cfa:92:1 error: in ?{}, field a2 used before being constructed
     1raii/memberCtors.cfa:94:1 error: in ?{}, field a2 used before being constructed
  • tests/raii/memberCtors.cfa

    rd7874052 r6c7fe7b  
     1#include <fstream.hfa>
     2
    13struct WrappedInt {
    2   int x;
    3   int id;
     4        int x;
     5        int id;
    46};
    57int intID = 0;
    68
    7 void ?{}(WrappedInt & this) {
    8   this.id = intID++;
    9   printf("constructing int id: %d\n", this.id);
    10   this.x = 0;
     9void ?{}( WrappedInt & this ) {
     10        this.id = intID++;
     11        sout | "constructing int id: " | this.id;
     12        this.x = 0;
    1113}
    1214
    13 void ?{}(WrappedInt & this, WrappedInt other) {
    14   this.id = intID++;
    15   printf("copy constructing int: %d id: %d\n", other.x, this.id);
    16   this.x = other.x;
     15void ?{}( WrappedInt & this, WrappedInt other ) {
     16        this.id = intID++;
     17        sout | "copy constructing int: " | other.x | "id: " | this.id;
     18        this.x = other.x;
    1719}
    1820
    19 void ?{}(WrappedInt & this, int x) {
    20   this.id = intID++;
    21   printf("constructing int: %d id: %d\n", x, this.id);
    22   this.x = x;
     21void ?{}( WrappedInt & this, int x ) {
     22        this.id = intID++;
     23        sout | "constructing int: " | x | "id: " | this.id;
     24        this.x = x;
    2325}
    2426
    25 void ^?{}(WrappedInt & this) {
    26   printf("destructing int: %d id: %d\n", this.x, this.id);
     27void ^?{}( WrappedInt & this ) {
     28        sout | "destructing int: " | this.x | "id: " | this.id;
    2729}
    2830
    29 /* WrappedInt */ void ?=?(WrappedInt & this, int x) {
    30   printf("assigning int: %d %d id: %d\n", this.x, x, this.id);
    31   this.x = x;
    32   // return this;
     31/* WrappedInt */ void ?=?( WrappedInt & this, int x ) {
     32        sout | "assigning int: " | this.x | x | "id: " | this.id;
     33        this.x = x;
     34        // return this;
    3335}
    3436
    35 // WrappedInt ?=?(WrappedInt & this, WrappedInt other) {
    36 //   printf("assigning int: %d %d\n", this.x, other.x);
     37// WrappedInt ?=?( WrappedInt & this, WrappedInt other ) {
     38//   sout | "assigning int: " | this.x | other.x;
    3739//   this.x = other.x;
    3840//   return this;
     
    4042
    4143struct A {
    42   WrappedInt x, y, z;
    43   int id;
     44        WrappedInt x, y, z;
     45        int id;
    4446};
    4547int AID = 0;
    4648
    47 void ?{}(A & a) {
    48   // currently must define default ctor, since there's no "= default" syntax
    49   a.id = AID++;
    50   printf("default construct A %d\n", a.id);
     49void ?{}( A & a ) {
     50        // currently must define default ctor, since there's no "= default" syntax
     51        a.id = AID++;
     52        sout | "default construct A" | a.id;
    5153}
    5254
    53 void ?{}(A & a, int x) {
    54   a.id = AID++;
    55   printf("begin construct A id: %d\n", a.id);
    56   printf("construct a.x\n");
    57   (a.x){ x+999 };
    58   printf("assign a.y\n");
    59   a.y = 0; // not a constructor - default constructor will be inserted
    60   printf("end construct A\n");
     55void ?{}( A & a, int x ) {
     56        a.id = AID++;
     57        sout | "begin construct A id: " | a.id;
     58        sout | "construct a.x";
     59        (a.x){ x+999 };
     60        sout | "assign a.y";
     61        a.y = 0; // not a constructor - default constructor will be inserted
     62        sout | "end construct A";
    6163} // z never constructed - will be automatically default constructed
    6264
    63 void ?{}(A & this, A other) {
    64   this.id = AID++;
    65   printf("begin copy construct A id: %d\n", this.id);
    66   printf("copy construct this.x\n");
    67   (this.x){ other.x };
    68   printf("assign this.y\n");
    69   this.y = other.y; // not a constructor - copy constructor will be inserted
    70   printf("end copy construct A\n");
     65void ?{}( A & this, A other ) {
     66        this.id = AID++;
     67        sout | "begin copy construct A id: " | this.id;
     68        sout | "copy construct this.x";
     69        (this.x){ other.x };
     70        sout | "assign this.y";
     71        this.y = other.y; // not a constructor - copy constructor will be inserted
     72        sout | "end copy construct A";
    7173} // z never constructed - will be automatically copy constructed
    7274
    73 A ?=?(A & this, A other) {
    74   printf("begin ?=? A id: %d\n", this.id);
    75   this.x = other.x;
    76   this.y = other.y;
    77   this.z = other.z;
    78   printf("end ?=? A\n");
    79   return this;
     75A ?=?( A & this, A other ) {
     76        sout | "begin ?=? A id: " | this.id;
     77        this.x = other.x;
     78        this.y = other.y;
     79        this.z = other.z;
     80        sout | "end ?=? A";
     81        return this;
    8082}
    8183
    8284struct B {
    83   A a1, a2, a3;
    84   int id;
     85        A a1, a2, a3;
     86        int id;
    8587};
    8688int BID = 0;
    8789
    88 void ?{}(B & b) {
    89   b.id = BID++;
    90   printf("begin construct B id: %d\n", b.id);
    91   printf("assign b.a2\n");
    92   b.a2 = (A) { 2 };
    93   printf("construct b.a1\n");
    94   (b.a1){ 1 };
     90void ?{}( B & b ) {
     91        b.id = BID++;
     92        sout | "begin construct B id: " | b.id;
     93        sout | "assign b.a2";
     94        b.a2 = (A){ 2 };
     95        sout | "construct b.a1";
     96        (b.a1){ 1 };
    9597#ifdef ERR1
    96   (b.a2){ b.a3 }; // error, b->a2 was used previously but is explicitly constructed
     98        (b.a2){ b.a3 }; // error, b->a2 was used previously but is explicitly constructed
    9799#endif
    98   printf("end construct B\n");
     100        sout | "end construct B";
    99101} // a2, a3 never constructed - will be automatically default constructed
    100102
    101 void ^?{}(B & b) {
    102   b.id = BID++;
    103   printf("begin destruct B id: %d\n", b.id);
    104   b.a2 = (A) { 0 };
    105   ^(b.a1){};
    106   printf("end destruct B\n");
     103void ^?{}( B & b ) {
     104        b.id = BID++;
     105        sout | "begin destruct B id: " | b.id;
     106        b.a2 = (A) { 0 };
     107        ^(b.a1){};
     108        sout | "end destruct B";
    107109} // a2, a3 never destructed - will be automatically destructed
    108110
    109111int main() {
    110   printf("Before declaration of b1\n");
    111   B b1;  // b1 = { { 1000, 0, 0 }, { 1001, 0, 0 }, { 0, 0, 0 } }
    112   printf("Before declaration of b2\n");
    113   B b2 = b1;
    114   printf("End of main\n");
     112        sout | "Before declaration of b1";
     113        B b1;  // b1 = { { 1000, 0, 0 }, { 1001, 0, 0 }, { 0, 0, 0 } }
     114        sout | "Before declaration of b2";
     115        B b2 = b1;
     116        sout | "End of main";
    115117}
Note: See TracChangeset for help on using the changeset viewer.