xref: /llvm-project/libcxxabi/test/noexception2.pass.cpp (revision eb8650a75793b2bd079d0c8901ff066f129061da)
1*eb8650a7SLouis Dionne //===----------------------------------------------------------------------===//
257e446daSAsiri Rathnayake //
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
657e446daSAsiri Rathnayake //
757e446daSAsiri Rathnayake //===----------------------------------------------------------------------===//
857e446daSAsiri Rathnayake 
931cbe0f2SLouis Dionne // UNSUPPORTED: c++03
108c61114cSLouis Dionne // REQUIRES: no-exceptions
1157e446daSAsiri Rathnayake 
1257e446daSAsiri Rathnayake #include <cxxabi.h>
1357e446daSAsiri Rathnayake #include <exception>
1457e446daSAsiri Rathnayake #include <cassert>
1557e446daSAsiri Rathnayake #include <stdlib.h>
1657e446daSAsiri Rathnayake 
1757e446daSAsiri Rathnayake // namespace __cxxabiv1 {
1857e446daSAsiri Rathnayake //      void __cxa_decrement_exception_refcount(void *thrown_object) throw();
1957e446daSAsiri Rathnayake // }
2057e446daSAsiri Rathnayake 
2157e446daSAsiri Rathnayake unsigned gCounter = 0;
2257e446daSAsiri Rathnayake 
my_terminate()2357e446daSAsiri Rathnayake void my_terminate() { exit(0); }
2457e446daSAsiri Rathnayake 
main()2557e446daSAsiri Rathnayake int main ()
2657e446daSAsiri Rathnayake {
2757e446daSAsiri Rathnayake     // should not call std::terminate()
2857e446daSAsiri Rathnayake     __cxxabiv1::__cxa_decrement_exception_refcount(nullptr);
2957e446daSAsiri Rathnayake 
3057e446daSAsiri Rathnayake     std::set_terminate(my_terminate);
3157e446daSAsiri Rathnayake 
3257e446daSAsiri Rathnayake     // should call std::terminate()
3357e446daSAsiri Rathnayake     __cxxabiv1::__cxa_decrement_exception_refcount((void*) &gCounter);
3457e446daSAsiri Rathnayake     assert(false);
3557e446daSAsiri Rathnayake 
3657e446daSAsiri Rathnayake     return 0;
3757e446daSAsiri Rathnayake }
38