-
-
Notifications
You must be signed in to change notification settings - Fork 685
fix Issue 14246 - RAII - proper destruction of partially constructed … #8697
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| fix Issue 14246 - RAII - proper destruction of partically constructed objects | ||
|
|
||
| Since destructors for object fields can now get called by the constructor for that | ||
| object if the constructor fails, the attributes of the destructors must be covariant | ||
| with the attributes for the constructor. | ||
|
|
||
| I.e. if the constructor is marked @safe, the fields' destructors must also be @safe | ||
| or @trusted. | ||
|
|
||
| Since this behavior was never checked before, this fix causes breakage of existing | ||
| code. Hence, enabling this behavior is behind the new `transition=dtorfields` compiler | ||
| switch. It will eventually become the default behavior, so it is recommended to | ||
| fix any of these destructor attribute issues. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| // PERMUTE_ARGS: -unittest -O -release -inline -fPIC -g | ||
| // REQUIRED_ARGS: -transition=dtorfields | ||
|
|
||
| import core.vararg; | ||
|
|
||
|
|
@@ -4229,6 +4230,38 @@ 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 | ||
|
|
||
|
|
@@ -4563,6 +4596,22 @@ void test18045() nothrow | |
|
|
||
| /**********************************/ | ||
|
|
||
| struct S66 | ||
| { | ||
| ~this() { } | ||
| } | ||
|
|
||
| nothrow void notthrow() { } | ||
|
|
||
| class C66 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the purpose of this code? I don't see any instances of this class anywhere. Maybe it should be moved to the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
To compile successfully.
Perhaps, but I wanted the struct destructor tests in one file. |
||
| { | ||
| S66 s; | ||
|
|
||
| this() nothrow { notthrow(); } | ||
| } | ||
|
|
||
| /**********************************/ | ||
|
|
||
| int main() | ||
| { | ||
| test1(); | ||
|
|
@@ -4687,6 +4736,7 @@ int main() | |
| test14815(); | ||
| test16197(); | ||
| test14860(); | ||
| test14246(); | ||
| test14696(); | ||
| test14838(); | ||
| test63(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the check for
adreally necessary? Isn't this already checked in semantic1 ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sometimes, as a result of previous errors and error recovery, the AST isn't always in a completely consistent state. Expression nodes could be ErrorExp, Type nodes could be Terror, and even that isn't always done properly.