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
1 change: 1 addition & 0 deletions cpp2rust/converter/converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2720,6 +2720,7 @@ bool Converter::VisitImplicitCastExpr(clang::ImplicitCastExpr *expr) {
}
case clang::CastKind::CK_ConstructorConversion:
case clang::CastKind::CK_DerivedToBase:
case clang::CastKind::CK_UncheckedDerivedToBase:
Convert(sub_expr);
break;
case clang::CastKind::CK_IntegralToBoolean:
Expand Down
31 changes: 31 additions & 0 deletions tests/unit/out/refcount/stdcopy_ostream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,38 @@ fn main_0() -> i32 {
__out.try_clone().unwrap()
}
};
write!(ofs.as_pointer(), "{:}", 42,);
}
let mut f: Ptr<CFile> = match CFile::open(
&file.decay().to_rust_string(),
&Ptr::<i8>::from_string_literal(b"rb").to_rust_string(),
) {
Some(__f) => Ptr::alloc(__f),
None => Ptr::null(),
};
let buf: Value<Box<[i8]>> = Rc::new(RefCell::new(Box::new([
0_i8, 0_i8, 0_i8, 0_i8, 0_i8, 0_i8, 0_i8, 0_i8, 0_i8, 0_i8, 0_i8, 0_i8, 0_i8, 0_i8, 0_i8,
0_i8, 0_i8, 0_i8, 0_i8, 0_i8, 0_i8, 0_i8, 0_i8, 0_i8, 0_i8, 0_i8, 0_i8, 0_i8, 0_i8, 0_i8,
0_i8, 0_i8,
])));
let mut n: usize = libcc2rs::fread_refcount(
(buf.decay()).to_any(),
1_usize,
::std::mem::size_of::<[i8; 32]>(),
(f).clone(),
);
{
let __r = f.with(|__f| __f.close());
f.delete();
__r
};
assert!((n == 16_usize));
assert!(
({
(((*buf.borrow())[(14) as usize] as i32) == (('4' as i8) as i32))
&& (((*buf.borrow())[(15) as usize] as i32) == (('2' as i8) as i32))
})
);
match nix::unistd::unlink(file.decay().to_rust_string().as_str()) {
Ok(()) => 0,
Err(__e) => {
Expand Down
48 changes: 48 additions & 0 deletions tests/unit/out/unsafe/stdcopy_ostream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,55 @@ unsafe fn main_0() -> i32 {
__out.try_clone().unwrap()
}
};
write!(ofs, "{:}", 42,);
}
let mut f: *mut ::libc::FILE = libc::fopen(file.as_ptr(), c"rb".as_ptr());
let mut buf: [libc::c_char; 32] = [
(0 as libc::c_char),
(0 as libc::c_char),
(0 as libc::c_char),
(0 as libc::c_char),
(0 as libc::c_char),
(0 as libc::c_char),
(0 as libc::c_char),
(0 as libc::c_char),
(0 as libc::c_char),
(0 as libc::c_char),
(0 as libc::c_char),
(0 as libc::c_char),
(0 as libc::c_char),
(0 as libc::c_char),
(0 as libc::c_char),
(0 as libc::c_char),
(0 as libc::c_char),
(0 as libc::c_char),
(0 as libc::c_char),
(0 as libc::c_char),
(0 as libc::c_char),
(0 as libc::c_char),
(0 as libc::c_char),
(0 as libc::c_char),
(0 as libc::c_char),
(0 as libc::c_char),
(0 as libc::c_char),
(0 as libc::c_char),
(0 as libc::c_char),
(0 as libc::c_char),
(0 as libc::c_char),
(0 as libc::c_char),
];
let mut n: usize = libcc2rs::fread_unsafe(
(buf.as_mut_ptr() as *mut ::libc::c_void),
1_usize,
::std::mem::size_of::<[libc::c_char; 32]>(),
f,
);
libc::fclose(f);
assert!(((n) == (16_usize)));
assert!(
((buf[(14) as usize] as i32) == (('4' as libc::c_char) as i32))
&& ((buf[(15) as usize] as i32) == (('2' as libc::c_char) as i32))
);
libc::unlink(file.as_ptr());
return 0;
}
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/stdcopy_ostream.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <fstream>
#include <iterator>
#include <string>
Expand All @@ -10,7 +12,14 @@ int main() {
{
std::ofstream ofs(file, std::ios::binary);
std::copy(str.begin(), str.end(), std::ostream_iterator<char>(ofs));
ofs << 42;
}
FILE *f = fopen(file, "rb");
char buf[32] = {0};
size_t n = fread(buf, 1, sizeof(buf), f);
fclose(f);
assert(n == 16);
assert(buf[14] == '4' && buf[15] == '2');
unlink(file);
return 0;
}
Loading