Skip to content

Commit 39a810b

Browse files
h0nzZikchathhorn
authored andcommitted
Fix #574. (#576)
* Fix #574. * Destruct the exception object
1 parent 6ea18d7 commit 39a810b

File tree

5 files changed

+49
-6
lines changed

5 files changed

+49
-6
lines changed

semantics/common/execution/thread_local.k

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ module COMMON-THREAD-LOCAL
4949
<this> .K </this>
5050
// object being constructed
5151
<constructing> .K </constructing>
52+
<constructing-history> .List </constructing-history>
5253
// most derived class being constructed
5354
<most-derived-class> .K </most-derived-class>
5455

@@ -82,7 +83,6 @@ module COMMON-THREAD-LOCAL
8283
// used to store the catch handlers if this
8384
// block is a try block in C++
8485
<catch-handlers> .List </catch-handlers>
85-
<current-exception> .K </current-exception>
8686
</block-control>
8787

8888
// used to control initialization when gotoing
@@ -99,6 +99,7 @@ module COMMON-THREAD-LOCAL
9999
// Used to catch potential stack size overflows.
100100
<stack-depth> 0 </stack-depth>
101101

102+
<current-exception> .K </current-exception>
102103
<uncaught-exception> false </uncaught-exception>
103104

104105
// stdarg

semantics/cpp/language/execution/binding.k

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,19 @@ module CPP-EXECUTION-BINDING
5656
<this> _ => Obj </this>
5757

5858
rule <k> beginConstruction(Obj:LVal, IsBaseClassSubobject:Bool) => Obj ...</k>
59-
<constructing> _ => Obj </constructing>
60-
<most-derived-class> MostDerived:K => #if IsBaseClassSubobject #then MostDerived #else type(Obj) #fi </most-derived-class>
59+
<constructing> Old::K => Obj </constructing>
60+
<constructing-history>
61+
.List => ListItem(<constructing>Old</constructing>)
62+
...</constructing-history>
63+
<most-derived-class>
64+
MostDerived:K => #if IsBaseClassSubobject #then MostDerived #else type(Obj) #fi
65+
</most-derived-class>
6166

6267
rule <k> endConstruction(Obj:LVal, IsConstructor::Bool) => finishConstruction(Obj, IsConstructor) ...</k>
63-
<constructing> _ => .K </constructing>
68+
<constructing> _ => Old </constructing>
69+
<constructing-history>
70+
ListItem(<constructing> Old::K </constructing>) => .List
71+
...</constructing-history>
6472

6573
rule <k> finishConstruction(Obj:LVal, IsConstructor:Bool) => Obj ...</k>
6674
<locally-constructed> .List =>

semantics/cpp/language/execution/stmt/try.k

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,9 @@ module CPP-EXECUTION-STMT-TRY
196196
rule <k> activateHandler => .K ...</k>
197197
<uncaught-exception> _ => false </uncaught-exception>
198198

199-
rule <k> deactivateHandler => .K ...</k>
200-
<current-exception> _ => .K </current-exception>
199+
// @ref n4296 15.1/4
200+
rule <k> deactivateHandler => destructLocal(false, lcentry(V, true, true, false)) ...</k>
201+
<current-exception> V::LVal => .K </current-exception>
201202

202203
rule tryMark(_) => .K
203204

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
struct E {
2+
E(){}
3+
~E(){}
4+
E(E const &){}
5+
int x;
6+
};
7+
8+
E foo() {
9+
return E();
10+
//return {};
11+
}
12+
13+
int main() {
14+
foo();
15+
//E(E());
16+
E e = E();
17+
try { throw E(); } catch(...){}
18+
}

tests/unit-pass/destruct-thrown.C

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
extern "C" int puts(char const *);
2+
3+
struct E {
4+
int x = 0;
5+
E(){puts("E()");}
6+
~E(){puts("~E()");}
7+
E(E const &){puts("E(E const &)");}
8+
};
9+
10+
int main() {
11+
try {
12+
throw E();
13+
} catch(E const &e) {}
14+
puts("---");
15+
}

0 commit comments

Comments
 (0)