Bug 61643 - [C++11] std::uncaught_exception returns wrong values after std::rethrow_if_nested
Summary: [C++11] std::uncaught_exception returns wrong values after std::rethrow_if_ne...
Status: RESOLVED DUPLICATE of bug 62258
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 5.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2014-06-29 05:55 UTC by Ai Azuma
Modified: 2014-10-07 09:02 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.8.4, 4.9.2, 5.0
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ai Azuma 2014-06-29 05:55:10 UTC
The following program should terminate successfully.

//=========================================================
#include <stdexcept>
#include <exception>
#include <cstdlib>

struct X
{
  ~X() {
    if (!std::uncaught_exception()) std::abort();    // (A)
  }
};

int main() {
  try {
    throw std::runtime_error("");
  }
  catch (...) {
    try {
      std::throw_with_nested(std::runtime_error(""));
    }
    catch (std::runtime_error const &e) {
      try {
        X x;
        std::rethrow_if_nested(e);
      }
      catch (std::runtime_error const &e) {
        if (std::uncaught_exception()) std::abort(); // (B)
      }
    }
  }
  return EXIT_SUCCESS;
}
//=========================================================

However, the program is aborted at the line marked with `(A)', and at the line marked with `(B)' if the line marked with `(A)' is commented out.

This problem is reproduced with 4.10.0 20140622, 4.9.1 20140625 and 4.8.4 20140619. The reproducer requires -std=c++11 flag to compile.
Comment 1 Ai Azuma 2014-10-07 09:01:35 UTC
See Comment 2 in PR62258. The proposed patch attached in that comment make the above test case work properly.
Comment 2 Ai Azuma 2014-10-07 09:02:11 UTC

*** This bug has been marked as a duplicate of bug 62258 ***