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

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

Closed
petrochenkov opened this issue Sep 30, 2020 · 1 comment · Fixed by #589
Closed

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

petrochenkov opened this issue Sep 30, 2020 · 1 comment · Fixed by #589

Comments

@petrochenkov
Copy link
Contributor

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++.

@emilio
Copy link
Collaborator

emilio commented Oct 1, 2020

Yeah, I think we should tweak can_handle to handle the kind of expressions we actually support rather than doing it based on the type of the expression...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants