4 ms·
> A language can avoid this by not having infinite template recursion. How does it know whether a definition is infinitely recursive? This IS the halting probl
by liontwist 2y ago
> A language can avoid this by not having infinite template recursion.
How does it know whether a definition is infinitely recursive? This IS the halting problem.
> But a future version could bake that limit into the language itself,
In other words, take away the Turing completeness of templates. Which goes back to my original comment.
Also note that limiting recursion hurts real world use case (types getting arbitrarily complex in a program over time) in favor of theoretical benefit (now you can say it’s not UB).
> pointer Deref
Let me explain again. In a language with pointers checking whether a deref is valid requires comparing every address to every allocation bounds. That’s ridiculously expensive.
The only solution is to take away pointers (Java, C#, etc) OR do what C does, crash on obviously bad derefs. Since “obviously bad” depends on the implementation (maybe you are a safety sadist and you want 2000 instructions per deref) the standard cannot guarantee any behavior. Maybe it crashes, maybe you get “lucky” and it doesn’t notice.
The only way to avoid UB is to limit expressiveness (pretend addresses don’t exist), and all Turing complete languages have UB.
I have more responses, but you’re not grasping the ones I already made.
- Dylan16807 2y ago> In other words, take away the Turing completeness of templates. Which goes back to my original comment. Template halting is only a correctness issue because it's done at compile time. Turing completeness is not a problem in general, and limiting the amount of computation at compile time is fine. > The only solution is to take away pointers (Java, C#, etc) OR do what C does Something along those lines. > The only way to avoid UB is to limit expressiveness (pretend addresses don’t exist), and all Turing complete languages have UB. The only way to avoid UB is to limit expressiveness, and NOT all Turing complete languages have UB. Pointers are a big thing to restrict for a safe language. But you really don't have to do that much else. Whether a program halts or doesn't halt at runtime isn't a safety issue, there's no UB involved. It just runs indefinitely.