[clang] [clang-format] Add SpacesInParensOption for attributes and filtering for repeated parens (PR #77522)
Owen Pan via cfe-commits
cfe-commits at lists.llvm.org
Sun Jan 21 19:01:42 PST 2024
owenca wrote:
> > It seems adding a boolean sub-option that targets double pairs of parentheses as I suggested before is feasible although a better name than `ConsecutiveParentheses` may be needed.
>
> I'm fine to fix but request a concrete suggestion or proposal before I spend much more time on this. It might also work to suppress optionally the additional space on the first/last parenthesis pair, for these special "paired" parens. I think the way I already worked this patch is the right way to go to preserve backward compatibility while still allowing control over the repeated parentheses.
>
> Looks like it is called `MultipleParentheses` in the `RemoveParentheses` option. I should rename to that.
My idea was:
- Keep the existing boolean suboptions and add a new one. Let's call it `ExceptDoubleParentheses` for now.
- If it's set to true, assuming all other suboptions are set to true, the above examples would be formatted as:
```
__attribute__(( noreturn ))
__attribute__(( __aligned__( x ) ))
if (( i = j ))
if ( ( i = j ) && ( k > 3 ) ) // not affected by ExceptDoubleParentheses
decltype(( x ))
while ( ( ( i + 1 ) * j - 2 ) * k > 3 ) // not affected by ExceptDoubleParentheses
```
- If it's set to false, assuming all other suboptions are set to true, the above examples would be formatted as:
```
__attribute__( ( noreturn ) )
__attribute__( ( __aligned__( x ) ) )
if ( ( i = j ) )
if ( ( i = j ) && ( k > 3 ) ) // not affected by ExceptDoubleParentheses
decltype( ( x ) )
while ( ( ( i + 1 ) * j - 2 ) * k > 3 ) // not affected by ExceptDoubleParentheses
```
This way, we would avoid making all suboptions an `enum` and repeating `NonConsecutive` in every suboption.
https://github.com/llvm/llvm-project/pull/77522
More information about the cfe-commits
mailing list