Skip to content

Commit

Permalink
Merge pull request #1110 from bsilver8192/subclass-std
Browse files Browse the repository at this point in the history
Fix and test subclasses with C++ std in scope
  • Loading branch information
adetaylor authored May 29, 2022
2 parents 922f98b + 4ae4d47 commit bdff5db
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion engine/src/conversion/codegen_rs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ impl<'a> RsCodeGenerator<'a> {
.as_ref()
.#borrow()
.expect(#reentrancy_panic_msg);
let r = std::ops::#deref_ty::#deref_call(& #mut_token b);
let r = ::std::ops::#deref_ty::#deref_call(& #mut_token b);
#methods_trait :: #method_name
(r,
#args)
Expand Down
43 changes: 43 additions & 0 deletions integration-tests/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7587,6 +7587,49 @@ fn test_non_pv_subclass_simple() {
);
}

#[test]
/// Tests the Rust code generated for subclasses when there's a `std` module in scope representing
/// the C++ `std` namespace. This breaks if any of the generated Rust code fails to fully qualify
/// its references to the Rust `std`.
fn test_subclass_with_std() {
let hdr = indoc! {"
#include <cstdint>
#include <chrono>
class Observer {
public:
Observer() {}
virtual void foo() const {}
virtual ~Observer() {}
void unused(std::chrono::nanoseconds) {}
};
"};
run_test_ex(
"",
hdr,
quote! {
let obs = MyObserver::new_rust_owned(MyObserver { a: 3, cpp_peer: Default::default() });
obs.borrow().foo();
},
quote! {
subclass!("Observer",MyObserver)
},
None,
None,
Some(quote! {
use autocxx::subclass::CppSubclass;
use ffi::Observer_methods;
#[autocxx::subclass::subclass]
pub struct MyObserver {
a: u32
}
impl Observer_methods for MyObserver {
}
}),
);
}

#[test]
fn test_two_subclasses() {
let hdr = indoc! {"
Expand Down

0 comments on commit bdff5db

Please sign in to comment.