Skip to content

Generics missing when allowlist_recursively is false #3373

@DexterHill0

Description

@DexterHill0

Take this example C++ code:

#pragma once

template <typename Type> class Vector2 {
  Type x;
  Type y;
};

template <typename Type> class Rectangle {
public:
  using Vector2Type = Vector2<Type>;

  Vector2Type p0;
  Vector2Type p1;
};

using Vector2f = Vector2<float>;
using Rectanglef = Rectangle<float>;

The bindings generated by bindgen when allowlist_recursively is false are:

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Vector2<Type> {
    pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<Type>>,
    x: Type,
    y: Type,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Rectangle<Type> {
    pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<Type>>,
    pub p0: Rectangle_Vector2Type,
    pub p1: Rectangle_Vector2Type,
}
pub type Rectangle_Vector2Type = Vector2<Type>;
pub type Vector2f = Vector2<f32>;
pub type Rectanglef = Rectangle<f32>;

The generic type from Rectangle_Vector2Type has been dropped and the code is no longer valid. Setting allowlist_recursively to true will generate the correct code:

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Rectangle<Type> {
    pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<Type>>,
    pub p0: Rectangle_Vector2Type<Type>,
    pub p1: Rectangle_Vector2Type<Type>,
}
pub type Rectangle_Vector2Type<Type> = Vector2<Type>;

Adding in more allowlist types, like Vector2Type or Rectangle::Vector2Type still does not prevent the generic from being generated correctly.

Bindgen version: 0.72.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions