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** (``TrailingCommentsAlignmentStyle``) :versionbadge:`clang-format 3.7`
850 Control of trailing comments.
852 NOTE: As of clang-format 16 this option is not a bool but can be set
853 to the options. Conventional bool options still can be parsed as before.
859 AlignTrailingComments:
863 Nested configuration flags:
867 * ``TrailingCommentsAlignmentKinds Kind``
868 Specifies the way to align trailing comments.
872 * ``TCAS_Leave`` (in configuration: ``Leave``)
873 Leave trailing comments as they are.
883 * ``TCAS_Always`` (in configuration: ``Always``)
884 Align trailing comments.
894 * ``TCAS_Never`` (in configuration: ``Never``)
895 Don't align trailing comments but other formatter applies.
906 * ``unsigned OverEmptyLines`` How many empty lines to apply alignment.
907 When both ``MaxEmptyLinesToKeep`` and ``OverEmptyLines`` are set to 2,
908 it formats like below.
914 int ab; // comments are
917 int abcdef; // aligned
919 When ``MaxEmptyLinesToKeep`` is set to 2 and ``OverEmptyLines`` is set
920 to 1, it formats like below.
929 int abcdef; // but this isn't
932 **AllowAllArgumentsOnNextLine** (``Boolean``) :versionbadge:`clang-format 9`
933 If a function call or braced initializer list doesn't fit on a
934 line, allow putting all arguments onto the next line, even if
935 ``BinPackArguments`` is ``false``.
949 **AllowAllConstructorInitializersOnNextLine** (``Boolean``) :versionbadge:`clang-format 9`
950 This option is **deprecated**. See ``NextLine`` of
951 ``PackConstructorInitializers``.
953 **AllowAllParametersOfDeclarationOnNextLine** (``Boolean``) :versionbadge:`clang-format 3.3`
954 If the function declaration doesn't fit on a line,
955 allow putting all parameters of a function declaration onto
956 the next line even if ``BinPackParameters`` is ``false``.
962 int a, int b, int c, int d, int e);
965 void myFunction(int a,
971 **AllowShortBlocksOnASingleLine** (``ShortBlockStyle``) :versionbadge:`clang-format 3.5`
972 Dependent on the value, ``while (true) { continue; }`` can be put on a
977 * ``SBS_Never`` (in configuration: ``Never``)
978 Never merge blocks into a single line.
988 * ``SBS_Empty`` (in configuration: ``Empty``)
989 Only merge empty blocks.
998 * ``SBS_Always`` (in configuration: ``Always``)
999 Always merge short blocks into a single line.
1004 while (true) { continue; }
1008 **AllowShortCaseLabelsOnASingleLine** (``Boolean``) :versionbadge:`clang-format 3.6`
1009 If ``true``, short case labels will be contracted to a single line.
1014 switch (a) { vs. switch (a) {
1015 case 1: x = 1; break; case 1:
1016 case 2: return; x = 1;
1022 **AllowShortEnumsOnASingleLine** (``Boolean``) :versionbadge:`clang-format 11`
1023 Allow short enums on a single line.
1028 enum { A, B } myEnum;
1036 **AllowShortFunctionsOnASingleLine** (``ShortFunctionStyle``) :versionbadge:`clang-format 3.5`
1037 Dependent on the value, ``int f() { return 0; }`` can be put on a
1042 * ``SFS_None`` (in configuration: ``None``)
1043 Never merge functions into a single line.
1045 * ``SFS_InlineOnly`` (in configuration: ``InlineOnly``)
1046 Only merge functions defined inside a class. Same as "inline",
1047 except it does not implies "empty": i.e. top level empty functions
1048 are not merged either.
1061 * ``SFS_Empty`` (in configuration: ``Empty``)
1062 Only merge empty functions.
1071 * ``SFS_Inline`` (in configuration: ``Inline``)
1072 Only merge functions defined inside a class. Implies "empty".
1084 * ``SFS_All`` (in configuration: ``All``)
1085 Merge all functions fitting on a single line.
1096 **AllowShortIfStatementsOnASingleLine** (``ShortIfStyle``) :versionbadge:`clang-format 3.3`
1097 Dependent on the value, ``if (a) return;`` can be put on a single line.
1101 * ``SIS_Never`` (in configuration: ``Never``)
1102 Never put short ifs on the same line.
1120 * ``SIS_WithoutElse`` (in configuration: ``WithoutElse``)
1121 Put short ifs on the same line only if there is no else statement.
1138 * ``SIS_OnlyFirstIf`` (in configuration: ``OnlyFirstIf``)
1139 Put short ifs, but not else ifs nor else statements, on the same line.
1156 * ``SIS_AllIfsAndElse`` (in configuration: ``AllIfsAndElse``)
1157 Always put short ifs, else ifs and else statements on the same
1174 **AllowShortLambdasOnASingleLine** (``ShortLambdaStyle``) :versionbadge:`clang-format 9`
1175 Dependent on the value, ``auto lambda []() { return 0; }`` can be put on a
1180 * ``SLS_None`` (in configuration: ``None``)
1181 Never merge lambdas into a single line.
1183 * ``SLS_Empty`` (in configuration: ``Empty``)
1184 Only merge empty lambdas.
1188 auto lambda = [](int a) {};
1189 auto lambda2 = [](int a) {
1193 * ``SLS_Inline`` (in configuration: ``Inline``)
1194 Merge lambda into a single line if argument of a function.
1198 auto lambda = [](int a) {
1201 sort(a.begin(), a.end(), []() { return x < y; });
1203 * ``SLS_All`` (in configuration: ``All``)
1204 Merge all lambdas fitting on a single line.
1208 auto lambda = [](int a) {};
1209 auto lambda2 = [](int a) { return a; };
1213 **AllowShortLoopsOnASingleLine** (``Boolean``) :versionbadge:`clang-format 3.7`
1214 If ``true``, ``while (true) continue;`` can be put on a single
1217 **AlwaysBreakAfterDefinitionReturnType** (``DefinitionReturnTypeBreakingStyle``) :versionbadge:`clang-format 3.7`
1218 The function definition return type breaking style to use. This
1219 option is **deprecated** and is retained for backwards compatibility.
1223 * ``DRTBS_None`` (in configuration: ``None``)
1224 Break after return type automatically.
1225 ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
1227 * ``DRTBS_All`` (in configuration: ``All``)
1228 Always break after the return type.
1230 * ``DRTBS_TopLevel`` (in configuration: ``TopLevel``)
1231 Always break after the return types of top-level functions.
1235 **AlwaysBreakAfterReturnType** (``ReturnTypeBreakingStyle``) :versionbadge:`clang-format 3.8`
1236 The function declaration return type breaking style to use.
1240 * ``RTBS_None`` (in configuration: ``None``)
1241 Break after return type automatically.
1242 ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
1247 int f() { return 0; };
1250 int f() { return 1; }
1252 * ``RTBS_All`` (in configuration: ``All``)
1253 Always break after the return type.
1270 * ``RTBS_TopLevel`` (in configuration: ``TopLevel``)
1271 Always break after the return types of top-level functions.
1276 int f() { return 0; };
1285 * ``RTBS_AllDefinitions`` (in configuration: ``AllDefinitions``)
1286 Always break after the return type of function definitions.
1302 * ``RTBS_TopLevelDefinitions`` (in configuration: ``TopLevelDefinitions``)
1303 Always break after the return type of top-level definitions.
1308 int f() { return 0; };
1318 **AlwaysBreakBeforeMultilineStrings** (``Boolean``) :versionbadge:`clang-format 3.4`
1319 If ``true``, always break before multiline string literals.
1321 This flag is mean to make cases where there are multiple multiline strings
1322 in a file look more consistent. Thus, it will only take effect if wrapping
1323 the string at that point leads to it being indented
1324 ``ContinuationIndentWidth`` spaces from the start of the line.
1329 aaaa = vs. aaaa = "bbbb"
1333 **AlwaysBreakTemplateDeclarations** (``BreakTemplateDeclarationsStyle``) :versionbadge:`clang-format 3.4`
1334 The template declaration breaking style to use.
1338 * ``BTDS_No`` (in configuration: ``No``)
1339 Do not force break before declaration.
1340 ``PenaltyBreakTemplateDeclaration`` is taken into account.
1344 template <typename T> T foo() {
1346 template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa,
1347 int bbbbbbbbbbbbbbbbbbbbb) {
1350 * ``BTDS_MultiLine`` (in configuration: ``MultiLine``)
1351 Force break after template declaration only when the following
1352 declaration spans multiple lines.
1356 template <typename T> T foo() {
1358 template <typename T>
1359 T foo(int aaaaaaaaaaaaaaaaaaaaa,
1360 int bbbbbbbbbbbbbbbbbbbbb) {
1363 * ``BTDS_Yes`` (in configuration: ``Yes``)
1364 Always break after template declaration.
1368 template <typename T>
1371 template <typename T>
1372 T foo(int aaaaaaaaaaaaaaaaaaaaa,
1373 int bbbbbbbbbbbbbbbbbbbbb) {
1378 **AttributeMacros** (``List of Strings``) :versionbadge:`clang-format 12`
1379 A vector of strings that should be interpreted as attributes/qualifiers
1380 instead of identifiers. This can be useful for language extensions or
1381 static analyzer annotations.
1387 x = (char *__capability)&y;
1388 int function(void) __ununsed;
1389 void only_writes_to_buffer(char *__output buffer);
1391 In the .clang-format configuration file, this can be configured like:
1393 .. code-block:: yaml
1395 AttributeMacros: ['__capability', '__output', '__ununsed']
1397 **BinPackArguments** (``Boolean``) :versionbadge:`clang-format 3.7`
1398 If ``false``, a function call's arguments will either be all on the
1399 same line or will have one line each.
1405 f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa,
1406 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
1411 f(aaaaaaaaaaaaaaaaaaaa,
1412 aaaaaaaaaaaaaaaaaaaa,
1413 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
1416 **BinPackParameters** (``Boolean``) :versionbadge:`clang-format 3.7`
1417 If ``false``, a function declaration's or function definition's
1418 parameters will either all be on the same line or will have one line each.
1423 void f(int aaaaaaaaaaaaaaaaaaaa, int aaaaaaaaaaaaaaaaaaaa,
1424 int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
1427 void f(int aaaaaaaaaaaaaaaaaaaa,
1428 int aaaaaaaaaaaaaaaaaaaa,
1429 int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
1431 **BitFieldColonSpacing** (``BitFieldColonSpacingStyle``) :versionbadge:`clang-format 12`
1432 The BitFieldColonSpacingStyle to use for bitfields.
1436 * ``BFCS_Both`` (in configuration: ``Both``)
1437 Add one space on each side of the ``:``
1443 * ``BFCS_None`` (in configuration: ``None``)
1444 Add no space around the ``:`` (except when needed for
1445 ``AlignConsecutiveBitFields``).
1451 * ``BFCS_Before`` (in configuration: ``Before``)
1452 Add space before the ``:`` only
1458 * ``BFCS_After`` (in configuration: ``After``)
1459 Add space after the ``:`` only (space may be added before if
1460 needed for ``AlignConsecutiveBitFields``).
1468 **BraceWrapping** (``BraceWrappingFlags``) :versionbadge:`clang-format 3.8`
1469 Control of individual brace wrapping cases.
1471 If ``BreakBeforeBraces`` is set to ``BS_Custom``, use this to specify how
1472 each individual brace case should be handled. Otherwise, this is ignored.
1474 .. code-block:: yaml
1477 BreakBeforeBraces: Custom
1481 SplitEmptyFunction: false
1483 Nested configuration flags:
1485 Precise control over the wrapping of braces.
1489 # Should be declared this way:
1490 BreakBeforeBraces: Custom
1494 * ``bool AfterCaseLabel`` Wrap case labels.
1499 switch (foo) { vs. switch (foo) {
1511 * ``bool AfterClass`` Wrap class definitions.
1522 * ``BraceWrappingAfterControlStatementStyle AfterControlStatement``
1523 Wrap control statements (``if``/``for``/``while``/``switch``/..).
1527 * ``BWACS_Never`` (in configuration: ``Never``)
1528 Never wrap braces after a control statement.
1535 for (int i = 0; i < 10; ++i) {
1538 * ``BWACS_MultiLine`` (in configuration: ``MultiLine``)
1539 Only wrap braces after a multi-line control statement.
1548 while (foo || bar) {
1551 * ``BWACS_Always`` (in configuration: ``Always``)
1552 Always wrap braces after a control statement.
1560 for (int i = 0; i < 10; ++i)
1564 * ``bool AfterEnum`` Wrap enum definitions.
1577 * ``bool AfterFunction`` Wrap function definitions.
1594 * ``bool AfterNamespace`` Wrap namespace definitions.
1611 * ``bool AfterObjCDeclaration`` Wrap ObjC definitions (interfaces, implementations...).
1612 @autoreleasepool and @synchronized blocks are wrapped
1613 according to `AfterControlStatement` flag.
1615 * ``bool AfterStruct`` Wrap struct definitions.
1630 * ``bool AfterUnion`` Wrap union definitions.
1645 * ``bool AfterExternBlock`` Wrap extern blocks.
1660 * ``bool BeforeCatch`` Wrap before ``catch``.
1677 * ``bool BeforeElse`` Wrap before ``else``.
1692 * ``bool BeforeLambdaBody`` Wrap lambda block.
1710 * ``bool BeforeWhile`` Wrap before ``while``.
1725 * ``bool IndentBraces`` Indent the wrapped braces themselves.
1727 * ``bool SplitEmptyFunction`` If ``false``, empty function body can be put on a single line.
1728 This option is used only if the opening brace of the function has
1729 already been wrapped, i.e. the `AfterFunction` brace wrapping mode is
1730 set, and the function could/should not be put on a single line (as per
1731 `AllowShortFunctionsOnASingleLine` and constructor formatting options).
1740 * ``bool SplitEmptyRecord`` If ``false``, empty record (e.g. class, struct or union) body
1741 can be put on a single line. This option is used only if the opening
1742 brace of the record has already been wrapped, i.e. the `AfterClass`
1743 (for classes) brace wrapping mode is set.
1748 class Foo vs. class Foo
1752 * ``bool SplitEmptyNamespace`` If ``false``, empty namespace body can be put on a single line.
1753 This option is used only if the opening brace of the namespace has
1754 already been wrapped, i.e. the `AfterNamespace` brace wrapping mode is
1760 namespace Foo vs. namespace Foo
1765 **BreakAfterJavaFieldAnnotations** (``Boolean``) :versionbadge:`clang-format 3.8`
1766 Break after each annotation on a field in Java files.
1768 .. code-block:: java
1771 @Partial vs. @Partial @Mock DataLoad loader;
1775 **BreakArrays** (``Boolean``) :versionbadge:`clang-format 16`
1776 If ``true``, clang-format will always break after a Json array `[`
1777 otherwise it will scan until the closing `]` to determine if it should add
1778 newlines between elements (prettier compatible).
1780 NOTE: This is currently only for formatting JSON.
1792 **BreakBeforeBinaryOperators** (``BinaryOperatorStyle``) :versionbadge:`clang-format 3.6`
1793 The way to wrap binary operators.
1797 * ``BOS_None`` (in configuration: ``None``)
1798 Break after operators.
1802 LooooooooooongType loooooooooooooooooooooongVariable =
1803 someLooooooooooooooooongFunction();
1805 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
1806 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ==
1807 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
1808 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa >
1809 ccccccccccccccccccccccccccccccccccccccccc;
1811 * ``BOS_NonAssignment`` (in configuration: ``NonAssignment``)
1812 Break before operators that aren't assignments.
1816 LooooooooooongType loooooooooooooooooooooongVariable =
1817 someLooooooooooooooooongFunction();
1819 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1820 + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1821 == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1822 && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1823 > ccccccccccccccccccccccccccccccccccccccccc;
1825 * ``BOS_All`` (in configuration: ``All``)
1826 Break before operators.
1830 LooooooooooongType loooooooooooooooooooooongVariable
1831 = someLooooooooooooooooongFunction();
1833 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1834 + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1835 == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1836 && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1837 > ccccccccccccccccccccccccccccccccccccccccc;
1841 **BreakBeforeBraces** (``BraceBreakingStyle``) :versionbadge:`clang-format 3.7`
1842 The brace breaking style to use.
1846 * ``BS_Attach`` (in configuration: ``Attach``)
1847 Always attach braces to surrounding context.
1890 void bar() { foo(true); }
1893 * ``BS_Linux`` (in configuration: ``Linux``)
1894 Like ``Attach``, but break before braces on function, namespace and
1942 void bar() { foo(true); }
1945 * ``BS_Mozilla`` (in configuration: ``Mozilla``)
1946 Like ``Attach``, but break before braces on enum, function, and record
1994 void bar() { foo(true); }
1997 * ``BS_Stroustrup`` (in configuration: ``Stroustrup``)
1998 Like ``Attach``, but break before function definitions, ``catch``, and
2046 void bar() { foo(true); }
2049 * ``BS_Allman`` (in configuration: ``Allman``)
2050 Always break before braces.
2108 void bar() { foo(true); }
2111 * ``BS_Whitesmiths`` (in configuration: ``Whitesmiths``)
2112 Like ``Allman`` but always indent braces and line up code with braces.
2170 void bar() { foo(true); }
2173 * ``BS_GNU`` (in configuration: ``GNU``)
2174 Always break before braces and add an extra level of indentation to
2175 braces of control statements, not to those of class, function
2176 or other definitions.
2235 void bar() { foo(true); }
2238 * ``BS_WebKit`` (in configuration: ``WebKit``)
2239 Like ``Attach``, but break before functions.
2284 void bar() { foo(true); }
2287 * ``BS_Custom`` (in configuration: ``Custom``)
2288 Configure each individual brace in `BraceWrapping`.
2292 **BreakBeforeConceptDeclarations** (``BreakBeforeConceptDeclarationsStyle``) :versionbadge:`clang-format 12`
2293 The concept declaration style to use.
2297 * ``BBCDS_Never`` (in configuration: ``Never``)
2298 Keep the template declaration line together with ``concept``.
2302 template <typename T> concept C = ...;
2304 * ``BBCDS_Allowed`` (in configuration: ``Allowed``)
2305 Breaking between template declaration and ``concept`` is allowed. The
2306 actual behavior depends on the content and line breaking rules and
2309 * ``BBCDS_Always`` (in configuration: ``Always``)
2310 Always break before ``concept``, putting it in the line after the
2311 template declaration.
2315 template <typename T>
2320 **BreakBeforeInlineASMColon** (``BreakBeforeInlineASMColonStyle``) :versionbadge:`clang-format 16`
2321 The inline ASM colon style to use.
2325 * ``BBIAS_Never`` (in configuration: ``Never``)
2326 No break before inline ASM colon.
2330 asm volatile("string", : : val);
2332 * ``BBIAS_OnlyMultiline`` (in configuration: ``OnlyMultiline``)
2333 Break before inline ASM colon if the line length is longer than column
2338 asm volatile("string", : : val);
2339 asm("cmoveq %1, %2, %[result]"
2340 : [result] "=r"(result)
2341 : "r"(test), "r"(new), "[result]"(old));
2343 * ``BBIAS_Always`` (in configuration: ``Always``)
2344 Always break before inline ASM colon.
2348 asm volatile("string",
2354 **BreakBeforeTernaryOperators** (``Boolean``) :versionbadge:`clang-format 3.7`
2355 If ``true``, ternary operators will be placed after line breaks.
2360 veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription
2362 : SecondValueVeryVeryVeryVeryLong;
2365 veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ?
2367 SecondValueVeryVeryVeryVeryLong;
2369 **BreakConstructorInitializers** (``BreakConstructorInitializersStyle``) :versionbadge:`clang-format 5`
2370 The break constructor initializers style to use.
2374 * ``BCIS_BeforeColon`` (in configuration: ``BeforeColon``)
2375 Break constructor initializers before the colon and after the commas.
2383 * ``BCIS_BeforeComma`` (in configuration: ``BeforeComma``)
2384 Break constructor initializers before the colon and commas, and align
2385 the commas with the colon.
2393 * ``BCIS_AfterColon`` (in configuration: ``AfterColon``)
2394 Break constructor initializers after the colon and commas.
2404 **BreakInheritanceList** (``BreakInheritanceListStyle``) :versionbadge:`clang-format 7`
2405 The inheritance list style to use.
2409 * ``BILS_BeforeColon`` (in configuration: ``BeforeColon``)
2410 Break inheritance list before the colon and after the commas.
2419 * ``BILS_BeforeComma`` (in configuration: ``BeforeComma``)
2420 Break inheritance list before the colon and commas, and align
2421 the commas with the colon.
2430 * ``BILS_AfterColon`` (in configuration: ``AfterColon``)
2431 Break inheritance list after the colon and commas.
2440 * ``BILS_AfterComma`` (in configuration: ``AfterComma``)
2441 Break inheritance list only after the commas.
2451 **BreakStringLiterals** (``Boolean``) :versionbadge:`clang-format 3.9`
2452 Allow breaking string literals when formatting.
2457 const char* x = "veryVeryVeryVeryVeryVe"
2458 "ryVeryVeryVeryVeryVery"
2463 "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
2465 **ColumnLimit** (``Unsigned``) :versionbadge:`clang-format 3.7`
2468 A column limit of ``0`` means that there is no column limit. In this case,
2469 clang-format will respect the input's line breaking decisions within
2470 statements unless they contradict other rules.
2472 **CommentPragmas** (``String``) :versionbadge:`clang-format 3.7`
2473 A regular expression that describes comments with special meaning,
2474 which should not be split into lines or otherwise changed.
2478 // CommentPragmas: '^ FOOBAR pragma:'
2479 // Will leave the following line unaffected
2480 #include <vector> // FOOBAR pragma: keep
2482 **CompactNamespaces** (``Boolean``) :versionbadge:`clang-format 5`
2483 If ``true``, consecutive namespace declarations will be on the same
2484 line. If ``false``, each namespace is declared on a new line.
2489 namespace Foo { namespace Bar {
2498 If it does not fit on a single line, the overflowing namespaces get
2503 namespace Foo { namespace Bar {
2507 **ConstructorInitializerAllOnOneLineOrOnePerLine** (``Boolean``) :versionbadge:`clang-format 3.7`
2508 This option is **deprecated**. See ``CurrentLine`` of
2509 ``PackConstructorInitializers``.
2511 **ConstructorInitializerIndentWidth** (``Unsigned``) :versionbadge:`clang-format 3.7`
2512 The number of characters to use for indentation of constructor
2513 initializer lists as well as inheritance lists.
2515 **ContinuationIndentWidth** (``Unsigned``) :versionbadge:`clang-format 3.7`
2516 Indent width for line continuations.
2520 ContinuationIndentWidth: 2
2522 int i = // VeryVeryVeryVeryVeryLongComment
2523 longFunction( // Again a long comment
2526 **Cpp11BracedListStyle** (``Boolean``) :versionbadge:`clang-format 3.4`
2527 If ``true``, format braced lists as best suited for C++11 braced
2530 Important differences:
2531 - No spaces inside the braced list.
2532 - No line break before the closing brace.
2533 - Indentation with the continuation indent, not with the block indent.
2535 Fundamentally, C++11 braced lists are formatted exactly like function
2536 calls would be formatted in their place. If the braced list follows a name
2537 (e.g. a type or variable name), clang-format formats as if the ``{}`` were
2538 the parentheses of a function call with that name. If there is no name,
2539 a zero-length name is assumed.
2544 vector<int> x{1, 2, 3, 4}; vs. vector<int> x{ 1, 2, 3, 4 };
2545 vector<T> x{{}, {}, {}, {}}; vector<T> x{ {}, {}, {}, {} };
2546 f(MyMap[{composite, key}]); f(MyMap[{ composite, key }]);
2547 new int[3]{1, 2, 3}; new int[3]{ 1, 2, 3 };
2549 **DeriveLineEnding** (``Boolean``) :versionbadge:`clang-format 10`
2550 Analyze the formatted file for the most used line ending (``\r\n``
2551 or ``\n``). ``UseCRLF`` is only used as a fallback if none can be derived.
2553 **DerivePointerAlignment** (``Boolean``) :versionbadge:`clang-format 3.7`
2554 If ``true``, analyze the formatted file for the most common
2555 alignment of ``&`` and ``*``.
2556 Pointer and reference alignment styles are going to be updated according
2557 to the preferences found in the file.
2558 ``PointerAlignment`` is then used only as fallback.
2560 **DisableFormat** (``Boolean``) :versionbadge:`clang-format 3.7`
2561 Disables formatting completely.
2563 **EmptyLineAfterAccessModifier** (``EmptyLineAfterAccessModifierStyle``) :versionbadge:`clang-format 13`
2564 Defines when to put an empty line after access modifiers.
2565 ``EmptyLineBeforeAccessModifier`` configuration handles the number of
2566 empty lines between two access modifiers.
2570 * ``ELAAMS_Never`` (in configuration: ``Never``)
2571 Remove all empty lines after access modifiers.
2587 * ``ELAAMS_Leave`` (in configuration: ``Leave``)
2588 Keep existing empty lines after access modifiers.
2589 MaxEmptyLinesToKeep is applied instead.
2591 * ``ELAAMS_Always`` (in configuration: ``Always``)
2592 Always add empty line after access modifiers if there are none.
2593 MaxEmptyLinesToKeep is applied also.
2616 **EmptyLineBeforeAccessModifier** (``EmptyLineBeforeAccessModifierStyle``) :versionbadge:`clang-format 12`
2617 Defines in which cases to put empty line before access modifiers.
2621 * ``ELBAMS_Never`` (in configuration: ``Never``)
2622 Remove all empty lines before access modifiers.
2638 * ``ELBAMS_Leave`` (in configuration: ``Leave``)
2639 Keep existing empty lines before access modifiers.
2641 * ``ELBAMS_LogicalBlock`` (in configuration: ``LogicalBlock``)
2642 Add empty line only when access modifier starts a new logical block.
2643 Logical block is a group of one or more member fields or functions.
2661 * ``ELBAMS_Always`` (in configuration: ``Always``)
2662 Always add empty line before access modifiers unless access modifier
2663 is at the start of struct or class definition.
2685 **ExperimentalAutoDetectBinPacking** (``Boolean``) :versionbadge:`clang-format 3.7`
2686 If ``true``, clang-format detects whether function calls and
2687 definitions are formatted with one parameter per line.
2689 Each call can be bin-packed, one-per-line or inconclusive. If it is
2690 inconclusive, e.g. completely on one line, but a decision needs to be
2691 made, clang-format analyzes whether there are other bin-packed cases in
2692 the input file and act accordingly.
2694 NOTE: This is an experimental flag, that might go away or be renamed. Do
2695 not use this in config files, etc. Use at your own risk.
2697 **FixNamespaceComments** (``Boolean``) :versionbadge:`clang-format 5`
2698 If ``true``, clang-format adds missing namespace end comments for
2699 namespaces and fixes invalid existing ones. This doesn't affect short
2700 namespaces, which are controlled by ``ShortNamespaceLines``.
2705 namespace longNamespace { vs. namespace longNamespace {
2706 void foo(); void foo();
2707 void bar(); void bar();
2709 namespace shortNamespace { namespace shortNamespace {
2710 void baz(); void baz();
2713 **ForEachMacros** (``List of Strings``) :versionbadge:`clang-format 3.7`
2714 A vector of macros that should be interpreted as foreach loops
2715 instead of as function calls.
2717 These are expected to be macros of the form:
2721 FOREACH(<variable-declaration>, ...)
2724 In the .clang-format configuration file, this can be configured like:
2726 .. code-block:: yaml
2728 ForEachMacros: ['RANGES_FOR', 'FOREACH']
2730 For example: BOOST_FOREACH.
2732 **IfMacros** (``List of Strings``) :versionbadge:`clang-format 13`
2733 A vector of macros that should be interpreted as conditionals
2734 instead of as function calls.
2736 These are expected to be macros of the form:
2745 In the .clang-format configuration file, this can be configured like:
2747 .. code-block:: yaml
2751 For example: `KJ_IF_MAYBE
2752 <https://github.com/capnproto/capnproto/blob/master/kjdoc/tour.md#maybes>`_
2754 **IncludeBlocks** (``IncludeBlocksStyle``) :versionbadge:`clang-format 6`
2755 Dependent on the value, multiple ``#include`` blocks can be sorted
2756 as one and divided based on category.
2760 * ``IBS_Preserve`` (in configuration: ``Preserve``)
2761 Sort each ``#include`` block separately.
2765 #include "b.h" into #include "b.h"
2767 #include <lib/main.h> #include "a.h"
2768 #include "a.h" #include <lib/main.h>
2770 * ``IBS_Merge`` (in configuration: ``Merge``)
2771 Merge multiple ``#include`` blocks together and sort as one.
2775 #include "b.h" into #include "a.h"
2777 #include <lib/main.h> #include <lib/main.h>
2780 * ``IBS_Regroup`` (in configuration: ``Regroup``)
2781 Merge multiple ``#include`` blocks together and sort as one.
2782 Then split into groups based on category priority. See
2783 ``IncludeCategories``.
2787 #include "b.h" into #include "a.h"
2789 #include <lib/main.h>
2790 #include "a.h" #include <lib/main.h>
2794 **IncludeCategories** (``List of IncludeCategories``) :versionbadge:`clang-format 3.8`
2795 Regular expressions denoting the different ``#include`` categories
2796 used for ordering ``#includes``.
2799 <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html>`_
2800 regular expressions are supported.
2802 These regular expressions are matched against the filename of an include
2803 (including the <> or "") in order. The value belonging to the first
2804 matching regular expression is assigned and ``#includes`` are sorted first
2805 according to increasing category number and then alphabetically within
2808 If none of the regular expressions match, INT_MAX is assigned as
2809 category. The main header for a source file automatically gets category 0.
2810 so that it is generally kept at the beginning of the ``#includes``
2811 (https://llvm.org/docs/CodingStandards.html#include-style). However, you
2812 can also assign negative priorities if you have certain headers that
2813 always need to be first.
2815 There is a third and optional field ``SortPriority`` which can used while
2816 ``IncludeBlocks = IBS_Regroup`` to define the priority in which
2817 ``#includes`` should be ordered. The value of ``Priority`` defines the
2818 order of ``#include blocks`` and also allows the grouping of ``#includes``
2819 of different priority. ``SortPriority`` is set to the value of
2820 ``Priority`` as default if it is not assigned.
2822 Each regular expression can be marked as case sensitive with the field
2823 ``CaseSensitive``, per default it is not.
2825 To configure this in the .clang-format file, use:
2827 .. code-block:: yaml
2830 - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
2834 - Regex: '^((<|")(gtest|gmock|isl|json)/)'
2836 - Regex: '<[[:alnum:].]+>'
2842 **IncludeIsMainRegex** (``String``) :versionbadge:`clang-format 3.9`
2843 Specify a regular expression of suffixes that are allowed in the
2844 file-to-main-include mapping.
2846 When guessing whether a #include is the "main" include (to assign
2847 category 0, see above), use this regex of allowed suffixes to the header
2848 stem. A partial match is done, so that:
2849 - "" means "arbitrary suffix"
2850 - "$" means "no suffix"
2852 For example, if configured to "(_test)?$", then a header a.h would be seen
2853 as the "main" include in both a.cc and a_test.cc.
2855 **IncludeIsMainSourceRegex** (``String``) :versionbadge:`clang-format 10`
2856 Specify a regular expression for files being formatted
2857 that are allowed to be considered "main" in the
2858 file-to-main-include mapping.
2860 By default, clang-format considers files as "main" only when they end
2861 with: ``.c``, ``.cc``, ``.cpp``, ``.c++``, ``.cxx``, ``.m`` or ``.mm``
2863 For these files a guessing of "main" include takes place
2864 (to assign category 0, see above). This config option allows for
2865 additional suffixes and extensions for files to be considered as "main".
2867 For example, if this option is configured to ``(Impl\.hpp)$``,
2868 then a file ``ClassImpl.hpp`` is considered "main" (in addition to
2869 ``Class.c``, ``Class.cc``, ``Class.cpp`` and so on) and "main
2870 include file" logic will be executed (with *IncludeIsMainRegex* setting
2871 also being respected in later phase). Without this option set,
2872 ``ClassImpl.hpp`` would not have the main include file put on top
2873 before any other include.
2875 **IndentAccessModifiers** (``Boolean``) :versionbadge:`clang-format 13`
2876 Specify whether access modifiers should have their own indentation level.
2878 When ``false``, access modifiers are indented (or outdented) relative to
2879 the record members, respecting the ``AccessModifierOffset``. Record
2880 members are indented one level below the record.
2881 When ``true``, access modifiers get their own indentation level. As a
2882 consequence, record members are always indented 2 levels below the record,
2883 regardless of the access modifier presence. Value of the
2884 ``AccessModifierOffset`` is ignored.
2889 class C { vs. class C {
2891 void bar(); void bar();
2892 protected: protected:
2898 void foo() { void foo() {
2902 **IndentCaseBlocks** (``Boolean``) :versionbadge:`clang-format 11`
2903 Indent case label blocks one level from the case label.
2905 When ``false``, the block following the case label uses the same
2906 indentation level as for the case label, treating the case label the same
2908 When ``true``, the block gets indented as a scope block.
2913 switch (fool) { vs. switch (fool) {
2925 **IndentCaseLabels** (``Boolean``) :versionbadge:`clang-format 3.3`
2926 Indent case labels one level from the switch statement.
2928 When ``false``, use the same indentation level as for the switch
2929 statement. Switch statement body is always indented one level more than
2930 case labels (except the first block following the case label, which
2931 itself indents the code - unless IndentCaseBlocks is enabled).
2936 switch (fool) { vs. switch (fool) {
2944 **IndentExternBlock** (``IndentExternBlockStyle``) :versionbadge:`clang-format 11`
2945 IndentExternBlockStyle is the type of indenting of extern blocks.
2949 * ``IEBS_AfterExternBlock`` (in configuration: ``AfterExternBlock``)
2950 Backwards compatible with AfterExternBlock's indenting.
2954 IndentExternBlock: AfterExternBlock
2955 BraceWrapping.AfterExternBlock: true
2964 IndentExternBlock: AfterExternBlock
2965 BraceWrapping.AfterExternBlock: false
2970 * ``IEBS_NoIndent`` (in configuration: ``NoIndent``)
2971 Does not indent extern blocks.
2979 * ``IEBS_Indent`` (in configuration: ``Indent``)
2980 Indents extern blocks.
2990 **IndentGotoLabels** (``Boolean``) :versionbadge:`clang-format 10`
2993 When ``false``, goto labels are flushed left.
2998 int f() { vs. int f() {
2999 if (foo()) { if (foo()) {
3007 **IndentPPDirectives** (``PPDirectiveIndentStyle``) :versionbadge:`clang-format 6`
3008 The preprocessor directive indenting style to use.
3012 * ``PPDIS_None`` (in configuration: ``None``)
3013 Does not indent any directives.
3023 * ``PPDIS_AfterHash`` (in configuration: ``AfterHash``)
3024 Indents directives after the hash.
3034 * ``PPDIS_BeforeHash`` (in configuration: ``BeforeHash``)
3035 Indents directives before the hash.
3047 **IndentRequiresClause** (``Boolean``) :versionbadge:`clang-format 15`
3048 Indent the requires clause in a template. This only applies when
3049 ``RequiresClausePosition`` is ``OwnLine``, or ``WithFollowing``.
3051 In clang-format 12, 13 and 14 it was named ``IndentRequires``.
3056 template <typename It>
3057 requires Iterator<It>
3058 void sort(It begin, It end) {
3063 template <typename It>
3064 requires Iterator<It>
3065 void sort(It begin, It end) {
3069 **IndentWidth** (``Unsigned``) :versionbadge:`clang-format 3.7`
3070 The number of columns to use for indentation.
3083 **IndentWrappedFunctionNames** (``Boolean``) :versionbadge:`clang-format 3.7`
3084 Indent if a function definition or declaration is wrapped after the
3090 LoooooooooooooooooooooooooooooooooooooooongReturnType
3091 LoooooooooooooooooooooooooooooooongFunctionDeclaration();
3094 LoooooooooooooooooooooooooooooooooooooooongReturnType
3095 LoooooooooooooooooooooooooooooooongFunctionDeclaration();
3097 **InsertBraces** (``Boolean``) :versionbadge:`clang-format 15`
3098 Insert braces after control statements (``if``, ``else``, ``for``, ``do``,
3099 and ``while``) in C++ unless the control statements are inside macro
3100 definitions or the braces would enclose preprocessor directives.
3104 Setting this option to `true` could lead to incorrect code formatting due
3105 to clang-format's lack of complete semantic information. As such, extra
3106 care should be taken to review code changes made by this option.
3112 if (isa<FunctionDecl>(D)) vs. if (isa<FunctionDecl>(D)) {
3113 handleFunctionDecl(D); handleFunctionDecl(D);
3114 else if (isa<VarDecl>(D)) } else if (isa<VarDecl>(D)) {
3115 handleVarDecl(D); handleVarDecl(D);
3120 while (i--) vs. while (i--) {
3121 for (auto *A : D.attrs()) for (auto *A : D.attrs()) {
3122 handleAttr(A); handleAttr(A);
3128 while (i); } while (i);
3130 **InsertTrailingCommas** (``TrailingCommaStyle``) :versionbadge:`clang-format 11`
3131 If set to ``TCS_Wrapped`` will insert trailing commas in container
3132 literals (arrays and objects) that wrap across multiple lines.
3133 It is currently only available for JavaScript
3134 and disabled by default ``TCS_None``.
3135 ``InsertTrailingCommas`` cannot be used together with ``BinPackArguments``
3136 as inserting the comma disables bin-packing.
3142 aaaaaaaaaaaaaaaaaaaaaaaaaa,
3143 aaaaaaaaaaaaaaaaaaaaaaaaaa,
3144 aaaaaaaaaaaaaaaaaaaaaaaaaa,
3150 * ``TCS_None`` (in configuration: ``None``)
3151 Do not insert trailing commas.
3153 * ``TCS_Wrapped`` (in configuration: ``Wrapped``)
3154 Insert trailing commas in container literals that were wrapped over
3155 multiple lines. Note that this is conceptually incompatible with
3156 bin-packing, because the trailing comma is used as an indicator
3157 that a container should be formatted one-per-line (i.e. not bin-packed).
3158 So inserting a trailing comma counteracts bin-packing.
3162 **JavaImportGroups** (``List of Strings``) :versionbadge:`clang-format 8`
3163 A vector of prefixes ordered by the desired groups for Java imports.
3165 One group's prefix can be a subset of another - the longest prefix is
3166 always matched. Within a group, the imports are ordered lexicographically.
3167 Static imports are grouped separately and follow the same group rules.
3168 By default, static imports are placed before non-static imports,
3169 but this behavior is changed by another option,
3170 ``SortJavaStaticImport``.
3172 In the .clang-format configuration file, this can be configured like
3173 in the following yaml example. This will result in imports being
3174 formatted as in the Java example below.
3176 .. code-block:: yaml
3178 JavaImportGroups: ['com.example', 'com', 'org']
3181 .. code-block:: java
3183 import static com.example.function1;
3185 import static com.test.function2;
3187 import static org.example.function3;
3189 import com.example.ClassA;
3190 import com.example.Test;
3191 import com.example.a.ClassB;
3193 import com.test.ClassC;
3195 import org.example.ClassD;
3197 **JavaScriptQuotes** (``JavaScriptQuoteStyle``) :versionbadge:`clang-format 3.9`
3198 The JavaScriptQuoteStyle to use for JavaScript strings.
3202 * ``JSQS_Leave`` (in configuration: ``Leave``)
3203 Leave string quotes as they are.
3210 * ``JSQS_Single`` (in configuration: ``Single``)
3211 Always use single quotes.
3218 * ``JSQS_Double`` (in configuration: ``Double``)
3219 Always use double quotes.
3228 **JavaScriptWrapImports** (``Boolean``) :versionbadge:`clang-format 3.9`
3229 Whether to wrap JavaScript import/export statements.
3235 VeryLongImportsAreAnnoying,
3236 VeryLongImportsAreAnnoying,
3237 VeryLongImportsAreAnnoying,
3238 } from 'some/module.js'
3241 import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js"
3243 **KeepEmptyLinesAtTheStartOfBlocks** (``Boolean``) :versionbadge:`clang-format 3.7`
3244 If true, the empty line at the start of blocks is kept.
3249 if (foo) { vs. if (foo) {
3254 **LambdaBodyIndentation** (``LambdaBodyIndentationKind``) :versionbadge:`clang-format 13`
3255 The indentation style of lambda bodies. ``Signature`` (the default)
3256 causes the lambda body to be indented one additional level relative to
3257 the indentation level of the signature. ``OuterScope`` forces the lambda
3258 body to be indented one additional level relative to the parent scope
3259 containing the lambda signature. For callback-heavy code, it may improve
3260 readability to have the signature indented two levels and to use
3261 ``OuterScope``. The KJ style guide requires ``OuterScope``.
3263 <https://github.com/capnproto/capnproto/blob/master/style-guide.md>`_
3267 * ``LBI_Signature`` (in configuration: ``Signature``)
3268 Align lambda body relative to the lambda signature. This is the default.
3273 [](SomeReallyLongLambdaSignatureArgument foo) {
3277 * ``LBI_OuterScope`` (in configuration: ``OuterScope``)
3278 Align lambda body relative to the indentation level of the outer scope
3279 the lambda signature resides in.
3284 [](SomeReallyLongLambdaSignatureArgument foo) {
3290 **Language** (``LanguageKind``) :versionbadge:`clang-format 3.5`
3291 Language, this format style is targeted at.
3295 * ``LK_None`` (in configuration: ``None``)
3298 * ``LK_Cpp`` (in configuration: ``Cpp``)
3299 Should be used for C, C++.
3301 * ``LK_CSharp`` (in configuration: ``CSharp``)
3302 Should be used for C#.
3304 * ``LK_Java`` (in configuration: ``Java``)
3305 Should be used for Java.
3307 * ``LK_JavaScript`` (in configuration: ``JavaScript``)
3308 Should be used for JavaScript.
3310 * ``LK_Json`` (in configuration: ``Json``)
3311 Should be used for JSON.
3313 * ``LK_ObjC`` (in configuration: ``ObjC``)
3314 Should be used for Objective-C, Objective-C++.
3316 * ``LK_Proto`` (in configuration: ``Proto``)
3317 Should be used for Protocol Buffers
3318 (https://developers.google.com/protocol-buffers/).
3320 * ``LK_TableGen`` (in configuration: ``TableGen``)
3321 Should be used for TableGen code.
3323 * ``LK_TextProto`` (in configuration: ``TextProto``)
3324 Should be used for Protocol Buffer messages in text format
3325 (https://developers.google.com/protocol-buffers/).
3327 * ``LK_Verilog`` (in configuration: ``Verilog``)
3328 Should be used for Verilog and SystemVerilog.
3329 https://standards.ieee.org/ieee/1800/6700/
3330 https://sci-hub.st/10.1109/IEEESTD.2018.8299595
3334 **MacroBlockBegin** (``String``) :versionbadge:`clang-format 3.7`
3335 A regular expression matching macros that start a block.
3340 MacroBlockBegin: "^NS_MAP_BEGIN|\
3363 **MacroBlockEnd** (``String``) :versionbadge:`clang-format 3.7`
3364 A regular expression matching macros that end a block.
3366 **MaxEmptyLinesToKeep** (``Unsigned``) :versionbadge:`clang-format 3.7`
3367 The maximum number of consecutive empty lines to keep.
3371 MaxEmptyLinesToKeep: 1 vs. MaxEmptyLinesToKeep: 0
3375 i = foo(); return i;
3380 **NamespaceIndentation** (``NamespaceIndentationKind``) :versionbadge:`clang-format 3.7`
3381 The indentation used for namespaces.
3385 * ``NI_None`` (in configuration: ``None``)
3386 Don't indent in namespaces.
3397 * ``NI_Inner`` (in configuration: ``Inner``)
3398 Indent only in inner namespaces (nested in other namespaces).
3409 * ``NI_All`` (in configuration: ``All``)
3410 Indent in all namespaces.
3423 **NamespaceMacros** (``List of Strings``) :versionbadge:`clang-format 9`
3424 A vector of macros which are used to open namespace blocks.
3426 These are expected to be macros of the form:
3430 NAMESPACE(<namespace-name>, ...) {
3434 For example: TESTSUITE
3436 **ObjCBinPackProtocolList** (``BinPackStyle``) :versionbadge:`clang-format 7`
3437 Controls bin-packing Objective-C protocol conformance list
3438 items into as few lines as possible when they go over ``ColumnLimit``.
3440 If ``Auto`` (the default), delegates to the value in
3441 ``BinPackParameters``. If that is ``true``, bin-packs Objective-C
3442 protocol conformance list items into as few lines as possible
3443 whenever they go over ``ColumnLimit``.
3445 If ``Always``, always bin-packs Objective-C protocol conformance
3446 list items into as few lines as possible whenever they go over
3449 If ``Never``, lays out Objective-C protocol conformance list items
3450 onto individual lines whenever they go over ``ColumnLimit``.
3453 .. code-block:: objc
3455 Always (or Auto, if BinPackParameters=true):
3456 @interface ccccccccccccc () <
3457 ccccccccccccc, ccccccccccccc,
3458 ccccccccccccc, ccccccccccccc> {
3461 Never (or Auto, if BinPackParameters=false):
3462 @interface ddddddddddddd () <
3471 * ``BPS_Auto`` (in configuration: ``Auto``)
3472 Automatically determine parameter bin-packing behavior.
3474 * ``BPS_Always`` (in configuration: ``Always``)
3475 Always bin-pack parameters.
3477 * ``BPS_Never`` (in configuration: ``Never``)
3478 Never bin-pack parameters.
3482 **ObjCBlockIndentWidth** (``Unsigned``) :versionbadge:`clang-format 3.7`
3483 The number of characters to use for indentation of ObjC blocks.
3485 .. code-block:: objc
3487 ObjCBlockIndentWidth: 4
3489 [operation setCompletionBlock:^{
3490 [self onOperationDone];
3493 **ObjCBreakBeforeNestedBlockParam** (``Boolean``) :versionbadge:`clang-format 11`
3494 Break parameters list into lines when there is nested block
3495 parameters in a function call.
3502 [self.test1 t:self w:self callback:^(typeof(self) self, NSNumber
3512 callback:^(typeof(self) self, NSNumber *u, NSNumber *v) {
3517 **ObjCSpaceAfterProperty** (``Boolean``) :versionbadge:`clang-format 3.7`
3518 Add a space after ``@property`` in Objective-C, i.e. use
3519 ``@property (readonly)`` instead of ``@property(readonly)``.
3521 **ObjCSpaceBeforeProtocolList** (``Boolean``) :versionbadge:`clang-format 3.7`
3522 Add a space in front of an Objective-C protocol list, i.e. use
3523 ``Foo <Protocol>`` instead of ``Foo<Protocol>``.
3525 **PPIndentWidth** (``Integer``) :versionbadge:`clang-format 13`
3526 The number of columns to use for indentation of preprocessor statements.
3527 When set to -1 (default) ``IndentWidth`` is used also for preprocessor
3540 **PackConstructorInitializers** (``PackConstructorInitializersStyle``) :versionbadge:`clang-format 14`
3541 The pack constructor initializers style to use.
3545 * ``PCIS_Never`` (in configuration: ``Never``)
3546 Always put each constructor initializer on its own line.
3554 * ``PCIS_BinPack`` (in configuration: ``BinPack``)
3555 Bin-pack constructor initializers.
3560 : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(),
3561 cccccccccccccccccccc()
3563 * ``PCIS_CurrentLine`` (in configuration: ``CurrentLine``)
3564 Put all constructor initializers on the current line if they fit.
3565 Otherwise, put each one on its own line.
3569 Constructor() : a(), b()
3572 : aaaaaaaaaaaaaaaaaaaa(),
3573 bbbbbbbbbbbbbbbbbbbb(),
3576 * ``PCIS_NextLine`` (in configuration: ``NextLine``)
3577 Same as ``PCIS_CurrentLine`` except that if all constructor initializers
3578 do not fit on the current line, try to fit them on the next line.
3582 Constructor() : a(), b()
3585 : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), ddddddddddddd()
3588 : aaaaaaaaaaaaaaaaaaaa(),
3589 bbbbbbbbbbbbbbbbbbbb(),
3590 cccccccccccccccccccc()
3594 **PenaltyBreakAssignment** (``Unsigned``) :versionbadge:`clang-format 5`
3595 The penalty for breaking around an assignment operator.
3597 **PenaltyBreakBeforeFirstCallParameter** (``Unsigned``) :versionbadge:`clang-format 3.7`
3598 The penalty for breaking a function call after ``call(``.
3600 **PenaltyBreakComment** (``Unsigned``) :versionbadge:`clang-format 3.7`
3601 The penalty for each line break introduced inside a comment.
3603 **PenaltyBreakFirstLessLess** (``Unsigned``) :versionbadge:`clang-format 3.7`
3604 The penalty for breaking before the first ``<<``.
3606 **PenaltyBreakOpenParenthesis** (``Unsigned``) :versionbadge:`clang-format 14`
3607 The penalty for breaking after ``(``.
3609 **PenaltyBreakString** (``Unsigned``) :versionbadge:`clang-format 3.7`
3610 The penalty for each line break introduced inside a string literal.
3612 **PenaltyBreakTemplateDeclaration** (``Unsigned``) :versionbadge:`clang-format 7`
3613 The penalty for breaking after template declaration.
3615 **PenaltyExcessCharacter** (``Unsigned``) :versionbadge:`clang-format 3.7`
3616 The penalty for each character outside of the column limit.
3618 **PenaltyIndentedWhitespace** (``Unsigned``) :versionbadge:`clang-format 12`
3619 Penalty for each character of whitespace indentation
3620 (counted relative to leading non-whitespace column).
3622 **PenaltyReturnTypeOnItsOwnLine** (``Unsigned``) :versionbadge:`clang-format 3.7`
3623 Penalty for putting the return type of a function onto its own line.
3625 **PointerAlignment** (``PointerAlignmentStyle``) :versionbadge:`clang-format 3.7`
3626 Pointer and reference alignment style.
3630 * ``PAS_Left`` (in configuration: ``Left``)
3631 Align pointer to the left.
3637 * ``PAS_Right`` (in configuration: ``Right``)
3638 Align pointer to the right.
3644 * ``PAS_Middle`` (in configuration: ``Middle``)
3645 Align pointer in the middle.
3653 **QualifierAlignment** (``QualifierAlignmentStyle``) :versionbadge:`clang-format 14`
3654 Different ways to arrange specifiers and qualifiers (e.g. const/volatile).
3658 Setting ``QualifierAlignment`` to something other than `Leave`, COULD
3659 lead to incorrect code formatting due to incorrect decisions made due to
3660 clang-formats lack of complete semantic information.
3661 As such extra care should be taken to review code changes made by the use
3666 * ``QAS_Leave`` (in configuration: ``Leave``)
3667 Don't change specifiers/qualifiers to either Left or Right alignment
3675 * ``QAS_Left`` (in configuration: ``Left``)
3676 Change specifiers/qualifiers to be left-aligned.
3683 * ``QAS_Right`` (in configuration: ``Right``)
3684 Change specifiers/qualifiers to be right-aligned.
3691 * ``QAS_Custom`` (in configuration: ``Custom``)
3692 Change specifiers/qualifiers to be aligned based on ``QualifierOrder``.
3695 .. code-block:: yaml
3697 QualifierOrder: ['inline', 'static', 'type', 'const']
3708 **QualifierOrder** (``List of Strings``) :versionbadge:`clang-format 14`
3709 The order in which the qualifiers appear.
3710 Order is an array that can contain any of the following:
3720 Note: it MUST contain 'type'.
3721 Items to the left of 'type' will be placed to the left of the type and
3722 aligned in the order supplied. Items to the right of 'type' will be placed
3723 to the right of the type and aligned in the order supplied.
3726 .. code-block:: yaml
3728 QualifierOrder: ['inline', 'static', 'type', 'const', 'volatile' ]
3730 **RawStringFormats** (``List of RawStringFormats``) :versionbadge:`clang-format 6`
3731 Defines hints for detecting supported languages code blocks in raw
3734 A raw string with a matching delimiter or a matching enclosing function
3735 name will be reformatted assuming the specified language based on the
3736 style for that language defined in the .clang-format file. If no style has
3737 been defined in the .clang-format file for the specific language, a
3738 predefined style given by 'BasedOnStyle' is used. If 'BasedOnStyle' is not
3739 found, the formatting is based on llvm style. A matching delimiter takes
3740 precedence over a matching enclosing function name for determining the
3741 language of the raw string contents.
3743 If a canonical delimiter is specified, occurrences of other delimiters for
3744 the same language will be updated to the canonical if possible.
3746 There should be at most one specification per language and each delimiter
3747 and enclosing function should not occur in multiple specifications.
3749 To configure this in the .clang-format file, use:
3751 .. code-block:: yaml
3754 - Language: TextProto
3759 - 'PARSE_TEXT_PROTO'
3760 BasedOnStyle: google
3766 CanonicalDelimiter: 'cc'
3768 **ReferenceAlignment** (``ReferenceAlignmentStyle``) :versionbadge:`clang-format 13`
3769 Reference alignment style (overrides ``PointerAlignment`` for
3774 * ``RAS_Pointer`` (in configuration: ``Pointer``)
3775 Align reference like ``PointerAlignment``.
3777 * ``RAS_Left`` (in configuration: ``Left``)
3778 Align reference to the left.
3784 * ``RAS_Right`` (in configuration: ``Right``)
3785 Align reference to the right.
3791 * ``RAS_Middle`` (in configuration: ``Middle``)
3792 Align reference in the middle.
3800 **ReflowComments** (``Boolean``) :versionbadge:`clang-format 3.8`
3801 If ``true``, clang-format will attempt to re-flow comments. That is it
3802 will touch a comment and *reflow* long comments into new lines, trying to
3803 obey the ``ColumnLimit``.
3808 // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
3809 /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */
3812 // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
3814 /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
3817 **RemoveBracesLLVM** (``Boolean``) :versionbadge:`clang-format 14`
3818 Remove optional braces of control statements (``if``, ``else``, ``for``,
3819 and ``while``) in C++ according to the LLVM coding style.
3823 This option will be renamed and expanded to support other styles.
3827 Setting this option to `true` could lead to incorrect code formatting due
3828 to clang-format's lack of complete semantic information. As such, extra
3829 care should be taken to review code changes made by this option.
3835 if (isa<FunctionDecl>(D)) { vs. if (isa<FunctionDecl>(D))
3836 handleFunctionDecl(D); handleFunctionDecl(D);
3837 } else if (isa<VarDecl>(D)) { else if (isa<VarDecl>(D))
3838 handleVarDecl(D); handleVarDecl(D);
3841 if (isa<VarDecl>(D)) { vs. if (isa<VarDecl>(D)) {
3842 for (auto *A : D.attrs()) { for (auto *A : D.attrs())
3843 if (shouldProcessAttr(A)) { if (shouldProcessAttr(A))
3844 handleAttr(A); handleAttr(A);
3849 if (isa<FunctionDecl>(D)) { vs. if (isa<FunctionDecl>(D))
3850 for (auto *A : D.attrs()) { for (auto *A : D.attrs())
3851 handleAttr(A); handleAttr(A);
3855 if (auto *D = (T)(D)) { vs. if (auto *D = (T)(D)) {
3856 if (shouldProcess(D)) { if (shouldProcess(D))
3857 handleVarDecl(D); handleVarDecl(D);
3859 markAsIgnored(D); markAsIgnored(D);
3865 } else { else if (c)
3873 **RemoveSemicolon** (``Boolean``) :versionbadge:`clang-format 16`
3874 Remove semicolons after the closing brace of a non-empty function.
3878 Setting this option to `true` could lead to incorrect code formatting due
3879 to clang-format's lack of complete semantic information. As such, extra
3880 care should be taken to review code changes made by this option.
3886 int max(int a, int b) { int max(int a, int b) {
3887 return a > b ? a : b; return a > b ? a : b;
3890 **RequiresClausePosition** (``RequiresClausePositionStyle``) :versionbadge:`clang-format 15`
3891 The position of the ``requires`` clause.
3895 * ``RCPS_OwnLine`` (in configuration: ``OwnLine``)
3896 Always put the ``requires`` clause on its own line.
3900 template <typename T>
3904 template <typename T>
3908 template <typename T>
3913 * ``RCPS_WithPreceding`` (in configuration: ``WithPreceding``)
3914 Try to put the clause together with the preceding part of a declaration.
3915 For class templates: stick to the template declaration.
3916 For function templates: stick to the template declaration.
3917 For function declaration followed by a requires clause: stick to the
3922 template <typename T> requires C<T>
3925 template <typename T> requires C<T>
3928 template <typename T>
3929 void baz(T t) requires C<T>
3932 * ``RCPS_WithFollowing`` (in configuration: ``WithFollowing``)
3933 Try to put the ``requires`` clause together with the class or function
3938 template <typename T>
3939 requires C<T> struct Foo {...
3941 template <typename T>
3942 requires C<T> void bar(T t) {...
3944 template <typename T>
3948 * ``RCPS_SingleLine`` (in configuration: ``SingleLine``)
3949 Try to put everything in the same line if possible. Otherwise normal
3950 line breaking rules take over.
3955 template <typename T> requires C<T> struct Foo {...
3957 template <typename T> requires C<T> void bar(T t) {...
3959 template <typename T> void bar(T t) requires C<T> {...
3961 // Not fitting, one possible example:
3962 template <typename LongName>
3963 requires C<LongName>
3966 template <typename LongName>
3967 requires C<LongName>
3968 void bar(LongName ln) {
3970 template <typename LongName>
3971 void bar(LongName ln)
3972 requires C<LongName> {
3976 **RequiresExpressionIndentation** (``RequiresExpressionIndentationKind``) :versionbadge:`clang-format 16`
3977 The indentation used for requires expression bodies.
3981 * ``REI_OuterScope`` (in configuration: ``OuterScope``)
3982 Align requires expression body relative to the indentation level of the
3983 outer scope the requires expression resides in.
3984 This is the default.
3988 template <typename T>
3989 concept C = requires(T t) {
3993 * ``REI_Keyword`` (in configuration: ``Keyword``)
3994 Align requires expression body relative to the `requires` keyword.
3998 template <typename T>
3999 concept C = requires(T t) {
4005 **SeparateDefinitionBlocks** (``SeparateDefinitionStyle``) :versionbadge:`clang-format 14`
4006 Specifies the use of empty lines to separate definition blocks, including
4007 classes, structs, enums, and functions.
4012 #include <cstring> #include <cstring>
4014 int a, b, c; struct Foo {
4018 public: namespace Ns {
4019 struct Foobar { class Bar {
4021 int b; struct Foobar {
4029 ITEM1, int method1() {
4032 template<typename T>
4033 int method2(T x) { enum List {
4037 int method3(int par) {
4038 // ... template<typename T>
4039 } int method2(T x) {
4045 int method3(int par) {
4055 * ``SDS_Leave`` (in configuration: ``Leave``)
4056 Leave definition blocks as they are.
4058 * ``SDS_Always`` (in configuration: ``Always``)
4059 Insert an empty line between definition blocks.
4061 * ``SDS_Never`` (in configuration: ``Never``)
4062 Remove any empty line between definition blocks.
4066 **ShortNamespaceLines** (``Unsigned``) :versionbadge:`clang-format 13`
4067 The maximal number of unwrapped lines that a short namespace spans.
4070 This determines the maximum length of short namespaces by counting
4071 unwrapped lines (i.e. containing neither opening nor closing
4072 namespace brace) and makes "FixNamespaceComments" omit adding
4073 end comments for those.
4077 ShortNamespaceLines: 1 vs. ShortNamespaceLines: 0
4078 namespace a { namespace a {
4082 ShortNamespaceLines: 1 vs. ShortNamespaceLines: 0
4083 namespace b { namespace b {
4086 } // namespace b } // namespace b
4088 **SortIncludes** (``SortIncludesOptions``) :versionbadge:`clang-format 3.8`
4089 Controls if and how clang-format will sort ``#includes``.
4090 If ``Never``, includes are never sorted.
4091 If ``CaseInsensitive``, includes are sorted in an ASCIIbetical or case
4092 insensitive fashion.
4093 If ``CaseSensitive``, includes are sorted in an alphabetical or case
4098 * ``SI_Never`` (in configuration: ``Never``)
4099 Includes are never sorted.
4109 * ``SI_CaseSensitive`` (in configuration: ``CaseSensitive``)
4110 Includes are sorted in an ASCIIbetical or case sensitive fashion.
4120 * ``SI_CaseInsensitive`` (in configuration: ``CaseInsensitive``)
4121 Includes are sorted in an alphabetical or case insensitive fashion.
4133 **SortJavaStaticImport** (``SortJavaStaticImportOptions``) :versionbadge:`clang-format 12`
4134 When sorting Java imports, by default static imports are placed before
4135 non-static imports. If ``JavaStaticImportAfterImport`` is ``After``,
4136 static imports are placed after non-static imports.
4140 * ``SJSIO_Before`` (in configuration: ``Before``)
4141 Static imports are placed before non-static imports.
4143 .. code-block:: java
4145 import static org.example.function1;
4147 import org.example.ClassA;
4149 * ``SJSIO_After`` (in configuration: ``After``)
4150 Static imports are placed after non-static imports.
4152 .. code-block:: java
4154 import org.example.ClassA;
4156 import static org.example.function1;
4160 **SortUsingDeclarations** (``Boolean``) :versionbadge:`clang-format 5`
4161 If ``true``, clang-format will sort using declarations.
4163 The order of using declarations is defined as follows:
4164 Split the strings by "::" and discard any initial empty strings. The last
4165 element of each list is a non-namespace name; all others are namespace
4166 names. Sort the lists of names lexicographically, where the sort order of
4167 individual names is that all non-namespace names come before all namespace
4168 names, and within those groups, names are in case-insensitive
4169 lexicographic order.
4174 using std::cout; vs. using std::cin;
4175 using std::cin; using std::cout;
4177 **SpaceAfterCStyleCast** (``Boolean``) :versionbadge:`clang-format 3.5`
4178 If ``true``, a space is inserted after C style casts.
4183 (int) i; vs. (int)i;
4185 **SpaceAfterLogicalNot** (``Boolean``) :versionbadge:`clang-format 9`
4186 If ``true``, a space is inserted after the logical not operator (``!``).
4191 ! someExpression(); vs. !someExpression();
4193 **SpaceAfterTemplateKeyword** (``Boolean``) :versionbadge:`clang-format 4`
4194 If ``true``, a space will be inserted after the 'template' keyword.
4199 template <int> void foo(); vs. template<int> void foo();
4201 **SpaceAroundPointerQualifiers** (``SpaceAroundPointerQualifiersStyle``) :versionbadge:`clang-format 12`
4202 Defines in which cases to put a space before or after pointer qualifiers
4206 * ``SAPQ_Default`` (in configuration: ``Default``)
4207 Don't ensure spaces around pointer qualifiers and use PointerAlignment
4212 PointerAlignment: Left PointerAlignment: Right
4213 void* const* x = NULL; vs. void *const *x = NULL;
4215 * ``SAPQ_Before`` (in configuration: ``Before``)
4216 Ensure that there is a space before pointer qualifiers.
4220 PointerAlignment: Left PointerAlignment: Right
4221 void* const* x = NULL; vs. void * const *x = NULL;
4223 * ``SAPQ_After`` (in configuration: ``After``)
4224 Ensure that there is a space after pointer qualifiers.
4228 PointerAlignment: Left PointerAlignment: Right
4229 void* const * x = NULL; vs. void *const *x = NULL;
4231 * ``SAPQ_Both`` (in configuration: ``Both``)
4232 Ensure that there is a space both before and after pointer qualifiers.
4236 PointerAlignment: Left PointerAlignment: Right
4237 void* const * x = NULL; vs. void * const *x = NULL;
4241 **SpaceBeforeAssignmentOperators** (``Boolean``) :versionbadge:`clang-format 3.7`
4242 If ``false``, spaces will be removed before assignment operators.
4247 int a = 5; vs. int a= 5;
4250 **SpaceBeforeCaseColon** (``Boolean``) :versionbadge:`clang-format 12`
4251 If ``false``, spaces will be removed before case colon.
4256 switch (x) { vs. switch (x) {
4257 case 1 : break; case 1: break;
4260 **SpaceBeforeCpp11BracedList** (``Boolean``) :versionbadge:`clang-format 7`
4261 If ``true``, a space will be inserted before a C++11 braced list
4262 used to initialize an object (after the preceding identifier or type).
4267 Foo foo { bar }; vs. Foo foo{ bar };
4269 vector<int> { 1, 2, 3 }; vector<int>{ 1, 2, 3 };
4270 new int[3] { 1, 2, 3 }; new int[3]{ 1, 2, 3 };
4272 **SpaceBeforeCtorInitializerColon** (``Boolean``) :versionbadge:`clang-format 7`
4273 If ``false``, spaces will be removed before constructor initializer
4279 Foo::Foo() : a(a) {} Foo::Foo(): a(a) {}
4281 **SpaceBeforeInheritanceColon** (``Boolean``) :versionbadge:`clang-format 7`
4282 If ``false``, spaces will be removed before inheritance colon.
4287 class Foo : Bar {} vs. class Foo: Bar {}
4289 **SpaceBeforeParens** (``SpaceBeforeParensStyle``) :versionbadge:`clang-format 3.5`
4290 Defines in which cases to put a space before opening parentheses.
4294 * ``SBPO_Never`` (in configuration: ``Never``)
4295 Never put a space before opening parentheses.
4305 * ``SBPO_ControlStatements`` (in configuration: ``ControlStatements``)
4306 Put a space before opening parentheses only after control statement
4307 keywords (``for/if/while...``).
4317 * ``SBPO_ControlStatementsExceptControlMacros`` (in configuration: ``ControlStatementsExceptControlMacros``)
4318 Same as ``SBPO_ControlStatements`` except this option doesn't apply to
4319 ForEach and If macros. This is useful in projects where ForEach/If
4320 macros are treated as function calls instead of control statements.
4321 ``SBPO_ControlStatementsExceptForEachMacros`` remains an alias for
4322 backward compatibility.
4332 * ``SBPO_NonEmptyParentheses`` (in configuration: ``NonEmptyParentheses``)
4333 Put a space before opening parentheses only if the parentheses are not
4345 * ``SBPO_Always`` (in configuration: ``Always``)
4346 Always put a space before opening parentheses, except when it's
4347 prohibited by the syntax rules (in function-like macro definitions) or
4348 when determined by other style rules (after unary operators, opening
4359 * ``SBPO_Custom`` (in configuration: ``Custom``)
4360 Configure each individual space before parentheses in
4361 `SpaceBeforeParensOptions`.
4365 **SpaceBeforeParensOptions** (``SpaceBeforeParensCustom``) :versionbadge:`clang-format 14`
4366 Control of individual space before parentheses.
4368 If ``SpaceBeforeParens`` is set to ``Custom``, use this to specify
4369 how each individual space before parentheses case should be handled.
4370 Otherwise, this is ignored.
4372 .. code-block:: yaml
4375 SpaceBeforeParens: Custom
4376 SpaceBeforeParensOptions:
4377 AfterControlStatements: true
4378 AfterFunctionDefinitionName: true
4380 Nested configuration flags:
4382 Precise control over the spacing before parentheses.
4386 # Should be declared this way:
4387 SpaceBeforeParens: Custom
4388 SpaceBeforeParensOptions:
4389 AfterControlStatements: true
4390 AfterFunctionDefinitionName: true
4392 * ``bool AfterControlStatements`` If ``true``, put space betwee control statement keywords
4393 (for/if/while...) and opening parentheses.
4398 if (...) {} vs. if(...) {}
4400 * ``bool AfterForeachMacros`` If ``true``, put space between foreach macros and opening parentheses.
4405 FOREACH (...) vs. FOREACH(...)
4406 <loop-body> <loop-body>
4408 * ``bool AfterFunctionDeclarationName`` If ``true``, put a space between function declaration name and opening
4414 void f (); vs. void f();
4416 * ``bool AfterFunctionDefinitionName`` If ``true``, put a space between function definition name and opening
4422 void f () {} vs. void f() {}
4424 * ``bool AfterIfMacros`` If ``true``, put space between if macros and opening parentheses.
4429 IF (...) vs. IF(...)
4430 <conditional-body> <conditional-body>
4432 * ``bool AfterOverloadedOperator`` If ``true``, put a space between operator overloading and opening
4438 void operator++ (int a); vs. void operator++(int a);
4439 object.operator++ (10); object.operator++(10);
4441 * ``bool AfterRequiresInClause`` If ``true``, put space between requires keyword in a requires clause and
4442 opening parentheses, if there is one.
4447 template<typename T> vs. template<typename T>
4448 requires (A<T> && B<T>) requires(A<T> && B<T>)
4451 * ``bool AfterRequiresInExpression`` If ``true``, put space between requires keyword in a requires expression
4452 and opening parentheses.
4457 template<typename T> vs. template<typename T>
4458 concept C = requires (T t) { concept C = requires(T t) {
4462 * ``bool BeforeNonEmptyParentheses`` If ``true``, put a space before opening parentheses only if the
4463 parentheses are not empty.
4468 void f (int a); vs. void f();
4472 **SpaceBeforeRangeBasedForLoopColon** (``Boolean``) :versionbadge:`clang-format 7`
4473 If ``false``, spaces will be removed before range-based for loop
4479 for (auto v : values) {} vs. for(auto v: values) {}
4481 **SpaceBeforeSquareBrackets** (``Boolean``) :versionbadge:`clang-format 10`
4482 If ``true``, spaces will be before ``[``.
4483 Lambdas will not be affected. Only the first ``[`` will get a space added.
4488 int a [5]; vs. int a[5];
4489 int a [5][5]; vs. int a[5][5];
4491 **SpaceInEmptyBlock** (``Boolean``) :versionbadge:`clang-format 10`
4492 If ``true``, spaces will be inserted into ``{}``.
4497 void f() { } vs. void f() {}
4498 while (true) { } while (true) {}
4500 **SpaceInEmptyParentheses** (``Boolean``) :versionbadge:`clang-format 3.7`
4501 If ``true``, spaces may be inserted into ``()``.
4506 void f( ) { vs. void f() {
4507 int x[] = {foo( ), bar( )}; int x[] = {foo(), bar()};
4508 if (true) { if (true) {
4513 **SpacesBeforeTrailingComments** (``Unsigned``) :versionbadge:`clang-format 3.7`
4514 The number of spaces before trailing line comments
4515 (``//`` - comments).
4517 This does not affect trailing block comments (``/*`` - comments) as
4518 those commonly have different usage patterns and a number of special
4523 SpacesBeforeTrailingComments: 3
4530 **SpacesInAngles** (``SpacesInAnglesStyle``) :versionbadge:`clang-format 3.4`
4531 The SpacesInAnglesStyle to use for template argument lists.
4535 * ``SIAS_Never`` (in configuration: ``Never``)
4536 Remove spaces after ``<`` and before ``>``.
4540 static_cast<int>(arg);
4541 std::function<void(int)> fct;
4543 * ``SIAS_Always`` (in configuration: ``Always``)
4544 Add spaces after ``<`` and before ``>``.
4548 static_cast< int >(arg);
4549 std::function< void(int) > fct;
4551 * ``SIAS_Leave`` (in configuration: ``Leave``)
4552 Keep a single space after ``<`` and before ``>`` if any spaces were
4553 present. Option ``Standard: Cpp03`` takes precedence.
4557 **SpacesInCStyleCastParentheses** (``Boolean``) :versionbadge:`clang-format 3.7`
4558 If ``true``, spaces may be inserted into C style casts.
4563 x = ( int32 )y vs. x = (int32)y
4565 **SpacesInConditionalStatement** (``Boolean``) :versionbadge:`clang-format 10`
4566 If ``true``, spaces will be inserted around if/for/switch/while
4572 if ( a ) { ... } vs. if (a) { ... }
4573 while ( i < 5 ) { ... } while (i < 5) { ... }
4575 **SpacesInContainerLiterals** (``Boolean``) :versionbadge:`clang-format 3.7`
4576 If ``true``, spaces are inserted inside container literals (e.g.
4577 ObjC and Javascript array and dict literals).
4582 var arr = [ 1, 2, 3 ]; vs. var arr = [1, 2, 3];
4583 f({a : 1, b : 2, c : 3}); f({a: 1, b: 2, c: 3});
4585 **SpacesInLineCommentPrefix** (``SpacesInLineComment``) :versionbadge:`clang-format 13`
4586 How many spaces are allowed at the start of a line comment. To disable the
4587 maximum set it to ``-1``, apart from that the maximum takes precedence
4594 // One space is forced
4596 // but more spaces are possible
4600 //Forces to start every comment directly after the slashes
4602 Note that in line comment sections the relative indent of the subsequent
4603 lines is kept, that means the following:
4609 //if (b) { // if (b) {
4610 // return true; // return true;
4618 This option has only effect if ``ReflowComments`` is set to ``true``.
4620 Nested configuration flags:
4622 Control of spaces within a single line comment.
4624 * ``unsigned Minimum`` The minimum number of spaces at the start of the comment.
4626 * ``unsigned Maximum`` The maximum number of spaces at the start of the comment.
4629 **SpacesInParentheses** (``Boolean``) :versionbadge:`clang-format 3.7`
4630 If ``true``, spaces will be inserted after ``(`` and before ``)``.
4635 t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete;
4637 **SpacesInSquareBrackets** (``Boolean``) :versionbadge:`clang-format 3.7`
4638 If ``true``, spaces will be inserted after ``[`` and before ``]``.
4639 Lambdas without arguments or unspecified size array declarations will not
4645 int a[ 5 ]; vs. int a[5];
4646 std::unique_ptr<int[]> foo() {} // Won't be affected
4648 **Standard** (``LanguageStandard``) :versionbadge:`clang-format 3.7`
4649 Parse and format C++ constructs compatible with this standard.
4654 vector<set<int> > x; vs. vector<set<int>> x;
4658 * ``LS_Cpp03`` (in configuration: ``c++03``)
4659 Parse and format as C++03.
4660 ``Cpp03`` is a deprecated alias for ``c++03``
4662 * ``LS_Cpp11`` (in configuration: ``c++11``)
4663 Parse and format as C++11.
4665 * ``LS_Cpp14`` (in configuration: ``c++14``)
4666 Parse and format as C++14.
4668 * ``LS_Cpp17`` (in configuration: ``c++17``)
4669 Parse and format as C++17.
4671 * ``LS_Cpp20`` (in configuration: ``c++20``)
4672 Parse and format as C++20.
4674 * ``LS_Latest`` (in configuration: ``Latest``)
4675 Parse and format using the latest supported language version.
4676 ``Cpp11`` is a deprecated alias for ``Latest``
4678 * ``LS_Auto`` (in configuration: ``Auto``)
4679 Automatic detection based on the input.
4683 **StatementAttributeLikeMacros** (``List of Strings``) :versionbadge:`clang-format 12`
4684 Macros which are ignored in front of a statement, as if they were an
4685 attribute. So that they are not parsed as identifier, for example for Qts
4690 AlignConsecutiveDeclarations: true
4691 StatementAttributeLikeMacros: []
4692 unsigned char data = 'x';
4693 emit signal(data); // This is parsed as variable declaration.
4695 AlignConsecutiveDeclarations: true
4696 StatementAttributeLikeMacros: [emit]
4697 unsigned char data = 'x';
4698 emit signal(data); // Now it's fine again.
4700 **StatementMacros** (``List of Strings``) :versionbadge:`clang-format 8`
4701 A vector of macros that should be interpreted as complete
4704 Typical macros are expressions, and require a semi-colon to be
4705 added; sometimes this is not the case, and this allows to make
4706 clang-format aware of such cases.
4708 For example: Q_UNUSED
4710 **TabWidth** (``Unsigned``) :versionbadge:`clang-format 3.7`
4711 The number of columns used for tab stops.
4713 **TypenameMacros** (``List of Strings``) :versionbadge:`clang-format 9`
4714 A vector of macros that should be interpreted as type declarations
4715 instead of as function calls.
4717 These are expected to be macros of the form:
4723 In the .clang-format configuration file, this can be configured like:
4725 .. code-block:: yaml
4727 TypenameMacros: ['STACK_OF', 'LIST']
4729 For example: OpenSSL STACK_OF, BSD LIST_ENTRY.
4731 **UseCRLF** (``Boolean``) :versionbadge:`clang-format 10`
4732 Use ``\r\n`` instead of ``\n`` for line breaks.
4733 Also used as fallback if ``DeriveLineEnding`` is true.
4735 **UseTab** (``UseTabStyle``) :versionbadge:`clang-format 3.7`
4736 The way to use tab characters in the resulting file.
4740 * ``UT_Never`` (in configuration: ``Never``)
4743 * ``UT_ForIndentation`` (in configuration: ``ForIndentation``)
4744 Use tabs only for indentation.
4746 * ``UT_ForContinuationAndIndentation`` (in configuration: ``ForContinuationAndIndentation``)
4747 Fill all leading whitespace with tabs, and use spaces for alignment that
4748 appears within a line (e.g. consecutive assignments and declarations).
4750 * ``UT_AlignWithSpaces`` (in configuration: ``AlignWithSpaces``)
4751 Use tabs for line continuation and indentation, and spaces for
4754 * ``UT_Always`` (in configuration: ``Always``)
4755 Use tabs whenever we need to fill whitespace that spans at least from
4756 one tab stop to the next one.
4760 **WhitespaceSensitiveMacros** (``List of Strings``) :versionbadge:`clang-format 11`
4761 A vector of macros which are whitespace-sensitive and should not
4764 These are expected to be macros of the form:
4770 In the .clang-format configuration file, this can be configured like:
4772 .. code-block:: yaml
4774 WhitespaceSensitiveMacros: ['STRINGIZE', 'PP_STRINGIZE']
4776 For example: BOOST_PP_STRINGIZE
4778 .. END_FORMAT_STYLE_OPTIONS
4780 Adding additional style options
4781 ===============================
4783 Each additional style option adds costs to the clang-format project. Some of
4784 these costs affect the clang-format development itself, as we need to make
4785 sure that any given combination of options work and that new features don't
4786 break any of the existing options in any way. There are also costs for end users
4787 as options become less discoverable and people have to think about and make a
4788 decision on options they don't really care about.
4790 The goal of the clang-format project is more on the side of supporting a
4791 limited set of styles really well as opposed to supporting every single style
4792 used by a codebase somewhere in the wild. Of course, we do want to support all
4793 major projects and thus have established the following bar for adding style
4794 options. Each new style option must ..
4796 * be used in a project of significant size (have dozens of contributors)
4797 * have a publicly accessible style guide
4798 * have a person willing to contribute and maintain patches
4803 A style similar to the `Linux Kernel style
4804 <https://www.kernel.org/doc/Documentation/CodingStyle>`_:
4806 .. code-block:: yaml
4811 BreakBeforeBraces: Linux
4812 AllowShortIfStatementsOnASingleLine: false
4813 IndentCaseLabels: false
4815 The result is (imagine that tabs are used for indentation here):
4827 do_something_else();
4833 do_something_completely_different();
4844 A style similar to the default Visual Studio formatting style:
4846 .. code-block:: yaml
4850 BreakBeforeBraces: Allman
4851 AllowShortIfStatementsOnASingleLine: false
4852 IndentCaseLabels: false
4868 do_something_else();
4874 do_something_completely_different();