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
9 changes: 9 additions & 0 deletions cpp2rust/converter/models/converter_refcount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,14 @@ void ConverterRefCount::ConvertDeclRefValue(clang::Expr *expr,

static std::vector<const char *> printf2fmt(std::string &format) {
std::vector<const char *> types;
std::string escaped;
for (char c : format) {
escaped += c;
if (c == '{' || c == '}') {
escaped += c;
}
}
format = std::move(escaped);
size_t pos = 0;
while ((pos = format.find('%', pos)) != std::string::npos) {
if (pos + 1 >= format.size())
Expand Down Expand Up @@ -1181,6 +1189,7 @@ static std::vector<const char *> printf2fmt(std::string &format) {
continue;
}
break;
case 'j':
case 'z':
if (pos + 2 < format.size() &&
(format[pos + 2] == 'd' || format[pos + 2] == 'u')) {
Expand Down
1 change: 1 addition & 0 deletions tests/unit/out/refcount/printfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ fn main_0() -> i32 {
"{}",
(Ptr::<Vec<i8>>::decay(&({ fn2_1(s.as_pointer(),) })) as Ptr<i8>)
);
println!("{{}} {} {}", 5_u64, (-6_i32 as i64));
return 0;
}
pub fn __cpp2rust_init_globals() {}
5 changes: 5 additions & 0 deletions tests/unit/out/unsafe/printfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ unsafe fn main_0() -> i32 {
c"%s\n".as_ptr() as *const i8,
(*(unsafe { fn2_1(&s) })).as_ptr(),
);
printf(
c"{} %ju %jd\n".as_ptr() as *const i8,
5_u64,
(-6_i32 as i64),
);
return 0;
}
pub unsafe fn __cpp2rust_init_globals() {}
2 changes: 2 additions & 0 deletions tests/unit/printfs.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <cassert>
#include <cstdint>
#include <cstdio>
#include <string>

Expand All @@ -18,5 +19,6 @@ int main() {
printf("%s\n", s.data());
printf("%s\n", fn("foo").c_str());
printf("%s\n", fn2(s).c_str());
printf("{} %ju %jd\n", (uintmax_t)5, (intmax_t)-6);
return 0;
}
Loading