Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cpp2rust/converter/converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3088,7 +3088,7 @@ bool Converter::VisitOffsetOfExpr(clang::OffsetOfExpr *expr) {
member_path += GetNamedDeclAsString(node.getField());
}
StrCat(
std::format("::std::mem::offset_of!({}, {}) as u64",
std::format("::std::mem::offset_of!({}, {})",
GetUnsafeTypeAsString(expr->getTypeSourceInfo()->getType()),
member_path));
computed_expr_type_ = ComputedExprType::FreshValue;
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/out/unsafe/offsetof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ pub fn main() {
}
}
unsafe fn main_0() -> i32 {
assert!(((::std::mem::offset_of!(Layout, a) as u64) == (0_u64)));
assert!(((::std::mem::offset_of!(Layout, b) as u64) == (4_u64)));
assert!(((::std::mem::offset_of!(Layout, c) as u64) == (8_u64)));
assert!(((::std::mem::offset_of!(Outer, inner.y) as u64) == (8_u64)));
assert!(((::std::mem::offset_of!(Layout, a)) == (0_usize)));
assert!(((::std::mem::offset_of!(Layout, b)) == (4_usize)));
assert!(((::std::mem::offset_of!(Layout, c)) == (8_usize)));
assert!(((::std::mem::offset_of!(Outer, inner.y)) == (8_usize)));
let mut v: Layout = Layout {
a: 0_u8,
b: 0_u32,
Expand All @@ -43,7 +43,7 @@ unsafe fn main_0() -> i32 {
v.b = 3735928559_u32;
let mut base: *mut u8 = ((&mut v as *mut Layout) as *mut u8);
let mut bp: *mut u32 =
((base.offset((::std::mem::offset_of!(Layout, b) as u64) as isize)) as *mut u32);
((base.offset((::std::mem::offset_of!(Layout, b)) as isize)) as *mut u32);
assert!(((*bp) == (3735928559_u32)));
return 0;
}
Loading