rust-lang / rust-lang/rust-bindgen
Template specialization
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 5.3k
- Forks
- 829
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 15
Description
Hi,
bindgen ignore template specialization for class (and struct) and select the first "working answer".
For example :
template <typename T>
class test;
template<>
class test<int> {
int foo;
};
template<>
class test<float> {
float foo;
};
give
test.hpp:1:9: warning: #pragma once in main file [-Wpragma-once-outside-header]
/* automatically generated by rust-bindgen */
#[repr(C)]
#[derive(Debug, Copy)]
pub struct Struct_test {
pub foo: ::std::os::raw::c_int,
}
impl ::std::clone::Clone for Struct_test {
fn clone(&self) -> Self { *self }
}
#[test]
fn bindgen_test_layout_Struct_test() {
assert_eq!(::std::mem::size_of::<Struct_test>() , 4usize);
assert_eq!(::std::mem::align_of::<Struct_test>() , 4usize);
}
The float specialization is ignored.
And with a valid test<T>:
template <typename T>
class test{};
template<>
class test<int> {
int foo;
};
template<>
class test<float> {
float foo;
};
gives :
test.hpp:1:9: warning: #pragma once in main file [-Wpragma-once-outside-header]
/* automatically generated by rust-bindgen */
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Struct_test<T> {
pub _phantom0: ::std::marker::PhantomData<T>,
}
Both the float and int specialization are ignored.
Contributor 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.
Research direction
Reproduce the issue using the two C++ examples and compare the generated Rust output with the reported results. Trace how bindgen handles class template declarations and explicit specializations; done means distinct int and float specializations are represented rather than silently discarded, with coverage for both examples.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, rust
- Domain
- compilers, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100