<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - [C++98]Should continue search after unexpected() throw a exception allowed by exception-spec"
   href="http://llvm.org/bugs/show_bug.cgi?id=18245">18245</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[C++98]Should continue search after unexpected() throw a exception allowed by exception-spec
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>zhaoshiz@codeaurora.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=11731" name="attach_11731" title="test case for Sec 15.5.2">attachment 11731</a> <a href="attachment.cgi?id=11731&action=edit" title="test case for Sec 15.5.2">[details]</a></span>
test case for Sec 15.5.2

>From C++98 standard, Sec 15.5.2

The unexpected() function shall not return, but it can throw (or re-throw) an
exception. If it throws a new exception which is allowed by the exception
specification which previously was violated, then the search for another
handler will continue at the call of the function whose exception specification
was violated.

$ clang++ -target arm-none-linux-gnueabi -mfloat-abi=softfp -mfpu=neon
--sysroot=/prj/llvm-arm/home/common/build_tools/gcc-4.6.1-cs/arm-2011.09 -marm
-march=armv7-a 15.5.2.unexpected.cpp -o 15.5.2.unexpected.comm.exe -static

$ qemu-arm -cpu cortex-a15 ./15.5.2.unexpected.comm.exe  
terminate called after throwing an instance of 'B'
qemu: uncaught target signal 6 (Aborted) - core dumped
Aborted

$ cat 15.5.2.unexpected.cpp 
#include <exception>
#include <cstdlib>
#include <cstdio>

class B {
public:
  const char *s;
  B(const char *p) : s(p) {}
  B() : s("NULL") {}
};

class D : public B {
public:
  const char *t;
  D(const char *p) : B(p), t(p) {}
  D() : B(), t("NULL") {}
};

static void boo() {
  printf("UNREACHABLE!\n");
}

static void foo() throw (D, const char*) {
  throw B("x");  // violates exception-specification
}

static void goo() {
  try {
    foo();
  } catch (const B &b) {
    boo(); // should not reach here, given above expection-spec unexpected is
called
  } catch (const char *s) {
    exit(3);
  }
  boo(); // should not reach here
}

/*
Sec 15.5.2
The unexpected() function shall not return, but it can throw (or re-throw) an
exception. If it throws a
new exception which is allowed by the exception specification which previously
was violated, then the
search for another handler will continue at the call of the function whose
exception specification was vio-
lated.
*/
void shutdown() {
  static const char *s = "shutdown";
  throw s;
}

typedef void(*PFV)();
int main (int argc, char *argv[]) {
  PFV prev_fn = std::set_unexpected(&shutdown);
  goo();
  boo(); // should not reach here
  return 0;
}</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>