[libcxx-commits] [PATCH] D109835: [NFC][libc++] Update clang-format style.

Arthur O'Dwyer via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Sep 23 10:25:14 PDT 2021


Quuxplusone added inline comments.


================
Comment at: libcxx/.clang-format:16
+IndentPPDirectives: AfterHash
+PPIndentWidth: 1
+
----------------
ldionne wrote:
> ldionne wrote:
> > Mordante wrote:
> > > ldionne wrote:
> > > > Does this mean it'll always be only indented by one space? What we need is to indent it to tabs, whatever the size of tabs are in a given file. Is there a way to achieve that?
> > > I assume you mean our standard indention of 2 spaces with "tabs". That would be achieved by removing this line, then it uses the default indention. I added this since you requested a one space indention D103368 and I've seen that indention used before in libc++.
> > Sorry if we misunderstood each other -- what I want is for `#if`s to be indented consistently with the surrounding indentation, period. So if the surrounding indentation uses 4 tabs, nested preprocessor directives should look like:
> > 
> > ```
> > #if CONDITION
> > #   define FOO
> >     ^ 5th column, i.e. indentation consists of 1x'#' and 3x' '
> > #endif
> > ```
> > 
> > Similarly, if surrounding indentation uses 2 spaces, then it should look like:
> > 
> > ```
> > #if CONDITION
> > # define FOO
> >   ^ 3rd column, i.e. indentation consists of 1x'#' and 1x' '
> > #endif
> > ```
> > 
> > Does that make sense?
> > So if the surrounding indentation uses ~~4 tabs~~ 4 spaces
> 
> (just to clarify what I meant)
FWIW, bleagh. I've never seen libc++ do
```
void f() {
#if SOMETHING
    int x;
#    if SOMETHINGELSE
    int y;
#    endif // SOMETHINGELSE
#endif // SOMETHING
}
```
nor do I think that's a good style. I think that in running code libc++'s style is generally "no indents at all":
```
void f() {
#if SOMETHING
    int x;
#if SOMETHINGELSE
    int y;
#endif // SOMETHINGELSE
#endif // SOMETHING
}
```
and in preprocessor code it's generally "one space":
```
#if SOMETHING
# define X y
# if SOMETHINGELSE
#  define Y z
# endif // SOMETHINGELSE
#endif // SOMETHING
```
Of course as usual clang-format can't handle that complicated of a rule (it has no notion of "preprocessor code" versus "normal code"). Ultimately we just have to just pick //something// for the .clang-format file and advise people to ignore it if it seems to be doing the wrong thing.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109835/new/

https://reviews.llvm.org/D109835



More information about the libcxx-commits mailing list