Clang-format : Allow multiple lines for chained ternary operators
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
This is a feature proposal for clang-format.
I would like to have clang-format be able to allow chained ternary operators in a multiline format. This format is incredibly useful for conditional assignments like checking for the bounds of a variable.
Current Behavior:
```
int bounded = (value > max) ? max : (value < min) ? min : value;
```
Preferred:
```
int bounded = (value > max) ? max :
(value < min) ? min :
value;
```
Acceptable:
```
int bounded = (value > max) ? max :
(value < min) ? min : value;
```
This behavior would require adding a line break after the colon of a ternary operator if the right-hand operand is another ternary operator. If this condition is met, I'd prefer to have a line break after all colons in the chain which would include the final value. I realize that would complicate the rule, and it would be acceptable if it was not a part of the feature.
Thank you for your consideration!
Contributor guide
Assessment
This issue has not been assessed yet.