Generic namespaced pointers are dropped
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 62/100
Research direction
Use the minimal example in src/bindgen_entry.h and run the shown bindgen command with C++ parsing enabled. Compare the namespaced pointer alias output with the unnamespaced case, then trace the handling of generic parameters and namespaced template specializations. Done means f is generated with Quux<baz_Foo> and the behavior has a regression test.
Written by the indexing model from the issue text.
Description
In my test program, generic parameters are dropped, leading to incorrect code.
with src/bindgen_entry.h:
namespace baz {
class Foo;
}
template <typename T>
using Quux=T*;
void f(Quux<baz::Foo> bar);
$ bindgen src/bindgen_entry.h -- -x c++
/* automatically generated by rust-bindgen 0.73.2 */
#[repr(C)]
#[derive(Debug)]
pub struct baz_Foo {
_unused: [u8; 0],
}
pub type Quux<T> = *mut T;
unsafe extern "C" {
#[link_name = "\u{1}__Z1fPN3baz3FooE"]
pub fn f(bar: Quux);
}
I would expect to see pub fn f(bar: Quux<baz_Foo>).
If Quux is defined without the pointer, Quux gets ignored entirely (which is likely correct, or at least will compile):
namespace baz {
class Foo;
}
template <typename T>
using Quux=T;
void f(Quux<baz::Foo> bar);
$ bindgen src/bindgen_entry.h -- -x c++
/* automatically generated by rust-bindgen 0.73.2 */
#[repr(C)]
#[derive(Debug)]
pub struct baz_Foo {
_unused: [u8; 0],
}
pub type Quux<T> = T;
unsafe extern "C" {
#[link_name = "\u{1}__Z1fN3baz3FooE"]
pub fn f(bar: baz_Foo);
}
Note, though, that if I drop the namespace in the C++ code, it works as expected, even with the pointer:
class Foo;
template <typename T>
using Quux=T*;
void f(Quux<Foo> bar);
$ bindgen src/bindgen_entry.h -- -x c++
/* automatically generated by rust-bindgen 0.73.2 */
#[repr(C)]
#[derive(Debug)]
pub struct Foo {
_unused: [u8; 0],
}
pub type Quux<T> = *mut T;
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
const _: () = {
["Size of template specialization: Quux_open0_Foo_close0"]
[::std::mem::size_of::<Quux<Foo>>() - 8usize];
["Align of template specialization: Quux_open0_Foo_close0"]
[::std::mem::align_of::<Quux<Foo>>() - 8usize];
};
unsafe extern "C" {
#[link_name = "\u{1}__Z1fP3Foo"]
pub fn f(bar: Quux<Foo>);
}
None of --enable-cxx-namespaces, --disable-name-namespacing, nor --conservative-inline-namespaces correct this behavior.
I believe this is related to, but not quite the same as, https://github.com/rust-lang/rust-bindgen/issues/3373
- Dominant language
- Rust
- Stars
- 5.3k
- Forks
- 846
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 11
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from rust-lang/rust-bindgen
-
--enable-cxx-namespaces panics on namespace [[deprecated]] { ("[" is not a valid Ident)Possibly taken @lwz23 claimed this 47 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
rust-lang/rust-bindgen#3485 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
rust-lang/rust-bindgen#3483 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
rust-lang/rust-bindgen#3370 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
rust-lang/rust-bindgen#3363 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
rust-lang/rust-bindgen#3540 ·
Maintainers usually reply within 1 day
All issues in rust-lang/rust-bindgen
Similar issues
-
yara-x fails to build with rsa 0.10.0: unresolved import rsa::Pkcs1v15SignPossibly taken @CfirTsabari claimed this today. Open
Difficulty 1/5 Under an hour Newbie friendliness 87/100
VirusTotal/yara-x#865 ·
Maintainers usually reply within 1 day
-
good first issue help wanted program
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
hffgzktbcc-blip/ounce-core#297 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
nautechsystems/nautilus_trader#5631 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 69/100
bytecodealliance/rustix#1736 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
longbridge/gpui-kit#3871 ·
Maintainers usually reply within 1 day