| Issue |
165185
|
| Summary |
[clang-format] clang-format is not idempotent when a struct field with an all-caps typedef name wraps due to long comment
|
| Labels |
clang-format
|
| Assignees |
|
| Reporter |
chuyingy
|
### Description
clang-format produces inconsistent output between consecutive runs when a struct member uses an all-caps typedef name and the line contains a long trailing comment that exceeds the column limit.
On the first run, clang-format breaks the declaration across two lines and indents the wrapped line relative to the type name. On the second run, it removes this indent and aligns the continuation line with the type, resulting in non-idempotent output.
This may occur because clang-format fails to recognize an all-caps type name on a separate line as a typedef and instead treats it as a macro. Typedef names that use mixed upper- and lowercase letters are recognized correctly and do not trigger this behavior.
### Steps to Reproduce:
#### .clang-format
```yaml
BasedOnStyle: LLVM
ColumnLimit: 100
ReflowComments: Never
```
#### Source code
```c
typedef int Integer;
typedef int CAPITALTYPE;
typedef struct
{
int a;
Integer b;
Integer c; // A veryveryveryvery longlonglonglonglonglonglong comment that exceeds the column limit
CAPITALTYPE d;
CAPITALTYPE e; // A veryveryveryvery longlonglonglonglonglonglong comment that exceeds the column limit
};
```
#### First run
Breaks the declaration across two lines and indents the wrapped line.
```c
typedef int Integer;
typedef int CAPITALTYPE;
typedef struct {
int a;
Integer b;
Integer
c; // A veryveryveryvery longlonglonglonglonglonglong comment that exceeds the column limit
CAPITALTYPE d;
CAPITALTYPE
e; // A veryveryveryvery longlonglonglonglonglonglong comment that exceeds the column limit
};
```
#### Second run:
Removes that indent and aligns the wrapped line with the type.
```c
typedef int Integer;
typedef int CAPITALTYPE;
typedef struct {
int a;
Integer b;
Integer
c; // A veryveryveryvery longlonglonglonglonglonglong comment that exceeds the column limit
CAPITALTYPE d;
CAPITALTYPE
e; // A veryveryveryvery longlonglonglonglonglonglong comment that exceeds the column limit
};
```
### Environment
- clang-format version: **21.1.3**
- OS: Windows 11
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs