From 5f080172ad8e31dde26f984b7103e2fd7b0ea6b2 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 30 Aug 2024 14:50:20 -0700 Subject: [PATCH] Add test that opaque C++ types are unwind-safe --- tests/test.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/test.rs b/tests/test.rs index 5c6ff16fe..cecfe4e30 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -11,11 +11,12 @@ clippy::unseparated_literal_suffix )] -use cxx::SharedPtr; +use cxx::{SharedPtr, UniquePtr}; use cxx_test_suite::module::ffi2; use cxx_test_suite::{cast, ffi, R}; use std::cell::Cell; use std::ffi::CStr; +use std::panic; thread_local! { static CORRECT: Cell = const { Cell::new(false) }; @@ -380,3 +381,10 @@ fn test_raw_ptr() { assert_eq!(2025, unsafe { ffi::c_take_const_ptr(c3) }); assert_eq!(2025, unsafe { ffi::c_take_mut_ptr(c3 as *mut ffi::C) }); // deletes c3 } + +#[test] +fn test_unwind_safe() { + fn inspect(_c: &ffi::C) {} + let _unwind_safe = |c: UniquePtr| panic::catch_unwind(|| drop(c)); + let _ref_unwind_safe = |c: &ffi::C| panic::catch_unwind(|| inspect(c)); +}