This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/40918] New: uncaught_exception() returns wrong (inverted) value if some exception have crossed a DLL boundary before
- From: "andriys at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 30 Jul 2009 20:18:44 -0000
- Subject: [Bug c++/40918] New: uncaught_exception() returns wrong (inverted) value if some exception have crossed a DLL boundary before
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
I was not able to reproduce the bug on Linux, so I assume this is a
Windows-specific.
If an exception is generated inside shared library (DLL), then crosses the
DLL-boundary and gets caught in some other module, the std::uncaught_exception
will always return wrong (inverted) value from now on. Here's a small test
case.
The DLL (throw.dll) contains just a single function that throws an exception:
throw.cpp
~~~~~~~~~
void do_throw(void)
{
throw("");
}
The test program (test.exe) is linked against throw.dll:
test.cpp
~~~~~~~~
#include <exception>
#include <iostream>
bool b;
void do_throw(void);
struct UE
{
~UE()
{
b = std::uncaught_exception();
}
};
int main(void)
{
try
{
do_throw();
}
catch (...)
{
}
try
{
UE ue;
throw "";
}
catch (...)
{
}
std::cout << "Expecting 'true', got " << (b ? "'true'" : "'false'") <<
std::endl;
{
UE ue;
}
std::cout << "Expecting 'false', got " << (b ? "'true'" : "'false'") <<
std::endl;
return 0;
}
test.exe produces the following output:
C:\TEMP\bug>test.exe
Expecting 'true', got 'false'
Expecting 'false', got 'true'
If we comment out the call to do_throw(), std::uncaught_exception will work as
expected. If we put do_throw() in a statically linked module,
std::uncaught_exception will work as expected as well.
--
Summary: uncaught_exception() returns wrong (inverted) value if
some exception have crossed a DLL boundary before
Product: gcc
Version: 4.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: andriys at gmail dot com
GCC host triplet: mingw32
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40918