File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /*
2+ TEST_OUTPUT:
3+ ---
4+ fail_compilation/issue19408.d(36): Error: function `issue19408.Infidel!(S).Infidel.get` is not `nothrow`
5+ fail_compilation/issue19408.d(13): which calls `this(this) { if (this.x > 0) throw new Exception("fail", "fail_compilation/is...`
6+ fail_compilation/issue19408.d(35): Error: delegate `issue19408.main.__lambda_L35_C18` may throw but is marked as `nothrow`
7+ ---
8+ */
9+
10+ struct Infidel (T)
11+ {
12+ T value;
13+ T get () { return value; } // returns a copy
14+ }
15+
16+ void assertThrown (void delegate () nothrow dg)
17+ {
18+ dg();
19+ }
20+
21+ void main ()
22+ {
23+ static struct S {
24+ int x;
25+ this (this ) {
26+ if (x > 0 ) throw new Exception (" fail" );
27+ else x = 1 ;
28+ }
29+ }
30+
31+ S s;
32+ auto sneak = Infidel! S(s);
33+
34+ // shouldn't compile
35+ assertThrown(() nothrow {
36+ auto x = sneak.get ();
37+ });
38+ }
Original file line number Diff line number Diff line change 1+ struct Infidel (T)
2+ {
3+ T value;
4+ T get () { return value; } // returns a copy
5+ }
6+
7+ void main ()
8+ {
9+ static struct S {
10+ int x;
11+ this (this ) {
12+ if (x > 0 ) throw new Exception (" fail" );
13+ else x = 1 ;
14+ }
15+ }
16+
17+ // passes, cannot nothrow-copy
18+ static assert (! is (typeof (() nothrow { S* x; union U { S x; } U u = U(* x); })));
19+
20+ // passes, copy may throw
21+ static assert (is (typeof (() { S* x; union U { S x; } U u = U(* x); })));
22+
23+ S s;
24+ auto sneak = Infidel! S(s); // won't throw here, s.x was 0
25+
26+ // should pass
27+ static assert (! is (typeof (() nothrow { auto x = sneak.get (); })));
28+ }
You can’t perform that action at this time.
0 commit comments