Bug 40790 - throw in custom C++ terminate handler creates infinite recursion
throw in custom C++ terminate handler creates infinite recursion
Status: CLOSED CURRENTRELEASE
Product: Red Hat Linux
Classification: Retired
Component: gcc (Show other bugs)
7.1
i686 Linux
medium Severity high
: ---
: ---
Assigned To: Jakub Jelinek
David Lawrence
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2001-05-15 17:43 EDT by Louis-Dominique Dubeau
Modified: 2007-04-18 12:33 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2002-12-15 09:50:40 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Louis-Dominique Dubeau 2001-05-15 17:43:53 EDT
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux 2.4.2-2-ldd i686; en-US; 0.7)
Gecko/20010316

Description of problem:
Calling throw inside of a custom C++ terminate handler (set using
set_terminate) generates a call to terminate right away.  try-catch blocks
seem to be ignored.

How reproducible:
Always

Steps to Reproduce:
1. Create minimal.cc containing:

#include <string>
#include <exception>

void my_terminate()
{
    cout << "in terminate" << endl;
    cout.flush();
    try
    {
        throw;
    }
    catch (...)
    {
	cout << "caught" << endl;
	cout.flush();
    }
    exit(-1);
}

int
main(int argc, char *argv[])
{
    set_terminate(my_terminate);

    throw exception();
}

2. make minimal

3. ./minimal
	

Actual Results:
in terminate
in terminate
in terminate
in terminate
[This is repeated until the program crashes.  A stack trace shows that
my_terminate is being called recursively.]

Expected Results:
in terminate
caught
[program stops here]

Additional info:

Important note: on RedHat 6.1, compiling and running the above program
generates the expected results!
Comment 1 Jay Berkenbilt 2001-06-20 13:26:23 EDT
FWIW, this problem is fixed in gcc 3.0

Note You need to log in before you can comment on or make changes to this bug.