]> git.lizzy.rs Git - rust.git/blob - tests/run-make-fulldeps/foreign-double-unwind/foo.cpp
Rollup merge of #105526 - Xiretza:iter-from-generator-derive, r=scottmcm
[rust.git] / tests / run-make-fulldeps / foreign-double-unwind / foo.cpp
1 #include <cstdio>
2 #include <exception>
3
4 void println(const char* s) {
5     puts(s);
6     fflush(stdout);
7 }
8
9 struct outer_exception {};
10 struct inner_exception {};
11
12 extern "C" {
13     void throw_cxx_exception() {
14         if (std::uncaught_exception()) {
15             println("throwing inner C++ exception");
16             throw inner_exception();
17         } else {
18             println("throwing outer C++ exception");
19             throw outer_exception();
20         }
21     }
22
23     void cxx_catch_callback(void (*cb)()) {
24         try {
25             cb();
26             println("unreachable: callback returns");
27         } catch (outer_exception) {
28             println("unreachable: caught outer exception in catch (...)");
29         } catch (inner_exception) {
30             println("unreachable: caught inner exception in catch (...)");
31         }
32     }
33 }