Uploaded image for project: 'C++ Standard Library'
  1. C++ Standard Library
  2. STDCXX-537

[XLC++ 9.0] std::uncaught_exception() false in terminate handler

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: External
    • Labels:
      None

      Description

      According to 18.6.4, p1, std::uncaught_exception() is required to return true when terminate() is entered for any reason other than an explicit call to terminate(), and to continue to return true while executing the installed terminate handler. The program below shows that the XLC++ 9.0 implementation fails to follow this requirement:

      $ cat uncaught.cpp && xlC -qversion && xlC uncaught.cpp && ./a.out
      #include <exception>
      #include <stdio.h>
      #include <stdlib.h>

      bool expect_uncaught;
      const char* which;

      void handler ()
      {
      const bool uncaught = std::uncaught_exception ();

      printf ("%s handler: uncaught_exception () == %d, got %d\n",
      which, expect_uncaught, uncaught);

      exit (expect_uncaught == uncaught ? 0 : 1);
      }

      void invoke_unexpected () throw ()

      { throw 0; }

      void test_unexpected ()
      {
      puts ("testing uncaught_exception() after a call to unexpected()");

      std::set_unexpected (handler);

      expect_uncaught = false;
      which = "unexpected";
      invoke_unexpected ();
      }

      int evaluate (int select)
      {
      if (2 == select)

      { expect_uncaught = true; throw 0; }

      else if (3 == select)
      std::terminate ();
      else
      std::unexpected ();

      return 0;
      }

      void test_terminate (int select)
      {
      printf ("uncaught_exception() after an %s call to %s\n",
      2 == select ? "implicit" : "explicit",
      select < 4 ? "terminate()" : "unexpected() during a throw");

      std::set_terminate (handler);
      which = "terminate";

      throw evaluate (select);
      }

      int main (int argc, char *argv[])
      {
      if (1 == argc)

      { printf ("%s\n", system ("./a.out 1") ? "FAIL" : "PASS"); printf ("%s\n", system ("./a.out 2") ? "FAIL" : "PASS"); printf ("%s\n", system ("./a.out 3") ? "FAIL" : "PASS"); printf ("%s\n", system ("./a.out 4") ? "FAIL" : "PASS"); }

      else

      { int select = argv [1][0] - '0'; 1 < select ? test_terminate (select) : test_unexpected (); }

      }
      IBM XL C/C++ Enterprise Edition for AIX, V9.0
      Version: 09.00.0000.0000
      testing uncaught_exception() after a call to unexpected()
      unexpected handler: uncaught_exception () == 0, got 0
      PASS
      uncaught_exception() after an implicit call to terminate()
      terminate handler: uncaught_exception () == 1, got 0
      FAIL
      uncaught_exception() after an explicit call to terminate()
      terminate handler: uncaught_exception () == 0, got 0
      PASS
      uncaught_exception() after an explicit call to unexpected() during a throw
      terminate handler: uncaught_exception () == 0, got 0
      PASS

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              sebor Martin Sebor
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated: