You have to choose whether or not you want the compiler to generate code that spends time doing things that the programmer didn&#x27;t ask for.<p>If you write a library with a function which accepts variables x and y and computes x[y] (or x&lt;&lt;y), there&#x27;s no way for the compiler to know in advance whether the user will pass in well-behaved values for x and y.  If you insist on the behavior being defined in pathological cases, then the compiler <i>must</i> add some kind of branching logic in there to check what&#x27;s passed in at runtime.  In other words, spend time doing things the programmer didn&#x27;t ask for.<p>Maybe when we make more progress with formal proof-generating languages, we can create a &quot;friendly&quot; C where the compiler refuses to compile the code until it&#x27;s accompanied by formal proofs of UB-avoidance.