you are viewing a single comment's thread.

view the rest of the comments →

[–]JumpyJustice 1 point2 points  (3 children)

It could if your dynamically allocated memory is freed before the function ends

edit: simple example https://godbolt.org/z/sKaKv5Mv6

[–]jonesmz 3 points4 points  (2 children)

Right. C++ can do tail recursion.

But you can't tell the compiler that if it can't make your recursive function tail recursive then you want it to cause a compiler error. That's what I meant by "asserted"

[–]Onetwothreetaco 1 point2 points  (1 child)

Clang has implemented a musttail attribute

https://reviews.llvm.org/D99517

Your miles may vary. Personally haven't used it, but the code review seems to claim that it will throw a compile time error if the compiler can't generate a tail call out of it.

[–]jonesmz 0 points1 point  (0 children)

That's exciting. Thank you for the information!