Skip to content

Commit c11f71c

Browse files
authored
[deprecate] Add items for throw/catch object qualifiers (#3806)
1 parent 80708ba commit c11f71c

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

deprecate.dd

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ $(SPEC_S Deprecated Features,
5050
$(TROW $(DEPLINK .size property), ?, 0.107, 0.107, 2.061 )
5151
$(TROW $(DEPLINK .typeinfo property), ?, 0.093, 2.061, 2.067 )
5252
$(TROW $(DEPLINK unannotated asm blocks),  , &nbsp, 2.100, (never) )
53+
$(TROW $(DEPLINK Throwing qualified objects),  , 2.104, &nbsp, (never) )
54+
$(TROW $(DEPLINK Catching immutable/inout/shared objects),  , 2.106, &nbsp, (never) )
5355
)
5456

5557
$(DL
@@ -1022,6 +1024,41 @@ $(H4 Rationale)
10221024
interfaces.)
10231025
)
10241026

1027+
$(H3 $(DEPNAME Throwing qualified objects))
1028+
1029+
$(P
1030+
Previously, an `immutable`, `const`, `inout` or `shared` exception could be
1031+
thrown and then caught in an unqualified `catch (Exception e)` clause.
1032+
That breaks type safety.
1033+
Throwing a qualified object is now deprecated. This helps to prevent
1034+
possible mutation of an immutable object in a `catch` clause.
1035+
)
1036+
1037+
$(P
1038+
The runtime also modifies a thrown object (e.g. to contain a stack
1039+
trace) which can violate `const` or `immutable` objects. Throwing
1040+
qualified objects has been deprecated for this reason also.
1041+
)
1042+
1043+
$(H3 $(DEPNAME Catching immutable/inout/shared objects))
1044+
1045+
$(P
1046+
It is unsafe to catch an exception as `immutable`, `inout` or `shared`.
1047+
This is because the exception may still be accessible through another
1048+
mutable or non-shared reference.
1049+
)
1050+
1051+
---
1052+
auto e = new Exception("first");
1053+
try {
1054+
throw e;
1055+
} catch(immutable Exception ie) { // unsafe
1056+
e.msg = "second";
1057+
assert(ie.msg == "first"); // would fail
1058+
}
1059+
---
1060+
1061+
10251062
Macros:
10261063
DEPLINK=$(RELATIVE_LINK2 $0, $0)
10271064
DEPLINK2=$(LINK2 $1.html#$2, $2)

0 commit comments

Comments
 (0)