Skip to content

Commit 23156f4

Browse files
committed
Add correct rules for std::size_t
1 parent 5864ed7 commit 23156f4

4 files changed

Lines changed: 29 additions & 0 deletions

File tree

‎cpp2rust/converter/printer.cpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ std::string ToString(clang::ASTContext &ctx, clang::QualType qual_type,
141141
return ToString(ctx, ctx.getCanonicalTagType(record)) +
142142
"::" + decl->getNameAsString();
143143
}
144+
if (decl->getDeclContext()->getRedeclContext()->isNamespace()) {
145+
std::string name;
146+
llvm::raw_string_ostream os(name);
147+
decl->printQualifiedName(os, getPrintPolicy(ctx));
148+
return name;
149+
}
144150
return decl->getNameAsString();
145151
}
146152
} else if (const auto *predef = t->getAs<clang::PredefinedSugarType>()) {

‎rules/cstddef/src.cpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
#include <cstddef>
55

66
using t1 = std::byte;
7+
typedef std::size_t t9;
8+
typedef std::size_t *t10;
9+
typedef const std::size_t *t11;
710

811
std::byte f1(const std::byte &a0, unsigned a1) { return operator<<(a0, a1); }
912

‎rules/cstddef/tgt_refcount.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,11 @@ fn t7() -> Ptr::<isize> {
1818
fn t8() -> Ptr::<isize> {
1919
Ptr::<isize>::null()
2020
}
21+
22+
fn t10() -> Ptr::<usize> {
23+
Ptr::<usize>::null()
24+
}
25+
26+
fn t11() -> Ptr::<usize> {
27+
Ptr::<usize>::null()
28+
}

‎rules/cstddef/tgt_unsafe.rs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ fn t8() -> *const isize {
3333
std::ptr::null()
3434
}
3535

36+
fn t9() -> usize {
37+
0_usize
38+
}
39+
40+
fn t10() -> *mut usize {
41+
std::ptr::null_mut()
42+
}
43+
44+
fn t11() -> *const usize {
45+
std::ptr::null()
46+
}
47+
3648
fn f1(a0: &mut u8, a1: u32) -> u8 {
3749
*a0 << a1
3850
}

0 commit comments

Comments
 (0)