c++/2135: Exceptions broken using -O2 and method-pointers together
tgarnock-jones@eservglobal.co.nz
tgarnock-jones@eservglobal.co.nz
Sun Apr 1 00:00:00 GMT 2001
>Number: 2135
>Category: c++
>Synopsis: Exceptions broken using -O2 and method-pointers together
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Thu Mar 01 00:16:01 PST 2001
>Closed-Date:
>Last-Modified:
>Originator: Tony Garnock-Jones
>Release: gcc version 2.95.2 19991024 (release)
>Organization:
>Environment:
hp1:~/dev$ uname -a
HP-UX hp1 B.10.20 A 9000/785 2012728060 two-user license
>Description:
When using G++ to compile code *with -O2* which throws an exception from inside a method that was called via a method pointer, it gets caught not in the correct catch-block, nor in the dynamically *enclosing* catch-block, but the SECOND dynamically-enclosing catch-block, and even then, only after RESTARTING THE TRY BLOCK THAT THREW THE EXCEPTION IN THE FIRST PLACE! Strange, eh? Works fine without -O2 (and that's the workaround which makes this non-critical).
Here's the output from "gcc -v -g -O2 -Wall testexception.cc -o testexception":
Reading specs from /opt/gcc/lib/gcc-lib/hppa1.1-hp-hpux10.20/2.95.2/specs
gcc version 2.95.2 19991024 (release)
/opt/gcc/lib/gcc-lib/hppa1.1-hp-hpux10.20/2.95.2/cpp -lang-c++ -v -D__GNUC__=2 -D__GNUG__=2 -D__GNUC_MINOR__=95 -D__cplusplus -Dhppa -Dhp9000s800 -D__hp9000s800 -Dhp9k8 -DPWB -Dhpux -Dunix -D__hppa__ -D__hp9000s800__ -D__hp9000s800 -D__hp9k8__ -D__PWB__ -D__hpux__ -D__unix__ -D__hppa -D__hp9000s800 -D__hp9k8 -D__PWB -D__hpux -D__unix -Asystem(unix) -Asystem(hpux) -Acpu(hppa) -Amachine(hppa) -D__EXCEPTIONS -D__OPTIMIZE__ -g -Wall -D__hp9000s700 -D_PA_RISC1_1 -D_HPUX_SOURCE -D_HIUX_SOURCE -D__STDC_EXT__ -I/usr/local/include testexception.cc /var/tmp/ccx3KZjc.ii
GNU CPP version 2.95.2 19991024 (release) (hppa)
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/opt/gcc/lib/gcc-lib/hppa1.1-hp-hpux10.20/2.95.2/../../../../include/g++-3
/opt/gcc/include
/opt/gcc/lib/gcc-lib/hppa1.1-hp-hpux10.20/2.95.2/../../../../hppa1.1-hp-hpux10.20/include
/opt/gcc/lib/gcc-lib/hppa1.1-hp-hpux10.20/2.95.2/include
/usr/include
End of search list.
The following default directories have been omitted from the search path:
End of omitted list.
/opt/gcc/lib/gcc-lib/hppa1.1-hp-hpux10.20/2.95.2/cc1plus /var/tmp/ccx3KZjc.ii -quiet -dumpbase testexception.cc -g -O2 -Wall -version -o /var/tmp/ccMQstMa.s
GNU C++ version 2.95.2 19991024 (release) (hppa1.1-hp-hpux10.20) compiled by CC.
/opt/gcc/lib/gcc-lib/hppa1.1-hp-hpux10.20/2.95.2/as -o /var/tmp/ccZZHUia.o /var/tmp/ccMQstMa.s
/opt/gcc/lib/gcc-lib/hppa1.1-hp-hpux10.20/2.95.2/collect2 -L/lib/pa1.1 -L/usr/lib/pa1.1 -z -u main -o testexception /usr/ccs/lib/crt0.o -L/opt/gcc/lib/gcc-lib/hppa1.1-hp-hpux10.20/2.95.2 -L/usr/ccs/bin -L/usr/ccs/lib -L/opt/gcc/lib /var/tmp/ccZZHUia.o -lgcc -lc -lgcc
>How-To-Repeat:
Compile this code on an HPUX-10.20 system with GCC 2.95.2, with -O2. Run the code. You get output:
About to sub2
About to sub2
About to sub2
About to sub2
CAUGHT but SHOULDN'T HAVE!
when you should get:
About to sub2
CAUGHT i 123
>Fix:
Compile it again, without -O2 this time. It works as intended.
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="testexception.cc"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="testexception.cc"
Ly8gQ29tcGlsZSBtZSB3aXRoOgovLwovLwlnY2MgLXYgLWcgLU8yIC1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