Skip to content

Commit d5e431b

Browse files
committed
also note what can happen in case of non-determinism
1 parent 76537a0 commit d5e431b

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

rfcs/0000-const-ub.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ All of this UB has in common that there is an "obvious" way to continue evaluati
5151
we can just access the underlying memory despite alignment and/or aliasing rules being violated, and we can just ignore the existence of an invalid value as long as it is not used in some arithmetic, logical or control-flow operation.
5252
There is no guarantee that CTFE detects such UB: evaluation may either fail with an error, or continue with the "obvious" result.
5353

54+
If the compile-time evaluation uses operations that are specified as non-deterministic,
55+
and only some of the non-deterministic choices lead to CTFE-detected UB,
56+
then CTFE may choose any possible execution and thus miss the possible UB.
57+
For example, if we end up specifying the value of padding after a typed copy to be non-deterministically chosen, then padding will be initialized in some executions and uninitialized in others.
58+
If the program then performs integer arithmetic on a padding byte, that might or might not be detected as UB, depending on the non-deterministic choice made by CTFE.
59+
5460
## Note to implementors
5561

5662
This requirement implies that CTFE must happen on code that was *not subject to UB-exploiting optimizations*.

0 commit comments

Comments
 (0)