source: src/tests/memberCtors.c@ 6152c81

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since 6152c81 was f7e749f, checked in by Rob Schluntz <rschlunt@…>, 9 years ago

added tests for polymorphic tuples and cast on tuples, updated a couple of other tests

  • Property mode set to 100644
File size: 1.8 KB
RevLine 
[4d4882a]1struct WrappedInt {
2 int x;
3};
4
5void ?{}(WrappedInt * this) {
6 printf("constructing int\n");
7 this->x = 0;
8}
9
10void ?{}(WrappedInt * this, WrappedInt other) {
11 printf("copy constructing int: %d\n", other.x);
12 this->x = other.x;
13}
14
15void ?{}(WrappedInt * this, int x) {
16 printf("constructing int: %d\n", x);
17 this->x = x;
18}
19
20void ^?{}(WrappedInt * this) {
21 printf("destructing int: %d\n", this->x);
22}
23
24void ?=?(WrappedInt * this, int x) {
25 printf("assigning int: %d %d\n", this->x, x);
26 this->x = x;
27}
28
29struct A {
30 WrappedInt x, y, z;
31};
32
33void ?{}(A * a, int x) {
[f7e749f]34 printf("begin construct A\n");
35 printf("construct a->x\n");
[4d4882a]36 (&a->x){ x+999 };
[f7e749f]37 printf("assign a->y\n");
[4d4882a]38 a->y = 0; // not a constructor - default constructor will be inserted
[f7e749f]39 printf("end construct A\n");
[4d4882a]40} // z never constructed - will be automatically default constructed
41
42void ?{}(A * this, A other) {
[f7e749f]43 printf("begin copy construct A\n");
44 printf("copy construct this->x\n");
[4d4882a]45 (&this->x){ other.x };
[f7e749f]46 printf("assign this->y\n");
[4d4882a]47 this->y = other.y; // not a constructor - copy constructor will be inserted
[f7e749f]48 printf("end copy construct A\n");
[4d4882a]49} // z never constructed - will be automatically copy constructed
50
51struct B {
52 A a1, a2, a3;
53};
54
55void ?{}(B * b) {
[f7e749f]56 printf("begin construct B\n");
57 printf("assign b->a2\n");
[4d4882a]58 b->a2 = (A) { 2 };
[f7e749f]59 printf("construct b->a1\n");
[4d4882a]60 (&b->a1){ 1 };
61#ifdef ERR1
62 (&b->a2){ b->a3 }; // error, b->a2 was used previously but is explicitly constructed
63#endif
[f7e749f]64 printf("end construct B\n");
[4d4882a]65} // a2, a3 never constructed - will be automatically default constructed
66
67void ^?{}(B * b) {
68 b->a2 = (A) { 0 };
69 ^(&b->a1){};
70} // a2, a3 never destructed - will be automatically destructed
71
72int main() {
[44f6341]73 printf("Before declaration of b1\n");
[4d4882a]74 B b1;
[44f6341]75 printf("Before declaration of b2\n");
[4d4882a]76 B b2 = b1;
[44f6341]77 printf("End of main\n");
[4d4882a]78}
Note: See TracBrowser for help on using the repository browser.