Details
- Reviewers
ldionne • Quuxplusone - Group Reviewers
Restricted Project - Commits
- rG15dfe7834062: [NFC][libc++] Update clang-format style.
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Thanks. I still hope we can use clang-format after the LLVM-13 release. This should address our > > issue.
libcxx/.clang-format | ||
---|---|---|
16 | 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? |
Sorry I forgot the submit my comment before.
libcxx/.clang-format | ||
---|---|---|
16 | 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++. |
libcxx/.clang-format | ||
---|---|---|
16 | Sorry if we misunderstood each other -- what I want is for #ifs 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? |
libcxx/.clang-format | ||
---|---|---|
16 |
(just to clarify what I meant) |
libcxx/.clang-format | ||
---|---|---|
16 | 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. |
libcxx/.clang-format | ||
---|---|---|
16 | My comment only referred to "preprocessor code", not "normal code". Indeed, we don't do void f() { #if SOMETHING int x; # if SOMETHINGELSE int y; # endif // SOMETHINGELSE #endif // SOMETHING } However, what I want to avoid at all costs is unreadable crazy stuff like this: #if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) #if defined(__ANDROID__) && __ANDROID_API__ >= 30 #define _LIBCPP_HAS_COND_CLOCKWAIT #elif defined(_LIBCPP_GLIBC_PREREQ) #if _LIBCPP_GLIBC_PREREQ(2, 30) #define _LIBCPP_HAS_COND_CLOCKWAIT #endif #endif #endif If anyone wrote normal code with ifs without indentation like that, we'd tell them it's unreadable. The same applies to the preprocessor. To go back to this review, I think what we want is # libc++'s preferred indentions of preprocessor statements. IndentPPDirectives: AfterHash That's it. We don't specify the tab size cause that depends on what file you're in. |
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?