1 // REQUIRED_ARGS: -o- 2 3 class C0a { } ~this()4class C1a { ~this() {} } ~this()5class C2a { ~this() {} @nogc pure @safe delete(void* p) {} } ~this()6class C3a { @nogc pure @safe ~this() {} delete(void* p) {} } ~this()7class C4a { @nogc pure @safe ~this() {} @nogc pure @safe delete(void* p) {} } 8 9 class C0b { } ~this()10class C1b { ~this() {} } ~this()11class C2b { ~this() {} nothrow delete(void* p) {} } ~this()12class C3b { nothrow ~this() {} delete(void* p) {} } ~this()13class C4b { nothrow ~this() {} nothrow delete(void* p) {} } 14 15 struct S0a { } ~this()16struct S1a { ~this() {} } ~thisS2a17struct S2a { ~this() {} @nogc pure @safe delete(void* p) {} } ~this()18struct S3a { @nogc pure @safe ~this() {} delete(void* p) {} } ~thisS4a19struct S4a { @nogc pure @safe ~this() {} @nogc pure @safe delete(void* p) {} } 20 21 struct S0b { } ~thisS1b22struct S1b { ~this() {} } ~this()23struct S2b { ~this() {} nothrow delete(void* p) {} } ~thisS3b24struct S3b { nothrow ~this() {} delete(void* p) {} } ~this()25struct S4b { nothrow ~this() {} nothrow delete(void* p) {} } 26 27 /* 28 TEST_OUTPUT: 29 --- 30 fail_compilation/fail14486.d(44): Error: delete c0 is not @safe but is used in @safe function test1a 31 fail_compilation/fail14486.d(45): Error: pure function 'fail14486.test1a' cannot call impure destructor 'fail14486.C1a.~this' 32 fail_compilation/fail14486.d(45): Error: @safe function 'fail14486.test1a' cannot call @system destructor 'fail14486.C1a.~this' 33 fail_compilation/fail14486.d(45): Error: @nogc function 'fail14486.test1a' cannot call non-@nogc destructor 'fail14486.C1a.~this' 34 fail_compilation/fail14486.d(46): Error: pure function 'fail14486.test1a' cannot call impure destructor 'fail14486.C2a.~this' 35 fail_compilation/fail14486.d(46): Error: @safe function 'fail14486.test1a' cannot call @system destructor 'fail14486.C2a.~this' 36 fail_compilation/fail14486.d(46): Error: @nogc function 'fail14486.test1a' cannot call non-@nogc destructor 'fail14486.C2a.~this' 37 fail_compilation/fail14486.d(47): Error: pure function 'fail14486.test1a' cannot call impure deallocator 'fail14486.C3a.delete' 38 fail_compilation/fail14486.d(47): Error: @safe function 'fail14486.test1a' cannot call @system deallocator 'fail14486.C3a.delete' 39 fail_compilation/fail14486.d(47): Error: @nogc function 'fail14486.test1a' cannot call non-@nogc deallocator 'fail14486.C3a.delete' 40 fail_compilation/fail14486.d(48): Error: delete c4 is not @safe but is used in @safe function test1a 41 ---*/ test1a()42void test1a() @nogc pure @safe 43 { 44 C0a c0; delete c0; // error 45 C1a c1; delete c1; // error 46 C2a c2; delete c2; // error 47 C3a c3; delete c3; // error 48 C4a c4; delete c4; // no error 49 } 50 51 /* 52 TEST_OUTPUT: 53 --- 54 fail_compilation/fail14486.d(63): Error: destructor `fail14486.C1b.~this` is not nothrow 55 fail_compilation/fail14486.d(64): Error: destructor `fail14486.C2b.~this` is not nothrow 56 fail_compilation/fail14486.d(65): Error: deallocator `fail14486.C3b.delete` is not nothrow 57 fail_compilation/fail14486.d(60): Error: nothrow function `fail14486.test1b` may throw 58 --- 59 */ test1b()60void test1b() nothrow 61 { 62 C0b c0; delete c0; // no error 63 C1b c1; delete c1; // error 64 C2b c2; delete c2; // error 65 C3b c3; delete c3; // error 66 C4b c4; delete c4; // no error 67 } 68 69 /* 70 TEST_OUTPUT: 71 --- 72 fail_compilation/fail14486.d(86): Error: delete s0 is not @safe but is used in @safe function test2a 73 fail_compilation/fail14486.d(87): Error: pure function 'fail14486.test2a' cannot call impure destructor 'fail14486.S1a.~this' 74 fail_compilation/fail14486.d(87): Error: @safe function 'fail14486.test2a' cannot call @system destructor 'fail14486.S1a.~this' 75 fail_compilation/fail14486.d(87): Error: @nogc function 'fail14486.test2a' cannot call non-@nogc destructor 'fail14486.S1a.~this' 76 fail_compilation/fail14486.d(88): Error: pure function 'fail14486.test2a' cannot call impure destructor 'fail14486.S2a.~this' 77 fail_compilation/fail14486.d(88): Error: @safe function 'fail14486.test2a' cannot call @system destructor 'fail14486.S2a.~this' 78 fail_compilation/fail14486.d(88): Error: @nogc function 'fail14486.test2a' cannot call non-@nogc destructor 'fail14486.S2a.~this' 79 fail_compilation/fail14486.d(89): Error: pure function 'fail14486.test2a' cannot call impure deallocator 'fail14486.S3a.delete' 80 fail_compilation/fail14486.d(89): Error: @safe function 'fail14486.test2a' cannot call @system deallocator 'fail14486.S3a.delete' 81 fail_compilation/fail14486.d(89): Error: @nogc function 'fail14486.test2a' cannot call non-@nogc deallocator 'fail14486.S3a.delete' 82 --- 83 */ test2a()84void test2a() @nogc pure @safe 85 { 86 S0a* s0; delete s0; // error 87 S1a* s1; delete s1; // error 88 S2a* s2; delete s2; // error 89 S3a* s3; delete s3; // error 90 S4a* s4; delete s4; // no error 91 } 92 93 /* 94 TEST_OUTPUT: 95 --- 96 fail_compilation/fail14486.d(105): Error: destructor `fail14486.S1b.~this` is not nothrow 97 fail_compilation/fail14486.d(106): Error: destructor `fail14486.S2b.~this` is not nothrow 98 fail_compilation/fail14486.d(107): Error: deallocator `fail14486.S3b.delete` is not nothrow 99 fail_compilation/fail14486.d(102): Error: nothrow function `fail14486.test2b` may throw 100 --- 101 */ test2b()102void test2b() nothrow 103 { 104 S0b* s0; delete s0; // no error 105 S1b* s1; delete s1; // error 106 S2b* s2; delete s2; // error 107 S3b* s3; delete s3; // error 108 S4b* s4; delete s4; // no error 109 } 110 111 /* 112 TEST_OUTPUT: 113 --- 114 fail_compilation/fail14486.d(127): Error: delete a0 is not @safe but is used in @safe function test3a 115 fail_compilation/fail14486.d(128): Error: pure function 'fail14486.test3a' cannot call impure destructor 'fail14486.S1a.~this' 116 fail_compilation/fail14486.d(128): Error: @safe function 'fail14486.test3a' cannot call @system destructor 'fail14486.S1a.~this' 117 fail_compilation/fail14486.d(128): Error: @nogc function 'fail14486.test3a' cannot call non-@nogc destructor 'fail14486.S1a.~this' 118 fail_compilation/fail14486.d(129): Error: pure function 'fail14486.test3a' cannot call impure destructor 'fail14486.S2a.~this' 119 fail_compilation/fail14486.d(129): Error: @safe function 'fail14486.test3a' cannot call @system destructor 'fail14486.S2a.~this' 120 fail_compilation/fail14486.d(129): Error: @nogc function 'fail14486.test3a' cannot call non-@nogc destructor 'fail14486.S2a.~this' 121 fail_compilation/fail14486.d(130): Error: delete a3 is not @safe but is used in @safe function test3a 122 fail_compilation/fail14486.d(131): Error: delete a4 is not @safe but is used in @safe function test3a 123 --- 124 */ test3a()125void test3a() @nogc pure @safe 126 { 127 S0a[] a0; delete a0; // error 128 S1a[] a1; delete a1; // error 129 S2a[] a2; delete a2; // error 130 S3a[] a3; delete a3; // error 131 S4a[] a4; delete a4; // error 132 } 133 134 /* 135 TEST_OUTPUT: 136 --- 137 fail_compilation/fail14486.d(145): Error: destructor `fail14486.S1b.~this` is not nothrow 138 fail_compilation/fail14486.d(146): Error: destructor `fail14486.S2b.~this` is not nothrow 139 fail_compilation/fail14486.d(142): Error: nothrow function `fail14486.test3b` may throw 140 --- 141 */ test3b()142void test3b() nothrow 143 { 144 S0b[] a0; delete a0; // no error 145 S1b[] a1; delete a1; // error 146 S2b[] a2; delete a2; // error 147 S3b[] a3; delete a3; // no error 148 S4b[] a4; delete a4; // no error 149 } 150