UB has been already invoked by the malformed program.

The question is, what happens with this invalid program, when it is compiled and run.

It is your prerogative to rely on certain behavior of certain compilers. But it is not publicly known (even not for open-source compilers, as the rules are complicated and not fully analyzed), how to write UB programs showing correct behavior.

It is like keeping bugs on purpose, because they never were observed in practice, although they could be observed with unlucky input.

 

If you want to hack the functioning of C++ one level deeper, you should do it on the compiler level, e.g. write custom extensions, which you can call in your programs.

And if they are really useful they can be standardized.


 

The object model in C++ isn't as wild and wacky as some people make it out to be. There isn't and optimiser up on a lighthouse with a sniper rifle waiting for the perfect opportunity to invoke UB.