Changeset b067d9b for tests/raii/memberCtors.cfa
- Timestamp:
- Oct 29, 2019, 4:01:24 PM (6 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum, stuck-waitfor-destruct
- Children:
- 773db65, 9421f3d8
- Parents:
- 7951100 (diff), 8364209 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - File:
-
- 1 moved
-
tests/raii/memberCtors.cfa (moved) (moved from src/tests/raii/memberCtors.c ) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tests/raii/memberCtors.cfa
r7951100 rb067d9b 1 1 struct WrappedInt { 2 2 int x; 3 int id; 3 4 }; 5 int intID = 0; 4 6 5 7 void ?{}(WrappedInt & this) { 6 printf("constructing int\n"); 8 this.id = intID++; 9 printf("constructing int id: %d\n", this.id); 7 10 this.x = 0; 8 11 } 9 12 10 13 void ?{}(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); 12 16 this.x = other.x; 13 17 } 14 18 15 19 void ?{}(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); 17 22 this.x = x; 18 23 } 19 24 20 25 void ^?{}(WrappedInt & this) { 21 printf("destructing int: %d \n", this.x);26 printf("destructing int: %d id: %d\n", this.x, this.id); 22 27 } 23 28 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); 26 31 this.x = x; 32 // return this; 27 33 } 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 // } 28 40 29 41 struct A { 30 42 WrappedInt x, y, z; 43 int id; 31 44 }; 45 int AID = 0; 32 46 33 47 void ?{}(A & a) { 34 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); 35 51 } 36 52 37 53 void ?{}(A & a, int x) { 38 printf("begin construct A\n"); 54 a.id = AID++; 55 printf("begin construct A id: %d\n", a.id); 39 56 printf("construct a.x\n"); 40 57 (a.x){ x+999 }; … … 45 62 46 63 void ?{}(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); 48 66 printf("copy construct this.x\n"); 49 67 (this.x){ other.x }; … … 54 72 55 73 A ?=?(A & this, A other) { 56 printf("begin ?=? A \n");74 printf("begin ?=? A id: %d\n", this.id); 57 75 this.x = other.x; 58 76 this.y = other.y; … … 64 82 struct B { 65 83 A a1, a2, a3; 84 int id; 66 85 }; 86 int BID = 0; 67 87 68 88 void ?{}(B & b) { 69 printf("begin construct B\n"); 89 b.id = BID++; 90 printf("begin construct B id: %d\n", b.id); 70 91 printf("assign b.a2\n"); 71 92 b.a2 = (A) { 2 }; … … 79 100 80 101 void ^?{}(B & b) { 102 b.id = BID++; 103 printf("begin destruct B id: %d\n", b.id); 81 104 b.a2 = (A) { 0 }; 82 105 ^(b.a1){}; 106 printf("end destruct B\n"); 83 107 } // a2, a3 never destructed - will be automatically destructed 84 108 85 109 int main() { 86 110 printf("Before declaration of b1\n"); 87 B b1; 111 B b1; // b1 = { { 1000, 0, 0 }, { 1001, 0, 0 }, { 0, 0, 0 } } 88 112 printf("Before declaration of b2\n"); 89 113 B b2 = b1;
Note:
See TracChangeset
for help on using the changeset viewer.