> It surprises me that the compiler doesn't still take the inference from the assert and just disable emitting the code to perform the check.
The compiler isn't as clever as I think you're envisioning: assert() only works that way because it exits the control flow if the statement isn't true.
My point is that even though the assert() is optimised out, the compiler could still assume that the condition is valid.