Skip to content

Commit bdff5db

Browse files
authored
Merge pull request #1110 from bsilver8192/subclass-std
Fix and test subclasses with C++ std in scope
2 parents 922f98b + 4ae4d47 commit bdff5db

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

engine/src/conversion/codegen_rs/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ impl<'a> RsCodeGenerator<'a> {
831831
.as_ref()
832832
.#borrow()
833833
.expect(#reentrancy_panic_msg);
834-
let r = std::ops::#deref_ty::#deref_call(& #mut_token b);
834+
let r = ::std::ops::#deref_ty::#deref_call(& #mut_token b);
835835
#methods_trait :: #method_name
836836
(r,
837837
#args)

integration-tests/tests/integration_test.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7587,6 +7587,49 @@ fn test_non_pv_subclass_simple() {
75877587
);
75887588
}
75897589

7590+
#[test]
7591+
/// Tests the Rust code generated for subclasses when there's a `std` module in scope representing
7592+
/// the C++ `std` namespace. This breaks if any of the generated Rust code fails to fully qualify
7593+
/// its references to the Rust `std`.
7594+
fn test_subclass_with_std() {
7595+
let hdr = indoc! {"
7596+
#include <cstdint>
7597+
#include <chrono>
7598+
7599+
class Observer {
7600+
public:
7601+
Observer() {}
7602+
virtual void foo() const {}
7603+
virtual ~Observer() {}
7604+
7605+
void unused(std::chrono::nanoseconds) {}
7606+
};
7607+
"};
7608+
run_test_ex(
7609+
"",
7610+
hdr,
7611+
quote! {
7612+
let obs = MyObserver::new_rust_owned(MyObserver { a: 3, cpp_peer: Default::default() });
7613+
obs.borrow().foo();
7614+
},
7615+
quote! {
7616+
subclass!("Observer",MyObserver)
7617+
},
7618+
None,
7619+
None,
7620+
Some(quote! {
7621+
use autocxx::subclass::CppSubclass;
7622+
use ffi::Observer_methods;
7623+
#[autocxx::subclass::subclass]
7624+
pub struct MyObserver {
7625+
a: u32
7626+
}
7627+
impl Observer_methods for MyObserver {
7628+
}
7629+
}),
7630+
);
7631+
}
7632+
75907633
#[test]
75917634
fn test_two_subclasses() {
75927635
let hdr = indoc! {"

0 commit comments

Comments
 (0)