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_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ bool IsStringLiteralExpr(const clang::Expr *expr) {

bool IsCodeUnitStringLiteral(const clang::StringLiteral *expr) {
return expr->getCharByteWidth() != 1 ||
expr->getKind() == clang::StringLiteralKind::UTF8;
expr->getType()->getArrayElementTypeNoTypeQual()->isChar8Type();
}

bool IsUserDefinedDecl(const clang::Decl *decl) {
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/char_signed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ int main() {
printf("%d %d\n", lit[0], ulit[0]);
printf("%d\n", is_negative(lit));

const char *u8s = u8"\u00e9";
printf("%d %d\n", u8s[0], u8s[1]);

const char *p = "\x80";
printf("%d %d\n", p[0], (unsigned char)p[0]);

Expand Down
6 changes: 6 additions & 0 deletions tests/unit/out/refcount/char_signed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ fn main_0() -> i32 {
"{}",
(({ is_negative_1((lit.as_pointer() as Ptr::<i8>),) }) as i32)
);
let mut u8s: Ptr<i8> = Ptr::<i8>::from_string_literal(b"\xc3\xa9");
println!(
"{} {}",
((elem!(u8s, 0).read()) as i32),
((elem!(u8s, 1).read()) as i32)
);
let mut p: Ptr<i8> = Ptr::<i8>::from_string_literal(b"\x80");
println!(
"{} {}",
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/out/unsafe/char_signed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ unsafe fn main_0() -> i32 {
c"%d\n".as_ptr() as *const i8,
((unsafe { is_negative_1((lit.as_mut_ptr()).cast_const()) }) as i32),
);
let mut u8s: *const libc::c_char = c"\xc3\xa9".as_ptr();
printf(
c"%d %d\n".as_ptr() as *const i8,
((*u8s.offset((0) as isize)) as i32),
((*u8s.offset((1) as isize)) as i32),
);
let mut p: *const libc::c_char = c"\x80".as_ptr();
printf(
c"%d %d\n".as_ptr() as *const i8,
Expand Down
Loading