[Bug c++/41174] uncaught_exception always returns true

2009-08-26 Thread redi at gcc dot gnu dot org


--- Comment #1 from redi at gcc dot gnu dot org  2009-08-26 15:31 ---
Reduced:

#include cassert
#include exception

struct GoodE {
GoodE()
{
try {
throw 1;
} catch (...) {
}
}
};

struct BadE {
BadE()
try {
throw 1;
} catch (...) {
}
};

int main()
{
try {
throw GoodE();
} catch (...) {
assert( !std::uncaught_exception() );
}

try {
throw BadE();
} catch (...) {
assert( !std::uncaught_exception() );
}
}

Note that GoodE doesn't cause the problem. The difference is that BadE has a
function-try-block


-- 


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



[Bug c++/41174] uncaught_exception always returns true

2009-08-26 Thread redi at gcc dot gnu dot org


--- Comment #2 from redi at gcc dot gnu dot org  2009-08-26 15:52 ---
It looks as though uncaught_exception() does not always become false when
entering the handler of a function-try-block, and this causes it to stay true.

Maybe the count of uncaught exceptions is not decremented in the
function-try-block's handler, but is incremented when the exception is rethrown
at the end of the handler, causing it to be one more than it should not be.


-- 


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



[Bug c++/41174] uncaught_exception always returns true

2009-08-26 Thread redi at gcc dot gnu dot org


--- Comment #3 from redi at gcc dot gnu dot org  2009-08-26 16:01 ---
(In reply to comment #2)
 at the end of the handler, causing it to be one more than it should not be.

Oops, obviously I meant one more than it should be


-- 


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



[Bug c++/41174] uncaught_exception always returns true

2009-08-26 Thread redi at gcc dot gnu dot org


--- Comment #4 from redi at gcc dot gnu dot org  2009-08-26 16:17 ---
(In reply to comment #1)
 Note that GoodE doesn't cause the problem. The difference is that BadE has a
 function-try-block

And, of course, that the exception is rethrown by BadE at the end of the
handler. Changing GoodE to rethrow makes it have the same behaviour, so it's
not specific to function-try-blocks.

I give up for now, I'll just link to bug 10606 and
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#475 for reference


-- 


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



[Bug c++/41174] uncaught_exception always returns true

2009-08-26 Thread redi at gcc dot gnu dot org


--- Comment #5 from redi at gcc dot gnu dot org  2009-08-26 16:50 ---
I think the problem is that the uncaught_exception() is true as soon as the
memory for the exception has been allocated, but if the exception's copy
constructor is elided then happens before entering the exception's constructor.
 If the exception constructor throws another exception then uncaughtExceptions
goes to 2, and never goes back to zero.

uncaught_exception() should return true after evaluating the operand of throw.
If the operand cannot be constructed (because it throws) then that evaluation
never completes.

My understanding is that this should run to completeion, but all four
assertions fail:

#include cassert
#include exception

struct e {
e()
{
assert( !std::uncaught_exception() );
try {
throw 1;
} catch (int i) {
assert( !std::uncaught_exception() );
throw;
}
}
};

int main()
{
try {
throw e();
} catch (int i) {
assert( !std::uncaught_exception() );
}
assert( !std::uncaught_exception() );
}


-- 


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