15a83710eSEric Fiselier //===----------------------------------------------------------------------===// 25a83710eSEric Fiselier // 357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 65a83710eSEric Fiselier // 75a83710eSEric Fiselier //===----------------------------------------------------------------------===// 85a83710eSEric Fiselier 9*31cbe0f2SLouis Dionne // REQUIRES: c++03 || c++11 || c++14 102a1bfa98SEric Fiselier 115a83710eSEric Fiselier // test set_unexpected 125a83710eSEric Fiselier 135a83710eSEric Fiselier #include <exception> 145a83710eSEric Fiselier #include <cassert> 155a83710eSEric Fiselier #include <cstdlib> 165a83710eSEric Fiselier 177fc6a556SMarshall Clow #include "test_macros.h" 187fc6a556SMarshall Clow f1()195a83710eSEric Fiseliervoid f1() {} f2()205a83710eSEric Fiseliervoid f2() {} 215a83710eSEric Fiselier f3()225a83710eSEric Fiseliervoid f3() 235a83710eSEric Fiselier { 245a83710eSEric Fiselier std::exit(0); 255a83710eSEric Fiselier } 265a83710eSEric Fiselier main(int,char **)272df59c50SJF Bastienint main(int, char**) 285a83710eSEric Fiselier { 295a83710eSEric Fiselier std::unexpected_handler old = std::set_unexpected(f1); 305a83710eSEric Fiselier // verify there is a previous unexpected handler 315a83710eSEric Fiselier assert(old); 325a83710eSEric Fiselier // verify f1 was replace with f2 335a83710eSEric Fiselier assert(std::set_unexpected(f2) == f1); 345a83710eSEric Fiselier // verify calling original unexpected handler calls terminate 355a83710eSEric Fiselier std::set_terminate(f3); 365a83710eSEric Fiselier (*old)(); 375a83710eSEric Fiselier assert(0); 382df59c50SJF Bastien 392df59c50SJF Bastien return 0; 405a83710eSEric Fiselier } 41