rust-lang / rust-lang/rust-bindgen
Invalid generated code with C++ templated static constant.
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 5.3k
- Forks
- 829
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 15
Description
Input C/C++ Header
template <class temp>
class MyClass {
public:
MyClass(){}
temp options;
static MyClass *first;
};
template <class temp> MyClass<temp> *MyClass<temp>::first = nullptr;
Bindgen Invocation
$ bindgen wrapper.hpp -- -x c++
Actual Results
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct MyClass<temp> {
pub options: temp,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<temp>>,
}
extern "C" {
pub static mut first: *mut MyClass<temp>;
}
If you try to compile this, you get:
error[E0412]: cannot find type `temp` in this scope
--> src/main.rs:15:40
|
15 | pub static mut first: *mut MyClass<temp>;
| ^^^^ not found in this scope
Expected Results
No compile errors?
Mitigation
Removing
static MyClass *first;
and
template <class temp> MyClass<temp> *MyClass<temp>::first = nullptr;
and inserting
static MyClass *first = nullptr;
If I'm not wrong, it is equivalent.
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 report with the shown wrapper.hpp input and bindgen wrapper.hpp -- -x c++, then inspect the generated MyClass<temp> binding and its first declaration. Done means the generated Rust no longer refers to the undeclared temp type and compiles for this templated static-constant case; no source file or test is named in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100