Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bindgen cannot generate Default trait for enum #2748

Open
Forsworns opened this issue Feb 5, 2024 · 0 comments
Open

bindgen cannot generate Default trait for enum #2748

Forsworns opened this issue Feb 5, 2024 · 0 comments

Comments

@Forsworns
Copy link

I don't know if this is a bug, or it is by design.

Input C/C++ Header

A minimal header

typedef enum cudaError_enum {
    CUDA_SUCCESS = 0,
    CUDA_ERROR_INVALID_VALUE = 1,
    CUDA_ERROR_OUT_OF_MEMORY = 2,
};

Bindgen Invocation

With bindgen 0.69.4.

bindgen \
    --default-enum-style=newtype \
    --with-derive-default \
    header.h

Actual Results

impl cudaError_enum {
    pub const CUDA_SUCCESS: cudaError_enum = cudaError_enum(0);
}
impl cudaError_enum {
    pub const CUDA_ERROR_INVALID_VALUE: cudaError_enum = cudaError_enum(1);
}
impl cudaError_enum {
    pub const CUDA_ERROR_OUT_OF_MEMORY: cudaError_enum = cudaError_enum(2);
}
#[repr(transparent)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct cudaError_enum(pub ::std::os::raw::c_uint);

Expected Results

Currently I have to use

bindgen \
    --default-enum-style=newtype \
    --with-derive-default \
    --with-derive-custom .*_enum=Default \ 
    header.h

to generate

impl cudaError_enum {
    pub const CUDA_SUCCESS: cudaError_enum = cudaError_enum(0);
}
impl cudaError_enum {
    pub const CUDA_ERROR_INVALID_VALUE: cudaError_enum = cudaError_enum(1);
}
impl cudaError_enum {
    pub const CUDA_ERROR_OUT_OF_MEMORY: cudaError_enum = cudaError_enum(2);
}
#[repr(transparent)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, Default)]
pub struct cudaError_enum(pub ::std::os::raw::c_uint);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant