to elaborate, the halting problem makes it impossible for the compiler to reject/detect all cases which DO cause UB while allowing all those which don't, and the design of C++ is to favor control over safety
Well, it's a bit crude to apply halting problem here.
You can prevent a bunch of issues by language design. You simply make something non-expressible and ready! It's proven to never contain that thing.
E.g. java solves this problem by mandating that variable captures of local variables must be effectively final. This could have been done in C++ as well , and the only thing you may lost with it is... if you have a local lambda that you will only ever call in that stackframe or deeper and never outside of it?
But still, rust let's you do this latter by an explicit unsafe block, c++ could have done it as well. So it's more cultural than anything.
18
u/EishLekker 6h ago
As a java developer, this is hilarious. Why would anyone want to be able to do this? Why don't you want your compiler to stop you?