From 29deed3e36d45807824d2bd78a319a9414f7e448 Mon Sep 17 00:00:00 2001 From: Martin Nowak Date: Sat, 17 Jun 2017 10:47:15 +0200 Subject: [PATCH 1/2] Revert "Merge pull request #6816 from WalterBright/fix14246" This reverts commit 6b3d406be3670613d862ec6eda1bf3669443a926, reversing changes made to c6c3c11dcda1fab5610be0dc2f3d74cce1a773aa. --- src/ddmd/aggregate.d | 1 - src/ddmd/aggregate.h | 1 - src/ddmd/clone.d | 1 - src/ddmd/func.d | 31 +------------------------------ test/runnable/sdtor.d | 33 --------------------------------- 5 files changed, 1 insertion(+), 66 deletions(-) diff --git a/src/ddmd/aggregate.d b/src/ddmd/aggregate.d index aa569a12f6c6..10161aa1aa6d 100644 --- a/src/ddmd/aggregate.d +++ b/src/ddmd/aggregate.d @@ -97,7 +97,6 @@ extern (C++) abstract class AggregateDeclaration : ScopeDsymbol FuncDeclarations dtors; // Array of destructors FuncDeclaration dtor; // aggregate destructor - FuncDeclaration fieldDtor; // aggregate destructor for just the fields Expression getRTInfo; // pointer to GC info generated by object.RTInfo(this) diff --git a/src/ddmd/aggregate.h b/src/ddmd/aggregate.h index 024c23b6be45..324597370fd6 100644 --- a/src/ddmd/aggregate.h +++ b/src/ddmd/aggregate.h @@ -115,7 +115,6 @@ class AggregateDeclaration : public ScopeDsymbol FuncDeclarations dtors; // Array of destructors FuncDeclaration *dtor; // aggregate destructor - FuncDeclaration *fieldDtor; // aggregate destructor for just the fields Expression *getRTInfo; // pointer to GC info generated by object.RTInfo(this) diff --git a/src/ddmd/clone.d b/src/ddmd/clone.d index 9b22142bf33c..0421d5a602e0 100644 --- a/src/ddmd/clone.d +++ b/src/ddmd/clone.d @@ -1081,7 +1081,6 @@ extern (C++) FuncDeclaration buildDtor(AggregateDeclaration ad, Scope* sc) ad.dtors.shift(dd); ad.members.push(dd); dd.semantic(sc); - ad.fieldDtor = dd; } FuncDeclaration xdtor = null; diff --git a/src/ddmd/func.d b/src/ddmd/func.d index 93fa8d62e115..16d444ce9193 100644 --- a/src/ddmd/func.d +++ b/src/ddmd/func.d @@ -1102,7 +1102,7 @@ extern (C++) class FuncDeclaration : Declaration } // Do the semantic analysis on the internals of the function. - override void semantic3(Scope* sc) + override final void semantic3(Scope* sc) { VarDeclaration _arguments = null; @@ -4710,35 +4710,6 @@ extern (C++) final class CtorDeclaration : FuncDeclaration } } - override final void semantic3(Scope* sc) - { - if (semanticRun >= PASSsemantic3) - return; - - /* If any of the fields of the struct have a destructor, add - * scope (failure) { this.fieldDtor(); } - * as the first statement. It is not necessary to add it after - * each initialization of a field, because destruction of .init constructed - * structs should be benign. - */ - AggregateDeclaration ad = toParent2().isAggregateDeclaration(); - if (ad && ad.fieldDtor) - { - /* Generate: - * scope (failure) { this.fieldDtor(); } - */ - Expression e = new ThisExp(loc); - e.type = ad.type.mutableOf(); - e = new DotVarExp(loc, e, ad.fieldDtor, false); - e = new CallExp(loc, e); - auto sexp = new ExpStatement(loc, e); - auto s = new OnScopeStatement(loc, TOKon_scope_failure, sexp); - - fbody = new CompoundStatement(loc, s, fbody); - } - FuncDeclaration.semantic3(sc); - } - override const(char)* kind() const { return "constructor"; diff --git a/test/runnable/sdtor.d b/test/runnable/sdtor.d index f01345be9620..fa7874ee45d2 100644 --- a/test/runnable/sdtor.d +++ b/test/runnable/sdtor.d @@ -4222,38 +4222,6 @@ int test14860() } static assert(test14860()); -/**********************************/ -// https://issues.dlang.org/show_bug.cgi?id=14246 - -struct A14246 { - int a = 3; - static string s; - this( int var ) { printf("A()\n"); a += var; s ~= "a"; } - - ~this() { printf("~A()\n"); s ~= "b"; } -} - -struct B14246 { - int i; - A14246 a; - - this( int var ) { - A14246.s ~= "c"; - a = A14246(var+1); - throw new Exception("An exception"); - } -} - -void test14246() { - try { - auto b = B14246(2); - } catch( Exception ex ) { - printf("Caught ex\n"); - A14246.s ~= "d"; - } - assert(A14246.s == "cabd"); -} - /**********************************/ // 14696 @@ -4675,7 +4643,6 @@ int main() test14815(); test16197(); test14860(); - test14246(); test14696(); test14838(); test63(); From 558773e64d42d56ad02970adfdc1371311ca3291 Mon Sep 17 00:00:00 2001 From: Martin Nowak Date: Sat, 17 Jun 2017 10:48:32 +0200 Subject: [PATCH 2/2] add test cases for existing production code - fixes Issues 17494, 17505, 17506 --- test/compilable/riia_ctor.d | 44 +++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 test/compilable/riia_ctor.d diff --git a/test/compilable/riia_ctor.d b/test/compilable/riia_ctor.d new file mode 100644 index 000000000000..1c8e142b7964 --- /dev/null +++ b/test/compilable/riia_ctor.d @@ -0,0 +1,44 @@ +// https://issues.dlang.org/show_bug.cgi?id=17494 +struct S +{ + ~this() {} +} + +class C +{ + S s; + + this() nothrow {} +} + +// https://issues.dlang.org/show_bug.cgi?id=17505 +struct Array +{ + int[] _payload; + ~this() + { + import core.stdc.stdlib : free; + free(_payload.ptr); + } +} + +class Scanner +{ + Array arr; + this() @safe {} +} + +// https://issues.dlang.org/show_bug.cgi?id=17506 +struct TreeMap +{ + this() @disable; + this(TTree tree) { this.tree = tree; } + TTree tree; +} + +struct TTree +{ + this() @disable; + this(int foo) {} + ~this() {} +}