2 REQUIRED_ARGS: -w -o- -d
4 More complex examples from the DIP
5 https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1034.md
8 alias noreturn
= typeof(*null);
9 static assert (!is(noreturn
== void));
14 noreturn b
= noreturn
.init
;
17 void foo(const noreturn
);
30 // /*****************************************************************************/
32 auto inferNoreturn(int i
)
42 auto inferReturn(int i
)
52 // /*****************************************************************************/
53 // // https://issues.dlang.org/show_bug.cgi?id=22004
55 alias fun22004
= _
=> {}();
56 alias gun22004
= _
=> assert(0);
65 static assert(is(typeof(bun22004(true)) == void));
68 auto bun22004_reversed(bool b
)
76 static assert(is(typeof(bun22004_reversed(true)) == void));
78 // /*****************************************************************************/
80 // // Also works fine with non-void types and ref inference
84 auto ref forwardOrExit(ref int num
)
92 static assert( is(typeof(forwardOrExit(global
)) == int));
94 // Noreturn types do not affect `auto ref` deduction
95 static assert(is(typeof(&forwardOrExit(global
))));
97 auto ref forwardOrExit2(ref int num
)
100 return assert(false);
105 static assert( is(typeof(forwardOrExit2(global
)) == int));
107 // Noreturn types do not affect `auto ref` deduction
108 static assert(is(typeof(&forwardOrExit2(global
))));
110 /*****************************************************************************/
114 auto inf
= cast(noreturn
) 1;
115 static assert(is(typeof(inf
) == noreturn
));
118 auto c
= cast(const shared noreturn
) n
;
119 static assert(is(typeof(c
) == const shared noreturn
));
120 static assert(is(typeof(n
) == noreturn
));
122 auto c2
= cast(immutable noreturn
) n
;
123 static assert(is(typeof(c
) == const shared noreturn
));
124 static assert(is(typeof(c2
) == immutable noreturn
));
125 static assert(is(typeof(n
) == noreturn
));
129 /******************************************************************************/
130 // https://issues.dlang.org/show_bug.cgi?id=21957
131 // Calculate proper alignment and size for noreturn members
133 enum longPad
= long.alignof
- int.sizeof
;
142 static assert(BasicStruct
.sizeof
== (int.sizeof
+ longPad
+ long.sizeof
));
144 static assert(BasicStruct
.firstInt
.offsetof
== 0);
145 static assert(BasicStruct
.noRet
.offsetof
== 4);
146 static assert(BasicStruct
.lastLong
.offsetof
== (4 + longPad
));
151 align(16) noreturn noRet
;
155 static assert(AlignedStruct
.sizeof
== 32);
157 static assert(AlignedStruct
.firstInt
.offsetof
== 0);
158 static assert(AlignedStruct
.noRet
.offsetof
== 16);
159 static assert(AlignedStruct
.lastLong
.offsetof
== 16);
168 static assert(BasicUnion
.sizeof
== 8);
170 static assert(BasicUnion
.firstInt
.offsetof
== 0);
171 static assert(BasicUnion
.noRet
.offsetof
== 0);
172 static assert(BasicUnion
.lastLong
.offsetof
== 0);
177 align(16) noreturn noRet
;
181 static assert(AlignedUnion
.sizeof
== 16);
183 static assert(AlignedUnion
.firstInt
.offsetof
== 0);
184 static assert(AlignedUnion
.noRet
.offsetof
== 0);
185 static assert(AlignedUnion
.lastLong
.offsetof
== 0);
194 enum objectMemberSize
= __traits(classInstanceSize
, Object
);
196 static assert(__traits(classInstanceSize
, BasicClass
) == objectMemberSize
+ (int.sizeof
+ longPad
+ long.sizeof
));
198 static assert(BasicClass
.firstInt
.offsetof
== objectMemberSize
+ 0);
199 static assert(BasicClass
.noRet
.offsetof
== objectMemberSize
+ 4);
200 static assert(BasicClass
.lastLong
.offsetof
== objectMemberSize
+ (4 + longPad
));
205 align(16) noreturn noRet
;
209 enum offset
= (objectMemberSize
+ 4 + 16) & ~15;
211 static assert(__traits(classInstanceSize
, AlignedClass
) == offset
+ 8);
213 static assert(AlignedClass
.firstInt
.offsetof
== objectMemberSize
+ 0);
214 static assert(AlignedClass
.noRet
.offsetof
== offset
);
215 static assert(AlignedClass
.lastLong
.offsetof
== offset
);
222 static assert(EmptyStruct
.sizeof
== 1);
223 static assert(EmptyStruct
.noRet
.offsetof
== 0);
230 static assert(EmptyStruct2
.sizeof
== 1);
231 static assert(EmptyStruct2
.noRet
.offsetof
== 0);
233 // https://issues.dlang.org/show_bug.cgi?id=22858
234 // Shouldn't mess with the alignment of other zero-sized types.
245 static assert (S22858
.arr
.offsetof
% size_t
.sizeof
== 0);
246 static assert (S22858
.arr2
.offsetof
== S22858
.c
.offsetof
+ 1);
247 static assert (S22858
.arr2
.offsetof
== S22858
.c2
.offsetof
);