| Issue |
174577
|
| Summary |
Preprocessor directive indentation doesn’t follow code indentation
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
sd016808
|
Hi,
I’m running into an indentation behavior with C/C++ preprocessor directives that makes the formatted output look inconsistent with the surrounding code.
Reproduction
Input (desired style / already aligned with code indentation):
```c
#if I2C
typedef struct rx
{
uint8_t id;
union
{
#if (EN == 1)
hid_cert_status_segment_t cert_status_segment;
#endif
uint8_t input_mode;
hid_switch_mode_t switch_mode;
uint8_t aaa_mode;
hid_reg_data_t reg_data;
uint8_t bbb_data[BURST_SIZE];
hid_reg_data_t ccc_data;
#if (CLIENT_ENABLE == 1)
client_hid_data_t data;
#endif
} hid_data;
} rx_report_t;
#pragma pack()
typedef union tx
{
hid_desc_t desc;
struct
{
uint16_t len;
uint8_t id;
hid_data_t report;
};
} tx_data_t;
#endif
```
Formatted output I get:
```c
#if I2C
typedef struct rx
{
uint8_t id;
union
{
#if (EN == 1)
hid_cert_status_segment_t cert_status_segment;
#endif
uint8_t input_mode;
hid_switch_mode_t switch_mode;
uint8_t latency_mode;
hid_reg_data_t aaa_data;
uint8_t bbb_data[BURST_SIZE];
hid_reg_data_t ccc_data;
#if (CLIENT_ENABLE == 1)
client_hid_data_t data;
#endif
} hid_data;
} rx_report_t;
#pragma pack()
typedef union tx
{
desc_t desc;
struct
{
uint16_t en;
uint8_t id;
hid_data_t report;
};
} tx_data_t;
#endif
```
```yaml
IndentWidth: 4
TabWidth: 4
UseTab: Never
ColumnLimit: 150
SortIncludes: true
PPIndentWidth: -1
IndentPPDirectives: BeforeHash
```
This makes the code harder to read because the PP blocks no longer visually belong to the scope they are in. It feels like “PP indentation only follows PP”, instead of following the actual code structure.
Ultimately, my goal is for the formatter output to match my original input style—i.e., keep the same indentation and alignment behavior I used, instead of re-aligning preprocessor directives independently.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs