rust-bindgen icon indicating copy to clipboard operation
rust-bindgen copied to clipboard

std::size_t declared with using ::size_t does not get usize treatment

Open capickett opened this issue 7 months ago • 1 comments

Input C/C++ Header

using size_t = decltype(sizeof(0));

namespace std { inline namespace __1 {
#ifdef BROKEN
using ::size_t;
#else
using size_t = ::size_t;
#endif
}}

void foo(std::size_t i);

Bindgen Invocation

$ bindgen usize_issue.h -- -x c++ --std=c++11 -DBROKEN

Actual Results

/* automatically generated by rust-bindgen 0.69.4 */

extern "C" {
    #[link_name = "\u{1}__Z3foom"]
    pub fn foo(i: ::std::os::raw::c_ulong);
}

Expected Results

/* automatically generated by rust-bindgen 0.69.4 */

extern "C" {
    #[link_name = "\u{1}__Z3foom"]
    pub fn foo(i: usize);
}

Debugging notes

I ran this on my local m1 macbook pro using Xcode 15.1 toolchain.

Dumping the ast via --emit-clang-ast shows the working version as having a TypeAliasDecl with spelling "size_t", with type.kind = Typedef. The broken version has a UsingDeclaration with spelling "size_t" and type.kind = Invalid. I suspect the UsingDeclaration + Invalid type here is causing some issues within bindgen.

capickett avatar Jul 18 '24 17:07 capickett