Bug 44954 - exception ignores catch-clause when using a variable for the message
Summary: exception ignores catch-clause when using a variable for the message
Status: RESOLVED DUPLICATE of bug 42159
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.4.4
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-15 16:47 UTC by Mike Glass
Modified: 2010-07-15 16:57 UTC (History)
5 users (show)

See Also:
Host:
Target: x86_64-apple-darwin10
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Glass 2010-07-15 16:47:45 UTC
I believe this is related to Bug #43493 

I cannot catch exceptions if a variable (non-static) is use for the message...

Using the following program:

#include <cstdlib>
#include <iostream>
#include <sstream>
#include <stdexcept>
#include <string>
using namespace std;

void generateException(int whichException);

int main(int argc, char ** argv) {
    for (int i=1; ; i++) {  // Loop forever
        try {
            cout << i;
            generateException(i);
        } catch (runtime_error rex) {
            cout << "    Catching: runtime_error - " << rex.what() << endl;
        } catch (...) {
            cout << "    ERROR: Nobody caught this!" << endl;
        }
    }     
    return 0;
}

void generateException(int whichException) {
    switch (whichException) {
    case 1:
	cout << "  Throwing runtime_error (1)" << endl;
        throw runtime_error( "a comment" );
	break;
    case 2:
	cout << "  Throwing runtime_error (2)" << endl;
        {
        static string msg( "a comment" );
        throw runtime_error( msg );
        }
	break;
    case 3:
	cout << "  Throwing runtime_error (3)" << endl;
        {
        string msg( "a comment" );
        throw runtime_error( msg );
        }
	break;
    case 4:
	cout << "  Throwing runtime_error (4)" << endl;
        {
        std::ostringstream msg ;
        msg << "a comment" ;
        throw runtime_error( msg.str() );
        }
	break;
    default:
        cout << "  Throwing up" << endl;
        exit(0);
    }
    return;
}



When I build with apple's g++ (4.2.1) or intel 11.1 icpc C++ compilers I get the following expected output:

1  Throwing runtime_error (1)
    Catching: runtime_error - a comment
2  Throwing runtime_error (2)
    Catching: runtime_error - a comment
3  Throwing runtime_error (3)
    Catching: runtime_error - a comment
4  Throwing runtime_error (4)
    Catching: runtime_error - a comment
5  Throwing up


However, when I compile with gcc 4.3 or 4.4 installed with macports 1.9.1 I get:

1  Throwing runtime_error (1)
    Catching: runtime_error - a comment
2  Throwing runtime_error (2)
    Catching: runtime_error - a comment
3  Throwing runtime_error (3)
Abort trap


I also tried building gcc44 with the --without-system-libunwind configure flag and also got the same behavior.

My system configuration is:

MacPro 2x2.93GHz quad-core xeon
MacOSX 10.6.4
Xcode 3.2.3
MacPorts 1.9.1
Comment 1 Jonathan Wakely 2010-07-15 16:53:46 UTC
(In reply to comment #0)
> However, when I compile with gcc 4.3 or 4.4 installed with macports 1.9.1 I
> get:

How is that gcc configured?
Comment 2 Mike Glass 2010-07-15 16:56:25 UTC
Using built-in specs.
Target: x86_64-apple-darwin10
Configured with: ../gcc-4.4.4/configure --prefix=/opt/local --build=x86_64-apple-darwin10 --enable-languages=c,c++,objc,obj-c++,java,fortran --libdir=/opt/local/lib/gcc44 --includedir=/opt/local/include/gcc44 --infodir=/opt/local/share/info --mandir=/opt/local/share/man --with-local-prefix=/opt/local --with-system-zlib --disable-nls --program-suffix=-mp-4.4 --with-gxx-include-dir=/opt/local/include/gcc44/c++/ --with-gmp=/opt/local --with-mpfr=/opt/local --enable-stage1-checking --enable-fully-dynamic-string
Thread model: posix
gcc version 4.4.4 (GCC) 
Comment 3 Andrew Pinski 2010-07-15 16:57:05 UTC
IIRC this is a bug in Apple's unwinder.
Comment 4 Andrew Pinski 2010-07-15 16:57:56 UTC

*** This bug has been marked as a duplicate of 42159 ***