Skip to content

Invalid generated code with C++ templated static constant. #1838

Open
@Volker-Weissmann

Description

@Volker-Weissmann

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions