source: src/tests/ctor-autogen.c @ b93a3de

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since b93a3de was b93a3de, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

Update ctor-autogen test case

  • Property mode set to 100644
File size: 1.4 KB
Line 
1// TODO: add error cases (e.g., use of field constructors for managed types, etc.)
2
3enum Color { R, G, B };
4
5// empty struct/union should have generated ctor/dtors
6union U {};
7struct S {};
8
9struct SimpleUnion {
10        int x;
11        double y;
12        char z;
13};
14
15struct SimpleStruct {
16        int x;
17        double y;
18        char z;
19};
20
21// struct/union with members with generated ctor/dtors should themselves have generated ctor/dtors
22union PopulatedUnion {
23        Color c;
24        U u;
25        S s;
26};
27
28struct PopulatedStruct {
29        Color c;
30        U u;
31        S s;
32};
33
34// managed type - defines a constructor - can't use field constructors
35struct Managed {
36        int x;
37};
38
39void ?{}(Managed & m) { m.x = 0; }
40
41// managed type since it contains a managed type - can't use field constructors
42struct InheritManaged {
43        Managed m;
44};
45
46forall(otype T)
47T identity(T x) { return x; }
48
49// can identity e if only sized or only the assertion, but the combination breaks...
50// forall(dtype T | sized(T) | { void ?{}(T &); })
51// void identity(T x) {  }
52
53int main() {
54        S s;
55        U u;
56        Color e;
57
58        // identity(R);  // Color should be an otype
59        // identity((Color)e);
60        identity(u);  // U should be an otype
61        identity(s);  // S should be an otype
62
63        SimpleStruct ss;
64        SimpleUnion su;
65
66        identity(ss);
67        identity(su);
68
69        PopulatedStruct ps;
70        PopulatedUnion pu;
71
72        identity(ps); // should recursively be an otype
73        identity(pu); // should recursively be an otype
74
75#if ERR1
76        Managed x = { 123 }; // error
77        Managed y;           // okay
78
79        InheritManaged z = { y };  // error?
80#endif
81
82}
Note: See TracBrowser for help on using the repository browser.