Skip to content

Commit f5c2b67

Browse files
authored
Translate unions in C++ mode (#251)
1 parent 7e308eb commit f5c2b67

4 files changed

Lines changed: 10 additions & 5 deletions

File tree

‎cpp2rust/converter/converter.cpp‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,11 @@ bool Converter::VisitCXXRecordDecl(clang::CXXRecordDecl *decl) {
891891
}
892892
}
893893

894+
EmitRustStructOrUnion(decl);
895+
} else if (decl->isUnion()) {
896+
if (!record_decls_.MarkDefined(GetRecordName(decl))) {
897+
return false;
898+
}
894899
EmitRustStructOrUnion(decl);
895900
} else {
896901
// FIXME: improve error handling

‎tests/unit/out/refcount/union_basic.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ pub fn main() {
4848
std::process::exit(main_0());
4949
}
5050
fn main_0() -> i32 {
51-
let u: Value<basic> = <Value<basic>>::default();
51+
let u: Value<basic> = Rc::new(RefCell::new(<basic>::default()));
5252
(*u.borrow_mut()).i().write(42);
53-
assert!((((((*u.borrow()).i().read()) == 42) as i32) != 0));
53+
assert!((((*u.borrow()).i().read()) == 42));
5454
(*u.borrow_mut()).f().write(3.140000105E+0);
55-
assert!((((((*u.borrow()).f().read()) == 3.140000105E+0) as i32) != 0));
55+
assert!((((*u.borrow()).f().read()) == 3.140000105E+0));
5656
return 0;
5757
}

‎tests/unit/out/unsafe/union_basic.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ pub fn main() {
2525
unsafe fn main_0() -> i32 {
2626
let mut u: basic = <basic>::default();
2727
u.i = 42;
28-
assert!(((((u.i) == (42)) as i32) != 0));
28+
assert!(((u.i) == (42)));
2929
u.f = 3.140000105E+0;
30-
assert!(((((u.f) == (3.140000105E+0)) as i32) != 0));
30+
assert!(((u.f) == (3.140000105E+0)));
3131
return 0;
3232
}

0 commit comments

Comments
 (0)