This small program --------------------------- #include <fstream> #include <string> void foo (const int i) { std::ifstream in("irrelevant"); std::string line; if (i == 1) return; foo (1); } int main () { foo (0); } --------------------------- segfaults on running when compiled with the tree-ssa branch from gcc version 3.5-tree-ssa 20031024 (merged 20031017) It doesn't segfault with mainline from the same day, though. Assuming that the code in libstdc++ is the same on the two branches, this means that something is being miscompiled. This could, theoretically also include a miscompilation in libstdc++ itself, since I can't get around using parts of it, but it strikes me as odd that I need the tail recursion in foo() to actually trigger the bug in the program. Maybe it is just some interaction of the tail recursion and the stack space/ constructors/exception handling details of the objects in use in this function that make this happen, so this could actually be simple to track down than it looks like. W.
Most likely the same bug as PR 12751.
This is indeed almost certainly the same bug. Here's something smaller: ----------------------------- #include <cstdio> struct X { X() { printf ("X::X\n"); } ~X() { printf ("X::~X\n"); } }; void foo (const int i) { X x1, x2; if (i == 1) return; foo (1); } int main () { foo (0); } ------------------------------ I get 4 calls to the ctor, and 5 to the dtor. W.
It is a dup of bug 12751, as it works correctly with -fno-exception and it has nothing to do with tail recursion (or switch's), it is eh related.
*** This bug has been marked as a duplicate of 12751 ***
Confirmed fixed with rth's patch to 12751. Thanks a lot!