2010-05-11 19:42:16 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2010-05-11 21:36:01 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
2010-05-11 19:42:16 +00:00
|
|
|
//
|
2010-11-16 22:09:02 +00:00
|
|
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
|
|
|
// Source Licenses. See LICENSE.TXT for details.
|
2010-05-11 19:42:16 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2010-08-22 00:31:12 +00:00
|
|
|
|
2010-05-11 19:42:16 +00:00
|
|
|
// test set_unexpected
|
|
|
|
|
|
|
|
#include <exception>
|
|
|
|
#include <cassert>
|
2010-05-14 20:17:42 +00:00
|
|
|
#include <cstdlib>
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
void f1() {}
|
|
|
|
void f2() {}
|
|
|
|
|
2010-05-14 20:17:42 +00:00
|
|
|
void f3()
|
|
|
|
{
|
|
|
|
std::exit(0);
|
|
|
|
}
|
|
|
|
|
2010-05-11 19:42:16 +00:00
|
|
|
int main()
|
|
|
|
{
|
2010-08-22 13:53:14 +00:00
|
|
|
std::unexpected_handler old = std::set_unexpected(f1);
|
2010-05-14 20:17:42 +00:00
|
|
|
// verify there is a previous unexpected handler
|
2010-08-22 13:53:14 +00:00
|
|
|
assert(old);
|
|
|
|
// verify f1 was replace with f2
|
2010-08-22 00:31:12 +00:00
|
|
|
assert(std::set_unexpected(f2) == f1);
|
2010-08-22 13:53:14 +00:00
|
|
|
// verify calling original unexpected handler calls terminate
|
|
|
|
std::set_terminate(f3);
|
|
|
|
(*old)();
|
|
|
|
assert(0);
|
2010-05-11 19:42:16 +00:00
|
|
|
}
|