Menu

#534 Format breaks when bit field width is a preprocessor object

closed-fixed
None
2023-04-01
2020-02-06
wto605
No

I'm seeing the following behavior on the latest (and a few older) versions of astyle where using a #define object as a bit field width causes unexpected line break and indentation.

This format is held:

typedef struct {
    uint32_t member_1 : 16;
    uint32_t member_2 : 16;
    bool (*func)(void);
}

So I would expect this to be valid

#define MY_BITFIELD_WIDTH
typedef struct {
    uint32_t member_1 : MY_BITFIELD_WIDTH;
    uint32_t member_2 : MY_BITFIELD_WIDTH;
    bool (*func)(void);
}

Instead it is re-formated:

#define MY_BITFIELD_WIDTH
typedef struct {
uint32_t member_1 :
    MY_BITFIELD_WIDTH;
uint32_t member_2 :
    MY_BITFIELD_WIDTH;
    bool (*func)(void);
}

I can at least keep valid C using --keep-one-line-statements, but this is still misindented

#define MY_BITFIELD_WIDTH
typedef struct {
uint32_t member_1 : MY_BITFIELD_WIDTH;
uint32_t member_2 : MY_BITFIELD_WIDTH;
    bool (*func)(void);
}

Other notes:
1) This does not seem to be impacted by any options, but I am running in otbs style.
2) All availiable --indent-... options have no effect (with or without --keep-one-line-statements)

Discussion

  • André Simon

    André Simon - 2023-01-30
    • status: open --> open-accepted
    • assigned_to: André Simon
     
  • André Simon

    André Simon - 2023-02-17
    • status: open-accepted --> open-fixed
     
  • André Simon

    André Simon - 2023-02-17

    Fixed in 3.2 beta

     
  • André Simon

    André Simon - 2023-04-01
    • status: open-fixed --> closed-fixed
     

Log in to post a comment.