Open abalogstromer opened 1 month ago
thanks for filling an issue.
It is true that using a C++ keyword as a name of a field of an exported struct (or the name of an exported component/struct) will result as an error.
(In rust we workaround that with r#
raw identifier, but that's not possible in C++)
The solution would probably be to somehow "mangle" such names, eg: rename it to delete_
or something like that. Or just forbid it in the compiler by throwing a slint compiler error when using such name and integrating with C++
I had this issue again, but with default
this time. Probably the best fit for C++ would be to prefix/suffix the generated part with, as you mentioned, an underscore _
or anything that would fit for a generated code.
This should be fixable in cpp.rs
One easy way to solve this is to change the ident
function to rename the identifier matching C++ keywords to something else. That's generic and is applied to every identifier, also struct name, component name and such.
I found an issue where if you expose a struct from slint to C++, depending on the fields name, it could come in conflict with C++ specific keywords (e.g. delete). Here is an example:
generates the following:
Since
delete
is a keyword used in C++, the build failed with the following:error: expected unqualified-id before ‘delete’
As a workaround, I am using a different name of the variable. I think the generated code should be valid regardless of the namings used in slint code.