[antlr-interest] Stack overflow problem with C++

Ric Klaren ric.klaren at gmail.com
Tue Jul 19 00:24:17 PDT 2005


On 7/19/05, Jorg Halker <jogi1978 at gmx.de> wrote:
> If i run the following code i get a stack overflow error:
> 
> ****************************************
> #include <antlr/CommonAST.hpp>
> 
> using namespace antlr;
> using namespace std;
> 
> int main(int argc, char * * argv)
> {
>         RefCommonAST first = RefCommonAST( new CommonAST());
>         RefCommonAST current = first;
>         for (unsigned int counter = 0; counter < 9000; ++counter)
>         {
>                 current->setNextSibling(RefAST( new CommonAST()));
>                 current = current->getNextSibling();
>         }
> }
> ****************************************
> 
> It looks like a problem with the destructor of CommonAST or its base
> classes. The error occours if 'first' runs out of the scope.
> If i create a parser that parses an input file into the same AST scheme,
> everything works fine. But if i create a copy of the AST from the parser i
> run into the same problem.
> 
> What's wrong? The code snippet should not produce an stack overflow error,
> am i right?

Nope it shouldn't (and it doesn't on a number of machines I have acces
to) Which leads to the question:  What antlr version? What OS? What
compiler?

Cheers,

Ric


More information about the antlr-interest mailing list