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
3 changes: 3 additions & 0 deletions cpp2rust/converter/converter_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,9 @@ bool RustSizeDivergesFromC(clang::QualType qt) {
if (auto *arr = qt->getAsArrayTypeUnsafe()) {
return RustSizeDivergesFromC(arr->getElementType());
}
if (qt->isPointerType()) {
return true;
}
return false;
}

Expand Down
7 changes: 7 additions & 0 deletions tests/unit/out/refcount/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ use std::io::prelude::*;
use std::io::{Read, Seek, Write};
use std::os::fd::AsFd;
use std::rc::{Rc, Weak};
const _: () = assert!(
(::std::mem::size_of::<usize>() == 8usize),
"sizeof(std::size_t) == sizeof(void *)"
);
const _: () = assert!((8usize == 8_usize), "sizeof(int *) == 8");
pub fn main() {
__cpp2rust_init_globals();
std::process::exit(main_0());
Expand Down Expand Up @@ -42,6 +47,8 @@ fn main_0() -> i32 {
assert!(((xld * 2_f64) == 3_f64));
assert!(((((xwc + (xc8 as i32)) + (xc16 as i32)) as u32).wrapping_add(xc32) == 266_u32));
assert!((AnyPtr::default()).is_null());
let mut ip: Ptr<i32> = Ptr::<i32>::null();
assert!((8usize == 8usize));
return 0;
}
pub fn __cpp2rust_init_globals() {}
12 changes: 12 additions & 0 deletions tests/unit/out/unsafe/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ use std::collections::BTreeMap;
use std::io::{Read, Seek, Write};
use std::os::fd::{AsFd, FromRawFd, IntoRawFd};
use std::rc::Rc;
const _: () = assert!(
((::std::mem::size_of::<usize>()) == (::std::mem::size_of::<*mut ::libc::c_void>())),
"sizeof(std::size_t) == sizeof(void *)"
);
const _: () = assert!(
((::std::mem::size_of::<*mut i32>()) == (8_usize)),
"sizeof(int *) == 8"
);
pub fn main() {
unsafe {
__cpp2rust_init_globals();
Expand Down Expand Up @@ -44,6 +52,10 @@ unsafe fn main_0() -> i32 {
assert!((((xld) * (2_f64)) == (3_f64)));
assert!(((((((xwc) + (xc8 as i32)) + (xc16 as i32)) as u32).wrapping_add(xc32)) == (266_u32)));
assert!((std::ptr::null_mut::<::libc::c_void>()).is_null());
let mut ip: *mut i32 = std::ptr::null_mut();
assert!(
((::std::mem::size_of::<*mut i32>()) == (::std::mem::size_of::<*mut ::libc::c_void>()))
);
return 0;
}
pub unsafe fn __cpp2rust_init_globals() {}
5 changes: 5 additions & 0 deletions tests/unit/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include <cstdint>
#include <inttypes.h>

static_assert(sizeof(std::size_t) == sizeof(void *), "");
static_assert(sizeof(int *) == 8, "");

int main() {
const uint8_t xu8 = 8;
const uint16_t xu16 = 16;
Expand All @@ -27,5 +30,7 @@ int main() {
assert(xld * 2 == 3);
assert(xwc + xc8 + xc16 + xc32 == 266);
assert(xnp == nullptr);
int *ip = nullptr;
assert(sizeof(ip) == sizeof(void *));
return 0;
}
Loading