Skip to content

Commit 6cefcbc

Browse files
committed
Add test with opaque C++ type containing lifetime
1 parent 24d4a8b commit 6cefcbc

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

tests/ffi/lib.rs

+9
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,15 @@ pub mod ffi {
209209
type Job = crate::module::ffi::Job;
210210
}
211211

212+
unsafe extern "C++" {
213+
type Borrow<'a>;
214+
215+
fn c_return_borrow<'a>(s: &'a CxxString) -> UniquePtr<Borrow<'a>>;
216+
217+
#[rust_name = "c_return_borrow_elided"]
218+
fn c_return_borrow(s: &CxxString) -> UniquePtr<Borrow>;
219+
}
220+
212221
#[repr(u32)]
213222
#[derive(Hash)]
214223
enum COwnedEnum {

tests/ffi/tests.cc

+6
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@ ::A::B::ABEnum c_return_nested_ns_enum(uint16_t n) {
207207
}
208208
}
209209

210+
Borrow::Borrow(const std::string &s) : s(s) {}
211+
212+
std::unique_ptr<Borrow> c_return_borrow(const std::string &s) {
213+
return std::unique_ptr<Borrow>(new Borrow(s));
214+
}
215+
210216
void c_take_primitive(size_t n) {
211217
if (n == 2020) {
212218
cxx_test_suite_set_correct();

tests/ffi/tests.h

+6
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ enum COwnedEnum {
7777
CVAL2,
7878
};
7979

80+
struct Borrow {
81+
Borrow(const std::string &s);
82+
const std::string &s;
83+
};
84+
8085
size_t c_return_primitive();
8186
Shared c_return_shared();
8287
::A::AShared c_return_ns_shared();
@@ -110,6 +115,7 @@ size_t c_return_sum(size_t n1, size_t n2);
110115
Enum c_return_enum(uint16_t n);
111116
::A::AEnum c_return_ns_enum(uint16_t n);
112117
::A::B::ABEnum c_return_nested_ns_enum(uint16_t n);
118+
std::unique_ptr<Borrow> c_return_borrow(const std::string &s);
113119

114120
void c_take_primitive(size_t n);
115121
void c_take_shared(Shared shared);

0 commit comments

Comments
 (0)