brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · e4533a0 Raw
45 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// test get_unexpected10 11// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS12 13#include <exception>14#include <cassert>15#include <cstdlib>16 17#include "test_macros.h"18 19void f1() {}20void f2() {}21 22void f3()23{24    std::exit(0);25}26 27int main(int, char**)28{29 30    std::unexpected_handler old = std::get_unexpected();31    // verify there is a previous unexpected handler32    assert(old);33    std::set_unexpected(f1);34    assert(std::get_unexpected() == f1);35    // verify f1 was replace with f236    std::set_unexpected(f2);37    assert(std::get_unexpected() == f2);38    // verify calling original unexpected handler calls terminate39    std::set_terminate(f3);40    (*old)();41    assert(0);42 43  return 0;44}45