https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92559
--- Comment #3 from Konstantin Kharlamov <Hi-Angel at yandex dot ru> --- (In reply to Andrew Pinski from comment #2) > I don't think this can ever be optimized. Mainly because there are copies > happening due to passing via value and returning by value. Please correct me if I'm wrong, but it seems like, given the code in question: MyMap foo(MyMap m) { if (m[0] == 0) return m; else { m[0] -= 1; return foo(m); } } When tail-recursion optimization applied, it should be analogous to this code: MyMap foo(MyMap m) { while(m[0] > 0) { m[0] -= 1; m = MyMap(m); } return m; } Doesn't look impossible to me, unless of course I am missing something.