Changeset 2afec66 for src/tests/memberCtors.c
- Timestamp:
- Jul 26, 2017, 5:24:33 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 25bd9074
- Parents:
- 8a6cf7e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/tests/memberCtors.c
r8a6cf7e r2afec66 3 3 }; 4 4 5 void ?{}(WrappedInt *this) {5 void ?{}(WrappedInt & this) { 6 6 printf("constructing int\n"); 7 this ->x = 0;7 this.x = 0; 8 8 } 9 9 10 void ?{}(WrappedInt *this, WrappedInt other) {10 void ?{}(WrappedInt & this, WrappedInt other) { 11 11 printf("copy constructing int: %d\n", other.x); 12 this ->x = other.x;12 this.x = other.x; 13 13 } 14 14 15 void ?{}(WrappedInt *this, int x) {15 void ?{}(WrappedInt & this, int x) { 16 16 printf("constructing int: %d\n", x); 17 this ->x = x;17 this.x = x; 18 18 } 19 19 20 void ^?{}(WrappedInt *this) {21 printf("destructing int: %d\n", this ->x);20 void ^?{}(WrappedInt & this) { 21 printf("destructing int: %d\n", this.x); 22 22 } 23 23 24 void ?=?(WrappedInt *this, int x) {25 printf("assigning int: %d %d\n", this ->x, x);26 this ->x = x;24 void ?=?(WrappedInt & this, int x) { 25 printf("assigning int: %d %d\n", this.x, x); 26 this.x = x; 27 27 } 28 28 … … 31 31 }; 32 32 33 void ?{}(A *a) {33 void ?{}(A & a) { 34 34 // currently must define default ctor, since there's no "= default" syntax 35 35 } 36 36 37 void ?{}(A *a, int x) {37 void ?{}(A & a, int x) { 38 38 printf("begin construct A\n"); 39 printf("construct a ->x\n");40 ( &a->x){ x+999 };41 printf("assign a ->y\n");42 a ->y = 0; // not a constructor - default constructor will be inserted39 printf("construct a.x\n"); 40 (a.x){ x+999 }; 41 printf("assign a.y\n"); 42 a.y = 0; // not a constructor - default constructor will be inserted 43 43 printf("end construct A\n"); 44 44 } // z never constructed - will be automatically default constructed 45 45 46 void ?{}(A *this, A other) {46 void ?{}(A & this, A other) { 47 47 printf("begin copy construct A\n"); 48 printf("copy construct this ->x\n");49 ( &this->x){ other.x };50 printf("assign this ->y\n");51 this ->y = other.y; // not a constructor - copy constructor will be inserted48 printf("copy construct this.x\n"); 49 (this.x){ other.x }; 50 printf("assign this.y\n"); 51 this.y = other.y; // not a constructor - copy constructor will be inserted 52 52 printf("end copy construct A\n"); 53 53 } // z never constructed - will be automatically copy constructed 54 54 55 A ?=?(A *this, A other) {55 A ?=?(A & this, A other) { 56 56 printf("begin ?=? A\n"); 57 this ->x = other.x;58 this ->y = other.y;59 this ->z = other.z;57 this.x = other.x; 58 this.y = other.y; 59 this.z = other.z; 60 60 printf("end ?=? A\n"); 61 return *this;61 return this; 62 62 } 63 63 … … 66 66 }; 67 67 68 void ?{}(B *b) {68 void ?{}(B & b) { 69 69 printf("begin construct B\n"); 70 printf("assign b ->a2\n");71 b ->a2 = (A) { 2 };72 printf("construct b ->a1\n");73 ( &b->a1){ 1 };70 printf("assign b.a2\n"); 71 b.a2 = (A) { 2 }; 72 printf("construct b.a1\n"); 73 (b.a1){ 1 }; 74 74 #ifdef ERR1 75 ( &b->a2){ b->a3 }; // error, b->a2 was used previously but is explicitly constructed75 (b.a2){ b.a3 }; // error, b->a2 was used previously but is explicitly constructed 76 76 #endif 77 77 printf("end construct B\n"); 78 78 } // a2, a3 never constructed - will be automatically default constructed 79 79 80 void ^?{}(B *b) {81 b ->a2 = (A) { 0 };82 ^( &b->a1){};80 void ^?{}(B & b) { 81 b.a2 = (A) { 0 }; 82 ^(b.a1){}; 83 83 } // a2, a3 never destructed - will be automatically destructed 84 84
Note: See TracChangeset
for help on using the changeset viewer.