3 <style type="text/css">
4 .versionbadge { background-color: #1c913d; height: 20px; display: inline-block; width: 120px; text-align: center; border-radius: 5px; color: #FFFFFF; font-family="Verdana,Geneva,DejaVu Sans,sans-serif" }
9 ==========================
10 Clang-Format Style Options
11 ==========================
13 :doc:`ClangFormatStyleOptions` describes configurable formatting style options
14 supported by :doc:`LibFormat` and :doc:`ClangFormat`.
16 When using :program:`clang-format` command line utility or
17 ``clang::format::reformat(...)`` functions from code, one can either use one of
18 the predefined styles (LLVM, Google, Chromium, Mozilla, WebKit, Microsoft) or
19 create a custom style by configuring specific style options.
22 Configuring Style with clang-format
23 ===================================
25 :program:`clang-format` supports two ways to provide custom style options:
26 directly specify style configuration in the ``-style=`` command line option or
27 use ``-style=file`` and put style configuration in the ``.clang-format`` or
28 ``_clang-format`` file in the project directory.
30 When using ``-style=file``, :program:`clang-format` for each input file will
31 try to find the ``.clang-format`` file located in the closest parent directory
32 of the input file. When the standard input is used, the search is started from
33 the current directory.
35 When using ``-style=file:<format_file_path>``, :program:`clang-format` for
36 each input file will use the format file located at `<format_file_path>`.
37 The path may be absolute or relative to the working directory.
39 The ``.clang-format`` file uses YAML format:
48 The configuration file can consist of several sections each having different
49 ``Language:`` parameter denoting the programming language this section of the
50 configuration is targeted at. See the description of the **Language** option
51 below for the list of supported languages. The first section may have no
52 language set, it will set the default style options for all languages.
53 Configuration sections for specific language will override options set in the
56 When :program:`clang-format` formats a file, it auto-detects the language using
57 the file name. When formatting standard input or a file that doesn't have the
58 extension corresponding to its language, ``-assume-filename=`` option can be
59 used to override the file name :program:`clang-format` uses to detect the
62 An example of a configuration file for multiple languages:
67 # We'll use defaults from the LLVM style, but with 4 columns indentation.
72 # Force pointers to the type for C++.
73 DerivePointerAlignment: false
74 PointerAlignment: Left
77 # Use 100 columns for JS.
81 # Don't format .proto files.
85 # Use 100 columns for C#.
89 An easy way to get a valid ``.clang-format`` file containing all configuration
90 options of a certain predefined style is:
92 .. code-block:: console
94 clang-format -style=llvm -dump-config > .clang-format
96 When specifying configuration in the ``-style=`` option, the same configuration
97 is applied for all input files. The format of the configuration is:
99 .. code-block:: console
101 -style='{key1: value1, key2: value2, ...}'
104 Disabling Formatting on a Piece of Code
105 =======================================
107 Clang-format understands also special comments that switch formatting in a
108 delimited range. The code between a comment ``// clang-format off`` or
109 ``/* clang-format off */`` up to a comment ``// clang-format on`` or
110 ``/* clang-format on */`` will not be formatted. The comments themselves
111 will be formatted (aligned) normally.
117 void unformatted_code ;
119 void formatted_code_again;
122 Configuring Style in Code
123 =========================
125 When using ``clang::format::reformat(...)`` functions, the format is specified
126 by supplying the `clang::format::FormatStyle
127 <https://clang.llvm.org/doxygen/structclang_1_1format_1_1FormatStyle.html>`_
131 Configurable Format Style Options
132 =================================
134 This section lists the supported style options. Value type is specified for
135 each option. For enumeration types possible values are specified both as a C++
136 enumeration member (with a prefix, e.g. ``LS_Auto``), and as a value usable in
137 the configuration (without a prefix: ``Auto``).
140 **BasedOnStyle** (``String``)
141 The style used for all options not specifically set in the configuration.
143 This option is supported only in the :program:`clang-format` configuration
144 (both within ``-style='{...}'`` and the ``.clang-format`` file).
149 A style complying with the `LLVM coding standards
150 <https://llvm.org/docs/CodingStandards.html>`_
152 A style complying with `Google's C++ style guide
153 <https://google.github.io/styleguide/cppguide.html>`_
155 A style complying with `Chromium's style guide
156 <https://chromium.googlesource.com/chromium/src/+/refs/heads/main/styleguide/styleguide.md>`_
158 A style complying with `Mozilla's style guide
159 <https://firefox-source-docs.mozilla.org/code-quality/coding-style/index.html>`_
161 A style complying with `WebKit's style guide
162 <https://www.webkit.org/coding/coding-style.html>`_
164 A style complying with `Microsoft's style guide
165 <https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference>`_
167 A style complying with the `GNU coding standards
168 <https://www.gnu.org/prep/standards/standards.html>`_
169 * ``InheritParentConfig``
170 Not a real style, but allows to use the ``.clang-format`` file from the
171 parent directory (or its parent if there is none). If there is no parent
172 file found it falls back to the ``fallback`` style, and applies the changes
175 With this option you can overwrite some parts of your main style for your
176 subdirectories. This is also possible through the command line, e.g.:
177 ``--style={BasedOnStyle: InheritParentConfig, ColumnLimit: 20}``
179 .. START_FORMAT_STYLE_OPTIONS
181 **AccessModifierOffset** (``Integer``) :versionbadge:`clang-format 3.3`
182 The extra indent or outdent of access modifiers, e.g. ``public:``.
184 **AlignAfterOpenBracket** (``BracketAlignmentStyle``) :versionbadge:`clang-format 3.8`
185 If ``true``, horizontally aligns arguments after an open bracket.
187 This applies to round brackets (parentheses), angle brackets and square
192 * ``BAS_Align`` (in configuration: ``Align``)
193 Align parameters on the open bracket, e.g.:
197 someLongFunction(argument1,
200 * ``BAS_DontAlign`` (in configuration: ``DontAlign``)
201 Don't align, instead use ``ContinuationIndentWidth``, e.g.:
205 someLongFunction(argument1,
208 * ``BAS_AlwaysBreak`` (in configuration: ``AlwaysBreak``)
209 Always break after an open bracket, if the parameters don't fit
210 on a single line, e.g.:
215 argument1, argument2);
217 * ``BAS_BlockIndent`` (in configuration: ``BlockIndent``)
218 Always break after an open bracket, if the parameters don't fit
219 on a single line. Closing brackets will be placed on a new line.
231 Note: This currently only applies to parentheses.
235 **AlignArrayOfStructures** (``ArrayInitializerAlignmentStyle``) :versionbadge:`clang-format 13`
236 if not ``None``, when using initialization for an array of structs
237 aligns the fields into columns.
239 NOTE: As of clang-format 15 this option only applied to arrays with equal
240 number of columns per row.
244 * ``AIAS_Left`` (in configuration: ``Left``)
245 Align array column and left justify the columns e.g.:
252 {-1, 93463, "world"},
256 * ``AIAS_Right`` (in configuration: ``Right``)
257 Align array column and right justify the columns e.g.:
264 {-1, 93463, "world"},
268 * ``AIAS_None`` (in configuration: ``None``)
269 Don't align array initializer columns.
273 **AlignConsecutiveAssignments** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 3.8`
274 Style of aligning consecutive assignments.
276 ``Consecutive`` will result in formattings like:
281 int somelongname = 2;
284 Nested configuration flags:
288 They can also be read as a whole for compatibility. The choices are:
293 - AcrossEmptyLinesAndComments
295 For example, to align across empty lines and not across comments, either
300 AlignConsecutiveMacros: AcrossEmptyLines
302 AlignConsecutiveMacros:
304 AcrossEmptyLines: true
305 AcrossComments: false
307 * ``bool Enabled`` Whether aligning is enabled.
311 #define SHORT_NAME 42
312 #define LONGER_NAME 0x007f
313 #define EVEN_LONGER_NAME (2)
314 #define foo(x) (x * x)
315 #define bar(y, z) (y + z)
318 int somelongname = 2;
329 * ``bool AcrossEmptyLines`` Whether to align across empty lines.
335 int somelongname = 2;
342 int somelongname = 2;
347 * ``bool AcrossComments`` Whether to align across comments.
361 * ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound assignments
362 like ``+=`` are aligned along with ``=``.
374 * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment
375 operators are left-padded to the same length as long ones in order to
376 put all assignment operators to the right of the left hand side.
395 **AlignConsecutiveBitFields** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 11`
396 Style of aligning consecutive bit fields.
398 ``Consecutive`` will align the bitfield separators of consecutive lines.
399 This will result in formattings like:
407 Nested configuration flags:
411 They can also be read as a whole for compatibility. The choices are:
416 - AcrossEmptyLinesAndComments
418 For example, to align across empty lines and not across comments, either
423 AlignConsecutiveMacros: AcrossEmptyLines
425 AlignConsecutiveMacros:
427 AcrossEmptyLines: true
428 AcrossComments: false
430 * ``bool Enabled`` Whether aligning is enabled.
434 #define SHORT_NAME 42
435 #define LONGER_NAME 0x007f
436 #define EVEN_LONGER_NAME (2)
437 #define foo(x) (x * x)
438 #define bar(y, z) (y + z)
441 int somelongname = 2;
452 * ``bool AcrossEmptyLines`` Whether to align across empty lines.
458 int somelongname = 2;
465 int somelongname = 2;
470 * ``bool AcrossComments`` Whether to align across comments.
484 * ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound assignments
485 like ``+=`` are aligned along with ``=``.
497 * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment
498 operators are left-padded to the same length as long ones in order to
499 put all assignment operators to the right of the left hand side.
518 **AlignConsecutiveDeclarations** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 3.8`
519 Style of aligning consecutive declarations.
521 ``Consecutive`` will align the declaration names of consecutive lines.
522 This will result in formattings like:
530 Nested configuration flags:
534 They can also be read as a whole for compatibility. The choices are:
539 - AcrossEmptyLinesAndComments
541 For example, to align across empty lines and not across comments, either
546 AlignConsecutiveMacros: AcrossEmptyLines
548 AlignConsecutiveMacros:
550 AcrossEmptyLines: true
551 AcrossComments: false
553 * ``bool Enabled`` Whether aligning is enabled.
557 #define SHORT_NAME 42
558 #define LONGER_NAME 0x007f
559 #define EVEN_LONGER_NAME (2)
560 #define foo(x) (x * x)
561 #define bar(y, z) (y + z)
564 int somelongname = 2;
575 * ``bool AcrossEmptyLines`` Whether to align across empty lines.
581 int somelongname = 2;
588 int somelongname = 2;
593 * ``bool AcrossComments`` Whether to align across comments.
607 * ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound assignments
608 like ``+=`` are aligned along with ``=``.
620 * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment
621 operators are left-padded to the same length as long ones in order to
622 put all assignment operators to the right of the left hand side.
641 **AlignConsecutiveMacros** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 9`
642 Style of aligning consecutive macro definitions.
644 ``Consecutive`` will result in formattings like:
648 #define SHORT_NAME 42
649 #define LONGER_NAME 0x007f
650 #define EVEN_LONGER_NAME (2)
651 #define foo(x) (x * x)
652 #define bar(y, z) (y + z)
654 Nested configuration flags:
658 They can also be read as a whole for compatibility. The choices are:
663 - AcrossEmptyLinesAndComments
665 For example, to align across empty lines and not across comments, either
670 AlignConsecutiveMacros: AcrossEmptyLines
672 AlignConsecutiveMacros:
674 AcrossEmptyLines: true
675 AcrossComments: false
677 * ``bool Enabled`` Whether aligning is enabled.
681 #define SHORT_NAME 42
682 #define LONGER_NAME 0x007f
683 #define EVEN_LONGER_NAME (2)
684 #define foo(x) (x * x)
685 #define bar(y, z) (y + z)
688 int somelongname = 2;
699 * ``bool AcrossEmptyLines`` Whether to align across empty lines.
705 int somelongname = 2;
712 int somelongname = 2;
717 * ``bool AcrossComments`` Whether to align across comments.
731 * ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound assignments
732 like ``+=`` are aligned along with ``=``.
744 * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment
745 operators are left-padded to the same length as long ones in order to
746 put all assignment operators to the right of the left hand side.
765 **AlignEscapedNewlines** (``EscapedNewlineAlignmentStyle``) :versionbadge:`clang-format 5`
766 Options for aligning backslashes in escaped newlines.
770 * ``ENAS_DontAlign`` (in configuration: ``DontAlign``)
771 Don't align escaped newlines.
780 * ``ENAS_Left`` (in configuration: ``Left``)
781 Align escaped newlines as far left as possible.
793 * ``ENAS_Right`` (in configuration: ``Right``)
794 Align escaped newlines in the right-most column.
805 **AlignOperands** (``OperandAlignmentStyle``) :versionbadge:`clang-format 3.5`
806 If ``true``, horizontally align operands of binary and ternary
811 * ``OAS_DontAlign`` (in configuration: ``DontAlign``)
812 Do not align operands of binary and ternary expressions.
813 The wrapped lines are indented ``ContinuationIndentWidth`` spaces from
814 the start of the line.
816 * ``OAS_Align`` (in configuration: ``Align``)
817 Horizontally align operands of binary and ternary expressions.
819 Specifically, this aligns operands of a single expression that needs
820 to be split over multiple lines, e.g.:
824 int aaa = bbbbbbbbbbbbbbb +
827 When ``BreakBeforeBinaryOperators`` is set, the wrapped operator is
828 aligned with the operand on the first line.
832 int aaa = bbbbbbbbbbbbbbb
835 * ``OAS_AlignAfterOperator`` (in configuration: ``AlignAfterOperator``)
836 Horizontally align operands of binary and ternary expressions.
838 This is similar to ``AO_Align``, except when
839 ``BreakBeforeBinaryOperators`` is set, the operator is un-indented so
840 that the wrapped operand is aligned with the operand on the first line.
844 int aaa = bbbbbbbbbbbbbbb
849 **AlignTrailingComments** (``Boolean``) :versionbadge:`clang-format 3.7`
850 If ``true``, aligns trailing comments.
855 int a; // My comment a vs. int a; // My comment a
856 int b = 2; // comment b int b = 2; // comment about b
858 **AllowAllArgumentsOnNextLine** (``Boolean``) :versionbadge:`clang-format 9`
859 If a function call or braced initializer list doesn't fit on a
860 line, allow putting all arguments onto the next line, even if
861 ``BinPackArguments`` is ``false``.
875 **AllowAllConstructorInitializersOnNextLine** (``Boolean``) :versionbadge:`clang-format 9`
876 This option is **deprecated**. See ``NextLine`` of
877 ``PackConstructorInitializers``.
879 **AllowAllParametersOfDeclarationOnNextLine** (``Boolean``) :versionbadge:`clang-format 3.3`
880 If the function declaration doesn't fit on a line,
881 allow putting all parameters of a function declaration onto
882 the next line even if ``BinPackParameters`` is ``false``.
888 int a, int b, int c, int d, int e);
891 void myFunction(int a,
897 **AllowShortBlocksOnASingleLine** (``ShortBlockStyle``) :versionbadge:`clang-format 3.5`
898 Dependent on the value, ``while (true) { continue; }`` can be put on a
903 * ``SBS_Never`` (in configuration: ``Never``)
904 Never merge blocks into a single line.
914 * ``SBS_Empty`` (in configuration: ``Empty``)
915 Only merge empty blocks.
924 * ``SBS_Always`` (in configuration: ``Always``)
925 Always merge short blocks into a single line.
930 while (true) { continue; }
934 **AllowShortCaseLabelsOnASingleLine** (``Boolean``) :versionbadge:`clang-format 3.6`
935 If ``true``, short case labels will be contracted to a single line.
940 switch (a) { vs. switch (a) {
941 case 1: x = 1; break; case 1:
942 case 2: return; x = 1;
948 **AllowShortEnumsOnASingleLine** (``Boolean``) :versionbadge:`clang-format 11`
949 Allow short enums on a single line.
954 enum { A, B } myEnum;
962 **AllowShortFunctionsOnASingleLine** (``ShortFunctionStyle``) :versionbadge:`clang-format 3.5`
963 Dependent on the value, ``int f() { return 0; }`` can be put on a
968 * ``SFS_None`` (in configuration: ``None``)
969 Never merge functions into a single line.
971 * ``SFS_InlineOnly`` (in configuration: ``InlineOnly``)
972 Only merge functions defined inside a class. Same as "inline",
973 except it does not implies "empty": i.e. top level empty functions
974 are not merged either.
987 * ``SFS_Empty`` (in configuration: ``Empty``)
988 Only merge empty functions.
997 * ``SFS_Inline`` (in configuration: ``Inline``)
998 Only merge functions defined inside a class. Implies "empty".
1010 * ``SFS_All`` (in configuration: ``All``)
1011 Merge all functions fitting on a single line.
1022 **AllowShortIfStatementsOnASingleLine** (``ShortIfStyle``) :versionbadge:`clang-format 3.3`
1023 Dependent on the value, ``if (a) return;`` can be put on a single line.
1027 * ``SIS_Never`` (in configuration: ``Never``)
1028 Never put short ifs on the same line.
1046 * ``SIS_WithoutElse`` (in configuration: ``WithoutElse``)
1047 Put short ifs on the same line only if there is no else statement.
1064 * ``SIS_OnlyFirstIf`` (in configuration: ``OnlyFirstIf``)
1065 Put short ifs, but not else ifs nor else statements, on the same line.
1082 * ``SIS_AllIfsAndElse`` (in configuration: ``AllIfsAndElse``)
1083 Always put short ifs, else ifs and else statements on the same
1100 **AllowShortLambdasOnASingleLine** (``ShortLambdaStyle``) :versionbadge:`clang-format 9`
1101 Dependent on the value, ``auto lambda []() { return 0; }`` can be put on a
1106 * ``SLS_None`` (in configuration: ``None``)
1107 Never merge lambdas into a single line.
1109 * ``SLS_Empty`` (in configuration: ``Empty``)
1110 Only merge empty lambdas.
1114 auto lambda = [](int a) {}
1115 auto lambda2 = [](int a) {
1119 * ``SLS_Inline`` (in configuration: ``Inline``)
1120 Merge lambda into a single line if argument of a function.
1124 auto lambda = [](int a) {
1127 sort(a.begin(), a.end(), ()[] { return x < y; })
1129 * ``SLS_All`` (in configuration: ``All``)
1130 Merge all lambdas fitting on a single line.
1134 auto lambda = [](int a) {}
1135 auto lambda2 = [](int a) { return a; };
1139 **AllowShortLoopsOnASingleLine** (``Boolean``) :versionbadge:`clang-format 3.7`
1140 If ``true``, ``while (true) continue;`` can be put on a single
1143 **AlwaysBreakAfterDefinitionReturnType** (``DefinitionReturnTypeBreakingStyle``) :versionbadge:`clang-format 3.7`
1144 The function definition return type breaking style to use. This
1145 option is **deprecated** and is retained for backwards compatibility.
1149 * ``DRTBS_None`` (in configuration: ``None``)
1150 Break after return type automatically.
1151 ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
1153 * ``DRTBS_All`` (in configuration: ``All``)
1154 Always break after the return type.
1156 * ``DRTBS_TopLevel`` (in configuration: ``TopLevel``)
1157 Always break after the return types of top-level functions.
1161 **AlwaysBreakAfterReturnType** (``ReturnTypeBreakingStyle``) :versionbadge:`clang-format 3.8`
1162 The function declaration return type breaking style to use.
1166 * ``RTBS_None`` (in configuration: ``None``)
1167 Break after return type automatically.
1168 ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
1173 int f() { return 0; };
1176 int f() { return 1; }
1178 * ``RTBS_All`` (in configuration: ``All``)
1179 Always break after the return type.
1196 * ``RTBS_TopLevel`` (in configuration: ``TopLevel``)
1197 Always break after the return types of top-level functions.
1202 int f() { return 0; };
1211 * ``RTBS_AllDefinitions`` (in configuration: ``AllDefinitions``)
1212 Always break after the return type of function definitions.
1228 * ``RTBS_TopLevelDefinitions`` (in configuration: ``TopLevelDefinitions``)
1229 Always break after the return type of top-level definitions.
1234 int f() { return 0; };
1244 **AlwaysBreakBeforeMultilineStrings** (``Boolean``) :versionbadge:`clang-format 3.4`
1245 If ``true``, always break before multiline string literals.
1247 This flag is mean to make cases where there are multiple multiline strings
1248 in a file look more consistent. Thus, it will only take effect if wrapping
1249 the string at that point leads to it being indented
1250 ``ContinuationIndentWidth`` spaces from the start of the line.
1255 aaaa = vs. aaaa = "bbbb"
1259 **AlwaysBreakTemplateDeclarations** (``BreakTemplateDeclarationsStyle``) :versionbadge:`clang-format 3.4`
1260 The template declaration breaking style to use.
1264 * ``BTDS_No`` (in configuration: ``No``)
1265 Do not force break before declaration.
1266 ``PenaltyBreakTemplateDeclaration`` is taken into account.
1270 template <typename T> T foo() {
1272 template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa,
1273 int bbbbbbbbbbbbbbbbbbbbb) {
1276 * ``BTDS_MultiLine`` (in configuration: ``MultiLine``)
1277 Force break after template declaration only when the following
1278 declaration spans multiple lines.
1282 template <typename T> T foo() {
1284 template <typename T>
1285 T foo(int aaaaaaaaaaaaaaaaaaaaa,
1286 int bbbbbbbbbbbbbbbbbbbbb) {
1289 * ``BTDS_Yes`` (in configuration: ``Yes``)
1290 Always break after template declaration.
1294 template <typename T>
1297 template <typename T>
1298 T foo(int aaaaaaaaaaaaaaaaaaaaa,
1299 int bbbbbbbbbbbbbbbbbbbbb) {
1304 **AttributeMacros** (``List of Strings``) :versionbadge:`clang-format 12`
1305 A vector of strings that should be interpreted as attributes/qualifiers
1306 instead of identifiers. This can be useful for language extensions or
1307 static analyzer annotations.
1313 x = (char *__capability)&y;
1314 int function(void) __ununsed;
1315 void only_writes_to_buffer(char *__output buffer);
1317 In the .clang-format configuration file, this can be configured like:
1319 .. code-block:: yaml
1321 AttributeMacros: ['__capability', '__output', '__ununsed']
1323 **BinPackArguments** (``Boolean``) :versionbadge:`clang-format 3.7`
1324 If ``false``, a function call's arguments will either be all on the
1325 same line or will have one line each.
1331 f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa,
1332 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
1337 f(aaaaaaaaaaaaaaaaaaaa,
1338 aaaaaaaaaaaaaaaaaaaa,
1339 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
1342 **BinPackParameters** (``Boolean``) :versionbadge:`clang-format 3.7`
1343 If ``false``, a function declaration's or function definition's
1344 parameters will either all be on the same line or will have one line each.
1349 void f(int aaaaaaaaaaaaaaaaaaaa, int aaaaaaaaaaaaaaaaaaaa,
1350 int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
1353 void f(int aaaaaaaaaaaaaaaaaaaa,
1354 int aaaaaaaaaaaaaaaaaaaa,
1355 int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
1357 **BitFieldColonSpacing** (``BitFieldColonSpacingStyle``) :versionbadge:`clang-format 12`
1358 The BitFieldColonSpacingStyle to use for bitfields.
1362 * ``BFCS_Both`` (in configuration: ``Both``)
1363 Add one space on each side of the ``:``
1369 * ``BFCS_None`` (in configuration: ``None``)
1370 Add no space around the ``:`` (except when needed for
1371 ``AlignConsecutiveBitFields``).
1377 * ``BFCS_Before`` (in configuration: ``Before``)
1378 Add space before the ``:`` only
1384 * ``BFCS_After`` (in configuration: ``After``)
1385 Add space after the ``:`` only (space may be added before if
1386 needed for ``AlignConsecutiveBitFields``).
1394 **BraceWrapping** (``BraceWrappingFlags``) :versionbadge:`clang-format 3.8`
1395 Control of individual brace wrapping cases.
1397 If ``BreakBeforeBraces`` is set to ``BS_Custom``, use this to specify how
1398 each individual brace case should be handled. Otherwise, this is ignored.
1400 .. code-block:: yaml
1403 BreakBeforeBraces: Custom
1407 SplitEmptyFunction: false
1409 Nested configuration flags:
1411 Precise control over the wrapping of braces.
1415 # Should be declared this way:
1416 BreakBeforeBraces: Custom
1420 * ``bool AfterCaseLabel`` Wrap case labels.
1425 switch (foo) { vs. switch (foo) {
1437 * ``bool AfterClass`` Wrap class definitions.
1448 * ``BraceWrappingAfterControlStatementStyle AfterControlStatement``
1449 Wrap control statements (``if``/``for``/``while``/``switch``/..).
1453 * ``BWACS_Never`` (in configuration: ``Never``)
1454 Never wrap braces after a control statement.
1461 for (int i = 0; i < 10; ++i) {
1464 * ``BWACS_MultiLine`` (in configuration: ``MultiLine``)
1465 Only wrap braces after a multi-line control statement.
1474 while (foo || bar) {
1477 * ``BWACS_Always`` (in configuration: ``Always``)
1478 Always wrap braces after a control statement.
1486 for (int i = 0; i < 10; ++i)
1490 * ``bool AfterEnum`` Wrap enum definitions.
1503 * ``bool AfterFunction`` Wrap function definitions.
1520 * ``bool AfterNamespace`` Wrap namespace definitions.
1537 * ``bool AfterObjCDeclaration`` Wrap ObjC definitions (interfaces, implementations...).
1538 @autoreleasepool and @synchronized blocks are wrapped
1539 according to `AfterControlStatement` flag.
1541 * ``bool AfterStruct`` Wrap struct definitions.
1556 * ``bool AfterUnion`` Wrap union definitions.
1571 * ``bool AfterExternBlock`` Wrap extern blocks.
1586 * ``bool BeforeCatch`` Wrap before ``catch``.
1603 * ``bool BeforeElse`` Wrap before ``else``.
1618 * ``bool BeforeLambdaBody`` Wrap lambda block.
1636 * ``bool BeforeWhile`` Wrap before ``while``.
1651 * ``bool IndentBraces`` Indent the wrapped braces themselves.
1653 * ``bool SplitEmptyFunction`` If ``false``, empty function body can be put on a single line.
1654 This option is used only if the opening brace of the function has
1655 already been wrapped, i.e. the `AfterFunction` brace wrapping mode is
1656 set, and the function could/should not be put on a single line (as per
1657 `AllowShortFunctionsOnASingleLine` and constructor formatting options).
1666 * ``bool SplitEmptyRecord`` If ``false``, empty record (e.g. class, struct or union) body
1667 can be put on a single line. This option is used only if the opening
1668 brace of the record has already been wrapped, i.e. the `AfterClass`
1669 (for classes) brace wrapping mode is set.
1674 class Foo vs. class Foo
1678 * ``bool SplitEmptyNamespace`` If ``false``, empty namespace body can be put on a single line.
1679 This option is used only if the opening brace of the namespace has
1680 already been wrapped, i.e. the `AfterNamespace` brace wrapping mode is
1686 namespace Foo vs. namespace Foo
1691 **BreakAfterJavaFieldAnnotations** (``Boolean``) :versionbadge:`clang-format 3.8`
1692 Break after each annotation on a field in Java files.
1694 .. code-block:: java
1697 @Partial vs. @Partial @Mock DataLoad loader;
1701 **BreakBeforeBinaryOperators** (``BinaryOperatorStyle``) :versionbadge:`clang-format 3.6`
1702 The way to wrap binary operators.
1706 * ``BOS_None`` (in configuration: ``None``)
1707 Break after operators.
1711 LooooooooooongType loooooooooooooooooooooongVariable =
1712 someLooooooooooooooooongFunction();
1714 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
1715 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ==
1716 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
1717 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa >
1718 ccccccccccccccccccccccccccccccccccccccccc;
1720 * ``BOS_NonAssignment`` (in configuration: ``NonAssignment``)
1721 Break before operators that aren't assignments.
1725 LooooooooooongType loooooooooooooooooooooongVariable =
1726 someLooooooooooooooooongFunction();
1728 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1729 + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1730 == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1731 && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1732 > ccccccccccccccccccccccccccccccccccccccccc;
1734 * ``BOS_All`` (in configuration: ``All``)
1735 Break before operators.
1739 LooooooooooongType loooooooooooooooooooooongVariable
1740 = someLooooooooooooooooongFunction();
1742 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1743 + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1744 == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1745 && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1746 > ccccccccccccccccccccccccccccccccccccccccc;
1750 **BreakBeforeBraces** (``BraceBreakingStyle``) :versionbadge:`clang-format 3.7`
1751 The brace breaking style to use.
1755 * ``BS_Attach`` (in configuration: ``Attach``)
1756 Always attach braces to surrounding context.
1799 void bar() { foo(true); }
1802 * ``BS_Linux`` (in configuration: ``Linux``)
1803 Like ``Attach``, but break before braces on function, namespace and
1851 void bar() { foo(true); }
1854 * ``BS_Mozilla`` (in configuration: ``Mozilla``)
1855 Like ``Attach``, but break before braces on enum, function, and record
1903 void bar() { foo(true); }
1906 * ``BS_Stroustrup`` (in configuration: ``Stroustrup``)
1907 Like ``Attach``, but break before function definitions, ``catch``, and
1955 void bar() { foo(true); }
1958 * ``BS_Allman`` (in configuration: ``Allman``)
1959 Always break before braces.
2017 void bar() { foo(true); }
2020 * ``BS_Whitesmiths`` (in configuration: ``Whitesmiths``)
2021 Like ``Allman`` but always indent braces and line up code with braces.
2079 void bar() { foo(true); }
2082 * ``BS_GNU`` (in configuration: ``GNU``)
2083 Always break before braces and add an extra level of indentation to
2084 braces of control statements, not to those of class, function
2085 or other definitions.
2144 void bar() { foo(true); }
2147 * ``BS_WebKit`` (in configuration: ``WebKit``)
2148 Like ``Attach``, but break before functions.
2193 void bar() { foo(true); }
2196 * ``BS_Custom`` (in configuration: ``Custom``)
2197 Configure each individual brace in `BraceWrapping`.
2201 **BreakBeforeConceptDeclarations** (``BreakBeforeConceptDeclarationsStyle``) :versionbadge:`clang-format 12`
2202 The concept declaration style to use.
2206 * ``BBCDS_Never`` (in configuration: ``Never``)
2207 Keep the template declaration line together with ``concept``.
2211 template <typename T> concept C = ...;
2213 * ``BBCDS_Allowed`` (in configuration: ``Allowed``)
2214 Breaking between template declaration and ``concept`` is allowed. The
2215 actual behavior depends on the content and line breaking rules and
2218 * ``BBCDS_Always`` (in configuration: ``Always``)
2219 Always break before ``concept``, putting it in the line after the
2220 template declaration.
2224 template <typename T>
2229 **BreakBeforeTernaryOperators** (``Boolean``) :versionbadge:`clang-format 3.7`
2230 If ``true``, ternary operators will be placed after line breaks.
2235 veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription
2237 : SecondValueVeryVeryVeryVeryLong;
2240 veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ?
2242 SecondValueVeryVeryVeryVeryLong;
2244 **BreakConstructorInitializers** (``BreakConstructorInitializersStyle``) :versionbadge:`clang-format 5`
2245 The break constructor initializers style to use.
2249 * ``BCIS_BeforeColon`` (in configuration: ``BeforeColon``)
2250 Break constructor initializers before the colon and after the commas.
2258 * ``BCIS_BeforeComma`` (in configuration: ``BeforeComma``)
2259 Break constructor initializers before the colon and commas, and align
2260 the commas with the colon.
2268 * ``BCIS_AfterColon`` (in configuration: ``AfterColon``)
2269 Break constructor initializers after the colon and commas.
2279 **BreakInheritanceList** (``BreakInheritanceListStyle``) :versionbadge:`clang-format 7`
2280 The inheritance list style to use.
2284 * ``BILS_BeforeColon`` (in configuration: ``BeforeColon``)
2285 Break inheritance list before the colon and after the commas.
2294 * ``BILS_BeforeComma`` (in configuration: ``BeforeComma``)
2295 Break inheritance list before the colon and commas, and align
2296 the commas with the colon.
2305 * ``BILS_AfterColon`` (in configuration: ``AfterColon``)
2306 Break inheritance list after the colon and commas.
2315 * ``BILS_AfterComma`` (in configuration: ``AfterComma``)
2316 Break inheritance list only after the commas.
2326 **BreakStringLiterals** (``Boolean``) :versionbadge:`clang-format 3.9`
2327 Allow breaking string literals when formatting.
2332 const char* x = "veryVeryVeryVeryVeryVe"
2333 "ryVeryVeryVeryVeryVery"
2338 "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
2340 **ColumnLimit** (``Unsigned``) :versionbadge:`clang-format 3.7`
2343 A column limit of ``0`` means that there is no column limit. In this case,
2344 clang-format will respect the input's line breaking decisions within
2345 statements unless they contradict other rules.
2347 **CommentPragmas** (``String``) :versionbadge:`clang-format 3.7`
2348 A regular expression that describes comments with special meaning,
2349 which should not be split into lines or otherwise changed.
2353 // CommentPragmas: '^ FOOBAR pragma:'
2354 // Will leave the following line unaffected
2355 #include <vector> // FOOBAR pragma: keep
2357 **CompactNamespaces** (``Boolean``) :versionbadge:`clang-format 5`
2358 If ``true``, consecutive namespace declarations will be on the same
2359 line. If ``false``, each namespace is declared on a new line.
2364 namespace Foo { namespace Bar {
2373 If it does not fit on a single line, the overflowing namespaces get
2378 namespace Foo { namespace Bar {
2382 **ConstructorInitializerAllOnOneLineOrOnePerLine** (``Boolean``) :versionbadge:`clang-format 3.7`
2383 This option is **deprecated**. See ``CurrentLine`` of
2384 ``PackConstructorInitializers``.
2386 **ConstructorInitializerIndentWidth** (``Unsigned``) :versionbadge:`clang-format 3.7`
2387 The number of characters to use for indentation of constructor
2388 initializer lists as well as inheritance lists.
2390 **ContinuationIndentWidth** (``Unsigned``) :versionbadge:`clang-format 3.7`
2391 Indent width for line continuations.
2395 ContinuationIndentWidth: 2
2397 int i = // VeryVeryVeryVeryVeryLongComment
2398 longFunction( // Again a long comment
2401 **Cpp11BracedListStyle** (``Boolean``) :versionbadge:`clang-format 3.4`
2402 If ``true``, format braced lists as best suited for C++11 braced
2405 Important differences:
2406 - No spaces inside the braced list.
2407 - No line break before the closing brace.
2408 - Indentation with the continuation indent, not with the block indent.
2410 Fundamentally, C++11 braced lists are formatted exactly like function
2411 calls would be formatted in their place. If the braced list follows a name
2412 (e.g. a type or variable name), clang-format formats as if the ``{}`` were
2413 the parentheses of a function call with that name. If there is no name,
2414 a zero-length name is assumed.
2419 vector<int> x{1, 2, 3, 4}; vs. vector<int> x{ 1, 2, 3, 4 };
2420 vector<T> x{{}, {}, {}, {}}; vector<T> x{ {}, {}, {}, {} };
2421 f(MyMap[{composite, key}]); f(MyMap[{ composite, key }]);
2422 new int[3]{1, 2, 3}; new int[3]{ 1, 2, 3 };
2424 **DeriveLineEnding** (``Boolean``) :versionbadge:`clang-format 10`
2425 Analyze the formatted file for the most used line ending (``\r\n``
2426 or ``\n``). ``UseCRLF`` is only used as a fallback if none can be derived.
2428 **DerivePointerAlignment** (``Boolean``) :versionbadge:`clang-format 3.7`
2429 If ``true``, analyze the formatted file for the most common
2430 alignment of ``&`` and ``*``.
2431 Pointer and reference alignment styles are going to be updated according
2432 to the preferences found in the file.
2433 ``PointerAlignment`` is then used only as fallback.
2435 **DisableFormat** (``Boolean``) :versionbadge:`clang-format 3.7`
2436 Disables formatting completely.
2438 **EmptyLineAfterAccessModifier** (``EmptyLineAfterAccessModifierStyle``) :versionbadge:`clang-format 13`
2439 Defines when to put an empty line after access modifiers.
2440 ``EmptyLineBeforeAccessModifier`` configuration handles the number of
2441 empty lines between two access modifiers.
2445 * ``ELAAMS_Never`` (in configuration: ``Never``)
2446 Remove all empty lines after access modifiers.
2462 * ``ELAAMS_Leave`` (in configuration: ``Leave``)
2463 Keep existing empty lines after access modifiers.
2464 MaxEmptyLinesToKeep is applied instead.
2466 * ``ELAAMS_Always`` (in configuration: ``Always``)
2467 Always add empty line after access modifiers if there are none.
2468 MaxEmptyLinesToKeep is applied also.
2491 **EmptyLineBeforeAccessModifier** (``EmptyLineBeforeAccessModifierStyle``) :versionbadge:`clang-format 12`
2492 Defines in which cases to put empty line before access modifiers.
2496 * ``ELBAMS_Never`` (in configuration: ``Never``)
2497 Remove all empty lines before access modifiers.
2513 * ``ELBAMS_Leave`` (in configuration: ``Leave``)
2514 Keep existing empty lines before access modifiers.
2516 * ``ELBAMS_LogicalBlock`` (in configuration: ``LogicalBlock``)
2517 Add empty line only when access modifier starts a new logical block.
2518 Logical block is a group of one or more member fields or functions.
2536 * ``ELBAMS_Always`` (in configuration: ``Always``)
2537 Always add empty line before access modifiers unless access modifier
2538 is at the start of struct or class definition.
2560 **ExperimentalAutoDetectBinPacking** (``Boolean``) :versionbadge:`clang-format 3.7`
2561 If ``true``, clang-format detects whether function calls and
2562 definitions are formatted with one parameter per line.
2564 Each call can be bin-packed, one-per-line or inconclusive. If it is
2565 inconclusive, e.g. completely on one line, but a decision needs to be
2566 made, clang-format analyzes whether there are other bin-packed cases in
2567 the input file and act accordingly.
2569 NOTE: This is an experimental flag, that might go away or be renamed. Do
2570 not use this in config files, etc. Use at your own risk.
2572 **FixNamespaceComments** (``Boolean``) :versionbadge:`clang-format 5`
2573 If ``true``, clang-format adds missing namespace end comments for
2574 short namespaces and fixes invalid existing ones. Short ones are
2575 controlled by "ShortNamespaceLines".
2580 namespace a { vs. namespace a {
2585 **ForEachMacros** (``List of Strings``) :versionbadge:`clang-format 3.7`
2586 A vector of macros that should be interpreted as foreach loops
2587 instead of as function calls.
2589 These are expected to be macros of the form:
2593 FOREACH(<variable-declaration>, ...)
2596 In the .clang-format configuration file, this can be configured like:
2598 .. code-block:: yaml
2600 ForEachMacros: ['RANGES_FOR', 'FOREACH']
2602 For example: BOOST_FOREACH.
2604 **IfMacros** (``List of Strings``) :versionbadge:`clang-format 13`
2605 A vector of macros that should be interpreted as conditionals
2606 instead of as function calls.
2608 These are expected to be macros of the form:
2617 In the .clang-format configuration file, this can be configured like:
2619 .. code-block:: yaml
2623 For example: `KJ_IF_MAYBE
2624 <https://github.com/capnproto/capnproto/blob/master/kjdoc/tour.md#maybes>`_
2626 **IncludeBlocks** (``IncludeBlocksStyle``) :versionbadge:`clang-format 6`
2627 Dependent on the value, multiple ``#include`` blocks can be sorted
2628 as one and divided based on category.
2632 * ``IBS_Preserve`` (in configuration: ``Preserve``)
2633 Sort each ``#include`` block separately.
2637 #include "b.h" into #include "b.h"
2639 #include <lib/main.h> #include "a.h"
2640 #include "a.h" #include <lib/main.h>
2642 * ``IBS_Merge`` (in configuration: ``Merge``)
2643 Merge multiple ``#include`` blocks together and sort as one.
2647 #include "b.h" into #include "a.h"
2649 #include <lib/main.h> #include <lib/main.h>
2652 * ``IBS_Regroup`` (in configuration: ``Regroup``)
2653 Merge multiple ``#include`` blocks together and sort as one.
2654 Then split into groups based on category priority. See
2655 ``IncludeCategories``.
2659 #include "b.h" into #include "a.h"
2661 #include <lib/main.h>
2662 #include "a.h" #include <lib/main.h>
2666 **IncludeCategories** (``List of IncludeCategories``) :versionbadge:`clang-format 3.8`
2667 Regular expressions denoting the different ``#include`` categories
2668 used for ordering ``#includes``.
2671 <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html>`_
2672 regular expressions are supported.
2674 These regular expressions are matched against the filename of an include
2675 (including the <> or "") in order. The value belonging to the first
2676 matching regular expression is assigned and ``#includes`` are sorted first
2677 according to increasing category number and then alphabetically within
2680 If none of the regular expressions match, INT_MAX is assigned as
2681 category. The main header for a source file automatically gets category 0.
2682 so that it is generally kept at the beginning of the ``#includes``
2683 (https://llvm.org/docs/CodingStandards.html#include-style). However, you
2684 can also assign negative priorities if you have certain headers that
2685 always need to be first.
2687 There is a third and optional field ``SortPriority`` which can used while
2688 ``IncludeBlocks = IBS_Regroup`` to define the priority in which
2689 ``#includes`` should be ordered. The value of ``Priority`` defines the
2690 order of ``#include blocks`` and also allows the grouping of ``#includes``
2691 of different priority. ``SortPriority`` is set to the value of
2692 ``Priority`` as default if it is not assigned.
2694 Each regular expression can be marked as case sensitive with the field
2695 ``CaseSensitive``, per default it is not.
2697 To configure this in the .clang-format file, use:
2699 .. code-block:: yaml
2702 - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
2706 - Regex: '^((<|")(gtest|gmock|isl|json)/)'
2708 - Regex: '<[[:alnum:].]+>'
2714 **IncludeIsMainRegex** (``String``) :versionbadge:`clang-format 3.9`
2715 Specify a regular expression of suffixes that are allowed in the
2716 file-to-main-include mapping.
2718 When guessing whether a #include is the "main" include (to assign
2719 category 0, see above), use this regex of allowed suffixes to the header
2720 stem. A partial match is done, so that:
2721 - "" means "arbitrary suffix"
2722 - "$" means "no suffix"
2724 For example, if configured to "(_test)?$", then a header a.h would be seen
2725 as the "main" include in both a.cc and a_test.cc.
2727 **IncludeIsMainSourceRegex** (``String``) :versionbadge:`clang-format 10`
2728 Specify a regular expression for files being formatted
2729 that are allowed to be considered "main" in the
2730 file-to-main-include mapping.
2732 By default, clang-format considers files as "main" only when they end
2733 with: ``.c``, ``.cc``, ``.cpp``, ``.c++``, ``.cxx``, ``.m`` or ``.mm``
2735 For these files a guessing of "main" include takes place
2736 (to assign category 0, see above). This config option allows for
2737 additional suffixes and extensions for files to be considered as "main".
2739 For example, if this option is configured to ``(Impl\.hpp)$``,
2740 then a file ``ClassImpl.hpp`` is considered "main" (in addition to
2741 ``Class.c``, ``Class.cc``, ``Class.cpp`` and so on) and "main
2742 include file" logic will be executed (with *IncludeIsMainRegex* setting
2743 also being respected in later phase). Without this option set,
2744 ``ClassImpl.hpp`` would not have the main include file put on top
2745 before any other include.
2747 **IndentAccessModifiers** (``Boolean``) :versionbadge:`clang-format 13`
2748 Specify whether access modifiers should have their own indentation level.
2750 When ``false``, access modifiers are indented (or outdented) relative to
2751 the record members, respecting the ``AccessModifierOffset``. Record
2752 members are indented one level below the record.
2753 When ``true``, access modifiers get their own indentation level. As a
2754 consequence, record members are always indented 2 levels below the record,
2755 regardless of the access modifier presence. Value of the
2756 ``AccessModifierOffset`` is ignored.
2761 class C { vs. class C {
2763 void bar(); void bar();
2764 protected: protected:
2770 void foo() { void foo() {
2774 **IndentCaseBlocks** (``Boolean``) :versionbadge:`clang-format 11`
2775 Indent case label blocks one level from the case label.
2777 When ``false``, the block following the case label uses the same
2778 indentation level as for the case label, treating the case label the same
2780 When ``true``, the block gets indented as a scope block.
2785 switch (fool) { vs. switch (fool) {
2797 **IndentCaseLabels** (``Boolean``) :versionbadge:`clang-format 3.3`
2798 Indent case labels one level from the switch statement.
2800 When ``false``, use the same indentation level as for the switch
2801 statement. Switch statement body is always indented one level more than
2802 case labels (except the first block following the case label, which
2803 itself indents the code - unless IndentCaseBlocks is enabled).
2808 switch (fool) { vs. switch (fool) {
2816 **IndentExternBlock** (``IndentExternBlockStyle``) :versionbadge:`clang-format 11`
2817 IndentExternBlockStyle is the type of indenting of extern blocks.
2821 * ``IEBS_AfterExternBlock`` (in configuration: ``AfterExternBlock``)
2822 Backwards compatible with AfterExternBlock's indenting.
2826 IndentExternBlock: AfterExternBlock
2827 BraceWrapping.AfterExternBlock: true
2836 IndentExternBlock: AfterExternBlock
2837 BraceWrapping.AfterExternBlock: false
2842 * ``IEBS_NoIndent`` (in configuration: ``NoIndent``)
2843 Does not indent extern blocks.
2851 * ``IEBS_Indent`` (in configuration: ``Indent``)
2852 Indents extern blocks.
2862 **IndentGotoLabels** (``Boolean``) :versionbadge:`clang-format 10`
2865 When ``false``, goto labels are flushed left.
2870 int f() { vs. int f() {
2871 if (foo()) { if (foo()) {
2879 **IndentPPDirectives** (``PPDirectiveIndentStyle``) :versionbadge:`clang-format 6`
2880 The preprocessor directive indenting style to use.
2884 * ``PPDIS_None`` (in configuration: ``None``)
2885 Does not indent any directives.
2895 * ``PPDIS_AfterHash`` (in configuration: ``AfterHash``)
2896 Indents directives after the hash.
2906 * ``PPDIS_BeforeHash`` (in configuration: ``BeforeHash``)
2907 Indents directives before the hash.
2919 **IndentRequiresClause** (``Boolean``) :versionbadge:`clang-format 15`
2920 Indent the requires clause in a template. This only applies when
2921 ``RequiresClausePosition`` is ``OwnLine``, or ``WithFollowing``.
2923 In clang-format 12, 13 and 14 it was named ``IndentRequires``.
2928 template <typename It>
2929 requires Iterator<It>
2930 void sort(It begin, It end) {
2935 template <typename It>
2936 requires Iterator<It>
2937 void sort(It begin, It end) {
2941 **IndentWidth** (``Unsigned``) :versionbadge:`clang-format 3.7`
2942 The number of columns to use for indentation.
2955 **IndentWrappedFunctionNames** (``Boolean``) :versionbadge:`clang-format 3.7`
2956 Indent if a function definition or declaration is wrapped after the
2962 LoooooooooooooooooooooooooooooooooooooooongReturnType
2963 LoooooooooooooooooooooooooooooooongFunctionDeclaration();
2966 LoooooooooooooooooooooooooooooooooooooooongReturnType
2967 LoooooooooooooooooooooooooooooooongFunctionDeclaration();
2969 **InsertBraces** (``Boolean``) :versionbadge:`clang-format 15`
2970 Insert braces after control statements (``if``, ``else``, ``for``, ``do``,
2971 and ``while``) in C++ unless the control statements are inside macro
2972 definitions or the braces would enclose preprocessor directives.
2976 Setting this option to `true` could lead to incorrect code formatting due
2977 to clang-format's lack of complete semantic information. As such, extra
2978 care should be taken to review code changes made by this option.
2984 if (isa<FunctionDecl>(D)) vs. if (isa<FunctionDecl>(D)) {
2985 handleFunctionDecl(D); handleFunctionDecl(D);
2986 else if (isa<VarDecl>(D)) } else if (isa<VarDecl>(D)) {
2987 handleVarDecl(D); handleVarDecl(D);
2992 while (i--) vs. while (i--) {
2993 for (auto *A : D.attrs()) for (auto *A : D.attrs()) {
2994 handleAttr(A); handleAttr(A);
3000 while (i); } while (i);
3002 **InsertTrailingCommas** (``TrailingCommaStyle``) :versionbadge:`clang-format 11`
3003 If set to ``TCS_Wrapped`` will insert trailing commas in container
3004 literals (arrays and objects) that wrap across multiple lines.
3005 It is currently only available for JavaScript
3006 and disabled by default ``TCS_None``.
3007 ``InsertTrailingCommas`` cannot be used together with ``BinPackArguments``
3008 as inserting the comma disables bin-packing.
3014 aaaaaaaaaaaaaaaaaaaaaaaaaa,
3015 aaaaaaaaaaaaaaaaaaaaaaaaaa,
3016 aaaaaaaaaaaaaaaaaaaaaaaaaa,
3022 * ``TCS_None`` (in configuration: ``None``)
3023 Do not insert trailing commas.
3025 * ``TCS_Wrapped`` (in configuration: ``Wrapped``)
3026 Insert trailing commas in container literals that were wrapped over
3027 multiple lines. Note that this is conceptually incompatible with
3028 bin-packing, because the trailing comma is used as an indicator
3029 that a container should be formatted one-per-line (i.e. not bin-packed).
3030 So inserting a trailing comma counteracts bin-packing.
3034 **JavaImportGroups** (``List of Strings``) :versionbadge:`clang-format 8`
3035 A vector of prefixes ordered by the desired groups for Java imports.
3037 One group's prefix can be a subset of another - the longest prefix is
3038 always matched. Within a group, the imports are ordered lexicographically.
3039 Static imports are grouped separately and follow the same group rules.
3040 By default, static imports are placed before non-static imports,
3041 but this behavior is changed by another option,
3042 ``SortJavaStaticImport``.
3044 In the .clang-format configuration file, this can be configured like
3045 in the following yaml example. This will result in imports being
3046 formatted as in the Java example below.
3048 .. code-block:: yaml
3050 JavaImportGroups: ['com.example', 'com', 'org']
3053 .. code-block:: java
3055 import static com.example.function1;
3057 import static com.test.function2;
3059 import static org.example.function3;
3061 import com.example.ClassA;
3062 import com.example.Test;
3063 import com.example.a.ClassB;
3065 import com.test.ClassC;
3067 import org.example.ClassD;
3069 **JavaScriptQuotes** (``JavaScriptQuoteStyle``) :versionbadge:`clang-format 3.9`
3070 The JavaScriptQuoteStyle to use for JavaScript strings.
3074 * ``JSQS_Leave`` (in configuration: ``Leave``)
3075 Leave string quotes as they are.
3082 * ``JSQS_Single`` (in configuration: ``Single``)
3083 Always use single quotes.
3090 * ``JSQS_Double`` (in configuration: ``Double``)
3091 Always use double quotes.
3100 **JavaScriptWrapImports** (``Boolean``) :versionbadge:`clang-format 3.9`
3101 Whether to wrap JavaScript import/export statements.
3107 VeryLongImportsAreAnnoying,
3108 VeryLongImportsAreAnnoying,
3109 VeryLongImportsAreAnnoying,
3110 } from 'some/module.js'
3113 import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js"
3115 **KeepEmptyLinesAtTheStartOfBlocks** (``Boolean``) :versionbadge:`clang-format 3.7`
3116 If true, the empty line at the start of blocks is kept.
3121 if (foo) { vs. if (foo) {
3126 **LambdaBodyIndentation** (``LambdaBodyIndentationKind``) :versionbadge:`clang-format 13`
3127 The indentation style of lambda bodies. ``Signature`` (the default)
3128 causes the lambda body to be indented one additional level relative to
3129 the indentation level of the signature. ``OuterScope`` forces the lambda
3130 body to be indented one additional level relative to the parent scope
3131 containing the lambda signature. For callback-heavy code, it may improve
3132 readability to have the signature indented two levels and to use
3133 ``OuterScope``. The KJ style guide requires ``OuterScope``.
3135 <https://github.com/capnproto/capnproto/blob/master/style-guide.md>`_
3139 * ``LBI_Signature`` (in configuration: ``Signature``)
3140 Align lambda body relative to the lambda signature. This is the default.
3145 [](SomeReallyLongLambdaSignatureArgument foo) {
3149 * ``LBI_OuterScope`` (in configuration: ``OuterScope``)
3150 Align lambda body relative to the indentation level of the outer scope
3151 the lambda signature resides in.
3156 [](SomeReallyLongLambdaSignatureArgument foo) {
3162 **Language** (``LanguageKind``) :versionbadge:`clang-format 3.5`
3163 Language, this format style is targeted at.
3167 * ``LK_None`` (in configuration: ``None``)
3170 * ``LK_Cpp`` (in configuration: ``Cpp``)
3171 Should be used for C, C++.
3173 * ``LK_CSharp`` (in configuration: ``CSharp``)
3174 Should be used for C#.
3176 * ``LK_Java`` (in configuration: ``Java``)
3177 Should be used for Java.
3179 * ``LK_JavaScript`` (in configuration: ``JavaScript``)
3180 Should be used for JavaScript.
3182 * ``LK_Json`` (in configuration: ``Json``)
3183 Should be used for JSON.
3185 * ``LK_ObjC`` (in configuration: ``ObjC``)
3186 Should be used for Objective-C, Objective-C++.
3188 * ``LK_Proto`` (in configuration: ``Proto``)
3189 Should be used for Protocol Buffers
3190 (https://developers.google.com/protocol-buffers/).
3192 * ``LK_TableGen`` (in configuration: ``TableGen``)
3193 Should be used for TableGen code.
3195 * ``LK_TextProto`` (in configuration: ``TextProto``)
3196 Should be used for Protocol Buffer messages in text format
3197 (https://developers.google.com/protocol-buffers/).
3199 * ``LK_Verilog`` (in configuration: ``Verilog``)
3200 Should be used for Verilog and SystemVerilog.
3201 https://standards.ieee.org/ieee/1800/6700/
3202 https://sci-hub.st/10.1109/IEEESTD.2018.8299595
3206 **MacroBlockBegin** (``String``) :versionbadge:`clang-format 3.7`
3207 A regular expression matching macros that start a block.
3212 MacroBlockBegin: "^NS_MAP_BEGIN|\
3235 **MacroBlockEnd** (``String``) :versionbadge:`clang-format 3.7`
3236 A regular expression matching macros that end a block.
3238 **MaxEmptyLinesToKeep** (``Unsigned``) :versionbadge:`clang-format 3.7`
3239 The maximum number of consecutive empty lines to keep.
3243 MaxEmptyLinesToKeep: 1 vs. MaxEmptyLinesToKeep: 0
3247 i = foo(); return i;
3252 **NamespaceIndentation** (``NamespaceIndentationKind``) :versionbadge:`clang-format 3.7`
3253 The indentation used for namespaces.
3257 * ``NI_None`` (in configuration: ``None``)
3258 Don't indent in namespaces.
3269 * ``NI_Inner`` (in configuration: ``Inner``)
3270 Indent only in inner namespaces (nested in other namespaces).
3281 * ``NI_All`` (in configuration: ``All``)
3282 Indent in all namespaces.
3295 **NamespaceMacros** (``List of Strings``) :versionbadge:`clang-format 9`
3296 A vector of macros which are used to open namespace blocks.
3298 These are expected to be macros of the form:
3302 NAMESPACE(<namespace-name>, ...) {
3306 For example: TESTSUITE
3308 **ObjCBinPackProtocolList** (``BinPackStyle``) :versionbadge:`clang-format 7`
3309 Controls bin-packing Objective-C protocol conformance list
3310 items into as few lines as possible when they go over ``ColumnLimit``.
3312 If ``Auto`` (the default), delegates to the value in
3313 ``BinPackParameters``. If that is ``true``, bin-packs Objective-C
3314 protocol conformance list items into as few lines as possible
3315 whenever they go over ``ColumnLimit``.
3317 If ``Always``, always bin-packs Objective-C protocol conformance
3318 list items into as few lines as possible whenever they go over
3321 If ``Never``, lays out Objective-C protocol conformance list items
3322 onto individual lines whenever they go over ``ColumnLimit``.
3325 .. code-block:: objc
3327 Always (or Auto, if BinPackParameters=true):
3328 @interface ccccccccccccc () <
3329 ccccccccccccc, ccccccccccccc,
3330 ccccccccccccc, ccccccccccccc> {
3333 Never (or Auto, if BinPackParameters=false):
3334 @interface ddddddddddddd () <
3343 * ``BPS_Auto`` (in configuration: ``Auto``)
3344 Automatically determine parameter bin-packing behavior.
3346 * ``BPS_Always`` (in configuration: ``Always``)
3347 Always bin-pack parameters.
3349 * ``BPS_Never`` (in configuration: ``Never``)
3350 Never bin-pack parameters.
3354 **ObjCBlockIndentWidth** (``Unsigned``) :versionbadge:`clang-format 3.7`
3355 The number of characters to use for indentation of ObjC blocks.
3357 .. code-block:: objc
3359 ObjCBlockIndentWidth: 4
3361 [operation setCompletionBlock:^{
3362 [self onOperationDone];
3365 **ObjCBreakBeforeNestedBlockParam** (``Boolean``) :versionbadge:`clang-format 11`
3366 Break parameters list into lines when there is nested block
3367 parameters in a function call.
3374 [self.test1 t:self w:self callback:^(typeof(self) self, NSNumber
3384 callback:^(typeof(self) self, NSNumber *u, NSNumber *v) {
3389 **ObjCSpaceAfterProperty** (``Boolean``) :versionbadge:`clang-format 3.7`
3390 Add a space after ``@property`` in Objective-C, i.e. use
3391 ``@property (readonly)`` instead of ``@property(readonly)``.
3393 **ObjCSpaceBeforeProtocolList** (``Boolean``) :versionbadge:`clang-format 3.7`
3394 Add a space in front of an Objective-C protocol list, i.e. use
3395 ``Foo <Protocol>`` instead of ``Foo<Protocol>``.
3397 **PPIndentWidth** (``Integer``) :versionbadge:`clang-format 13`
3398 The number of columns to use for indentation of preprocessor statements.
3399 When set to -1 (default) ``IndentWidth`` is used also for preprocessor
3412 **PackConstructorInitializers** (``PackConstructorInitializersStyle``) :versionbadge:`clang-format 14`
3413 The pack constructor initializers style to use.
3417 * ``PCIS_Never`` (in configuration: ``Never``)
3418 Always put each constructor initializer on its own line.
3426 * ``PCIS_BinPack`` (in configuration: ``BinPack``)
3427 Bin-pack constructor initializers.
3432 : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(),
3433 cccccccccccccccccccc()
3435 * ``PCIS_CurrentLine`` (in configuration: ``CurrentLine``)
3436 Put all constructor initializers on the current line if they fit.
3437 Otherwise, put each one on its own line.
3441 Constructor() : a(), b()
3444 : aaaaaaaaaaaaaaaaaaaa(),
3445 bbbbbbbbbbbbbbbbbbbb(),
3448 * ``PCIS_NextLine`` (in configuration: ``NextLine``)
3449 Same as ``PCIS_CurrentLine`` except that if all constructor initializers
3450 do not fit on the current line, try to fit them on the next line.
3454 Constructor() : a(), b()
3457 : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), ddddddddddddd()
3460 : aaaaaaaaaaaaaaaaaaaa(),
3461 bbbbbbbbbbbbbbbbbbbb(),
3462 cccccccccccccccccccc()
3466 **PenaltyBreakAssignment** (``Unsigned``) :versionbadge:`clang-format 5`
3467 The penalty for breaking around an assignment operator.
3469 **PenaltyBreakBeforeFirstCallParameter** (``Unsigned``) :versionbadge:`clang-format 3.7`
3470 The penalty for breaking a function call after ``call(``.
3472 **PenaltyBreakComment** (``Unsigned``) :versionbadge:`clang-format 3.7`
3473 The penalty for each line break introduced inside a comment.
3475 **PenaltyBreakFirstLessLess** (``Unsigned``) :versionbadge:`clang-format 3.7`
3476 The penalty for breaking before the first ``<<``.
3478 **PenaltyBreakOpenParenthesis** (``Unsigned``) :versionbadge:`clang-format 14`
3479 The penalty for breaking after ``(``.
3481 **PenaltyBreakString** (``Unsigned``) :versionbadge:`clang-format 3.7`
3482 The penalty for each line break introduced inside a string literal.
3484 **PenaltyBreakTemplateDeclaration** (``Unsigned``) :versionbadge:`clang-format 7`
3485 The penalty for breaking after template declaration.
3487 **PenaltyExcessCharacter** (``Unsigned``) :versionbadge:`clang-format 3.7`
3488 The penalty for each character outside of the column limit.
3490 **PenaltyIndentedWhitespace** (``Unsigned``) :versionbadge:`clang-format 12`
3491 Penalty for each character of whitespace indentation
3492 (counted relative to leading non-whitespace column).
3494 **PenaltyReturnTypeOnItsOwnLine** (``Unsigned``) :versionbadge:`clang-format 3.7`
3495 Penalty for putting the return type of a function onto its own
3498 **PointerAlignment** (``PointerAlignmentStyle``) :versionbadge:`clang-format 3.7`
3499 Pointer and reference alignment style.
3503 * ``PAS_Left`` (in configuration: ``Left``)
3504 Align pointer to the left.
3510 * ``PAS_Right`` (in configuration: ``Right``)
3511 Align pointer to the right.
3517 * ``PAS_Middle`` (in configuration: ``Middle``)
3518 Align pointer in the middle.
3526 **QualifierAlignment** (``QualifierAlignmentStyle``) :versionbadge:`clang-format 14`
3527 Different ways to arrange specifiers and qualifiers (e.g. const/volatile).
3531 Setting ``QualifierAlignment`` to something other than `Leave`, COULD
3532 lead to incorrect code formatting due to incorrect decisions made due to
3533 clang-formats lack of complete semantic information.
3534 As such extra care should be taken to review code changes made by the use
3539 * ``QAS_Leave`` (in configuration: ``Leave``)
3540 Don't change specifiers/qualifiers to either Left or Right alignment
3548 * ``QAS_Left`` (in configuration: ``Left``)
3549 Change specifiers/qualifiers to be left-aligned.
3556 * ``QAS_Right`` (in configuration: ``Right``)
3557 Change specifiers/qualifiers to be right-aligned.
3564 * ``QAS_Custom`` (in configuration: ``Custom``)
3565 Change specifiers/qualifiers to be aligned based on ``QualifierOrder``.
3568 .. code-block:: yaml
3570 QualifierOrder: ['inline', 'static', 'type', 'const']
3581 **QualifierOrder** (``List of Strings``) :versionbadge:`clang-format 14`
3582 The order in which the qualifiers appear.
3583 Order is an array that can contain any of the following:
3593 Note: it MUST contain 'type'.
3594 Items to the left of 'type' will be placed to the left of the type and
3595 aligned in the order supplied. Items to the right of 'type' will be placed
3596 to the right of the type and aligned in the order supplied.
3599 .. code-block:: yaml
3601 QualifierOrder: ['inline', 'static', 'type', 'const', 'volatile' ]
3603 **RawStringFormats** (``List of RawStringFormats``) :versionbadge:`clang-format 6`
3604 Defines hints for detecting supported languages code blocks in raw
3607 A raw string with a matching delimiter or a matching enclosing function
3608 name will be reformatted assuming the specified language based on the
3609 style for that language defined in the .clang-format file. If no style has
3610 been defined in the .clang-format file for the specific language, a
3611 predefined style given by 'BasedOnStyle' is used. If 'BasedOnStyle' is not
3612 found, the formatting is based on llvm style. A matching delimiter takes
3613 precedence over a matching enclosing function name for determining the
3614 language of the raw string contents.
3616 If a canonical delimiter is specified, occurrences of other delimiters for
3617 the same language will be updated to the canonical if possible.
3619 There should be at most one specification per language and each delimiter
3620 and enclosing function should not occur in multiple specifications.
3622 To configure this in the .clang-format file, use:
3624 .. code-block:: yaml
3627 - Language: TextProto
3632 - 'PARSE_TEXT_PROTO'
3633 BasedOnStyle: google
3639 CanonicalDelimiter: 'cc'
3641 **ReferenceAlignment** (``ReferenceAlignmentStyle``) :versionbadge:`clang-format 13`
3642 Reference alignment style (overrides ``PointerAlignment`` for
3647 * ``RAS_Pointer`` (in configuration: ``Pointer``)
3648 Align reference like ``PointerAlignment``.
3650 * ``RAS_Left`` (in configuration: ``Left``)
3651 Align reference to the left.
3657 * ``RAS_Right`` (in configuration: ``Right``)
3658 Align reference to the right.
3664 * ``RAS_Middle`` (in configuration: ``Middle``)
3665 Align reference in the middle.
3673 **ReflowComments** (``Boolean``) :versionbadge:`clang-format 4`
3674 If ``true``, clang-format will attempt to re-flow comments.
3679 // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
3680 /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */
3683 // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
3685 /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
3688 **RemoveBracesLLVM** (``Boolean``) :versionbadge:`clang-format 14`
3689 Remove optional braces of control statements (``if``, ``else``, ``for``,
3690 and ``while``) in C++ according to the LLVM coding style.
3694 This option will be renamed and expanded to support other styles.
3698 Setting this option to `true` could lead to incorrect code formatting due
3699 to clang-format's lack of complete semantic information. As such, extra
3700 care should be taken to review code changes made by this option.
3706 if (isa<FunctionDecl>(D)) { vs. if (isa<FunctionDecl>(D))
3707 handleFunctionDecl(D); handleFunctionDecl(D);
3708 } else if (isa<VarDecl>(D)) { else if (isa<VarDecl>(D))
3709 handleVarDecl(D); handleVarDecl(D);
3712 if (isa<VarDecl>(D)) { vs. if (isa<VarDecl>(D)) {
3713 for (auto *A : D.attrs()) { for (auto *A : D.attrs())
3714 if (shouldProcessAttr(A)) { if (shouldProcessAttr(A))
3715 handleAttr(A); handleAttr(A);
3720 if (isa<FunctionDecl>(D)) { vs. if (isa<FunctionDecl>(D))
3721 for (auto *A : D.attrs()) { for (auto *A : D.attrs())
3722 handleAttr(A); handleAttr(A);
3726 if (auto *D = (T)(D)) { vs. if (auto *D = (T)(D)) {
3727 if (shouldProcess(D)) { if (shouldProcess(D))
3728 handleVarDecl(D); handleVarDecl(D);
3730 markAsIgnored(D); markAsIgnored(D);
3736 } else { else if (c)
3744 **RequiresClausePosition** (``RequiresClausePositionStyle``) :versionbadge:`clang-format 15`
3745 The position of the ``requires`` clause.
3749 * ``RCPS_OwnLine`` (in configuration: ``OwnLine``)
3750 Always put the ``requires`` clause on its own line.
3754 template <typename T>
3758 template <typename T>
3762 template <typename T>
3767 * ``RCPS_WithPreceding`` (in configuration: ``WithPreceding``)
3768 Try to put the clause together with the preceding part of a declaration.
3769 For class templates: stick to the template declaration.
3770 For function templates: stick to the template declaration.
3771 For function declaration followed by a requires clause: stick to the
3776 template <typename T> requires C<T>
3779 template <typename T> requires C<T>
3782 template <typename T>
3783 void baz(T t) requires C<T>
3786 * ``RCPS_WithFollowing`` (in configuration: ``WithFollowing``)
3787 Try to put the ``requires`` clause together with the class or function
3792 template <typename T>
3793 requires C<T> struct Foo {...
3795 template <typename T>
3796 requires C<T> void bar(T t) {...
3798 template <typename T>
3802 * ``RCPS_SingleLine`` (in configuration: ``SingleLine``)
3803 Try to put everything in the same line if possible. Otherwise normal
3804 line breaking rules take over.
3809 template <typename T> requires C<T> struct Foo {...
3811 template <typename T> requires C<T> void bar(T t) {...
3813 template <typename T> void bar(T t) requires C<T> {...
3815 // Not fitting, one possible example:
3816 template <typename LongName>
3817 requires C<LongName>
3820 template <typename LongName>
3821 requires C<LongName>
3822 void bar(LongName ln) {
3824 template <typename LongName>
3825 void bar(LongName ln)
3826 requires C<LongName> {
3830 **SeparateDefinitionBlocks** (``SeparateDefinitionStyle``) :versionbadge:`clang-format 14`
3831 Specifies the use of empty lines to separate definition blocks, including
3832 classes, structs, enums, and functions.
3837 #include <cstring> #include <cstring>
3839 int a, b, c; struct Foo {
3843 public: namespace Ns {
3844 struct Foobar { class Bar {
3846 int b; struct Foobar {
3854 ITEM1, int method1() {
3857 template<typename T>
3858 int method2(T x) { enum List {
3862 int method3(int par) {
3863 // ... template<typename T>
3864 } int method2(T x) {
3870 int method3(int par) {
3880 * ``SDS_Leave`` (in configuration: ``Leave``)
3881 Leave definition blocks as they are.
3883 * ``SDS_Always`` (in configuration: ``Always``)
3884 Insert an empty line between definition blocks.
3886 * ``SDS_Never`` (in configuration: ``Never``)
3887 Remove any empty line between definition blocks.
3891 **ShortNamespaceLines** (``Unsigned``) :versionbadge:`clang-format 13`
3892 The maximal number of unwrapped lines that a short namespace spans.
3895 This determines the maximum length of short namespaces by counting
3896 unwrapped lines (i.e. containing neither opening nor closing
3897 namespace brace) and makes "FixNamespaceComments" omit adding
3898 end comments for those.
3902 ShortNamespaceLines: 1 vs. ShortNamespaceLines: 0
3903 namespace a { namespace a {
3907 ShortNamespaceLines: 1 vs. ShortNamespaceLines: 0
3908 namespace b { namespace b {
3911 } // namespace b } // namespace b
3913 **SortIncludes** (``SortIncludesOptions``) :versionbadge:`clang-format 4`
3914 Controls if and how clang-format will sort ``#includes``.
3915 If ``Never``, includes are never sorted.
3916 If ``CaseInsensitive``, includes are sorted in an ASCIIbetical or case
3917 insensitive fashion.
3918 If ``CaseSensitive``, includes are sorted in an alphabetical or case
3923 * ``SI_Never`` (in configuration: ``Never``)
3924 Includes are never sorted.
3934 * ``SI_CaseSensitive`` (in configuration: ``CaseSensitive``)
3935 Includes are sorted in an ASCIIbetical or case sensitive fashion.
3945 * ``SI_CaseInsensitive`` (in configuration: ``CaseInsensitive``)
3946 Includes are sorted in an alphabetical or case insensitive fashion.
3958 **SortJavaStaticImport** (``SortJavaStaticImportOptions``) :versionbadge:`clang-format 12`
3959 When sorting Java imports, by default static imports are placed before
3960 non-static imports. If ``JavaStaticImportAfterImport`` is ``After``,
3961 static imports are placed after non-static imports.
3965 * ``SJSIO_Before`` (in configuration: ``Before``)
3966 Static imports are placed before non-static imports.
3968 .. code-block:: java
3970 import static org.example.function1;
3972 import org.example.ClassA;
3974 * ``SJSIO_After`` (in configuration: ``After``)
3975 Static imports are placed after non-static imports.
3977 .. code-block:: java
3979 import org.example.ClassA;
3981 import static org.example.function1;
3985 **SortUsingDeclarations** (``Boolean``) :versionbadge:`clang-format 5`
3986 If ``true``, clang-format will sort using declarations.
3988 The order of using declarations is defined as follows:
3989 Split the strings by "::" and discard any initial empty strings. The last
3990 element of each list is a non-namespace name; all others are namespace
3991 names. Sort the lists of names lexicographically, where the sort order of
3992 individual names is that all non-namespace names come before all namespace
3993 names, and within those groups, names are in case-insensitive
3994 lexicographic order.
3999 using std::cout; vs. using std::cin;
4000 using std::cin; using std::cout;
4002 **SpaceAfterCStyleCast** (``Boolean``) :versionbadge:`clang-format 3.5`
4003 If ``true``, a space is inserted after C style casts.
4008 (int) i; vs. (int)i;
4010 **SpaceAfterLogicalNot** (``Boolean``) :versionbadge:`clang-format 9`
4011 If ``true``, a space is inserted after the logical not operator (``!``).
4016 ! someExpression(); vs. !someExpression();
4018 **SpaceAfterTemplateKeyword** (``Boolean``) :versionbadge:`clang-format 4`
4019 If ``true``, a space will be inserted after the 'template' keyword.
4024 template <int> void foo(); vs. template<int> void foo();
4026 **SpaceAroundPointerQualifiers** (``SpaceAroundPointerQualifiersStyle``) :versionbadge:`clang-format 12`
4027 Defines in which cases to put a space before or after pointer qualifiers
4031 * ``SAPQ_Default`` (in configuration: ``Default``)
4032 Don't ensure spaces around pointer qualifiers and use PointerAlignment
4037 PointerAlignment: Left PointerAlignment: Right
4038 void* const* x = NULL; vs. void *const *x = NULL;
4040 * ``SAPQ_Before`` (in configuration: ``Before``)
4041 Ensure that there is a space before pointer qualifiers.
4045 PointerAlignment: Left PointerAlignment: Right
4046 void* const* x = NULL; vs. void * const *x = NULL;
4048 * ``SAPQ_After`` (in configuration: ``After``)
4049 Ensure that there is a space after pointer qualifiers.
4053 PointerAlignment: Left PointerAlignment: Right
4054 void* const * x = NULL; vs. void *const *x = NULL;
4056 * ``SAPQ_Both`` (in configuration: ``Both``)
4057 Ensure that there is a space both before and after pointer qualifiers.
4061 PointerAlignment: Left PointerAlignment: Right
4062 void* const * x = NULL; vs. void * const *x = NULL;
4066 **SpaceBeforeAssignmentOperators** (``Boolean``) :versionbadge:`clang-format 3.7`
4067 If ``false``, spaces will be removed before assignment operators.
4072 int a = 5; vs. int a= 5;
4075 **SpaceBeforeCaseColon** (``Boolean``) :versionbadge:`clang-format 12`
4076 If ``false``, spaces will be removed before case colon.
4081 switch (x) { vs. switch (x) {
4082 case 1 : break; case 1: break;
4085 **SpaceBeforeCpp11BracedList** (``Boolean``) :versionbadge:`clang-format 7`
4086 If ``true``, a space will be inserted before a C++11 braced list
4087 used to initialize an object (after the preceding identifier or type).
4092 Foo foo { bar }; vs. Foo foo{ bar };
4094 vector<int> { 1, 2, 3 }; vector<int>{ 1, 2, 3 };
4095 new int[3] { 1, 2, 3 }; new int[3]{ 1, 2, 3 };
4097 **SpaceBeforeCtorInitializerColon** (``Boolean``) :versionbadge:`clang-format 7`
4098 If ``false``, spaces will be removed before constructor initializer
4104 Foo::Foo() : a(a) {} Foo::Foo(): a(a) {}
4106 **SpaceBeforeInheritanceColon** (``Boolean``) :versionbadge:`clang-format 7`
4107 If ``false``, spaces will be removed before inheritance colon.
4112 class Foo : Bar {} vs. class Foo: Bar {}
4114 **SpaceBeforeParens** (``SpaceBeforeParensStyle``) :versionbadge:`clang-format 3.5`
4115 Defines in which cases to put a space before opening parentheses.
4119 * ``SBPO_Never`` (in configuration: ``Never``)
4120 Never put a space before opening parentheses.
4130 * ``SBPO_ControlStatements`` (in configuration: ``ControlStatements``)
4131 Put a space before opening parentheses only after control statement
4132 keywords (``for/if/while...``).
4142 * ``SBPO_ControlStatementsExceptControlMacros`` (in configuration: ``ControlStatementsExceptControlMacros``)
4143 Same as ``SBPO_ControlStatements`` except this option doesn't apply to
4144 ForEach and If macros. This is useful in projects where ForEach/If
4145 macros are treated as function calls instead of control statements.
4146 ``SBPO_ControlStatementsExceptForEachMacros`` remains an alias for
4147 backward compatibility.
4157 * ``SBPO_NonEmptyParentheses`` (in configuration: ``NonEmptyParentheses``)
4158 Put a space before opening parentheses only if the parentheses are not
4170 * ``SBPO_Always`` (in configuration: ``Always``)
4171 Always put a space before opening parentheses, except when it's
4172 prohibited by the syntax rules (in function-like macro definitions) or
4173 when determined by other style rules (after unary operators, opening
4184 * ``SBPO_Custom`` (in configuration: ``Custom``)
4185 Configure each individual space before parentheses in
4186 `SpaceBeforeParensOptions`.
4190 **SpaceBeforeParensOptions** (``SpaceBeforeParensCustom``) :versionbadge:`clang-format 14`
4191 Control of individual space before parentheses.
4193 If ``SpaceBeforeParens`` is set to ``Custom``, use this to specify
4194 how each individual space before parentheses case should be handled.
4195 Otherwise, this is ignored.
4197 .. code-block:: yaml
4200 SpaceBeforeParens: Custom
4201 SpaceBeforeParensOptions:
4202 AfterControlStatements: true
4203 AfterFunctionDefinitionName: true
4205 Nested configuration flags:
4207 Precise control over the spacing before parentheses.
4211 # Should be declared this way:
4212 SpaceBeforeParens: Custom
4213 SpaceBeforeParensOptions:
4214 AfterControlStatements: true
4215 AfterFunctionDefinitionName: true
4217 * ``bool AfterControlStatements`` If ``true``, put space betwee control statement keywords
4218 (for/if/while...) and opening parentheses.
4223 if (...) {} vs. if(...) {}
4225 * ``bool AfterForeachMacros`` If ``true``, put space between foreach macros and opening parentheses.
4230 FOREACH (...) vs. FOREACH(...)
4231 <loop-body> <loop-body>
4233 * ``bool AfterFunctionDeclarationName`` If ``true``, put a space between function declaration name and opening
4239 void f (); vs. void f();
4241 * ``bool AfterFunctionDefinitionName`` If ``true``, put a space between function definition name and opening
4247 void f () {} vs. void f() {}
4249 * ``bool AfterIfMacros`` If ``true``, put space between if macros and opening parentheses.
4254 IF (...) vs. IF(...)
4255 <conditional-body> <conditional-body>
4257 * ``bool AfterOverloadedOperator`` If ``true``, put a space between operator overloading and opening
4263 void operator++ (int a); vs. void operator++(int a);
4264 object.operator++ (10); object.operator++(10);
4266 * ``bool AfterRequiresInClause`` If ``true``, put space between requires keyword in a requires clause and
4267 opening parentheses, if there is one.
4272 template<typename T> vs. template<typename T>
4273 requires (A<T> && B<T>) requires(A<T> && B<T>)
4276 * ``bool AfterRequiresInExpression`` If ``true``, put space between requires keyword in a requires expression
4277 and opening parentheses.
4282 template<typename T> vs. template<typename T>
4283 concept C = requires (T t) { concept C = requires(T t) {
4287 * ``bool BeforeNonEmptyParentheses`` If ``true``, put a space before opening parentheses only if the
4288 parentheses are not empty.
4293 void f (int a); vs. void f();
4297 **SpaceBeforeRangeBasedForLoopColon** (``Boolean``) :versionbadge:`clang-format 7`
4298 If ``false``, spaces will be removed before range-based for loop
4304 for (auto v : values) {} vs. for(auto v: values) {}
4306 **SpaceBeforeSquareBrackets** (``Boolean``) :versionbadge:`clang-format 10`
4307 If ``true``, spaces will be before ``[``.
4308 Lambdas will not be affected. Only the first ``[`` will get a space added.
4313 int a [5]; vs. int a[5];
4314 int a [5][5]; vs. int a[5][5];
4316 **SpaceInEmptyBlock** (``Boolean``) :versionbadge:`clang-format 10`
4317 If ``true``, spaces will be inserted into ``{}``.
4322 void f() { } vs. void f() {}
4323 while (true) { } while (true) {}
4325 **SpaceInEmptyParentheses** (``Boolean``) :versionbadge:`clang-format 3.7`
4326 If ``true``, spaces may be inserted into ``()``.
4331 void f( ) { vs. void f() {
4332 int x[] = {foo( ), bar( )}; int x[] = {foo(), bar()};
4333 if (true) { if (true) {
4338 **SpacesBeforeTrailingComments** (``Unsigned``) :versionbadge:`clang-format 3.7`
4339 The number of spaces before trailing line comments
4340 (``//`` - comments).
4342 This does not affect trailing block comments (``/*`` - comments) as
4343 those commonly have different usage patterns and a number of special
4348 SpacesBeforeTrailingComments: 3
4355 **SpacesInAngles** (``SpacesInAnglesStyle``) :versionbadge:`clang-format 3.4`
4356 The SpacesInAnglesStyle to use for template argument lists.
4360 * ``SIAS_Never`` (in configuration: ``Never``)
4361 Remove spaces after ``<`` and before ``>``.
4365 static_cast<int>(arg);
4366 std::function<void(int)> fct;
4368 * ``SIAS_Always`` (in configuration: ``Always``)
4369 Add spaces after ``<`` and before ``>``.
4373 static_cast< int >(arg);
4374 std::function< void(int) > fct;
4376 * ``SIAS_Leave`` (in configuration: ``Leave``)
4377 Keep a single space after ``<`` and before ``>`` if any spaces were
4378 present. Option ``Standard: Cpp03`` takes precedence.
4382 **SpacesInCStyleCastParentheses** (``Boolean``) :versionbadge:`clang-format 3.7`
4383 If ``true``, spaces may be inserted into C style casts.
4388 x = ( int32 )y vs. x = (int32)y
4390 **SpacesInConditionalStatement** (``Boolean``) :versionbadge:`clang-format 10`
4391 If ``true``, spaces will be inserted around if/for/switch/while
4397 if ( a ) { ... } vs. if (a) { ... }
4398 while ( i < 5 ) { ... } while (i < 5) { ... }
4400 **SpacesInContainerLiterals** (``Boolean``) :versionbadge:`clang-format 3.7`
4401 If ``true``, spaces are inserted inside container literals (e.g.
4402 ObjC and Javascript array and dict literals).
4407 var arr = [ 1, 2, 3 ]; vs. var arr = [1, 2, 3];
4408 f({a : 1, b : 2, c : 3}); f({a: 1, b: 2, c: 3});
4410 **SpacesInLineCommentPrefix** (``SpacesInLineComment``) :versionbadge:`clang-format 13`
4411 How many spaces are allowed at the start of a line comment. To disable the
4412 maximum set it to ``-1``, apart from that the maximum takes precedence
4419 // One space is forced
4421 // but more spaces are possible
4425 //Forces to start every comment directly after the slashes
4427 Note that in line comment sections the relative indent of the subsequent
4428 lines is kept, that means the following:
4434 //if (b) { // if (b) {
4435 // return true; // return true;
4443 Nested configuration flags:
4445 Control of spaces within a single line comment
4447 * ``unsigned Minimum`` The minimum number of spaces at the start of the comment.
4449 * ``unsigned Maximum`` The maximum number of spaces at the start of the comment.
4452 **SpacesInParentheses** (``Boolean``) :versionbadge:`clang-format 3.7`
4453 If ``true``, spaces will be inserted after ``(`` and before ``)``.
4458 t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete;
4460 **SpacesInSquareBrackets** (``Boolean``) :versionbadge:`clang-format 3.7`
4461 If ``true``, spaces will be inserted after ``[`` and before ``]``.
4462 Lambdas without arguments or unspecified size array declarations will not
4468 int a[ 5 ]; vs. int a[5];
4469 std::unique_ptr<int[]> foo() {} // Won't be affected
4471 **Standard** (``LanguageStandard``) :versionbadge:`clang-format 3.7`
4472 Parse and format C++ constructs compatible with this standard.
4477 vector<set<int> > x; vs. vector<set<int>> x;
4481 * ``LS_Cpp03`` (in configuration: ``c++03``)
4482 Parse and format as C++03.
4483 ``Cpp03`` is a deprecated alias for ``c++03``
4485 * ``LS_Cpp11`` (in configuration: ``c++11``)
4486 Parse and format as C++11.
4488 * ``LS_Cpp14`` (in configuration: ``c++14``)
4489 Parse and format as C++14.
4491 * ``LS_Cpp17`` (in configuration: ``c++17``)
4492 Parse and format as C++17.
4494 * ``LS_Cpp20`` (in configuration: ``c++20``)
4495 Parse and format as C++20.
4497 * ``LS_Latest`` (in configuration: ``Latest``)
4498 Parse and format using the latest supported language version.
4499 ``Cpp11`` is a deprecated alias for ``Latest``
4501 * ``LS_Auto`` (in configuration: ``Auto``)
4502 Automatic detection based on the input.
4506 **StatementAttributeLikeMacros** (``List of Strings``) :versionbadge:`clang-format 12`
4507 Macros which are ignored in front of a statement, as if they were an
4508 attribute. So that they are not parsed as identifier, for example for Qts
4513 AlignConsecutiveDeclarations: true
4514 StatementAttributeLikeMacros: []
4515 unsigned char data = 'x';
4516 emit signal(data); // This is parsed as variable declaration.
4518 AlignConsecutiveDeclarations: true
4519 StatementAttributeLikeMacros: [emit]
4520 unsigned char data = 'x';
4521 emit signal(data); // Now it's fine again.
4523 **StatementMacros** (``List of Strings``) :versionbadge:`clang-format 8`
4524 A vector of macros that should be interpreted as complete
4527 Typical macros are expressions, and require a semi-colon to be
4528 added; sometimes this is not the case, and this allows to make
4529 clang-format aware of such cases.
4531 For example: Q_UNUSED
4533 **TabWidth** (``Unsigned``) :versionbadge:`clang-format 3.7`
4534 The number of columns used for tab stops.
4536 **TypenameMacros** (``List of Strings``) :versionbadge:`clang-format 9`
4537 A vector of macros that should be interpreted as type declarations
4538 instead of as function calls.
4540 These are expected to be macros of the form:
4546 In the .clang-format configuration file, this can be configured like:
4548 .. code-block:: yaml
4550 TypenameMacros: ['STACK_OF', 'LIST']
4552 For example: OpenSSL STACK_OF, BSD LIST_ENTRY.
4554 **UseCRLF** (``Boolean``) :versionbadge:`clang-format 10`
4555 Use ``\r\n`` instead of ``\n`` for line breaks.
4556 Also used as fallback if ``DeriveLineEnding`` is true.
4558 **UseTab** (``UseTabStyle``) :versionbadge:`clang-format 3.7`
4559 The way to use tab characters in the resulting file.
4563 * ``UT_Never`` (in configuration: ``Never``)
4566 * ``UT_ForIndentation`` (in configuration: ``ForIndentation``)
4567 Use tabs only for indentation.
4569 * ``UT_ForContinuationAndIndentation`` (in configuration: ``ForContinuationAndIndentation``)
4570 Fill all leading whitespace with tabs, and use spaces for alignment that
4571 appears within a line (e.g. consecutive assignments and declarations).
4573 * ``UT_AlignWithSpaces`` (in configuration: ``AlignWithSpaces``)
4574 Use tabs for line continuation and indentation, and spaces for
4577 * ``UT_Always`` (in configuration: ``Always``)
4578 Use tabs whenever we need to fill whitespace that spans at least from
4579 one tab stop to the next one.
4583 **WhitespaceSensitiveMacros** (``List of Strings``) :versionbadge:`clang-format 11`
4584 A vector of macros which are whitespace-sensitive and should not
4587 These are expected to be macros of the form:
4593 In the .clang-format configuration file, this can be configured like:
4595 .. code-block:: yaml
4597 WhitespaceSensitiveMacros: ['STRINGIZE', 'PP_STRINGIZE']
4599 For example: BOOST_PP_STRINGIZE
4601 .. END_FORMAT_STYLE_OPTIONS
4603 Adding additional style options
4604 ===============================
4606 Each additional style option adds costs to the clang-format project. Some of
4607 these costs affect the clang-format development itself, as we need to make
4608 sure that any given combination of options work and that new features don't
4609 break any of the existing options in any way. There are also costs for end users
4610 as options become less discoverable and people have to think about and make a
4611 decision on options they don't really care about.
4613 The goal of the clang-format project is more on the side of supporting a
4614 limited set of styles really well as opposed to supporting every single style
4615 used by a codebase somewhere in the wild. Of course, we do want to support all
4616 major projects and thus have established the following bar for adding style
4617 options. Each new style option must ..
4619 * be used in a project of significant size (have dozens of contributors)
4620 * have a publicly accessible style guide
4621 * have a person willing to contribute and maintain patches
4626 A style similar to the `Linux Kernel style
4627 <https://www.kernel.org/doc/Documentation/CodingStyle>`_:
4629 .. code-block:: yaml
4634 BreakBeforeBraces: Linux
4635 AllowShortIfStatementsOnASingleLine: false
4636 IndentCaseLabels: false
4638 The result is (imagine that tabs are used for indentation here):
4650 do_something_else();
4656 do_something_completely_different();
4667 A style similar to the default Visual Studio formatting style:
4669 .. code-block:: yaml
4673 BreakBeforeBraces: Allman
4674 AllowShortIfStatementsOnASingleLine: false
4675 IndentCaseLabels: false
4691 do_something_else();
4697 do_something_completely_different();