public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/40918]  New: uncaught_exception() returns wrong (inverted) value if some exception have crossed a DLL boundary before
@ 2009-07-30 20:18 andriys at gmail dot com
  2009-07-30 20:22 ` [Bug c++/40918] " andriys at gmail dot com
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: andriys at gmail dot com @ 2009-07-30 20:18 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2010-01-26 12:16 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-30 20:18 [Bug c++/40918] New: uncaught_exception() returns wrong (inverted) value if some exception have crossed a DLL boundary before andriys at gmail dot com
2009-07-30 20:22 ` [Bug c++/40918] " andriys at gmail dot com
2009-07-31  4:18 ` dannysmith at users dot sourceforge dot net
2009-07-31  6:56 ` andriys at gmail dot com
2009-07-31  6:58 ` andriys at gmail dot com
2009-08-02  8:57 ` dannysmith at users dot sourceforge dot net
2009-08-04 13:41 ` andriys at gmail dot com
2009-08-04 13:53 ` andriys at gmail dot com
2009-08-05  4:55 ` dannysmith at users dot sourceforge dot net
2010-01-26 12:16 ` [Bug target/40918] " andriys at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).