On HP-UX we clashed with the problem that application falls in coredump if
exception is thrown by the function that returns float (or double) and this
function is placed in shared library.
What is interesting - the same function that returns int (or long, etc) works
correctly.
The example below illustrates it (these sources are also attached).
We are not sure if it's gcc bug and if this bug was already committed but we
can not find it anywhere.
So any help is appreciated.
Sample code:
// ---------------------------------
// File ncelib.hpp
// ---------------------------------
#include <stdexcept>
int lib_func_rInt();
float lib_func_rFloat();
// ---------------------------------
// File ncelib.cpp
// ---------------------------------
#include "ncelib.hpp"
int lib_func_rInt()
{
throw std::exception();
return 0;
}
float lib_func_rFloat()
{
throw std::exception();
return 0.0;
}
// ---------------------------------
// File nceexe.cpp
// ---------------------------------
#include "ncelib.hpp"
#include <stdlib.h>
int main()
{
printf("main() {\n");
try
{
lib_func_rInt();
}
catch (std::exception &)
{
}
printf("...\n");
try
{
lib_func_rFloat();
}
catch (std::exception &)
{
}
printf("}\n");
return 0;
}
// ---------------------------------
// File compile.sh
// ---------------------------------
set -ex
g++ -Wall -save-temps -fPIC -shared -g -D_GLIBCXX_DEBUG -o libncelib.sl
ncelib.cpp
g++ -Wall -save-temps -fPIC -g -D_GLIBCXX_DEBUG -o nceexe nceexe.cpp -L.
-lncelib
//---- Output sample ----------
bash-3.2$ gcc -v
Using built-in specs.
Target: hppa2.0w-hp-hpux11.11
Configured with: ../gcc/configure : (reconfigured) ../gcc/configure :
(reconfigured) ../gcc/configure
Thread model: posix
gcc version 4.1.2
bash-3.2$ ./compile.sh
++ g++ -Wall -save-temps -fPIC -shared -g -D_GLIBCXX_DEBUG -o libncelib.sl
ncelib.cpp
++ g++ -Wall -save-temps -fPIC -g -D_GLIBCXX_DEBUG -o nceexe nceexe.cpp -L.
-lncelib
bash-3.2$ ./nceexe
main() {
...
terminate called after throwing an instance of 'std::exception'
what(): St9exception
ABORT instruction (core dumped)
--
Summary: Exception from shared library's functions or methods
that return float (double, long double) value cannot be
caught on HP-UX.
Product: gcc
Version: 4.1.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: v dot grikyan at sam-solutions dot net
GCC target triplet: hppa2.0w-hp-hpux11.11
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37029