The following code, compiled with "g++ -O2", unrolls a number of the recursive calls of "is_frozen", then ends up with a "call" followed by a "leave" (non tail-call). It could use tail-recursion instead, which would be more space and cache efficient.
Using g++ (GCC) 4.4.0 20080727 (experimental). struct Tag { bool is_frozen() const { return frozen || (parent && parent->is_frozen()); }; Tag* parent; bool frozen; }; bool f(Tag& t) { return t.is_frozen(); } -- Summary: Unnecessary unrolling+regular call instead of tail call Product: gcc Version: 4.4.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: sam at gcc dot gnu dot org GCC host triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36965