Skip to content

Commit f60ab62

Browse files
committed
Update tests
1 parent c889b9a commit f60ab62

3 files changed

Lines changed: 15 additions & 4 deletions

File tree

cpp2rust/converter/converter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,8 +1944,8 @@ bool Converter::VisitImplicitCastExpr(clang::ImplicitCastExpr *expr) {
19441944
}
19451945
bool dest_pointee_const =
19461946
expr->getType()->getPointeeType().isConstQualified();
1947-
if (const auto *member = clang::dyn_cast<clang::MemberExpr>(
1948-
sub_expr->IgnoreParenImpCasts());
1947+
if (const auto *member =
1948+
clang::dyn_cast<clang::MemberExpr>(sub_expr->IgnoreParenImpCasts());
19491949
member && IsCharArrayFieldFromLibc(member->getMemberDecl())) {
19501950
PushParen paren(*this);
19511951
Convert(sub_expr);

tests/unit/libc_char_ptr_field.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// no-compile: refcount
2+
#include <dirent.h>
23
#include <pwd.h>
34
#include <unistd.h>
45

@@ -8,5 +9,11 @@ int main(void) {
89
return 0;
910
}
1011
char *home = pw->pw_dir;
11-
return home == 0;
12+
13+
struct dirent *d = readdir(opendir("/tmp"));
14+
// d_name is a char array which gets translated as i8. We model chars as u8 in
15+
// Rust.
16+
char *dname = d->d_name;
17+
18+
return 0;
1219
}

tests/unit/out/unsafe/libc_char_ptr_field.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,9 @@ unsafe fn main_0() -> i32 {
1717
return 0;
1818
}
1919
let mut home: *mut u8 = ((*pw).pw_dir as *mut u8);
20-
return (((home).is_null()) as i32);
20+
let mut d: *mut dirent = libc::readdir(libc::opendir(
21+
(b"/tmp\0".as_ptr().cast_mut()).cast_const() as *const i8,
22+
));
23+
let mut dname: *mut u8 = ((*d).d_name.as_mut_ptr() as *mut u8);
24+
return 0;
2125
}

0 commit comments

Comments
 (0)