Skip to content

Commit 2418999

Browse files
committed
mention that unsound code does not get stability guarantees
1 parent 96df19a commit 2418999

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

rfcs/0000-const-ub.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ For example, when UB arises while computing an array length, then the final arra
2828
No guarantees are made about this final value, and it can be different depending on host and target architecture, compiler flags, and more.
2929
However, UB will not otherwise adversely affect the currently running compiler; type-checking and lints and everything else will work correctly given whatever the result of the CTFE computation is.
3030

31+
Note, however, that this means compile-time UB can later cause runtime UB when the program is actually executed:
32+
for example, if there is UB while computing the initial value of a `Vec<i32>`, the result might be a completely invalid vector that causes UB at runtime when used in the program.
33+
3134
Sometimes, the compiler might be able to detect such problems and show an error or warning about CTFE computation having gone wrong (for example, the compiler might detect when the array length ends up being uninitialized).
3235
But other times, this might not be the case -- UB is not reliably detected during CTFE.
33-
34-
Note, in particular, that this means compile-time UB can later cause runtime UB when the program is actually executed:
35-
for example, if there is UB while computing the initial value of a `Vec<i32>`, the result might be a completely invalid vector that causes UB at runtime when used in the program.
36+
This can change from compiler version to compiler version: CTFE code that causes UB could build fine with one compiler and fail to build with another.
37+
(This is in accordance with the general policy that unsound code is not subject to strict stability guarantees.)
3638

3739
# Reference-level explanation
3840
[reference-level-explanation]: #reference-level-explanation

0 commit comments

Comments
 (0)