public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/41174]  New: uncaught_exception always returns true
@ 2009-08-26  6:20 wwashby at earthlink dot net
  2009-08-26 15:31 ` [Bug c++/41174] " redi at gcc dot gnu dot org
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: wwashby at earthlink dot net @ 2009-08-26  6:20 UTC (permalink / raw)
  To: gcc-bugs

C:\...>gcc -v
Using built-in specs.
Target: djgpp
Configured with: /v203/gcc-4.32/configure msdosdjgpp
Thread model: single
gcc version 4.3.2 (GCC)

Build command line:  gpp -oexcpt -DTESTBADE excpt.C

Execute command line:  excpt

The following source code is a pared down version of a short program I wrote to
try the boundaries of the functions in <exception>.  An exception object's
constructor itself throws and catches an exception.  After that,
uncaught_exception always returns true.  In the "Output:" comment at the end of
the source file, places where uncaught_exception should return false are marked
with "!!!".

// excpt.C uses exceptions in strange and unusual ways
//
// build command line:  gpp -oexcpt -DTESTBADE excpt.C
// execute command line:  excpt

#include <iostream>
#include <exception>

void uncaught(int i = 0)
{
    std::cerr << "[" << i <<"] std::uncaught_exception() = " << std::boolalpha
        << std::uncaught_exception() << std::endl;
}

class E {
    const char* descr;

public:
    E(const char* str): descr(str)
    {
        std::cerr << "E::E(\"" << descr << "\")\n";
        uncaught();    }
    E(const E& e): descr(e.descr)
    {
        std::cerr << "E::E(const E&)\n";
        uncaught();
    }
    ~E()
    {
        std::cerr << "E::~E()\n";
        uncaught();
    }
    const char* describe() { return descr; }
};

/*****************************************************/
#ifdef TESTBADE
class BadE {
    const char* str;

public:
    BadE(const char* s)
    try
        : str(s)
    {
        std::cerr << "BadE::BadE(const char*) throwing \"thrown by
Bade::BadE(const char*)\"\n";
        throw "thrown by BadE::BadE(const char*)";
    }
    catch (const char* str) {
        std::cerr << "BadE::BadE(const char*) caught \"" << str << "\"\n";
    }

    ~BadE()
    {
        std::cerr << "BadE::~BadE()\n";
    }

    const char* describe() { return str; }
};

void throwBadE()
{
    std::cerr << "throwBadE():  throw BadE(\"thrown by throwBadE()\")\n";
    throw BadE("thrown by throwBadE()");
}
#endif
/*****************************************************/

void x(int i)
{
    try {
        std::cerr
            << "[" << i <<"] x(int) throwing E(\"E from x(int) try block\")\n";
        throw E("E from x(int) try block");
    }
    catch (E e) {
        std::cerr << "[" << i <<"] x(int) entering catch (E) block\n";
        uncaught(i);
        std::cerr << "[" << i <<"] x(int) caught E(\"" << e.describe() << "\")
by value\n";
        uncaught(i);
        std::cerr << "[" << i <<"] x(int) exiting catch (E) block\n";
    }
    std::cerr << "[" << i << "] x(int) tries uncaught before exiting\n";
    uncaught(i);
}

int main()
{
    x(1);
#ifdef TESTBADE
/*****************************************************/
    std::cerr << "*****************************************************\n";
    try {
        std::cerr << "main() calling void throwBadE();\n";
        try {
            throwBadE();
        }
        catch (BadE& be) {
            std::cerr << "catch (BadE&) block => \"" << be.describe() <<
"\"\n";
        }
        catch (const char* str) {
            std::cerr << "catch (const char*) block:  " << str << "\n";
        }
        catch (...) {
            std::cerr << "catch (...) block after calling void throwBadE();\n";
        }
    }
    catch (...) {
        std::cerr << "catch (...) looking for leftover exceptions ???\n";
    }
/*****************************************************/
#endif
    std::cerr << "*****************************************************\n";
    x(2);
    std::cerr << "*****************************************************\n";
    std::cerr << "before returning from main() check uncaught\n";
    uncaught(3);
}

/*
Output:

[1] x(int) throwing E("E from x(int) try block")
E::E("E from x(int) try block")
[0] std::uncaught_exception() = true
E::E(const E&)
[0] std::uncaught_exception() = true
[1] x(int) entering catch (E) block
[1] std::uncaught_exception() = false
[1] x(int) caught E("E from x(int) try block") by value
[1] std::uncaught_exception() = false
[1] x(int) exiting catch (E) block
E::~E()
[0] std::uncaught_exception() = false
E::~E()
[0] std::uncaught_exception() = false
[1] x(int) tries uncaught before exiting
[1] std::uncaught_exception() = false
*****************************************************
main() calling void throwBadE();
throwBadE():  throw BadE("thrown by throwBadE()")
BadE::BadE(const char*) throwing "thrown by Bade::BadE(const char*)"
BadE::BadE(const char*) caught "thrown by BadE::BadE(const char*)"
catch (const char*) block:  thrown by BadE::BadE(const char*)
*****************************************************
[2] x(int) throwing E("E from x(int) try block")
E::E("E from x(int) try block")
[0] std::uncaught_exception() = true
E::E(const E&)
[0] std::uncaught_exception() = true
[2] x(int) entering catch (E) block
[2] std::uncaught_exception() = true                      !!!
[2] x(int) caught E("E from x(int) try block") by value
[2] std::uncaught_exception() = true                      !!!
[2] x(int) exiting catch (E) block
E::~E()
[0] std::uncaught_exception() = true                      !!!
E::~E()
[0] std::uncaught_exception() = true                      !!!
[2] x(int) tries uncaught before exiting
[2] std::uncaught_exception() = true                      !!!
*****************************************************
before returning from main() check uncaught
[3] std::uncaught_exception() = true                      !!!
*/


-- 
           Summary: uncaught_exception always returns true
           Product: gcc
           Version: 4.3.2
            Status: UNCONFIRMED
          Severity: trivial
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: wwashby at earthlink dot net
 GCC build triplet: same
  GCC host triplet: Microsoft Windows XP Home Edition, x86 Family 16 Model 2
                    Steppin
GCC target triplet: same


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41174


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

end of thread, other threads:[~2010-01-08 19:14 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-26  6:20 [Bug c++/41174] New: uncaught_exception always returns true wwashby at earthlink dot net
2009-08-26 15:31 ` [Bug c++/41174] " redi at gcc dot gnu dot org
2009-08-26 15:52 ` redi at gcc dot gnu dot org
2009-08-26 16:01 ` redi at gcc dot gnu dot org
2009-08-26 16:18 ` redi at gcc dot gnu dot org
2009-08-26 16:50 ` redi at gcc dot gnu dot org
2009-08-27 10:37 ` [Bug libstdc++/41174] " redi at gcc dot gnu dot org
2009-08-27 10:51 ` paolo dot carlini at oracle dot com
2009-08-27 11:37 ` redi at gcc dot gnu dot org
2009-08-27 11:59 ` paolo dot carlini at oracle dot com
2009-08-27 12:18 ` redi at gcc dot gnu dot org
2009-08-27 14:27 ` wwashby at earthlink dot net
2009-08-27 15:19 ` redi at gcc dot gnu dot org
2009-08-29 11:27 ` wwashby at earthlink dot net
2009-08-29 12:50 ` wwashby at earthlink dot net
2010-01-08 19:14 ` paolo dot carlini at oracle 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).