1 module it.c.compile.typedef_; 2 3 import it; 4 5 // 0 children 6 // underlying: UChar("unsigned char") 7 // underlying canonical: UChar("unsigned char") 8 @("unsigned char") 9 unittest { 10 shouldCompile( 11 C( 12 q{ 13 typedef unsigned char __u_char; 14 } 15 ), 16 D( 17 q{ 18 static assert(__u_char.sizeof == 1); 19 } 20 ) 21 ); 22 } 23 24 // 0 children 25 // underlying: Pointer("const char *") 26 // underlying canonical: Pointer("const char *") 27 @("const char*") 28 unittest { 29 shouldCompile( 30 C( 31 q{ 32 typedef const char* mystring; 33 } 34 ), 35 D( 36 q{ 37 const(char)[128] buffer; 38 } 39 ) 40 ); 41 } 42 43 // 1 child: StructDecl(""), Type.Record("Foo") 44 // underlying: Elaborated("struct Foo") 45 // underlying canonical: Record("Foo") 46 @("anonymous struct") 47 unittest { 48 shouldCompile( 49 C( 50 q{ 51 typedef struct { int i; } Foo; 52 } 53 ), 54 D( 55 q{ 56 Foo f; 57 f.i = 42; 58 static assert(!__traits(compiles, _Anonymous_1(42))); 59 } 60 ) 61 ); 62 } 63 64 // 1 child, StructDecl("Foo"), Type.Record("struct Foo") 65 // underlying: Elaborated("struct Foo") 66 // underlying canonical: Record("struct Foo") 67 @("struct") 68 unittest { 69 shouldCompile( 70 C( 71 q{ 72 typedef struct Foo { int i; } Foo; 73 } 74 ), 75 D( 76 q{ 77 Foo f1; 78 f1.i = 42; 79 Foo f2; 80 f2.i = 33; 81 } 82 ) 83 ); 84 } 85 86 // 1 child, UnionDecl("Foo"), Type.Record("union Foo") 87 // underlying: Elaborated("union Foo") 88 // underlying canonical: Record("union Foo") 89 @("union") 90 unittest { 91 shouldCompile( 92 C( 93 q{ 94 typedef union Foo { int i; } Foo; 95 } 96 ), 97 D( 98 q{ 99 Foo f1; 100 f1.i = 42; 101 Foo f2; 102 f2.i = 33; 103 } 104 ) 105 ); 106 } 107 108 // 1 child, EnumDecl("Foo"), Type.Enum("enum Foo") 109 // underlying: Elaborated("enum Foo") 110 // underlying canonical: Enum("enum Foo") 111 @("enum") 112 unittest { 113 shouldCompile( 114 C( 115 q{ 116 typedef enum Foo { i } Foo; 117 } 118 ), 119 D( 120 q{ 121 Foo f = Foo.i; 122 } 123 ) 124 ); 125 } 126 127 128 // 1 child, IntegerLiteral(""), Type.Int("int") 129 // underlying: ConstantArray("int [42]") 130 // underlying canonical: ConstantArray("int [42]") 131 @("array") 132 unittest { 133 shouldCompile( 134 C( 135 q{ 136 typedef int Array[42]; 137 } 138 ), 139 D( 140 q{ 141 Array a; 142 static assert(a.sizeof == 42 * int.sizeof); 143 } 144 ) 145 ); 146 } 147 148 // 0 children 149 // underling: Pointer("int *") 150 // underlying canonical: Pointer("int *") 151 @("pointer") 152 unittest { 153 shouldCompile( 154 C( 155 q{ 156 typedef int* IntPtr; 157 } 158 ), 159 D( 160 q{ 161 int i = 42; 162 IntPtr ptr = &i; 163 } 164 ) 165 ); 166 }