ClangSharp icon indicating copy to clipboard operation
ClangSharp copied to clipboard

Bitfield generations for bools generate invalid comparison expressions (and errors)

Open kkukshtel opened this issue 2 years ago • 3 comments

Screen Shot 2023-12-07 at 7 14 25 AM

For the get - "Cannot cast expression of type int to bool" For the set - "Cannot apply operator & to operands of type bool and int.

Here's the relevant struct parts this is generated from:

struct ImGuiDockNode
{
     ...
    bool IsVisible :1;
    bool IsFocused :1;
    bool IsBgDrawnThisFrame :1;
    bool HasCloseButton :1;
    bool HasWindowMenuButton :1;
    bool HasCentralNodeChild :1;
    bool WantCloseAll :1;
    bool WantLockSizeOnce :1;
    bool WantMouseMove :1;
    bool WantHiddenTabBarUpdate :1;
    bool WantHiddenTabBarToggle :1;
};

kkukshtel avatar Dec 07 '23 12:12 kkukshtel

Would a valid library fix here just be doing bool "conversion" by checking > 0 in the get and ternary switching for value in set?

kkukshtel avatar Dec 07 '23 19:12 kkukshtel

Will take a look in a bit. bool is generally tricky to handle due to it working completely differently between C/C++ and C#. Bitfields are apparently a scenario where I'm missing some of the manual conversions and comparisons that would otherwise be required.

In general it requires cond ? 1 : 0 to convert to a bool cond to an integer value and value != 0 to convert an int value to a boolean.

tannergooding avatar Dec 07 '23 21:12 tannergooding