Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/raii/memberCtors.c

    rbf71cfd ra42a654  
    11struct WrappedInt {
    22  int x;
     3  int id;
    34};
     5int intID = 0;
    46
    57void ?{}(WrappedInt & this) {
    6   printf("constructing int\n");
     8  this.id = intID++;
     9  printf("constructing int id: %d\n", this.id);
    710  this.x = 0;
    811}
    912
    1013void ?{}(WrappedInt & this, WrappedInt other) {
    11   printf("copy constructing int: %d\n", other.x);
     14  this.id = intID++;
     15  printf("copy constructing int: %d id: %d\n", other.x, this.id);
    1216  this.x = other.x;
    1317}
    1418
    1519void ?{}(WrappedInt & this, int x) {
    16   printf("constructing int: %d\n", x);
     20  this.id = intID++;
     21  printf("constructing int: %d id: %d\n", x, this.id);
    1722  this.x = x;
    1823}
    1924
    2025void ^?{}(WrappedInt & this) {
    21   printf("destructing int: %d\n", this.x);
     26  printf("destructing int: %d id: %d\n", this.x, this.id);
    2227}
    2328
    24 void ?=?(WrappedInt & this, int x) {
    25   printf("assigning int: %d %d\n", this.x, x);
     29/* WrappedInt */ void ?=?(WrappedInt & this, int x) {
     30  printf("assigning int: %d %d id: %d\n", this.x, x, this.id);
    2631  this.x = x;
     32  // return this;
    2733}
     34
     35// WrappedInt ?=?(WrappedInt & this, WrappedInt other) {
     36//   printf("assigning int: %d %d\n", this.x, other.x);
     37//   this.x = other.x;
     38//   return this;
     39// }
    2840
    2941struct A {
    3042  WrappedInt x, y, z;
     43  int id;
    3144};
     45int AID = 0;
    3246
    3347void ?{}(A & a) {
    3448  // currently must define default ctor, since there's no "= default" syntax
     49  a.id = AID++;
     50  printf("default construct A %d\n", a.id);
    3551}
    3652
    3753void ?{}(A & a, int x) {
    38   printf("begin construct A\n");
     54  a.id = AID++;
     55  printf("begin construct A id: %d\n", a.id);
    3956  printf("construct a.x\n");
    4057  (a.x){ x+999 };
     
    4562
    4663void ?{}(A & this, A other) {
    47   printf("begin copy construct A\n");
     64  this.id = AID++;
     65  printf("begin copy construct A id: %d\n", this.id);
    4866  printf("copy construct this.x\n");
    4967  (this.x){ other.x };
     
    5472
    5573A ?=?(A & this, A other) {
    56   printf("begin ?=? A\n");
     74  printf("begin ?=? A id: %d\n", this.id);
    5775  this.x = other.x;
    5876  this.y = other.y;
     
    6482struct B {
    6583  A a1, a2, a3;
     84  int id;
    6685};
     86int BID = 0;
    6787
    6888void ?{}(B & b) {
    69   printf("begin construct B\n");
     89  b.id = BID++;
     90  printf("begin construct B id: %d\n", b.id);
    7091  printf("assign b.a2\n");
    7192  b.a2 = (A) { 2 };
     
    79100
    80101void ^?{}(B & b) {
     102  b.id = BID++;
     103  printf("begin destruct B id: %d\n", b.id);
    81104  b.a2 = (A) { 0 };
    82105  ^(b.a1){};
     106  printf("end destruct B\n");
    83107} // a2, a3 never destructed - will be automatically destructed
    84108
    85109int main() {
    86110  printf("Before declaration of b1\n");
    87   B b1;
     111  B b1;  // b1 = { { 1000, 0, 0 }, { 1001, 0, 0 }, { 0, 0, 0 } }
    88112  printf("Before declaration of b2\n");
    89113  B b2 = b1;
Note: See TracChangeset for help on using the changeset viewer.