[v3] Add .clang-format style file
Checks
Context |
Check |
Description |
dj/TryBot-apply_patch |
success
|
Patch applied to master at the time it was sent
|
dj/TryBot-32bit |
success
|
Build for i686
|
Commit Message
Went with version >= 11.0 since it covers most of the major features
and should be pretty universally accessibly.
There are some issues:
1. indention of preprocessor directives:
Unfortunately there doesn't appear to be a switch for a seperate
'IndentWidth' for preprocessor directives vs. normal code so we
are stuck either not indenting the directives or over-indenting
them. i.e:
Desired:
```
#ifndef A
# define B
#endif
```
Options:
```
#ifndef A
# define B /* Two spaces instead of one. */
#endif
#ifndef C
#define D /* No spaces. */
#endif
```
Chose to over-indent as it generally seems easier to script
halving all pre-processor indentations than counting the nested
depth and indenting from scratch.
2. concatenation of lines missing semi-colons:
Throughout glibc there are macros used to setup aliasing that are
outside of functions and don't end in semi-colons i.e:
```
libc_hidden_def (__pthread_self)
weak_alias (__pthread_self, pthread_self)
```
clang-format reformats lines like these to:
```
libc_hidden_def (__pthread_self) weak_alias (__pthread_self, pthread_self)
```
which is generally undesirable.
Other than those two big concerns there are certainly some questions
diffs but for the most part it creates a easy to read and consistent
style.
---
.clang-format | 175 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 175 insertions(+)
create mode 100644 .clang-format
Comments
On 2022-03-30, Noah Goldstein via Libc-alpha wrote:
>Went with version >= 11.0 since it covers most of the major features
>and should be pretty universally accessibly.
>
>There are some issues:
>
>1. indention of preprocessor directives:
> Unfortunately there doesn't appear to be a switch for a seperate
> 'IndentWidth' for preprocessor directives vs. normal code so we
> are stuck either not indenting the directives or over-indenting
> them. i.e:
> Desired:
> ```
> #ifndef A
> # define B
> #endif
> ```
> Options:
> ```
> #ifndef A
> # define B /* Two spaces instead of one. */
> #endif
>
> #ifndef C
> #define D /* No spaces. */
> #endif
> ```
> Chose to over-indent as it generally seems easier to script
> halving all pre-processor indentations than counting the nested
> depth and indenting from scratch.
>
>2. concatenation of lines missing semi-colons:
> Throughout glibc there are macros used to setup aliasing that are
> outside of functions and don't end in semi-colons i.e:
> ```
> libc_hidden_def (__pthread_self)
> weak_alias (__pthread_self, pthread_self)
> ```
>
> clang-format reformats lines like these to:
> ```
> libc_hidden_def (__pthread_self) weak_alias (__pthread_self, pthread_self)
> ```
>
> which is generally undesirable.
>
>Other than those two big concerns there are certainly some questions
>diffs but for the most part it creates a easy to read and consistent
>style.
Thanks. I have spot checked a few files and having the file will be
helpful.
Side note: clang-format works even without .clang-format and falls back to LLVM
style. Having the file makes the format rules actually reflect the glibc coding
standard.
Reviewed-by: Fangrui Song <maskray@google.com>
>---
> .clang-format | 175 ++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 175 insertions(+)
> create mode 100644 .clang-format
>
>diff --git a/.clang-format b/.clang-format
>new file mode 100644
>index 0000000000..fcb344ef70
>--- /dev/null
>+++ b/.clang-format
>@@ -0,0 +1,175 @@
>+# clang-format file for GLIBC
>+# Copyright (C) 2022 Free Software Foundation, Inc.
>+# This file is part of the GNU C Library.
>+#
>+# The GNU C Library is free software; you can redistribute it and/or
>+# modify it under the terms of the GNU Lesser General Public
>+# License as published by the Free Software Foundation; either
>+# version 2.1 of the License, or (at your option) any later version.
>+#
>+# The GNU C Library is distributed in the hope that it will be useful,
>+# but WITHOUT ANY WARRANTY; without even the implied warranty of
>+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
>+# Lesser General Public License for more details.
>+#
>+# You should have received a copy of the GNU Lesser General Public
>+# License along with the GNU C Library; if not, see
>+# <https://www.gnu.org/licenses/>.
>+#
>+# Requires clang-format version >= 11.0
>+#
>+# For more information, see:
>+#
>+# Documentation/process/clang-format.rst
>+# https://clang.llvm.org/docs/ClangFormat.html
>+# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
>+#
>+# There are some known cases that this doesn't produce the desired
>+# style (i.e Preprocessor Directives are over-indented and not
>+# auto-commented). As a result, this is meant to be a utility to make
>+# formatting easier, not a definitive standard.
>+#
>+# To format the current git diff inplace (-i) the follow command can
>+# be used:
>+# $> git diff -U0 --no-color HEAD^ | clang-format-diff -i -p1
>+#
>+# To just view the diff clang-format would generate:
>+# $> git diff -U0 --no-color HEAD^ | clang-format-diff -p1
>+#
>+# NB: clang-format-diff, along with other clang-format related tools,
>+# can be found at: /path/to/llvm-project/clang/tools/clang-format/
>+#
The ability to re-format blocks of code is especially useful for
contributors sending patches. Thanks for highlighting it.
>+#
>+---
>+# BasedOnStyle: GNU
>+AccessModifierOffset: -2
>+AlignAfterOpenBracket: Align
>+AlignConsecutiveMacros: false
>+AlignConsecutiveAssignments: false
>+AlignConsecutiveBitFields: false
>+AlignConsecutiveDeclarations: false
>+AlignEscapedNewlines: Right
>+AlignOperands: true
>+AlignTrailingComments: true
>+AllowAllArgumentsOnNextLine: true
>+AllowAllConstructorInitializersOnNextLine: true
>+AllowAllParametersOfDeclarationOnNextLine: true
>+AllowShortEnumsOnASingleLine: true
>+AllowShortBlocksOnASingleLine: false
>+AllowShortCaseLabelsOnASingleLine: false
>+AllowShortFunctionsOnASingleLine: All
>+AllowShortLambdasOnASingleLine: All
>+AllowShortIfStatementsOnASingleLine: Never
>+AllowShortLoopsOnASingleLine: false
>+AlwaysBreakAfterDefinitionReturnType: All
>+AlwaysBreakAfterReturnType: AllDefinitions
>+AlwaysBreakBeforeMultilineStrings: false
>+AlwaysBreakTemplateDeclarations: MultiLine
>+BinPackArguments: true
>+BinPackParameters: true
>+BraceWrapping:
>+ AfterCaseLabel: true
>+ AfterClass: true
>+ AfterControlStatement: true
>+ AfterEnum: true
>+ AfterFunction: true
>+ AfterNamespace: true
>+ AfterStruct: true
>+ AfterUnion: true
>+ AfterExternBlock: true
>+ BeforeCatch: true
>+ BeforeElse: true
>+ BeforeWhile: true
>+ IndentBraces: true
>+ SplitEmptyFunction: true
>+ SplitEmptyRecord: true
>+ SplitEmptyNamespace: true
>+BreakBeforeBinaryOperators: All
>+BreakBeforeBraces: GNU
>+BreakBeforeInheritanceComma: false
>+BreakInheritanceList: BeforeColon
>+BreakBeforeTernaryOperators: true
>+BreakConstructorInitializersBeforeComma: false
>+BreakConstructorInitializers: BeforeColon
>+BreakStringLiterals: true
>+ColumnLimit: 79
>+CommentPragmas: '^ IWYU pragma:'
>+CompactNamespaces: false
>+ConstructorInitializerAllOnOneLineOrOnePerLine: false
>+ConstructorInitializerIndentWidth: 4
>+ContinuationIndentWidth: 4
>+Cpp11BracedListStyle: false
>+DeriveLineEnding: true
>+DerivePointerAlignment: false
>+DisableFormat: false
>+ExperimentalAutoDetectBinPacking: false
>+FixNamespaceComments: false
>+ForEachMacros:
>+ - foreach
>+ - Q_FOREACH
>+ - BOOST_FOREACH
>+IncludeBlocks: Preserve
>+IncludeCategories:
>+ - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
>+ Priority: 2
>+ - Regex: '^(<|"(gtest|gmock|isl|json)/)'
>+ Priority: 3
>+ - Regex: '.*'
>+ Priority: 1
>+IncludeIsMainRegex: '(Test)?$'
>+IndentCaseLabels: false
>+IndentCaseBlocks: false
>+IndentGotoLabels: true
>+IndentWidth: 2
>+IndentPPDirectives: AfterHash
>+IndentExternBlock: AfterExternBlock
>+IndentWrappedFunctionNames: false
>+InsertTrailingCommas: None
>+KeepEmptyLinesAtTheStartOfBlocks: true
>+MacroBlockBegin: ''
>+MacroBlockEnd: ''
>+MaxEmptyLinesToKeep: 1
>+NamespaceIndentation: None
>+PenaltyBreakAssignment: 2
>+PenaltyBreakBeforeFirstCallParameter: 19
>+PenaltyBreakComment: 300
>+PenaltyBreakFirstLessLess: 120
>+PenaltyBreakString: 1000
>+PenaltyBreakTemplateDeclaration: 10
>+PenaltyExcessCharacter: 1000000
>+PenaltyReturnTypeOnItsOwnLine: 60
>+PointerAlignment: Right
>+ReflowComments: true
>+SortIncludes: false
>+SortUsingDeclarations: true
>+SpaceAfterCStyleCast: true
>+SpaceAfterLogicalNot: false
>+SpaceAfterTemplateKeyword: true
>+SpaceBeforeAssignmentOperators: true
>+SpaceBeforeCpp11BracedList: false
>+SpaceBeforeCtorInitializerColon: true
>+SpaceBeforeInheritanceColon: true
>+SpaceBeforeParens: Always
>+SpaceBeforeRangeBasedForLoopColon: true
>+SpaceInEmptyBlock: false
>+SpaceInEmptyParentheses: false
>+SpacesBeforeTrailingComments: 1
>+SpacesInAngles: false
>+SpacesInConditionalStatement: false
>+SpacesInContainerLiterals: true
>+SpacesInCStyleCastParentheses: false
>+SpacesInParentheses: false
>+SpacesInSquareBrackets: false
>+SpaceBeforeSquareBrackets: false
>+Standard: Cpp03
>+StatementMacros:
>+ - Q_UNUSED
>+ - QT_REQUIRE_VERSION
>+TabWidth: 8
>+UseTab: Never
>+ForEachMacros:
>+ - 'FOR_EACH_IMPL'
>+ - 'list_for_each'
>+ - 'list_for_each_prev'
>+ - 'list_for_each_prev_safe'
>+...
>--
>2.25.1
>
* Noah Goldstein via Libc-alpha:
> Went with version >= 11.0 since it covers most of the major features
> and should be pretty universally accessibly.
>
> There are some issues:
>
> 1. indention of preprocessor directives:
> Unfortunately there doesn't appear to be a switch for a seperate
> 'IndentWidth' for preprocessor directives vs. normal code so we
> are stuck either not indenting the directives or over-indenting
> them. i.e:
> Desired:
> ```
> #ifndef A
> # define B
> #endif
> ```
> Options:
> ```
> #ifndef A
> # define B /* Two spaces instead of one. */
> #endif
>
> #ifndef C
> #define D /* No spaces. */
> #endif
> ```
> Chose to over-indent as it generally seems easier to script
> halving all pre-processor indentations than counting the nested
> depth and indenting from scratch.
>
> 2. concatenation of lines missing semi-colons:
> Throughout glibc there are macros used to setup aliasing that are
> outside of functions and don't end in semi-colons i.e:
> ```
> libc_hidden_def (__pthread_self)
> weak_alias (__pthread_self, pthread_self)
> ```
>
> clang-format reformats lines like these to:
> ```
> libc_hidden_def (__pthread_self) weak_alias (__pthread_self, pthread_self)
> ```
>
> which is generally undesirable.
>
> Other than those two big concerns there are certainly some questions
> diffs but for the most part it creates a easy to read and consistent
> style.
> ---
> .clang-format | 175 ++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 175 insertions(+)
> create mode 100644 .clang-format
>
> diff --git a/.clang-format b/.clang-format
> new file mode 100644
> index 0000000000..fcb344ef70
> --- /dev/null
> +++ b/.clang-format
> @@ -0,0 +1,175 @@
> +# clang-format file for GLIBC
> +# Copyright (C) 2022 Free Software Foundation, Inc.
> +# This file is part of the GNU C Library.
> +#
> +# The GNU C Library is free software; you can redistribute it and/or
> +# modify it under the terms of the GNU Lesser General Public
> +# License as published by the Free Software Foundation; either
> +# version 2.1 of the License, or (at your option) any later version.
> +#
> +# The GNU C Library is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> +# Lesser General Public License for more details.
> +#
> +# You should have received a copy of the GNU Lesser General Public
> +# License along with the GNU C Library; if not, see
> +# <https://www.gnu.org/licenses/>.
> +#
> +# Requires clang-format version >= 11.0
> +#
> +# For more information, see:
> +#
> +# Documentation/process/clang-format.rst
That's not a valid path in the glibc source tree.
> +# BasedOnStyle: GNU
Why is this commented out?
> +AccessModifierOffset: -2
> +AlignAfterOpenBracket: Align
> +AlignConsecutiveMacros: false
> +AlignConsecutiveAssignments: false
> +AlignConsecutiveBitFields: false
> +AlignConsecutiveDeclarations: false
> +AlignEscapedNewlines: Right
> +AlignOperands: true
> +AlignTrailingComments: true
> +AllowAllArgumentsOnNextLine: true
> +AllowAllConstructorInitializersOnNextLine: true
> +AllowAllParametersOfDeclarationOnNextLine: true
> +AllowShortEnumsOnASingleLine: true
> +AllowShortBlocksOnASingleLine: false
> +AllowShortCaseLabelsOnASingleLine: false
> +AllowShortFunctionsOnASingleLine: All
> +AllowShortLambdasOnASingleLine: All
> +AllowShortIfStatementsOnASingleLine: Never
> +AllowShortLoopsOnASingleLine: false
> +AlwaysBreakAfterDefinitionReturnType: All
> +AlwaysBreakAfterReturnType: AllDefinitions
> +AlwaysBreakBeforeMultilineStrings: false
> +AlwaysBreakTemplateDeclarations: MultiLine
> +BinPackArguments: true
> +BinPackParameters: true
> +BraceWrapping:
> + AfterCaseLabel: true
> + AfterClass: true
> + AfterControlStatement: true
> + AfterEnum: true
> + AfterFunction: true
> + AfterNamespace: true
> + AfterStruct: true
> + AfterUnion: true
> + AfterExternBlock: true
> + BeforeCatch: true
> + BeforeElse: true
> + BeforeWhile: true
> + IndentBraces: true
> + SplitEmptyFunction: true
> + SplitEmptyRecord: true
> + SplitEmptyNamespace: true
> +BreakBeforeBinaryOperators: All
> +BreakBeforeBraces: GNU
> +BreakBeforeInheritanceComma: false
> +BreakInheritanceList: BeforeColon
> +BreakBeforeTernaryOperators: true
> +BreakConstructorInitializersBeforeComma: false
> +BreakConstructorInitializers: BeforeColon
> +BreakStringLiterals: true
> +ColumnLimit: 79
> +CommentPragmas: '^ IWYU pragma:'
> +CompactNamespaces: false
> +ConstructorInitializerAllOnOneLineOrOnePerLine: false
> +ConstructorInitializerIndentWidth: 4
> +ContinuationIndentWidth: 4
> +Cpp11BracedListStyle: false
> +DeriveLineEnding: true
> +DerivePointerAlignment: false
> +DisableFormat: false
> +ExperimentalAutoDetectBinPacking: false
> +FixNamespaceComments: false
> +ForEachMacros:
> + - foreach
> + - Q_FOREACH
> + - BOOST_FOREACH
> +IncludeBlocks: Preserve
> +IncludeCategories:
> + - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
> + Priority: 2
> + - Regex: '^(<|"(gtest|gmock|isl|json)/)'
> + Priority: 3
> + - Regex: '.*'
> + Priority: 1
These regular expression do not seem to be relevant to glibc.
> +UseTab: Never
I prefer not using tabs, but others disagree, and most of the source
files use tabs instead of 8 spaces (and not just for indentation).
> +ForEachMacros:
> + - 'FOR_EACH_IMPL'
> + - 'list_for_each'
> + - 'list_for_each_prev'
> + - 'list_for_each_prev_safe'
If this is a YAML file, do these duplicate FoEachMacros keys have any
effect? Only the second one is relevant to glibc.
On Wed, Mar 30, 2022 at 3:01 PM Florian Weimer <fw@deneb.enyo.de> wrote:
>
> * Noah Goldstein via Libc-alpha:
>
> > Went with version >= 11.0 since it covers most of the major features
> > and should be pretty universally accessibly.
> >
> > There are some issues:
> >
> > 1. indention of preprocessor directives:
> > Unfortunately there doesn't appear to be a switch for a seperate
> > 'IndentWidth' for preprocessor directives vs. normal code so we
> > are stuck either not indenting the directives or over-indenting
> > them. i.e:
> > Desired:
> > ```
> > #ifndef A
> > # define B
> > #endif
> > ```
> > Options:
> > ```
> > #ifndef A
> > # define B /* Two spaces instead of one. */
> > #endif
> >
> > #ifndef C
> > #define D /* No spaces. */
> > #endif
> > ```
> > Chose to over-indent as it generally seems easier to script
> > halving all pre-processor indentations than counting the nested
> > depth and indenting from scratch.
> >
> > 2. concatenation of lines missing semi-colons:
> > Throughout glibc there are macros used to setup aliasing that are
> > outside of functions and don't end in semi-colons i.e:
> > ```
> > libc_hidden_def (__pthread_self)
> > weak_alias (__pthread_self, pthread_self)
> > ```
> >
> > clang-format reformats lines like these to:
> > ```
> > libc_hidden_def (__pthread_self) weak_alias (__pthread_self, pthread_self)
> > ```
> >
> > which is generally undesirable.
> >
> > Other than those two big concerns there are certainly some questions
> > diffs but for the most part it creates a easy to read and consistent
> > style.
> > ---
> > .clang-format | 175 ++++++++++++++++++++++++++++++++++++++++++++++++++
> > 1 file changed, 175 insertions(+)
> > create mode 100644 .clang-format
> >
> > diff --git a/.clang-format b/.clang-format
> > new file mode 100644
> > index 0000000000..fcb344ef70
> > --- /dev/null
> > +++ b/.clang-format
> > @@ -0,0 +1,175 @@
> > +# clang-format file for GLIBC
> > +# Copyright (C) 2022 Free Software Foundation, Inc.
> > +# This file is part of the GNU C Library.
> > +#
> > +# The GNU C Library is free software; you can redistribute it and/or
> > +# modify it under the terms of the GNU Lesser General Public
> > +# License as published by the Free Software Foundation; either
> > +# version 2.1 of the License, or (at your option) any later version.
> > +#
> > +# The GNU C Library is distributed in the hope that it will be useful,
> > +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> > +# Lesser General Public License for more details.
> > +#
> > +# You should have received a copy of the GNU Lesser General Public
> > +# License along with the GNU C Library; if not, see
> > +# <https://www.gnu.org/licenses/>.
> > +#
> > +# Requires clang-format version >= 11.0
> > +#
> > +# For more information, see:
> > +#
> > +# Documentation/process/clang-format.rst
>
> That's not a valid path in the glibc source tree.
>
> > +# BasedOnStyle: GNU
>
> Why is this commented out?
>
> > +AccessModifierOffset: -2
> > +AlignAfterOpenBracket: Align
> > +AlignConsecutiveMacros: false
> > +AlignConsecutiveAssignments: false
> > +AlignConsecutiveBitFields: false
> > +AlignConsecutiveDeclarations: false
> > +AlignEscapedNewlines: Right
> > +AlignOperands: true
> > +AlignTrailingComments: true
> > +AllowAllArgumentsOnNextLine: true
> > +AllowAllConstructorInitializersOnNextLine: true
> > +AllowAllParametersOfDeclarationOnNextLine: true
> > +AllowShortEnumsOnASingleLine: true
> > +AllowShortBlocksOnASingleLine: false
> > +AllowShortCaseLabelsOnASingleLine: false
> > +AllowShortFunctionsOnASingleLine: All
> > +AllowShortLambdasOnASingleLine: All
> > +AllowShortIfStatementsOnASingleLine: Never
> > +AllowShortLoopsOnASingleLine: false
> > +AlwaysBreakAfterDefinitionReturnType: All
> > +AlwaysBreakAfterReturnType: AllDefinitions
> > +AlwaysBreakBeforeMultilineStrings: false
> > +AlwaysBreakTemplateDeclarations: MultiLine
> > +BinPackArguments: true
> > +BinPackParameters: true
> > +BraceWrapping:
> > + AfterCaseLabel: true
> > + AfterClass: true
> > + AfterControlStatement: true
> > + AfterEnum: true
> > + AfterFunction: true
> > + AfterNamespace: true
> > + AfterStruct: true
> > + AfterUnion: true
> > + AfterExternBlock: true
> > + BeforeCatch: true
> > + BeforeElse: true
> > + BeforeWhile: true
> > + IndentBraces: true
> > + SplitEmptyFunction: true
> > + SplitEmptyRecord: true
> > + SplitEmptyNamespace: true
> > +BreakBeforeBinaryOperators: All
> > +BreakBeforeBraces: GNU
> > +BreakBeforeInheritanceComma: false
> > +BreakInheritanceList: BeforeColon
> > +BreakBeforeTernaryOperators: true
> > +BreakConstructorInitializersBeforeComma: false
> > +BreakConstructorInitializers: BeforeColon
> > +BreakStringLiterals: true
> > +ColumnLimit: 79
> > +CommentPragmas: '^ IWYU pragma:'
> > +CompactNamespaces: false
> > +ConstructorInitializerAllOnOneLineOrOnePerLine: false
> > +ConstructorInitializerIndentWidth: 4
> > +ContinuationIndentWidth: 4
> > +Cpp11BracedListStyle: false
> > +DeriveLineEnding: true
> > +DerivePointerAlignment: false
> > +DisableFormat: false
> > +ExperimentalAutoDetectBinPacking: false
> > +FixNamespaceComments: false
> > +ForEachMacros:
> > + - foreach
> > + - Q_FOREACH
> > + - BOOST_FOREACH
>
> > +IncludeBlocks: Preserve
> > +IncludeCategories:
> > + - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
> > + Priority: 2
> > + - Regex: '^(<|"(gtest|gmock|isl|json)/)'
> > + Priority: 3
> > + - Regex: '.*'
> > + Priority: 1
>
> These regular expression do not seem to be relevant to glibc.
Yeah. Will fix in v4.
>
> > +UseTab: Never
>
> I prefer not using tabs, but others disagree, and most of the source
> files use tabs instead of 8 spaces (and not just for indentation).
+1 but yeah the consistent style seems to be tabs so will update in v4.
>
> > +ForEachMacros:
> > + - 'FOR_EACH_IMPL'
> > + - 'list_for_each'
> > + - 'list_for_each_prev'
> > + - 'list_for_each_prev_safe'
>
> If this is a YAML file, do these duplicate FoEachMacros keys have any
> effect? Only the second one is relevant to glibc.
They all seem to have an effect.
What do you mean only the second is relevant? I see all but `list_for_each_prev`
used and `list_for_each_prev` appears to be defined so it could be used
to make a loop.
* Noah Goldstein:
>> > +UseTab: Never
>>
>> I prefer not using tabs, but others disagree, and most of the source
>> files use tabs instead of 8 spaces (and not just for indentation).
>
> +1 but yeah the consistent style seems to be tabs so will update in v4.
Is there an option to use tabs only if the file contains tab?
>> > +ForEachMacros:
>> > + - 'FOR_EACH_IMPL'
>> > + - 'list_for_each'
>> > + - 'list_for_each_prev'
>> > + - 'list_for_each_prev_safe'
>>
>> If this is a YAML file, do these duplicate FoEachMacros keys have any
>> effect? Only the second one is relevant to glibc.
>
> They all seem to have an effect.
<https://yaml.org/spec/1.2.2/#mapping> says that keys have to be
unique, so I don't think to ForEachMacros is valid YAML syntax.
> What do you mean only the second is relevant?
glibc does not use the Boost and Qt macros.
On Wed, Mar 30, 2022 at 3:14 PM Florian Weimer <fw@deneb.enyo.de> wrote:
>
> * Noah Goldstein:
>
> >> > +UseTab: Never
> >>
> >> I prefer not using tabs, but others disagree, and most of the source
> >> files use tabs instead of 8 spaces (and not just for indentation).
> >
> > +1 but yeah the consistent style seems to be tabs so will update in v4.
>
> Is there an option to use tabs only if the file contains tab?
There doesn't appear to be one. Only
https://clang.llvm.org/docs/ClangFormatStyleOptions.html
UT_Never (in configuration: Never) Never use tab.
UT_ForIndentation (in configuration: ForIndentation) Use tabs only for
indentation.
UT_ForContinuationAndIndentation (in configuration:
ForContinuationAndIndentation) Fill all leading whitespace with tabs,
and use spaces for alignment that appears within a line (e.g.
consecutive assignments and declarations).
UT_AlignWithSpaces (in configuration: AlignWithSpaces) Use tabs for
line continuation and indentation, and spaces for alignment.
UT_Always (in configuration: Always) Use tabs whenever we need to fill
whitespace that spans at least from one tab stop to the next one.
>
> >> > +ForEachMacros:
> >> > + - 'FOR_EACH_IMPL'
> >> > + - 'list_for_each'
> >> > + - 'list_for_each_prev'
> >> > + - 'list_for_each_prev_safe'
> >>
> >> If this is a YAML file, do these duplicate FoEachMacros keys have any
> >> effect? Only the second one is relevant to glibc.
> >
> > They all seem to have an effect.
>
> <https://yaml.org/spec/1.2.2/#mapping> says that keys have to be
> unique, so I don't think to ForEachMacros is valid YAML syntax.
>
> > What do you mean only the second is relevant?
>
> glibc does not use the Boost and Qt macros.
Oh I see, sorry started from the clang default GNU style.
clang-format will pick up latest configuration. Thought you
had meant the second one meaning 'list_for_each'.
new file mode 100644
@@ -0,0 +1,175 @@
+# clang-format file for GLIBC
+# Copyright (C) 2022 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+#
+# The GNU C Library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# The GNU C Library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with the GNU C Library; if not, see
+# <https://www.gnu.org/licenses/>.
+#
+# Requires clang-format version >= 11.0
+#
+# For more information, see:
+#
+# Documentation/process/clang-format.rst
+# https://clang.llvm.org/docs/ClangFormat.html
+# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
+#
+# There are some known cases that this doesn't produce the desired
+# style (i.e Preprocessor Directives are over-indented and not
+# auto-commented). As a result, this is meant to be a utility to make
+# formatting easier, not a definitive standard.
+#
+# To format the current git diff inplace (-i) the follow command can
+# be used:
+# $> git diff -U0 --no-color HEAD^ | clang-format-diff -i -p1
+#
+# To just view the diff clang-format would generate:
+# $> git diff -U0 --no-color HEAD^ | clang-format-diff -p1
+#
+# NB: clang-format-diff, along with other clang-format related tools,
+# can be found at: /path/to/llvm-project/clang/tools/clang-format/
+#
+#
+---
+# BasedOnStyle: GNU
+AccessModifierOffset: -2
+AlignAfterOpenBracket: Align
+AlignConsecutiveMacros: false
+AlignConsecutiveAssignments: false
+AlignConsecutiveBitFields: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlines: Right
+AlignOperands: true
+AlignTrailingComments: true
+AllowAllArgumentsOnNextLine: true
+AllowAllConstructorInitializersOnNextLine: true
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortEnumsOnASingleLine: true
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: All
+AllowShortLambdasOnASingleLine: All
+AllowShortIfStatementsOnASingleLine: Never
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: All
+AlwaysBreakAfterReturnType: AllDefinitions
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: MultiLine
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+ AfterCaseLabel: true
+ AfterClass: true
+ AfterControlStatement: true
+ AfterEnum: true
+ AfterFunction: true
+ AfterNamespace: true
+ AfterStruct: true
+ AfterUnion: true
+ AfterExternBlock: true
+ BeforeCatch: true
+ BeforeElse: true
+ BeforeWhile: true
+ IndentBraces: true
+ SplitEmptyFunction: true
+ SplitEmptyRecord: true
+ SplitEmptyNamespace: true
+BreakBeforeBinaryOperators: All
+BreakBeforeBraces: GNU
+BreakBeforeInheritanceComma: false
+BreakInheritanceList: BeforeColon
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializersBeforeComma: false
+BreakConstructorInitializers: BeforeColon
+BreakStringLiterals: true
+ColumnLimit: 79
+CommentPragmas: '^ IWYU pragma:'
+CompactNamespaces: false
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: false
+DeriveLineEnding: true
+DerivePointerAlignment: false
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: false
+ForEachMacros:
+ - foreach
+ - Q_FOREACH
+ - BOOST_FOREACH
+IncludeBlocks: Preserve
+IncludeCategories:
+ - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
+ Priority: 2
+ - Regex: '^(<|"(gtest|gmock|isl|json)/)'
+ Priority: 3
+ - Regex: '.*'
+ Priority: 1
+IncludeIsMainRegex: '(Test)?$'
+IndentCaseLabels: false
+IndentCaseBlocks: false
+IndentGotoLabels: true
+IndentWidth: 2
+IndentPPDirectives: AfterHash
+IndentExternBlock: AfterExternBlock
+IndentWrappedFunctionNames: false
+InsertTrailingCommas: None
+KeepEmptyLinesAtTheStartOfBlocks: true
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+PenaltyBreakAssignment: 2
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakString: 1000
+PenaltyBreakTemplateDeclaration: 10
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 60
+PointerAlignment: Right
+ReflowComments: true
+SortIncludes: false
+SortUsingDeclarations: true
+SpaceAfterCStyleCast: true
+SpaceAfterLogicalNot: false
+SpaceAfterTemplateKeyword: true
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeCpp11BracedList: false
+SpaceBeforeCtorInitializerColon: true
+SpaceBeforeInheritanceColon: true
+SpaceBeforeParens: Always
+SpaceBeforeRangeBasedForLoopColon: true
+SpaceInEmptyBlock: false
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: false
+SpacesInConditionalStatement: false
+SpacesInContainerLiterals: true
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+SpaceBeforeSquareBrackets: false
+Standard: Cpp03
+StatementMacros:
+ - Q_UNUSED
+ - QT_REQUIRE_VERSION
+TabWidth: 8
+UseTab: Never
+ForEachMacros:
+ - 'FOR_EACH_IMPL'
+ - 'list_for_each'
+ - 'list_for_each_prev'
+ - 'list_for_each_prev_safe'
+...