[PATCH] D155529: [clang-format] Add SpaceInParensOption for __attribute__ keyword
Gedare Bloom via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 17 22:14:23 PDT 2023
gedare planned changes to this revision.
gedare added inline comments.
================
Comment at: clang/include/clang/Format/Format.h:4208-4213
+ /// Put a space in parentheses inside attribute specifier lists.
+ /// \code
+ /// true: false:
+ /// __attribute__(( noreturn )) vs. __attribute__((noreturn))
+ /// \endcode
+ bool InAttributeSpecifierLists;
----------------
owenpan wrote:
> This should be covered by `SpacesInParetheses`, so we really should not have a special option for `__attribute__`.
Currently, the behavior of `SpacesInParentheses` does this:
```
__attribute__( ( noreturn ) )
```
In order to prevent this from happening, it is necessary to add an option to disable it somehow, because I don't see that this kind of spacing should ever be used by anyone, but probably someone does it, and it should be maintained for backward compatibility anyway.
================
Comment at: clang/include/clang/Format/Format.h:4214-4220
+ /// Put a space in parentheses around the outside of attribute specifier
+ /// lists.
+ /// \code
+ /// true: false:
+ /// __attribute__( (noreturn) ) vs. __attribute__((noreturn))
+ /// \endcode
+ bool InAttributeSpecifiers;
----------------
owenpan wrote:
> I'm against this as the double parens, IMO, should never be separated.
I'm happy to consolidate these to a single option, that only allows to toggle between all spaces and no spaces, i.e.,
```
__attribute__( ( noreturn ) ) // enabled
__attribute__((noreturn)) // disabled
```
The style I aim for, uses no spaces around attributes, but likes to have spaces in other places. I will prepare a revision.
================
Comment at: clang/lib/Format/TokenAnnotator.cpp:3818
+ if (Right.is(TT_AttributeParen) ||
+ (Left.MatchingParen && Left.MatchingParen->is(TT_AttributeParen))) {
+ return Style.SpacesInParensOptions.InAttributeSpecifiers;
----------------
This logic can be simplified, since the parser labels both the left and right parentheses (unlike with the ``CastRParen`` case.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D155529/new/
https://reviews.llvm.org/D155529
More information about the cfe-commits
mailing list