[clang-format] UseTab = AlignWithSpaces ignored for ternary operator and/or parantheses
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
clang-format ignores the config setting for these operators under these circumstances:
(tabs are marked as `│⸱⸱⸱⸱⸱⸱⸱`, 2 spaces as ` ⸱`)
Happened on my actual code, where ColumnLimit caused line breaks instead of comments.
Can reproduce on https://clang-format-configurator.site/
Version 21.1.8
BasedOnStyle LLVM
UseTab AlignWithSpaces
IndentWidth 8
ContinuationIndentWidth 8
Code
```
void f_ternary(void)
{
// ok
int a = 1111111111111111111 ? 2 // break
: 3;
// bug
int b = // break
1111111111111111111 ? 2 // break
: 3;
// bug
int c = // break
(1111111111111111111 ? 2 // break
: 3);
// bug
1111111111111111111 ? 2 // break
: 3;
// ok
(1111111111111111111 ? 2 // break
: 3);
// clang-format off: supposed to be
int d = // break
1111111111111111111 ? 2 // break
: 3;
int e = // break
(1111111111111111111 ? 2 // break
: 3);
// clang-format on
}
void f_parentheses(void)
{
// bug
int d = // break
((((((((((((((((((((1111111111111111111 << 2 // break
& 3))))))))))))))))))));
// ok
int e = ((((((((((((((((((((1111111111111111111 << 2 // break
& 3))))))))))))))))))));
// ok
((((((((((((((((((((1111111111111111111 << 2 // break
& 3))))))))))))))))))));
// clang-format off: supposed to be
int f = // break
((((((((((((((((((((1111111111111111111 << 2 // break
& 3))))))))))))))))))));
// clang-format on
}
```
Contributor guide
Research direction
Start with the reproducible clang-format configuration and examples in the issue, then trace the formatter's UseTab handling for ternary operators and nested parentheses. Verify the result against the expected spacing in all listed cases, including comment-induced breaks and ColumnLimit behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100