Skip to content

"Unhandled const definition" on a constant with a type alias (typedef) type #583

Closed
@petrochenkov

Description

@petrochenkov
type MyInt = i32;

const MY_CONST: MyInt = 10;

cbindgen will produce a "Unhandled const definition" error on MY_CONST because MyInt is not a "can_handle" type
https://github.com/eqrion/cbindgen/blob/1fc4cb072422e722f8bcb3af5766f84587a180c6/src/bindgen/ir/constant.rs#L393-L395
https://github.com/eqrion/cbindgen/blob/1fc4cb072422e722f8bcb3af5766f84587a180c6/src/bindgen/ir/constant.rs#L366-L374

The "can_handle" restriction looks artificial and unnecessary, if it is commented out, then the correct constant definition is generated.

// C++
static const MyInt MY_CONST = 10;

// C
#define MY_CONST 10

In both cases it doesn't matter what MyInt actually is, cbindgen just can put it into the constant definition textually and it will work in most cases if the right hand side can be converted to C/C++.

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