3 This file is automatically generated, in part. Do not edit the style options
4 in this file directly. Instead, modify them in include/clang/Format/Format.h
5 and run the docs/tools/dump_format_style.py script to update this file.
9 <style type="text/css">
10 .versionbadge { background-color: #1c913d; height: 20px; display: inline-block; min-width: 120px; text-align: center; border-radius: 5px; color: #FFFFFF; font-family: "Verdana,Geneva,DejaVu Sans,sans-serif"; }
13 .. role:: versionbadge
15 ==========================
16 Clang-Format Style Options
17 ==========================
19 :doc:`ClangFormatStyleOptions` describes configurable formatting style options
20 supported by :doc:`LibFormat` and :doc:`ClangFormat`.
22 When using :program:`clang-format` command line utility or
23 ``clang::format::reformat(...)`` functions from code, one can either use one of
24 the predefined styles (LLVM, Google, Chromium, Mozilla, WebKit, Microsoft) or
25 create a custom style by configuring specific style options.
28 Configuring Style with clang-format
29 ===================================
31 :program:`clang-format` supports two ways to provide custom style options:
32 directly specify style configuration in the ``-style=`` command line option or
33 use ``-style=file`` and put style configuration in the ``.clang-format`` or
34 ``_clang-format`` file in the project directory.
36 When using ``-style=file``, :program:`clang-format` for each input file will
37 try to find the ``.clang-format`` file located in the closest parent directory
38 of the input file. When the standard input is used, the search is started from
39 the current directory.
41 When using ``-style=file:<format_file_path>``, :program:`clang-format` for
42 each input file will use the format file located at `<format_file_path>`.
43 The path may be absolute or relative to the working directory.
45 The ``.clang-format`` file uses YAML format:
54 The configuration file can consist of several sections each having different
55 ``Language:`` parameter denoting the programming language this section of the
56 configuration is targeted at. See the description of the **Language** option
57 below for the list of supported languages. The first section may have no
58 language set, it will set the default style options for all languages.
59 Configuration sections for specific language will override options set in the
62 When :program:`clang-format` formats a file, it auto-detects the language using
63 the file name. When formatting standard input or a file that doesn't have the
64 extension corresponding to its language, ``-assume-filename=`` option can be
65 used to override the file name :program:`clang-format` uses to detect the
68 An example of a configuration file for multiple languages:
73 # We'll use defaults from the LLVM style, but with 4 columns indentation.
78 # Force pointers to the type for C++.
79 DerivePointerAlignment: false
80 PointerAlignment: Left
83 # Use 100 columns for JS.
87 # Don't format .proto files.
91 # Use 100 columns for C#.
95 An easy way to get a valid ``.clang-format`` file containing all configuration
96 options of a certain predefined style is:
98 .. code-block:: console
100 clang-format -style=llvm -dump-config > .clang-format
102 When specifying configuration in the ``-style=`` option, the same configuration
103 is applied for all input files. The format of the configuration is:
105 .. code-block:: console
107 -style='{key1: value1, key2: value2, ...}'
110 Disabling Formatting on a Piece of Code
111 =======================================
113 Clang-format understands also special comments that switch formatting in a
114 delimited range. The code between a comment ``// clang-format off`` or
115 ``/* clang-format off */`` up to a comment ``// clang-format on`` or
116 ``/* clang-format on */`` will not be formatted. The comments themselves will be
117 formatted (aligned) normally. Also, a colon (``:``) and additional text may
118 follow ``// clang-format off`` or ``// clang-format on`` to explain why
119 clang-format is turned off or back on.
125 void unformatted_code ;
127 void formatted_code_again;
130 Configuring Style in Code
131 =========================
133 When using ``clang::format::reformat(...)`` functions, the format is specified
134 by supplying the `clang::format::FormatStyle
135 <https://clang.llvm.org/doxygen/structclang_1_1format_1_1FormatStyle.html>`_
139 Configurable Format Style Options
140 =================================
142 This section lists the supported style options. Value type is specified for
143 each option. For enumeration types possible values are specified both as a C++
144 enumeration member (with a prefix, e.g. ``LS_Auto``), and as a value usable in
145 the configuration (without a prefix: ``Auto``).
149 **BasedOnStyle** (``String``) :ref:`¶ <BasedOnStyle>`
150 The style used for all options not specifically set in the configuration.
152 This option is supported only in the :program:`clang-format` configuration
153 (both within ``-style='{...}'`` and the ``.clang-format`` file).
158 A style complying with the `LLVM coding standards
159 <https://llvm.org/docs/CodingStandards.html>`_
161 A style complying with `Google's C++ style guide
162 <https://google.github.io/styleguide/cppguide.html>`_
164 A style complying with `Chromium's style guide
165 <https://chromium.googlesource.com/chromium/src/+/refs/heads/main/styleguide/styleguide.md>`_
167 A style complying with `Mozilla's style guide
168 <https://firefox-source-docs.mozilla.org/code-quality/coding-style/index.html>`_
170 A style complying with `WebKit's style guide
171 <https://www.webkit.org/coding/coding-style.html>`_
173 A style complying with `Microsoft's style guide
174 <https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference>`_
176 A style complying with the `GNU coding standards
177 <https://www.gnu.org/prep/standards/standards.html>`_
178 * ``InheritParentConfig``
179 Not a real style, but allows to use the ``.clang-format`` file from the
180 parent directory (or its parent if there is none). If there is no parent
181 file found it falls back to the ``fallback`` style, and applies the changes
184 With this option you can overwrite some parts of your main style for your
185 subdirectories. This is also possible through the command line, e.g.:
186 ``--style={BasedOnStyle: InheritParentConfig, ColumnLimit: 20}``
188 .. START_FORMAT_STYLE_OPTIONS
190 .. _AccessModifierOffset:
192 **AccessModifierOffset** (``Integer``) :versionbadge:`clang-format 3.3` :ref:`¶ <AccessModifierOffset>`
193 The extra indent or outdent of access modifiers, e.g. ``public:``.
195 .. _AlignAfterOpenBracket:
197 **AlignAfterOpenBracket** (``BracketAlignmentStyle``) :versionbadge:`clang-format 3.8` :ref:`¶ <AlignAfterOpenBracket>`
198 If ``true``, horizontally aligns arguments after an open bracket.
200 This applies to round brackets (parentheses), angle brackets and square
205 * ``BAS_Align`` (in configuration: ``Align``)
206 Align parameters on the open bracket, e.g.:
210 someLongFunction(argument1,
213 * ``BAS_DontAlign`` (in configuration: ``DontAlign``)
214 Don't align, instead use ``ContinuationIndentWidth``, e.g.:
218 someLongFunction(argument1,
221 * ``BAS_AlwaysBreak`` (in configuration: ``AlwaysBreak``)
222 Always break after an open bracket, if the parameters don't fit
223 on a single line, e.g.:
228 argument1, argument2);
230 * ``BAS_BlockIndent`` (in configuration: ``BlockIndent``)
231 Always break after an open bracket, if the parameters don't fit
232 on a single line. Closing brackets will be placed on a new line.
244 This currently only applies to braced initializer lists (when
245 ``Cpp11BracedListStyle`` is ``true``) and parentheses.
249 .. _AlignArrayOfStructures:
251 **AlignArrayOfStructures** (``ArrayInitializerAlignmentStyle``) :versionbadge:`clang-format 13` :ref:`¶ <AlignArrayOfStructures>`
252 if not ``None``, when using initialization for an array of structs
253 aligns the fields into columns.
258 As of clang-format 15 this option only applied to arrays with equal
259 number of columns per row.
263 * ``AIAS_Left`` (in configuration: ``Left``)
264 Align array column and left justify the columns e.g.:
271 {-1, 93463, "world"},
275 * ``AIAS_Right`` (in configuration: ``Right``)
276 Align array column and right justify the columns e.g.:
283 {-1, 93463, "world"},
287 * ``AIAS_None`` (in configuration: ``None``)
288 Don't align array initializer columns.
292 .. _AlignConsecutiveAssignments:
294 **AlignConsecutiveAssignments** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 3.8` :ref:`¶ <AlignConsecutiveAssignments>`
295 Style of aligning consecutive assignments.
297 ``Consecutive`` will result in formattings like:
302 int somelongname = 2;
305 Nested configuration flags:
309 They can also be read as a whole for compatibility. The choices are:
314 - AcrossEmptyLinesAndComments
316 For example, to align across empty lines and not across comments, either
321 AlignConsecutiveMacros: AcrossEmptyLines
323 AlignConsecutiveMacros:
325 AcrossEmptyLines: true
326 AcrossComments: false
328 * ``bool Enabled`` Whether aligning is enabled.
332 #define SHORT_NAME 42
333 #define LONGER_NAME 0x007f
334 #define EVEN_LONGER_NAME (2)
335 #define foo(x) (x * x)
336 #define bar(y, z) (y + z)
339 int somelongname = 2;
350 * ``bool AcrossEmptyLines`` Whether to align across empty lines.
356 int somelongname = 2;
363 int somelongname = 2;
368 * ``bool AcrossComments`` Whether to align across comments.
382 * ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound assignments
383 like ``+=`` are aligned along with ``=``.
395 * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment
396 operators are left-padded to the same length as long ones in order to
397 put all assignment operators to the right of the left hand side.
416 .. _AlignConsecutiveBitFields:
418 **AlignConsecutiveBitFields** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 11` :ref:`¶ <AlignConsecutiveBitFields>`
419 Style of aligning consecutive bit fields.
421 ``Consecutive`` will align the bitfield separators of consecutive lines.
422 This will result in formattings like:
430 Nested configuration flags:
434 They can also be read as a whole for compatibility. The choices are:
439 - AcrossEmptyLinesAndComments
441 For example, to align across empty lines and not across comments, either
446 AlignConsecutiveMacros: AcrossEmptyLines
448 AlignConsecutiveMacros:
450 AcrossEmptyLines: true
451 AcrossComments: false
453 * ``bool Enabled`` Whether aligning is enabled.
457 #define SHORT_NAME 42
458 #define LONGER_NAME 0x007f
459 #define EVEN_LONGER_NAME (2)
460 #define foo(x) (x * x)
461 #define bar(y, z) (y + z)
464 int somelongname = 2;
475 * ``bool AcrossEmptyLines`` Whether to align across empty lines.
481 int somelongname = 2;
488 int somelongname = 2;
493 * ``bool AcrossComments`` Whether to align across comments.
507 * ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound assignments
508 like ``+=`` are aligned along with ``=``.
520 * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment
521 operators are left-padded to the same length as long ones in order to
522 put all assignment operators to the right of the left hand side.
541 .. _AlignConsecutiveDeclarations:
543 **AlignConsecutiveDeclarations** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 3.8` :ref:`¶ <AlignConsecutiveDeclarations>`
544 Style of aligning consecutive declarations.
546 ``Consecutive`` will align the declaration names of consecutive lines.
547 This will result in formattings like:
555 Nested configuration flags:
559 They can also be read as a whole for compatibility. The choices are:
564 - AcrossEmptyLinesAndComments
566 For example, to align across empty lines and not across comments, either
571 AlignConsecutiveMacros: AcrossEmptyLines
573 AlignConsecutiveMacros:
575 AcrossEmptyLines: true
576 AcrossComments: false
578 * ``bool Enabled`` Whether aligning is enabled.
582 #define SHORT_NAME 42
583 #define LONGER_NAME 0x007f
584 #define EVEN_LONGER_NAME (2)
585 #define foo(x) (x * x)
586 #define bar(y, z) (y + z)
589 int somelongname = 2;
600 * ``bool AcrossEmptyLines`` Whether to align across empty lines.
606 int somelongname = 2;
613 int somelongname = 2;
618 * ``bool AcrossComments`` Whether to align across comments.
632 * ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound assignments
633 like ``+=`` are aligned along with ``=``.
645 * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment
646 operators are left-padded to the same length as long ones in order to
647 put all assignment operators to the right of the left hand side.
666 .. _AlignConsecutiveMacros:
668 **AlignConsecutiveMacros** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 9` :ref:`¶ <AlignConsecutiveMacros>`
669 Style of aligning consecutive macro definitions.
671 ``Consecutive`` will result in formattings like:
675 #define SHORT_NAME 42
676 #define LONGER_NAME 0x007f
677 #define EVEN_LONGER_NAME (2)
678 #define foo(x) (x * x)
679 #define bar(y, z) (y + z)
681 Nested configuration flags:
685 They can also be read as a whole for compatibility. The choices are:
690 - AcrossEmptyLinesAndComments
692 For example, to align across empty lines and not across comments, either
697 AlignConsecutiveMacros: AcrossEmptyLines
699 AlignConsecutiveMacros:
701 AcrossEmptyLines: true
702 AcrossComments: false
704 * ``bool Enabled`` Whether aligning is enabled.
708 #define SHORT_NAME 42
709 #define LONGER_NAME 0x007f
710 #define EVEN_LONGER_NAME (2)
711 #define foo(x) (x * x)
712 #define bar(y, z) (y + z)
715 int somelongname = 2;
726 * ``bool AcrossEmptyLines`` Whether to align across empty lines.
732 int somelongname = 2;
739 int somelongname = 2;
744 * ``bool AcrossComments`` Whether to align across comments.
758 * ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound assignments
759 like ``+=`` are aligned along with ``=``.
771 * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment
772 operators are left-padded to the same length as long ones in order to
773 put all assignment operators to the right of the left hand side.
792 .. _AlignConsecutiveShortCaseStatements:
794 **AlignConsecutiveShortCaseStatements** (``ShortCaseStatementsAlignmentStyle``) :versionbadge:`clang-format 17` :ref:`¶ <AlignConsecutiveShortCaseStatements>`
795 Style of aligning consecutive short case labels.
796 Only applies if ``AllowShortCaseLabelsOnASingleLine`` is ``true``.
802 AlignConsecutiveShortCaseStatements:
804 AcrossEmptyLines: true
806 AlignCaseColons: false
808 Nested configuration flags:
812 * ``bool Enabled`` Whether aligning is enabled.
818 case log::info: return "info:";
819 case log::warning: return "warning:";
825 case log::info: return "info:";
826 case log::warning: return "warning:";
830 * ``bool AcrossEmptyLines`` Whether to align across empty lines.
836 case log::info: return "info:";
837 case log::warning: return "warning:";
844 case log::info: return "info:";
845 case log::warning: return "warning:";
850 * ``bool AcrossComments`` Whether to align across comments.
856 case log::info: return "info:";
857 case log::warning: return "warning:";
864 case log::info: return "info:";
865 case log::warning: return "warning:";
870 * ``bool AlignCaseColons`` Whether aligned case labels are aligned on the colon, or on the
871 , or on the tokens after the colon.
877 case log::info : return "info:";
878 case log::warning: return "warning:";
884 case log::info: return "info:";
885 case log::warning: return "warning:";
890 .. _AlignEscapedNewlines:
892 **AlignEscapedNewlines** (``EscapedNewlineAlignmentStyle``) :versionbadge:`clang-format 5` :ref:`¶ <AlignEscapedNewlines>`
893 Options for aligning backslashes in escaped newlines.
897 * ``ENAS_DontAlign`` (in configuration: ``DontAlign``)
898 Don't align escaped newlines.
907 * ``ENAS_Left`` (in configuration: ``Left``)
908 Align escaped newlines as far left as possible.
920 * ``ENAS_Right`` (in configuration: ``Right``)
921 Align escaped newlines in the right-most column.
934 **AlignOperands** (``OperandAlignmentStyle``) :versionbadge:`clang-format 3.5` :ref:`¶ <AlignOperands>`
935 If ``true``, horizontally align operands of binary and ternary
940 * ``OAS_DontAlign`` (in configuration: ``DontAlign``)
941 Do not align operands of binary and ternary expressions.
942 The wrapped lines are indented ``ContinuationIndentWidth`` spaces from
943 the start of the line.
945 * ``OAS_Align`` (in configuration: ``Align``)
946 Horizontally align operands of binary and ternary expressions.
948 Specifically, this aligns operands of a single expression that needs
949 to be split over multiple lines, e.g.:
953 int aaa = bbbbbbbbbbbbbbb +
956 When ``BreakBeforeBinaryOperators`` is set, the wrapped operator is
957 aligned with the operand on the first line.
961 int aaa = bbbbbbbbbbbbbbb
964 * ``OAS_AlignAfterOperator`` (in configuration: ``AlignAfterOperator``)
965 Horizontally align operands of binary and ternary expressions.
967 This is similar to ``AO_Align``, except when
968 ``BreakBeforeBinaryOperators`` is set, the operator is un-indented so
969 that the wrapped operand is aligned with the operand on the first line.
973 int aaa = bbbbbbbbbbbbbbb
978 .. _AlignTrailingComments:
980 **AlignTrailingComments** (``TrailingCommentsAlignmentStyle``) :versionbadge:`clang-format 3.7` :ref:`¶ <AlignTrailingComments>`
981 Control of trailing comments.
983 The alignment stops at closing braces after a line break, and only
984 followed by other closing braces, a (``do-``) ``while``, a lambda call, or
990 As of clang-format 16 this option is not a bool but can be set
991 to the options. Conventional bool options still can be parsed as before.
997 AlignTrailingComments:
1001 Nested configuration flags:
1005 * ``TrailingCommentsAlignmentKinds Kind``
1006 Specifies the way to align trailing comments.
1010 * ``TCAS_Leave`` (in configuration: ``Leave``)
1011 Leave trailing comments as they are.
1019 int abcd; // comment
1021 * ``TCAS_Always`` (in configuration: ``Always``)
1022 Align trailing comments.
1030 int abcd; // comment
1032 * ``TCAS_Never`` (in configuration: ``Never``)
1033 Don't align trailing comments but other formatter applies.
1041 int abcd; // comment
1044 * ``unsigned OverEmptyLines`` How many empty lines to apply alignment.
1045 When both ``MaxEmptyLinesToKeep`` and ``OverEmptyLines`` are set to 2,
1046 it formats like below.
1052 int ab; // comments are
1055 int abcdef; // aligned
1057 When ``MaxEmptyLinesToKeep`` is set to 2 and ``OverEmptyLines`` is set
1058 to 1, it formats like below.
1067 int abcdef; // but this isn't
1070 .. _AllowAllArgumentsOnNextLine:
1072 **AllowAllArgumentsOnNextLine** (``Boolean``) :versionbadge:`clang-format 9` :ref:`¶ <AllowAllArgumentsOnNextLine>`
1073 If a function call or braced initializer list doesn't fit on a
1074 line, allow putting all arguments onto the next line, even if
1075 ``BinPackArguments`` is ``false``.
1089 .. _AllowAllConstructorInitializersOnNextLine:
1091 **AllowAllConstructorInitializersOnNextLine** (``Boolean``) :versionbadge:`clang-format 9` :ref:`¶ <AllowAllConstructorInitializersOnNextLine>`
1092 This option is **deprecated**. See ``NextLine`` of
1093 ``PackConstructorInitializers``.
1095 .. _AllowAllParametersOfDeclarationOnNextLine:
1097 **AllowAllParametersOfDeclarationOnNextLine** (``Boolean``) :versionbadge:`clang-format 3.3` :ref:`¶ <AllowAllParametersOfDeclarationOnNextLine>`
1098 If the function declaration doesn't fit on a line,
1099 allow putting all parameters of a function declaration onto
1100 the next line even if ``BinPackParameters`` is ``false``.
1106 int a, int b, int c, int d, int e);
1109 void myFunction(int a,
1115 .. _AllowBreakBeforeNoexceptSpecifier:
1117 **AllowBreakBeforeNoexceptSpecifier** (``BreakBeforeNoexceptSpecifierStyle``) :versionbadge:`clang-format 18` :ref:`¶ <AllowBreakBeforeNoexceptSpecifier>`
1118 Controls if there could be a line break before a ``noexcept`` specifier.
1122 * ``BBNSS_Never`` (in configuration: ``Never``)
1123 No line break allowed.
1128 double arg2) noexcept;
1130 void bar(int arg1, double arg2) noexcept(
1131 noexcept(baz(arg1)) &&
1132 noexcept(baz(arg2)));
1134 * ``BBNSS_OnlyWithParen`` (in configuration: ``OnlyWithParen``)
1135 For a simple ``noexcept`` there is no line break allowed, but when we
1136 have a condition it is.
1141 double arg2) noexcept;
1143 void bar(int arg1, double arg2)
1144 noexcept(noexcept(baz(arg1)) &&
1145 noexcept(baz(arg2)));
1147 * ``BBNSS_Always`` (in configuration: ``Always``)
1148 Line breaks are allowed. But note that because of the associated
1149 penalties ``clang-format`` often prefers not to break before the
1155 double arg2) noexcept;
1157 void bar(int arg1, double arg2)
1158 noexcept(noexcept(baz(arg1)) &&
1159 noexcept(baz(arg2)));
1163 .. _AllowShortBlocksOnASingleLine:
1165 **AllowShortBlocksOnASingleLine** (``ShortBlockStyle``) :versionbadge:`clang-format 3.5` :ref:`¶ <AllowShortBlocksOnASingleLine>`
1166 Dependent on the value, ``while (true) { continue; }`` can be put on a
1171 * ``SBS_Never`` (in configuration: ``Never``)
1172 Never merge blocks into a single line.
1182 * ``SBS_Empty`` (in configuration: ``Empty``)
1183 Only merge empty blocks.
1192 * ``SBS_Always`` (in configuration: ``Always``)
1193 Always merge short blocks into a single line.
1198 while (true) { continue; }
1202 .. _AllowShortCaseLabelsOnASingleLine:
1204 **AllowShortCaseLabelsOnASingleLine** (``Boolean``) :versionbadge:`clang-format 3.6` :ref:`¶ <AllowShortCaseLabelsOnASingleLine>`
1205 If ``true``, short case labels will be contracted to a single line.
1210 switch (a) { vs. switch (a) {
1211 case 1: x = 1; break; case 1:
1212 case 2: return; x = 1;
1218 .. _AllowShortCompoundRequirementOnASingleLine:
1220 **AllowShortCompoundRequirementOnASingleLine** (``Boolean``) :versionbadge:`clang-format 18` :ref:`¶ <AllowShortCompoundRequirementOnASingleLine>`
1221 Allow short compound requirement on a single line.
1226 template <typename T>
1227 concept c = requires(T x) {
1228 { x + 1 } -> std::same_as<int>;
1232 template <typename T>
1233 concept c = requires(T x) {
1236 } -> std::same_as<int>;
1239 .. _AllowShortEnumsOnASingleLine:
1241 **AllowShortEnumsOnASingleLine** (``Boolean``) :versionbadge:`clang-format 11` :ref:`¶ <AllowShortEnumsOnASingleLine>`
1242 Allow short enums on a single line.
1247 enum { A, B } myEnum;
1255 .. _AllowShortFunctionsOnASingleLine:
1257 **AllowShortFunctionsOnASingleLine** (``ShortFunctionStyle``) :versionbadge:`clang-format 3.5` :ref:`¶ <AllowShortFunctionsOnASingleLine>`
1258 Dependent on the value, ``int f() { return 0; }`` can be put on a
1263 * ``SFS_None`` (in configuration: ``None``)
1264 Never merge functions into a single line.
1266 * ``SFS_InlineOnly`` (in configuration: ``InlineOnly``)
1267 Only merge functions defined inside a class. Same as "inline",
1268 except it does not implies "empty": i.e. top level empty functions
1269 are not merged either.
1282 * ``SFS_Empty`` (in configuration: ``Empty``)
1283 Only merge empty functions.
1292 * ``SFS_Inline`` (in configuration: ``Inline``)
1293 Only merge functions defined inside a class. Implies "empty".
1305 * ``SFS_All`` (in configuration: ``All``)
1306 Merge all functions fitting on a single line.
1317 .. _AllowShortIfStatementsOnASingleLine:
1319 **AllowShortIfStatementsOnASingleLine** (``ShortIfStyle``) :versionbadge:`clang-format 3.3` :ref:`¶ <AllowShortIfStatementsOnASingleLine>`
1320 Dependent on the value, ``if (a) return;`` can be put on a single line.
1324 * ``SIS_Never`` (in configuration: ``Never``)
1325 Never put short ifs on the same line.
1343 * ``SIS_WithoutElse`` (in configuration: ``WithoutElse``)
1344 Put short ifs on the same line only if there is no else statement.
1361 * ``SIS_OnlyFirstIf`` (in configuration: ``OnlyFirstIf``)
1362 Put short ifs, but not else ifs nor else statements, on the same line.
1379 * ``SIS_AllIfsAndElse`` (in configuration: ``AllIfsAndElse``)
1380 Always put short ifs, else ifs and else statements on the same
1397 .. _AllowShortLambdasOnASingleLine:
1399 **AllowShortLambdasOnASingleLine** (``ShortLambdaStyle``) :versionbadge:`clang-format 9` :ref:`¶ <AllowShortLambdasOnASingleLine>`
1400 Dependent on the value, ``auto lambda []() { return 0; }`` can be put on a
1405 * ``SLS_None`` (in configuration: ``None``)
1406 Never merge lambdas into a single line.
1408 * ``SLS_Empty`` (in configuration: ``Empty``)
1409 Only merge empty lambdas.
1413 auto lambda = [](int a) {};
1414 auto lambda2 = [](int a) {
1418 * ``SLS_Inline`` (in configuration: ``Inline``)
1419 Merge lambda into a single line if the lambda is argument of a function.
1423 auto lambda = [](int x, int y) {
1426 sort(a.begin(), a.end(), [](int x, int y) { return x < y; });
1428 * ``SLS_All`` (in configuration: ``All``)
1429 Merge all lambdas fitting on a single line.
1433 auto lambda = [](int a) {};
1434 auto lambda2 = [](int a) { return a; };
1438 .. _AllowShortLoopsOnASingleLine:
1440 **AllowShortLoopsOnASingleLine** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <AllowShortLoopsOnASingleLine>`
1441 If ``true``, ``while (true) continue;`` can be put on a single
1444 .. _AlwaysBreakAfterDefinitionReturnType:
1446 **AlwaysBreakAfterDefinitionReturnType** (``DefinitionReturnTypeBreakingStyle``) :versionbadge:`clang-format 3.7` :ref:`¶ <AlwaysBreakAfterDefinitionReturnType>`
1447 The function definition return type breaking style to use. This
1448 option is **deprecated** and is retained for backwards compatibility.
1452 * ``DRTBS_None`` (in configuration: ``None``)
1453 Break after return type automatically.
1454 ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
1456 * ``DRTBS_All`` (in configuration: ``All``)
1457 Always break after the return type.
1459 * ``DRTBS_TopLevel`` (in configuration: ``TopLevel``)
1460 Always break after the return types of top-level functions.
1464 .. _AlwaysBreakAfterReturnType:
1466 **AlwaysBreakAfterReturnType** (``ReturnTypeBreakingStyle``) :versionbadge:`clang-format 3.8` :ref:`¶ <AlwaysBreakAfterReturnType>`
1467 The function declaration return type breaking style to use.
1471 * ``RTBS_None`` (in configuration: ``None``)
1472 Break after return type automatically.
1473 ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
1478 int f() { return 0; };
1481 int f() { return 1; }
1483 * ``RTBS_All`` (in configuration: ``All``)
1484 Always break after the return type.
1501 * ``RTBS_TopLevel`` (in configuration: ``TopLevel``)
1502 Always break after the return types of top-level functions.
1507 int f() { return 0; };
1516 * ``RTBS_AllDefinitions`` (in configuration: ``AllDefinitions``)
1517 Always break after the return type of function definitions.
1533 * ``RTBS_TopLevelDefinitions`` (in configuration: ``TopLevelDefinitions``)
1534 Always break after the return type of top-level definitions.
1539 int f() { return 0; };
1549 .. _AlwaysBreakBeforeMultilineStrings:
1551 **AlwaysBreakBeforeMultilineStrings** (``Boolean``) :versionbadge:`clang-format 3.4` :ref:`¶ <AlwaysBreakBeforeMultilineStrings>`
1552 If ``true``, always break before multiline string literals.
1554 This flag is mean to make cases where there are multiple multiline strings
1555 in a file look more consistent. Thus, it will only take effect if wrapping
1556 the string at that point leads to it being indented
1557 ``ContinuationIndentWidth`` spaces from the start of the line.
1562 aaaa = vs. aaaa = "bbbb"
1566 .. _AlwaysBreakTemplateDeclarations:
1568 **AlwaysBreakTemplateDeclarations** (``BreakTemplateDeclarationsStyle``) :versionbadge:`clang-format 3.4` :ref:`¶ <AlwaysBreakTemplateDeclarations>`
1569 The template declaration breaking style to use.
1573 * ``BTDS_No`` (in configuration: ``No``)
1574 Do not force break before declaration.
1575 ``PenaltyBreakTemplateDeclaration`` is taken into account.
1579 template <typename T> T foo() {
1581 template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa,
1582 int bbbbbbbbbbbbbbbbbbbbb) {
1585 * ``BTDS_MultiLine`` (in configuration: ``MultiLine``)
1586 Force break after template declaration only when the following
1587 declaration spans multiple lines.
1591 template <typename T> T foo() {
1593 template <typename T>
1594 T foo(int aaaaaaaaaaaaaaaaaaaaa,
1595 int bbbbbbbbbbbbbbbbbbbbb) {
1598 * ``BTDS_Yes`` (in configuration: ``Yes``)
1599 Always break after template declaration.
1603 template <typename T>
1606 template <typename T>
1607 T foo(int aaaaaaaaaaaaaaaaaaaaa,
1608 int bbbbbbbbbbbbbbbbbbbbb) {
1613 .. _AttributeMacros:
1615 **AttributeMacros** (``List of Strings``) :versionbadge:`clang-format 12` :ref:`¶ <AttributeMacros>`
1616 A vector of strings that should be interpreted as attributes/qualifiers
1617 instead of identifiers. This can be useful for language extensions or
1618 static analyzer annotations.
1624 x = (char *__capability)&y;
1625 int function(void) __unused;
1626 void only_writes_to_buffer(char *__output buffer);
1628 In the .clang-format configuration file, this can be configured like:
1630 .. code-block:: yaml
1632 AttributeMacros: ['__capability', '__output', '__unused']
1634 .. _BinPackArguments:
1636 **BinPackArguments** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <BinPackArguments>`
1637 If ``false``, a function call's arguments will either be all on the
1638 same line or will have one line each.
1644 f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa,
1645 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
1650 f(aaaaaaaaaaaaaaaaaaaa,
1651 aaaaaaaaaaaaaaaaaaaa,
1652 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
1655 .. _BinPackParameters:
1657 **BinPackParameters** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <BinPackParameters>`
1658 If ``false``, a function declaration's or function definition's
1659 parameters will either all be on the same line or will have one line each.
1664 void f(int aaaaaaaaaaaaaaaaaaaa, int aaaaaaaaaaaaaaaaaaaa,
1665 int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
1668 void f(int aaaaaaaaaaaaaaaaaaaa,
1669 int aaaaaaaaaaaaaaaaaaaa,
1670 int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
1672 .. _BitFieldColonSpacing:
1674 **BitFieldColonSpacing** (``BitFieldColonSpacingStyle``) :versionbadge:`clang-format 12` :ref:`¶ <BitFieldColonSpacing>`
1675 The BitFieldColonSpacingStyle to use for bitfields.
1679 * ``BFCS_Both`` (in configuration: ``Both``)
1680 Add one space on each side of the ``:``
1686 * ``BFCS_None`` (in configuration: ``None``)
1687 Add no space around the ``:`` (except when needed for
1688 ``AlignConsecutiveBitFields``).
1694 * ``BFCS_Before`` (in configuration: ``Before``)
1695 Add space before the ``:`` only
1701 * ``BFCS_After`` (in configuration: ``After``)
1702 Add space after the ``:`` only (space may be added before if
1703 needed for ``AlignConsecutiveBitFields``).
1713 **BraceWrapping** (``BraceWrappingFlags``) :versionbadge:`clang-format 3.8` :ref:`¶ <BraceWrapping>`
1714 Control of individual brace wrapping cases.
1716 If ``BreakBeforeBraces`` is set to ``BS_Custom``, use this to specify how
1717 each individual brace case should be handled. Otherwise, this is ignored.
1719 .. code-block:: yaml
1722 BreakBeforeBraces: Custom
1726 SplitEmptyFunction: false
1728 Nested configuration flags:
1730 Precise control over the wrapping of braces.
1734 # Should be declared this way:
1735 BreakBeforeBraces: Custom
1739 * ``bool AfterCaseLabel`` Wrap case labels.
1744 switch (foo) { vs. switch (foo) {
1756 * ``bool AfterClass`` Wrap class definitions.
1767 * ``BraceWrappingAfterControlStatementStyle AfterControlStatement``
1768 Wrap control statements (``if``/``for``/``while``/``switch``/..).
1772 * ``BWACS_Never`` (in configuration: ``Never``)
1773 Never wrap braces after a control statement.
1780 for (int i = 0; i < 10; ++i) {
1783 * ``BWACS_MultiLine`` (in configuration: ``MultiLine``)
1784 Only wrap braces after a multi-line control statement.
1793 while (foo || bar) {
1796 * ``BWACS_Always`` (in configuration: ``Always``)
1797 Always wrap braces after a control statement.
1805 for (int i = 0; i < 10; ++i)
1809 * ``bool AfterEnum`` Wrap enum definitions.
1822 * ``bool AfterFunction`` Wrap function definitions.
1839 * ``bool AfterNamespace`` Wrap namespace definitions.
1856 * ``bool AfterObjCDeclaration`` Wrap ObjC definitions (interfaces, implementations...).
1860 @autoreleasepool and @synchronized blocks are wrapped
1861 according to ``AfterControlStatement`` flag.
1863 * ``bool AfterStruct`` Wrap struct definitions.
1878 * ``bool AfterUnion`` Wrap union definitions.
1893 * ``bool AfterExternBlock`` Wrap extern blocks.
1908 * ``bool BeforeCatch`` Wrap before ``catch``.
1925 * ``bool BeforeElse`` Wrap before ``else``.
1940 * ``bool BeforeLambdaBody`` Wrap lambda block.
1958 * ``bool BeforeWhile`` Wrap before ``while``.
1973 * ``bool IndentBraces`` Indent the wrapped braces themselves.
1975 * ``bool SplitEmptyFunction`` If ``false``, empty function body can be put on a single line.
1976 This option is used only if the opening brace of the function has
1977 already been wrapped, i.e. the ``AfterFunction`` brace wrapping mode is
1978 set, and the function could/should not be put on a single line (as per
1979 ``AllowShortFunctionsOnASingleLine`` and constructor formatting
1989 * ``bool SplitEmptyRecord`` If ``false``, empty record (e.g. class, struct or union) body
1990 can be put on a single line. This option is used only if the opening
1991 brace of the record has already been wrapped, i.e. the ``AfterClass``
1992 (for classes) brace wrapping mode is set.
1997 class Foo vs. class Foo
2001 * ``bool SplitEmptyNamespace`` If ``false``, empty namespace body can be put on a single line.
2002 This option is used only if the opening brace of the namespace has
2003 already been wrapped, i.e. the ``AfterNamespace`` brace wrapping mode is
2009 namespace Foo vs. namespace Foo
2014 .. _BracedInitializerIndentWidth:
2016 **BracedInitializerIndentWidth** (``Unsigned``) :versionbadge:`clang-format 17` :ref:`¶ <BracedInitializerIndentWidth>`
2017 The number of columns to use to indent the contents of braced init lists.
2018 If unset, ``ContinuationIndentWidth`` is used.
2022 AlignAfterOpenBracket: AlwaysBreak
2023 BracedInitializerIndentWidth: 2
2031 auto s = SomeStruct{
2049 .. _BreakAfterAttributes:
2051 **BreakAfterAttributes** (``AttributeBreakingStyle``) :versionbadge:`clang-format 16` :ref:`¶ <BreakAfterAttributes>`
2052 Break after a group of C++11 attributes before a function
2053 declaration/definition name.
2057 * ``ABS_Always`` (in configuration: ``Always``)
2058 Always break after attributes.
2064 [[gnu::const]] [[nodiscard]]
2067 * ``ABS_Leave`` (in configuration: ``Leave``)
2068 Leave the line breaking after attributes as is.
2072 [[nodiscard]] inline int f();
2073 [[gnu::const]] [[nodiscard]]
2076 * ``ABS_Never`` (in configuration: ``Never``)
2077 Never break after attributes.
2081 [[nodiscard]] inline int f();
2082 [[gnu::const]] [[nodiscard]] int g();
2086 .. _BreakAfterJavaFieldAnnotations:
2088 **BreakAfterJavaFieldAnnotations** (``Boolean``) :versionbadge:`clang-format 3.8` :ref:`¶ <BreakAfterJavaFieldAnnotations>`
2089 Break after each annotation on a field in Java files.
2091 .. code-block:: java
2094 @Partial vs. @Partial @Mock DataLoad loader;
2100 **BreakArrays** (``Boolean``) :versionbadge:`clang-format 16` :ref:`¶ <BreakArrays>`
2101 If ``true``, clang-format will always break after a Json array ``[``
2102 otherwise it will scan until the closing ``]`` to determine if it should
2103 add newlines between elements (prettier compatible).
2108 This is currently only for formatting JSON.
2120 .. _BreakBeforeBinaryOperators:
2122 **BreakBeforeBinaryOperators** (``BinaryOperatorStyle``) :versionbadge:`clang-format 3.6` :ref:`¶ <BreakBeforeBinaryOperators>`
2123 The way to wrap binary operators.
2127 * ``BOS_None`` (in configuration: ``None``)
2128 Break after operators.
2132 LooooooooooongType loooooooooooooooooooooongVariable =
2133 someLooooooooooooooooongFunction();
2135 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
2136 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ==
2137 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
2138 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa >
2139 ccccccccccccccccccccccccccccccccccccccccc;
2141 * ``BOS_NonAssignment`` (in configuration: ``NonAssignment``)
2142 Break before operators that aren't assignments.
2146 LooooooooooongType loooooooooooooooooooooongVariable =
2147 someLooooooooooooooooongFunction();
2149 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
2150 + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
2151 == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
2152 && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
2153 > ccccccccccccccccccccccccccccccccccccccccc;
2155 * ``BOS_All`` (in configuration: ``All``)
2156 Break before operators.
2160 LooooooooooongType loooooooooooooooooooooongVariable
2161 = someLooooooooooooooooongFunction();
2163 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
2164 + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
2165 == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
2166 && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
2167 > ccccccccccccccccccccccccccccccccccccccccc;
2171 .. _BreakBeforeBraces:
2173 **BreakBeforeBraces** (``BraceBreakingStyle``) :versionbadge:`clang-format 3.7` :ref:`¶ <BreakBeforeBraces>`
2174 The brace breaking style to use.
2178 * ``BS_Attach`` (in configuration: ``Attach``)
2179 Always attach braces to surrounding context.
2222 void bar() { foo(true); }
2225 * ``BS_Linux`` (in configuration: ``Linux``)
2226 Like ``Attach``, but break before braces on function, namespace and
2274 void bar() { foo(true); }
2277 * ``BS_Mozilla`` (in configuration: ``Mozilla``)
2278 Like ``Attach``, but break before braces on enum, function, and record
2326 void bar() { foo(true); }
2329 * ``BS_Stroustrup`` (in configuration: ``Stroustrup``)
2330 Like ``Attach``, but break before function definitions, ``catch``, and
2378 void bar() { foo(true); }
2381 * ``BS_Allman`` (in configuration: ``Allman``)
2382 Always break before braces.
2440 void bar() { foo(true); }
2443 * ``BS_Whitesmiths`` (in configuration: ``Whitesmiths``)
2444 Like ``Allman`` but always indent braces and line up code with braces.
2502 void bar() { foo(true); }
2505 * ``BS_GNU`` (in configuration: ``GNU``)
2506 Always break before braces and add an extra level of indentation to
2507 braces of control statements, not to those of class, function
2508 or other definitions.
2567 void bar() { foo(true); }
2570 * ``BS_WebKit`` (in configuration: ``WebKit``)
2571 Like ``Attach``, but break before functions.
2616 void bar() { foo(true); }
2619 * ``BS_Custom`` (in configuration: ``Custom``)
2620 Configure each individual brace in ``BraceWrapping``.
2624 .. _BreakBeforeConceptDeclarations:
2626 **BreakBeforeConceptDeclarations** (``BreakBeforeConceptDeclarationsStyle``) :versionbadge:`clang-format 12` :ref:`¶ <BreakBeforeConceptDeclarations>`
2627 The concept declaration style to use.
2631 * ``BBCDS_Never`` (in configuration: ``Never``)
2632 Keep the template declaration line together with ``concept``.
2636 template <typename T> concept C = ...;
2638 * ``BBCDS_Allowed`` (in configuration: ``Allowed``)
2639 Breaking between template declaration and ``concept`` is allowed. The
2640 actual behavior depends on the content and line breaking rules and
2643 * ``BBCDS_Always`` (in configuration: ``Always``)
2644 Always break before ``concept``, putting it in the line after the
2645 template declaration.
2649 template <typename T>
2654 .. _BreakBeforeInlineASMColon:
2656 **BreakBeforeInlineASMColon** (``BreakBeforeInlineASMColonStyle``) :versionbadge:`clang-format 16` :ref:`¶ <BreakBeforeInlineASMColon>`
2657 The inline ASM colon style to use.
2661 * ``BBIAS_Never`` (in configuration: ``Never``)
2662 No break before inline ASM colon.
2666 asm volatile("string", : : val);
2668 * ``BBIAS_OnlyMultiline`` (in configuration: ``OnlyMultiline``)
2669 Break before inline ASM colon if the line length is longer than column
2674 asm volatile("string", : : val);
2675 asm("cmoveq %1, %2, %[result]"
2676 : [result] "=r"(result)
2677 : "r"(test), "r"(new), "[result]"(old));
2679 * ``BBIAS_Always`` (in configuration: ``Always``)
2680 Always break before inline ASM colon.
2684 asm volatile("string",
2690 .. _BreakBeforeTernaryOperators:
2692 **BreakBeforeTernaryOperators** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <BreakBeforeTernaryOperators>`
2693 If ``true``, ternary operators will be placed after line breaks.
2698 veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription
2700 : SecondValueVeryVeryVeryVeryLong;
2703 veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ?
2705 SecondValueVeryVeryVeryVeryLong;
2707 .. _BreakConstructorInitializers:
2709 **BreakConstructorInitializers** (``BreakConstructorInitializersStyle``) :versionbadge:`clang-format 5` :ref:`¶ <BreakConstructorInitializers>`
2710 The break constructor initializers style to use.
2714 * ``BCIS_BeforeColon`` (in configuration: ``BeforeColon``)
2715 Break constructor initializers before the colon and after the commas.
2723 * ``BCIS_BeforeComma`` (in configuration: ``BeforeComma``)
2724 Break constructor initializers before the colon and commas, and align
2725 the commas with the colon.
2733 * ``BCIS_AfterColon`` (in configuration: ``AfterColon``)
2734 Break constructor initializers after the colon and commas.
2744 .. _BreakInheritanceList:
2746 **BreakInheritanceList** (``BreakInheritanceListStyle``) :versionbadge:`clang-format 7` :ref:`¶ <BreakInheritanceList>`
2747 The inheritance list style to use.
2751 * ``BILS_BeforeColon`` (in configuration: ``BeforeColon``)
2752 Break inheritance list before the colon and after the commas.
2761 * ``BILS_BeforeComma`` (in configuration: ``BeforeComma``)
2762 Break inheritance list before the colon and commas, and align
2763 the commas with the colon.
2772 * ``BILS_AfterColon`` (in configuration: ``AfterColon``)
2773 Break inheritance list after the colon and commas.
2782 * ``BILS_AfterComma`` (in configuration: ``AfterComma``)
2783 Break inheritance list only after the commas.
2793 .. _BreakStringLiterals:
2795 **BreakStringLiterals** (``Boolean``) :versionbadge:`clang-format 3.9` :ref:`¶ <BreakStringLiterals>`
2796 Allow breaking string literals when formatting.
2798 In C, C++, and Objective-C:
2803 const char* x = "veryVeryVeryVeryVeryVe"
2804 "ryVeryVeryVeryVeryVery"
2809 "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
2816 string x = "veryVeryVeryVeryVeryVe" +
2817 "ryVeryVeryVeryVeryVery" +
2822 "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
2824 C# interpolated strings are not broken.
2831 string x = {"veryVeryVeryVeryVeryVe",
2832 "ryVeryVeryVeryVeryVery",
2837 "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
2841 **ColumnLimit** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <ColumnLimit>`
2844 A column limit of ``0`` means that there is no column limit. In this case,
2845 clang-format will respect the input's line breaking decisions within
2846 statements unless they contradict other rules.
2850 **CommentPragmas** (``String``) :versionbadge:`clang-format 3.7` :ref:`¶ <CommentPragmas>`
2851 A regular expression that describes comments with special meaning,
2852 which should not be split into lines or otherwise changed.
2856 // CommentPragmas: '^ FOOBAR pragma:'
2857 // Will leave the following line unaffected
2858 #include <vector> // FOOBAR pragma: keep
2860 .. _CompactNamespaces:
2862 **CompactNamespaces** (``Boolean``) :versionbadge:`clang-format 5` :ref:`¶ <CompactNamespaces>`
2863 If ``true``, consecutive namespace declarations will be on the same
2864 line. If ``false``, each namespace is declared on a new line.
2869 namespace Foo { namespace Bar {
2878 If it does not fit on a single line, the overflowing namespaces get
2883 namespace Foo { namespace Bar {
2887 .. _ConstructorInitializerAllOnOneLineOrOnePerLine:
2889 **ConstructorInitializerAllOnOneLineOrOnePerLine** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <ConstructorInitializerAllOnOneLineOrOnePerLine>`
2890 This option is **deprecated**. See ``CurrentLine`` of
2891 ``PackConstructorInitializers``.
2893 .. _ConstructorInitializerIndentWidth:
2895 **ConstructorInitializerIndentWidth** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <ConstructorInitializerIndentWidth>`
2896 The number of characters to use for indentation of constructor
2897 initializer lists as well as inheritance lists.
2899 .. _ContinuationIndentWidth:
2901 **ContinuationIndentWidth** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <ContinuationIndentWidth>`
2902 Indent width for line continuations.
2906 ContinuationIndentWidth: 2
2908 int i = // VeryVeryVeryVeryVeryLongComment
2909 longFunction( // Again a long comment
2912 .. _Cpp11BracedListStyle:
2914 **Cpp11BracedListStyle** (``Boolean``) :versionbadge:`clang-format 3.4` :ref:`¶ <Cpp11BracedListStyle>`
2915 If ``true``, format braced lists as best suited for C++11 braced
2918 Important differences:
2919 - No spaces inside the braced list.
2920 - No line break before the closing brace.
2921 - Indentation with the continuation indent, not with the block indent.
2923 Fundamentally, C++11 braced lists are formatted exactly like function
2924 calls would be formatted in their place. If the braced list follows a name
2925 (e.g. a type or variable name), clang-format formats as if the ``{}`` were
2926 the parentheses of a function call with that name. If there is no name,
2927 a zero-length name is assumed.
2932 vector<int> x{1, 2, 3, 4}; vs. vector<int> x{ 1, 2, 3, 4 };
2933 vector<T> x{{}, {}, {}, {}}; vector<T> x{ {}, {}, {}, {} };
2934 f(MyMap[{composite, key}]); f(MyMap[{ composite, key }]);
2935 new int[3]{1, 2, 3}; new int[3]{ 1, 2, 3 };
2937 .. _DeriveLineEnding:
2939 **DeriveLineEnding** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ <DeriveLineEnding>`
2940 This option is **deprecated**. See ``DeriveLF`` and ``DeriveCRLF`` of
2943 .. _DerivePointerAlignment:
2945 **DerivePointerAlignment** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <DerivePointerAlignment>`
2946 If ``true``, analyze the formatted file for the most common
2947 alignment of ``&`` and ``*``.
2948 Pointer and reference alignment styles are going to be updated according
2949 to the preferences found in the file.
2950 ``PointerAlignment`` is then used only as fallback.
2954 **DisableFormat** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <DisableFormat>`
2955 Disables formatting completely.
2957 .. _EmptyLineAfterAccessModifier:
2959 **EmptyLineAfterAccessModifier** (``EmptyLineAfterAccessModifierStyle``) :versionbadge:`clang-format 13` :ref:`¶ <EmptyLineAfterAccessModifier>`
2960 Defines when to put an empty line after access modifiers.
2961 ``EmptyLineBeforeAccessModifier`` configuration handles the number of
2962 empty lines between two access modifiers.
2966 * ``ELAAMS_Never`` (in configuration: ``Never``)
2967 Remove all empty lines after access modifiers.
2983 * ``ELAAMS_Leave`` (in configuration: ``Leave``)
2984 Keep existing empty lines after access modifiers.
2985 MaxEmptyLinesToKeep is applied instead.
2987 * ``ELAAMS_Always`` (in configuration: ``Always``)
2988 Always add empty line after access modifiers if there are none.
2989 MaxEmptyLinesToKeep is applied also.
3012 .. _EmptyLineBeforeAccessModifier:
3014 **EmptyLineBeforeAccessModifier** (``EmptyLineBeforeAccessModifierStyle``) :versionbadge:`clang-format 12` :ref:`¶ <EmptyLineBeforeAccessModifier>`
3015 Defines in which cases to put empty line before access modifiers.
3019 * ``ELBAMS_Never`` (in configuration: ``Never``)
3020 Remove all empty lines before access modifiers.
3036 * ``ELBAMS_Leave`` (in configuration: ``Leave``)
3037 Keep existing empty lines before access modifiers.
3039 * ``ELBAMS_LogicalBlock`` (in configuration: ``LogicalBlock``)
3040 Add empty line only when access modifier starts a new logical block.
3041 Logical block is a group of one or more member fields or functions.
3059 * ``ELBAMS_Always`` (in configuration: ``Always``)
3060 Always add empty line before access modifiers unless access modifier
3061 is at the start of struct or class definition.
3083 .. _ExperimentalAutoDetectBinPacking:
3085 **ExperimentalAutoDetectBinPacking** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <ExperimentalAutoDetectBinPacking>`
3086 If ``true``, clang-format detects whether function calls and
3087 definitions are formatted with one parameter per line.
3089 Each call can be bin-packed, one-per-line or inconclusive. If it is
3090 inconclusive, e.g. completely on one line, but a decision needs to be
3091 made, clang-format analyzes whether there are other bin-packed cases in
3092 the input file and act accordingly.
3097 This is an experimental flag, that might go away or be renamed. Do
3098 not use this in config files, etc. Use at your own risk.
3100 .. _FixNamespaceComments:
3102 **FixNamespaceComments** (``Boolean``) :versionbadge:`clang-format 5` :ref:`¶ <FixNamespaceComments>`
3103 If ``true``, clang-format adds missing namespace end comments for
3104 namespaces and fixes invalid existing ones. This doesn't affect short
3105 namespaces, which are controlled by ``ShortNamespaceLines``.
3110 namespace longNamespace { vs. namespace longNamespace {
3111 void foo(); void foo();
3112 void bar(); void bar();
3114 namespace shortNamespace { namespace shortNamespace {
3115 void baz(); void baz();
3120 **ForEachMacros** (``List of Strings``) :versionbadge:`clang-format 3.7` :ref:`¶ <ForEachMacros>`
3121 A vector of macros that should be interpreted as foreach loops
3122 instead of as function calls.
3124 These are expected to be macros of the form:
3128 FOREACH(<variable-declaration>, ...)
3131 In the .clang-format configuration file, this can be configured like:
3133 .. code-block:: yaml
3135 ForEachMacros: ['RANGES_FOR', 'FOREACH']
3137 For example: BOOST_FOREACH.
3141 **IfMacros** (``List of Strings``) :versionbadge:`clang-format 13` :ref:`¶ <IfMacros>`
3142 A vector of macros that should be interpreted as conditionals
3143 instead of as function calls.
3145 These are expected to be macros of the form:
3154 In the .clang-format configuration file, this can be configured like:
3156 .. code-block:: yaml
3160 For example: `KJ_IF_MAYBE
3161 <https://github.com/capnproto/capnproto/blob/master/kjdoc/tour.md#maybes>`_
3165 **IncludeBlocks** (``IncludeBlocksStyle``) :versionbadge:`clang-format 6` :ref:`¶ <IncludeBlocks>`
3166 Dependent on the value, multiple ``#include`` blocks can be sorted
3167 as one and divided based on category.
3171 * ``IBS_Preserve`` (in configuration: ``Preserve``)
3172 Sort each ``#include`` block separately.
3176 #include "b.h" into #include "b.h"
3178 #include <lib/main.h> #include "a.h"
3179 #include "a.h" #include <lib/main.h>
3181 * ``IBS_Merge`` (in configuration: ``Merge``)
3182 Merge multiple ``#include`` blocks together and sort as one.
3186 #include "b.h" into #include "a.h"
3188 #include <lib/main.h> #include <lib/main.h>
3191 * ``IBS_Regroup`` (in configuration: ``Regroup``)
3192 Merge multiple ``#include`` blocks together and sort as one.
3193 Then split into groups based on category priority. See
3194 ``IncludeCategories``.
3198 #include "b.h" into #include "a.h"
3200 #include <lib/main.h>
3201 #include "a.h" #include <lib/main.h>
3205 .. _IncludeCategories:
3207 **IncludeCategories** (``List of IncludeCategories``) :versionbadge:`clang-format 3.8` :ref:`¶ <IncludeCategories>`
3208 Regular expressions denoting the different ``#include`` categories
3209 used for ordering ``#includes``.
3212 <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html>`_
3213 regular expressions are supported.
3215 These regular expressions are matched against the filename of an include
3216 (including the <> or "") in order. The value belonging to the first
3217 matching regular expression is assigned and ``#includes`` are sorted first
3218 according to increasing category number and then alphabetically within
3221 If none of the regular expressions match, INT_MAX is assigned as
3222 category. The main header for a source file automatically gets category 0.
3223 so that it is generally kept at the beginning of the ``#includes``
3224 (https://llvm.org/docs/CodingStandards.html#include-style). However, you
3225 can also assign negative priorities if you have certain headers that
3226 always need to be first.
3228 There is a third and optional field ``SortPriority`` which can used while
3229 ``IncludeBlocks = IBS_Regroup`` to define the priority in which
3230 ``#includes`` should be ordered. The value of ``Priority`` defines the
3231 order of ``#include blocks`` and also allows the grouping of ``#includes``
3232 of different priority. ``SortPriority`` is set to the value of
3233 ``Priority`` as default if it is not assigned.
3235 Each regular expression can be marked as case sensitive with the field
3236 ``CaseSensitive``, per default it is not.
3238 To configure this in the .clang-format file, use:
3240 .. code-block:: yaml
3243 - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
3247 - Regex: '^((<|")(gtest|gmock|isl|json)/)'
3249 - Regex: '<[[:alnum:].]+>'
3255 .. _IncludeIsMainRegex:
3257 **IncludeIsMainRegex** (``String``) :versionbadge:`clang-format 3.9` :ref:`¶ <IncludeIsMainRegex>`
3258 Specify a regular expression of suffixes that are allowed in the
3259 file-to-main-include mapping.
3261 When guessing whether a #include is the "main" include (to assign
3262 category 0, see above), use this regex of allowed suffixes to the header
3263 stem. A partial match is done, so that:
3264 - "" means "arbitrary suffix"
3265 - "$" means "no suffix"
3267 For example, if configured to "(_test)?$", then a header a.h would be seen
3268 as the "main" include in both a.cc and a_test.cc.
3270 .. _IncludeIsMainSourceRegex:
3272 **IncludeIsMainSourceRegex** (``String``) :versionbadge:`clang-format 10` :ref:`¶ <IncludeIsMainSourceRegex>`
3273 Specify a regular expression for files being formatted
3274 that are allowed to be considered "main" in the
3275 file-to-main-include mapping.
3277 By default, clang-format considers files as "main" only when they end
3278 with: ``.c``, ``.cc``, ``.cpp``, ``.c++``, ``.cxx``, ``.m`` or ``.mm``
3280 For these files a guessing of "main" include takes place
3281 (to assign category 0, see above). This config option allows for
3282 additional suffixes and extensions for files to be considered as "main".
3284 For example, if this option is configured to ``(Impl\.hpp)$``,
3285 then a file ``ClassImpl.hpp`` is considered "main" (in addition to
3286 ``Class.c``, ``Class.cc``, ``Class.cpp`` and so on) and "main
3287 include file" logic will be executed (with *IncludeIsMainRegex* setting
3288 also being respected in later phase). Without this option set,
3289 ``ClassImpl.hpp`` would not have the main include file put on top
3290 before any other include.
3292 .. _IndentAccessModifiers:
3294 **IndentAccessModifiers** (``Boolean``) :versionbadge:`clang-format 13` :ref:`¶ <IndentAccessModifiers>`
3295 Specify whether access modifiers should have their own indentation level.
3297 When ``false``, access modifiers are indented (or outdented) relative to
3298 the record members, respecting the ``AccessModifierOffset``. Record
3299 members are indented one level below the record.
3300 When ``true``, access modifiers get their own indentation level. As a
3301 consequence, record members are always indented 2 levels below the record,
3302 regardless of the access modifier presence. Value of the
3303 ``AccessModifierOffset`` is ignored.
3308 class C { vs. class C {
3310 void bar(); void bar();
3311 protected: protected:
3317 void foo() { void foo() {
3321 .. _IndentCaseBlocks:
3323 **IndentCaseBlocks** (``Boolean``) :versionbadge:`clang-format 11` :ref:`¶ <IndentCaseBlocks>`
3324 Indent case label blocks one level from the case label.
3326 When ``false``, the block following the case label uses the same
3327 indentation level as for the case label, treating the case label the same
3329 When ``true``, the block gets indented as a scope block.
3334 switch (fool) { vs. switch (fool) {
3346 .. _IndentCaseLabels:
3348 **IndentCaseLabels** (``Boolean``) :versionbadge:`clang-format 3.3` :ref:`¶ <IndentCaseLabels>`
3349 Indent case labels one level from the switch statement.
3351 When ``false``, use the same indentation level as for the switch
3352 statement. Switch statement body is always indented one level more than
3353 case labels (except the first block following the case label, which
3354 itself indents the code - unless IndentCaseBlocks is enabled).
3359 switch (fool) { vs. switch (fool) {
3367 .. _IndentExternBlock:
3369 **IndentExternBlock** (``IndentExternBlockStyle``) :versionbadge:`clang-format 11` :ref:`¶ <IndentExternBlock>`
3370 IndentExternBlockStyle is the type of indenting of extern blocks.
3374 * ``IEBS_AfterExternBlock`` (in configuration: ``AfterExternBlock``)
3375 Backwards compatible with AfterExternBlock's indenting.
3379 IndentExternBlock: AfterExternBlock
3380 BraceWrapping.AfterExternBlock: true
3389 IndentExternBlock: AfterExternBlock
3390 BraceWrapping.AfterExternBlock: false
3395 * ``IEBS_NoIndent`` (in configuration: ``NoIndent``)
3396 Does not indent extern blocks.
3404 * ``IEBS_Indent`` (in configuration: ``Indent``)
3405 Indents extern blocks.
3415 .. _IndentGotoLabels:
3417 **IndentGotoLabels** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ <IndentGotoLabels>`
3420 When ``false``, goto labels are flushed left.
3425 int f() { vs. int f() {
3426 if (foo()) { if (foo()) {
3434 .. _IndentPPDirectives:
3436 **IndentPPDirectives** (``PPDirectiveIndentStyle``) :versionbadge:`clang-format 6` :ref:`¶ <IndentPPDirectives>`
3437 The preprocessor directive indenting style to use.
3441 * ``PPDIS_None`` (in configuration: ``None``)
3442 Does not indent any directives.
3452 * ``PPDIS_AfterHash`` (in configuration: ``AfterHash``)
3453 Indents directives after the hash.
3463 * ``PPDIS_BeforeHash`` (in configuration: ``BeforeHash``)
3464 Indents directives before the hash.
3476 .. _IndentRequiresClause:
3478 **IndentRequiresClause** (``Boolean``) :versionbadge:`clang-format 15` :ref:`¶ <IndentRequiresClause>`
3479 Indent the requires clause in a template. This only applies when
3480 ``RequiresClausePosition`` is ``OwnLine``, or ``WithFollowing``.
3482 In clang-format 12, 13 and 14 it was named ``IndentRequires``.
3487 template <typename It>
3488 requires Iterator<It>
3489 void sort(It begin, It end) {
3494 template <typename It>
3495 requires Iterator<It>
3496 void sort(It begin, It end) {
3502 **IndentWidth** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <IndentWidth>`
3503 The number of columns to use for indentation.
3516 .. _IndentWrappedFunctionNames:
3518 **IndentWrappedFunctionNames** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <IndentWrappedFunctionNames>`
3519 Indent if a function definition or declaration is wrapped after the
3525 LoooooooooooooooooooooooooooooooooooooooongReturnType
3526 LoooooooooooooooooooooooooooooooongFunctionDeclaration();
3529 LoooooooooooooooooooooooooooooooooooooooongReturnType
3530 LoooooooooooooooooooooooooooooooongFunctionDeclaration();
3534 **InsertBraces** (``Boolean``) :versionbadge:`clang-format 15` :ref:`¶ <InsertBraces>`
3535 Insert braces after control statements (``if``, ``else``, ``for``, ``do``,
3536 and ``while``) in C++ unless the control statements are inside macro
3537 definitions or the braces would enclose preprocessor directives.
3541 Setting this option to ``true`` could lead to incorrect code formatting
3542 due to clang-format's lack of complete semantic information. As such,
3543 extra care should be taken to review code changes made by this option.
3549 if (isa<FunctionDecl>(D)) vs. if (isa<FunctionDecl>(D)) {
3550 handleFunctionDecl(D); handleFunctionDecl(D);
3551 else if (isa<VarDecl>(D)) } else if (isa<VarDecl>(D)) {
3552 handleVarDecl(D); handleVarDecl(D);
3557 while (i--) vs. while (i--) {
3558 for (auto *A : D.attrs()) for (auto *A : D.attrs()) {
3559 handleAttr(A); handleAttr(A);
3565 while (i); } while (i);
3567 .. _InsertNewlineAtEOF:
3569 **InsertNewlineAtEOF** (``Boolean``) :versionbadge:`clang-format 16` :ref:`¶ <InsertNewlineAtEOF>`
3570 Insert a newline at end of file if missing.
3572 .. _InsertTrailingCommas:
3574 **InsertTrailingCommas** (``TrailingCommaStyle``) :versionbadge:`clang-format 11` :ref:`¶ <InsertTrailingCommas>`
3575 If set to ``TCS_Wrapped`` will insert trailing commas in container
3576 literals (arrays and objects) that wrap across multiple lines.
3577 It is currently only available for JavaScript
3578 and disabled by default ``TCS_None``.
3579 ``InsertTrailingCommas`` cannot be used together with ``BinPackArguments``
3580 as inserting the comma disables bin-packing.
3586 aaaaaaaaaaaaaaaaaaaaaaaaaa,
3587 aaaaaaaaaaaaaaaaaaaaaaaaaa,
3588 aaaaaaaaaaaaaaaaaaaaaaaaaa,
3594 * ``TCS_None`` (in configuration: ``None``)
3595 Do not insert trailing commas.
3597 * ``TCS_Wrapped`` (in configuration: ``Wrapped``)
3598 Insert trailing commas in container literals that were wrapped over
3599 multiple lines. Note that this is conceptually incompatible with
3600 bin-packing, because the trailing comma is used as an indicator
3601 that a container should be formatted one-per-line (i.e. not bin-packed).
3602 So inserting a trailing comma counteracts bin-packing.
3606 .. _IntegerLiteralSeparator:
3608 **IntegerLiteralSeparator** (``IntegerLiteralSeparatorStyle``) :versionbadge:`clang-format 16` :ref:`¶ <IntegerLiteralSeparator>`
3609 Format integer literal separators (``'`` for C++ and ``_`` for C#, Java,
3612 Nested configuration flags:
3614 Separator format of integer literals of different bases.
3616 If negative, remove separators. If ``0``, leave the literal as is. If
3617 positive, insert separators between digits starting from the rightmost
3620 For example, the config below will leave separators in binary literals
3621 alone, insert separators in decimal literals to separate the digits into
3622 groups of 3, and remove separators in hexadecimal literals.
3626 IntegerLiteralSeparator:
3631 You can also specify a minimum number of digits (``BinaryMinDigits``,
3632 ``DecimalMinDigits``, and ``HexMinDigits``) the integer literal must
3633 have in order for the separators to be inserted.
3635 * ``int8_t Binary`` Format separators in binary literals.
3637 .. code-block:: text
3639 /* -1: */ b = 0b100111101101;
3640 /* 0: */ b = 0b10011'11'0110'1;
3641 /* 3: */ b = 0b100'111'101'101;
3642 /* 4: */ b = 0b1001'1110'1101;
3644 * ``int8_t BinaryMinDigits`` Format separators in binary literals with a minimum number of digits.
3646 .. code-block:: text
3649 // BinaryMinDigits: 7
3653 * ``int8_t Decimal`` Format separators in decimal literals.
3655 .. code-block:: text
3657 /* -1: */ d = 18446744073709550592ull;
3658 /* 0: */ d = 184467'440737'0'95505'92ull;
3659 /* 3: */ d = 18'446'744'073'709'550'592ull;
3661 * ``int8_t DecimalMinDigits`` Format separators in decimal literals with a minimum number of digits.
3663 .. code-block:: text
3666 // DecimalMinDigits: 5
3670 * ``int8_t Hex`` Format separators in hexadecimal literals.
3672 .. code-block:: text
3674 /* -1: */ h = 0xDEADBEEFDEADBEEFuz;
3675 /* 0: */ h = 0xDEAD'BEEF'DE'AD'BEE'Fuz;
3676 /* 2: */ h = 0xDE'AD'BE'EF'DE'AD'BE'EFuz;
3678 * ``int8_t HexMinDigits`` Format separators in hexadecimal literals with a minimum number of
3681 .. code-block:: text
3689 .. _JavaImportGroups:
3691 **JavaImportGroups** (``List of Strings``) :versionbadge:`clang-format 8` :ref:`¶ <JavaImportGroups>`
3692 A vector of prefixes ordered by the desired groups for Java imports.
3694 One group's prefix can be a subset of another - the longest prefix is
3695 always matched. Within a group, the imports are ordered lexicographically.
3696 Static imports are grouped separately and follow the same group rules.
3697 By default, static imports are placed before non-static imports,
3698 but this behavior is changed by another option,
3699 ``SortJavaStaticImport``.
3701 In the .clang-format configuration file, this can be configured like
3702 in the following yaml example. This will result in imports being
3703 formatted as in the Java example below.
3705 .. code-block:: yaml
3707 JavaImportGroups: ['com.example', 'com', 'org']
3710 .. code-block:: java
3712 import static com.example.function1;
3714 import static com.test.function2;
3716 import static org.example.function3;
3718 import com.example.ClassA;
3719 import com.example.Test;
3720 import com.example.a.ClassB;
3722 import com.test.ClassC;
3724 import org.example.ClassD;
3726 .. _JavaScriptQuotes:
3728 **JavaScriptQuotes** (``JavaScriptQuoteStyle``) :versionbadge:`clang-format 3.9` :ref:`¶ <JavaScriptQuotes>`
3729 The JavaScriptQuoteStyle to use for JavaScript strings.
3733 * ``JSQS_Leave`` (in configuration: ``Leave``)
3734 Leave string quotes as they are.
3741 * ``JSQS_Single`` (in configuration: ``Single``)
3742 Always use single quotes.
3749 * ``JSQS_Double`` (in configuration: ``Double``)
3750 Always use double quotes.
3759 .. _JavaScriptWrapImports:
3761 **JavaScriptWrapImports** (``Boolean``) :versionbadge:`clang-format 3.9` :ref:`¶ <JavaScriptWrapImports>`
3762 Whether to wrap JavaScript import/export statements.
3768 VeryLongImportsAreAnnoying,
3769 VeryLongImportsAreAnnoying,
3770 VeryLongImportsAreAnnoying,
3771 } from 'some/module.js'
3774 import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js"
3776 .. _KeepEmptyLinesAtEOF:
3778 **KeepEmptyLinesAtEOF** (``Boolean``) :versionbadge:`clang-format 17` :ref:`¶ <KeepEmptyLinesAtEOF>`
3779 Keep empty lines (up to ``MaxEmptyLinesToKeep``) at end of file.
3781 .. _KeepEmptyLinesAtTheStartOfBlocks:
3783 **KeepEmptyLinesAtTheStartOfBlocks** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <KeepEmptyLinesAtTheStartOfBlocks>`
3784 If true, the empty line at the start of blocks is kept.
3789 if (foo) { vs. if (foo) {
3794 .. _LambdaBodyIndentation:
3796 **LambdaBodyIndentation** (``LambdaBodyIndentationKind``) :versionbadge:`clang-format 13` :ref:`¶ <LambdaBodyIndentation>`
3797 The indentation style of lambda bodies. ``Signature`` (the default)
3798 causes the lambda body to be indented one additional level relative to
3799 the indentation level of the signature. ``OuterScope`` forces the lambda
3800 body to be indented one additional level relative to the parent scope
3801 containing the lambda signature.
3805 * ``LBI_Signature`` (in configuration: ``Signature``)
3806 Align lambda body relative to the lambda signature. This is the default.
3811 [](SomeReallyLongLambdaSignatureArgument foo) {
3815 * ``LBI_OuterScope`` (in configuration: ``OuterScope``)
3816 For statements within block scope, align lambda body relative to the
3817 indentation level of the outer scope the lambda signature resides in.
3822 [](SomeReallyLongLambdaSignatureArgument foo) {
3826 someMethod(someOtherMethod(
3827 [](SomeReallyLongLambdaSignatureArgument foo) {
3835 **Language** (``LanguageKind``) :versionbadge:`clang-format 3.5` :ref:`¶ <Language>`
3836 Language, this format style is targeted at.
3840 * ``LK_None`` (in configuration: ``None``)
3843 * ``LK_Cpp`` (in configuration: ``Cpp``)
3844 Should be used for C, C++.
3846 * ``LK_CSharp`` (in configuration: ``CSharp``)
3847 Should be used for C#.
3849 * ``LK_Java`` (in configuration: ``Java``)
3850 Should be used for Java.
3852 * ``LK_JavaScript`` (in configuration: ``JavaScript``)
3853 Should be used for JavaScript.
3855 * ``LK_Json`` (in configuration: ``Json``)
3856 Should be used for JSON.
3858 * ``LK_ObjC`` (in configuration: ``ObjC``)
3859 Should be used for Objective-C, Objective-C++.
3861 * ``LK_Proto`` (in configuration: ``Proto``)
3862 Should be used for Protocol Buffers
3863 (https://developers.google.com/protocol-buffers/).
3865 * ``LK_TableGen`` (in configuration: ``TableGen``)
3866 Should be used for TableGen code.
3868 * ``LK_TextProto`` (in configuration: ``TextProto``)
3869 Should be used for Protocol Buffer messages in text format
3870 (https://developers.google.com/protocol-buffers/).
3872 * ``LK_Verilog`` (in configuration: ``Verilog``)
3873 Should be used for Verilog and SystemVerilog.
3874 https://standards.ieee.org/ieee/1800/6700/
3875 https://sci-hub.st/10.1109/IEEESTD.2018.8299595
3881 **LineEnding** (``LineEndingStyle``) :versionbadge:`clang-format 16` :ref:`¶ <LineEnding>`
3882 Line ending style (``\n`` or ``\r\n``) to use.
3886 * ``LE_LF`` (in configuration: ``LF``)
3889 * ``LE_CRLF`` (in configuration: ``CRLF``)
3892 * ``LE_DeriveLF`` (in configuration: ``DeriveLF``)
3893 Use ``\n`` unless the input has more lines ending in ``\r\n``.
3895 * ``LE_DeriveCRLF`` (in configuration: ``DeriveCRLF``)
3896 Use ``\r\n`` unless the input has more lines ending in ``\n``.
3900 .. _MacroBlockBegin:
3902 **MacroBlockBegin** (``String``) :versionbadge:`clang-format 3.7` :ref:`¶ <MacroBlockBegin>`
3903 A regular expression matching macros that start a block.
3908 MacroBlockBegin: "^NS_MAP_BEGIN|\
3933 **MacroBlockEnd** (``String``) :versionbadge:`clang-format 3.7` :ref:`¶ <MacroBlockEnd>`
3934 A regular expression matching macros that end a block.
3938 **Macros** (``List of Strings``) :versionbadge:`clang-format 17` :ref:`¶ <Macros>`
3939 A list of macros of the form ``<definition>=<expansion>`` .
3941 Code will be parsed with macros expanded, in order to determine how to
3942 interpret and format the macro arguments.
3944 For example, the code:
3950 will usually be interpreted as a call to a function A, and the
3951 multiplication expression will be formatted as ``a * b``.
3953 If we specify the macro definition:
3955 .. code-block:: yaml
3960 the code will now be parsed as a declaration of the variable b of type a*,
3961 and formatted as ``a* b`` (depending on pointer-binding rules).
3963 Features and restrictions:
3964 * Both function-like macros and object-like macros are supported.
3965 * Macro arguments must be used exactly once in the expansion.
3966 * No recursive expansion; macros referencing other macros will be
3968 * Overloading by arity is supported: for example, given the macro
3969 definitions A=x, A()=y, A(a)=a
3977 A(a, b); // will not be expanded.
3979 .. _MaxEmptyLinesToKeep:
3981 **MaxEmptyLinesToKeep** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <MaxEmptyLinesToKeep>`
3982 The maximum number of consecutive empty lines to keep.
3986 MaxEmptyLinesToKeep: 1 vs. MaxEmptyLinesToKeep: 0
3990 i = foo(); return i;
3995 .. _NamespaceIndentation:
3997 **NamespaceIndentation** (``NamespaceIndentationKind``) :versionbadge:`clang-format 3.7` :ref:`¶ <NamespaceIndentation>`
3998 The indentation used for namespaces.
4002 * ``NI_None`` (in configuration: ``None``)
4003 Don't indent in namespaces.
4014 * ``NI_Inner`` (in configuration: ``Inner``)
4015 Indent only in inner namespaces (nested in other namespaces).
4026 * ``NI_All`` (in configuration: ``All``)
4027 Indent in all namespaces.
4040 .. _NamespaceMacros:
4042 **NamespaceMacros** (``List of Strings``) :versionbadge:`clang-format 9` :ref:`¶ <NamespaceMacros>`
4043 A vector of macros which are used to open namespace blocks.
4045 These are expected to be macros of the form:
4049 NAMESPACE(<namespace-name>, ...) {
4053 For example: TESTSUITE
4055 .. _ObjCBinPackProtocolList:
4057 **ObjCBinPackProtocolList** (``BinPackStyle``) :versionbadge:`clang-format 7` :ref:`¶ <ObjCBinPackProtocolList>`
4058 Controls bin-packing Objective-C protocol conformance list
4059 items into as few lines as possible when they go over ``ColumnLimit``.
4061 If ``Auto`` (the default), delegates to the value in
4062 ``BinPackParameters``. If that is ``true``, bin-packs Objective-C
4063 protocol conformance list items into as few lines as possible
4064 whenever they go over ``ColumnLimit``.
4066 If ``Always``, always bin-packs Objective-C protocol conformance
4067 list items into as few lines as possible whenever they go over
4070 If ``Never``, lays out Objective-C protocol conformance list items
4071 onto individual lines whenever they go over ``ColumnLimit``.
4074 .. code-block:: objc
4076 Always (or Auto, if BinPackParameters=true):
4077 @interface ccccccccccccc () <
4078 ccccccccccccc, ccccccccccccc,
4079 ccccccccccccc, ccccccccccccc> {
4082 Never (or Auto, if BinPackParameters=false):
4083 @interface ddddddddddddd () <
4092 * ``BPS_Auto`` (in configuration: ``Auto``)
4093 Automatically determine parameter bin-packing behavior.
4095 * ``BPS_Always`` (in configuration: ``Always``)
4096 Always bin-pack parameters.
4098 * ``BPS_Never`` (in configuration: ``Never``)
4099 Never bin-pack parameters.
4103 .. _ObjCBlockIndentWidth:
4105 **ObjCBlockIndentWidth** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <ObjCBlockIndentWidth>`
4106 The number of characters to use for indentation of ObjC blocks.
4108 .. code-block:: objc
4110 ObjCBlockIndentWidth: 4
4112 [operation setCompletionBlock:^{
4113 [self onOperationDone];
4116 .. _ObjCBreakBeforeNestedBlockParam:
4118 **ObjCBreakBeforeNestedBlockParam** (``Boolean``) :versionbadge:`clang-format 11` :ref:`¶ <ObjCBreakBeforeNestedBlockParam>`
4119 Break parameters list into lines when there is nested block
4120 parameters in a function call.
4127 [self.test1 t:self w:self callback:^(typeof(self) self, NSNumber
4137 callback:^(typeof(self) self, NSNumber *u, NSNumber *v) {
4142 .. _ObjCSpaceAfterProperty:
4144 **ObjCSpaceAfterProperty** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <ObjCSpaceAfterProperty>`
4145 Add a space after ``@property`` in Objective-C, i.e. use
4146 ``@property (readonly)`` instead of ``@property(readonly)``.
4148 .. _ObjCSpaceBeforeProtocolList:
4150 **ObjCSpaceBeforeProtocolList** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <ObjCSpaceBeforeProtocolList>`
4151 Add a space in front of an Objective-C protocol list, i.e. use
4152 ``Foo <Protocol>`` instead of ``Foo<Protocol>``.
4156 **PPIndentWidth** (``Integer``) :versionbadge:`clang-format 13` :ref:`¶ <PPIndentWidth>`
4157 The number of columns to use for indentation of preprocessor statements.
4158 When set to -1 (default) ``IndentWidth`` is used also for preprocessor
4171 .. _PackConstructorInitializers:
4173 **PackConstructorInitializers** (``PackConstructorInitializersStyle``) :versionbadge:`clang-format 14` :ref:`¶ <PackConstructorInitializers>`
4174 The pack constructor initializers style to use.
4178 * ``PCIS_Never`` (in configuration: ``Never``)
4179 Always put each constructor initializer on its own line.
4187 * ``PCIS_BinPack`` (in configuration: ``BinPack``)
4188 Bin-pack constructor initializers.
4193 : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(),
4194 cccccccccccccccccccc()
4196 * ``PCIS_CurrentLine`` (in configuration: ``CurrentLine``)
4197 Put all constructor initializers on the current line if they fit.
4198 Otherwise, put each one on its own line.
4202 Constructor() : a(), b()
4205 : aaaaaaaaaaaaaaaaaaaa(),
4206 bbbbbbbbbbbbbbbbbbbb(),
4209 * ``PCIS_NextLine`` (in configuration: ``NextLine``)
4210 Same as ``PCIS_CurrentLine`` except that if all constructor initializers
4211 do not fit on the current line, try to fit them on the next line.
4215 Constructor() : a(), b()
4218 : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), ddddddddddddd()
4221 : aaaaaaaaaaaaaaaaaaaa(),
4222 bbbbbbbbbbbbbbbbbbbb(),
4223 cccccccccccccccccccc()
4225 * ``PCIS_NextLineOnly`` (in configuration: ``NextLineOnly``)
4226 Put all constructor initializers on the next line if they fit.
4227 Otherwise, put each one on its own line.
4235 : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), ddddddddddddd()
4238 : aaaaaaaaaaaaaaaaaaaa(),
4239 bbbbbbbbbbbbbbbbbbbb(),
4240 cccccccccccccccccccc()
4244 .. _PenaltyBreakAssignment:
4246 **PenaltyBreakAssignment** (``Unsigned``) :versionbadge:`clang-format 5` :ref:`¶ <PenaltyBreakAssignment>`
4247 The penalty for breaking around an assignment operator.
4249 .. _PenaltyBreakBeforeFirstCallParameter:
4251 **PenaltyBreakBeforeFirstCallParameter** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <PenaltyBreakBeforeFirstCallParameter>`
4252 The penalty for breaking a function call after ``call(``.
4254 .. _PenaltyBreakComment:
4256 **PenaltyBreakComment** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <PenaltyBreakComment>`
4257 The penalty for each line break introduced inside a comment.
4259 .. _PenaltyBreakFirstLessLess:
4261 **PenaltyBreakFirstLessLess** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <PenaltyBreakFirstLessLess>`
4262 The penalty for breaking before the first ``<<``.
4264 .. _PenaltyBreakOpenParenthesis:
4266 **PenaltyBreakOpenParenthesis** (``Unsigned``) :versionbadge:`clang-format 14` :ref:`¶ <PenaltyBreakOpenParenthesis>`
4267 The penalty for breaking after ``(``.
4269 .. _PenaltyBreakString:
4271 **PenaltyBreakString** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <PenaltyBreakString>`
4272 The penalty for each line break introduced inside a string literal.
4274 .. _PenaltyBreakTemplateDeclaration:
4276 **PenaltyBreakTemplateDeclaration** (``Unsigned``) :versionbadge:`clang-format 7` :ref:`¶ <PenaltyBreakTemplateDeclaration>`
4277 The penalty for breaking after template declaration.
4279 .. _PenaltyExcessCharacter:
4281 **PenaltyExcessCharacter** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <PenaltyExcessCharacter>`
4282 The penalty for each character outside of the column limit.
4284 .. _PenaltyIndentedWhitespace:
4286 **PenaltyIndentedWhitespace** (``Unsigned``) :versionbadge:`clang-format 12` :ref:`¶ <PenaltyIndentedWhitespace>`
4287 Penalty for each character of whitespace indentation
4288 (counted relative to leading non-whitespace column).
4290 .. _PenaltyReturnTypeOnItsOwnLine:
4292 **PenaltyReturnTypeOnItsOwnLine** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <PenaltyReturnTypeOnItsOwnLine>`
4293 Penalty for putting the return type of a function onto its own line.
4295 .. _PointerAlignment:
4297 **PointerAlignment** (``PointerAlignmentStyle``) :versionbadge:`clang-format 3.7` :ref:`¶ <PointerAlignment>`
4298 Pointer and reference alignment style.
4302 * ``PAS_Left`` (in configuration: ``Left``)
4303 Align pointer to the left.
4309 * ``PAS_Right`` (in configuration: ``Right``)
4310 Align pointer to the right.
4316 * ``PAS_Middle`` (in configuration: ``Middle``)
4317 Align pointer in the middle.
4325 .. _QualifierAlignment:
4327 **QualifierAlignment** (``QualifierAlignmentStyle``) :versionbadge:`clang-format 14` :ref:`¶ <QualifierAlignment>`
4328 Different ways to arrange specifiers and qualifiers (e.g. const/volatile).
4332 Setting ``QualifierAlignment`` to something other than ``Leave``, COULD
4333 lead to incorrect code formatting due to incorrect decisions made due to
4334 clang-formats lack of complete semantic information.
4335 As such extra care should be taken to review code changes made by the use
4340 * ``QAS_Leave`` (in configuration: ``Leave``)
4341 Don't change specifiers/qualifiers to either Left or Right alignment
4349 * ``QAS_Left`` (in configuration: ``Left``)
4350 Change specifiers/qualifiers to be left-aligned.
4357 * ``QAS_Right`` (in configuration: ``Right``)
4358 Change specifiers/qualifiers to be right-aligned.
4365 * ``QAS_Custom`` (in configuration: ``Custom``)
4366 Change specifiers/qualifiers to be aligned based on ``QualifierOrder``.
4369 .. code-block:: yaml
4371 QualifierOrder: ['inline', 'static', 'type', 'const']
4384 **QualifierOrder** (``List of Strings``) :versionbadge:`clang-format 14` :ref:`¶ <QualifierOrder>`
4385 The order in which the qualifiers appear.
4386 Order is an array that can contain any of the following:
4400 it MUST contain 'type'.
4402 Items to the left of 'type' will be placed to the left of the type and
4403 aligned in the order supplied. Items to the right of 'type' will be
4404 placed to the right of the type and aligned in the order supplied.
4407 .. code-block:: yaml
4409 QualifierOrder: ['inline', 'static', 'type', 'const', 'volatile' ]
4411 .. _RawStringFormats:
4413 **RawStringFormats** (``List of RawStringFormats``) :versionbadge:`clang-format 6` :ref:`¶ <RawStringFormats>`
4414 Defines hints for detecting supported languages code blocks in raw
4417 A raw string with a matching delimiter or a matching enclosing function
4418 name will be reformatted assuming the specified language based on the
4419 style for that language defined in the .clang-format file. If no style has
4420 been defined in the .clang-format file for the specific language, a
4421 predefined style given by 'BasedOnStyle' is used. If 'BasedOnStyle' is not
4422 found, the formatting is based on llvm style. A matching delimiter takes
4423 precedence over a matching enclosing function name for determining the
4424 language of the raw string contents.
4426 If a canonical delimiter is specified, occurrences of other delimiters for
4427 the same language will be updated to the canonical if possible.
4429 There should be at most one specification per language and each delimiter
4430 and enclosing function should not occur in multiple specifications.
4432 To configure this in the .clang-format file, use:
4434 .. code-block:: yaml
4437 - Language: TextProto
4442 - 'PARSE_TEXT_PROTO'
4443 BasedOnStyle: google
4449 CanonicalDelimiter: 'cc'
4451 .. _ReferenceAlignment:
4453 **ReferenceAlignment** (``ReferenceAlignmentStyle``) :versionbadge:`clang-format 13` :ref:`¶ <ReferenceAlignment>`
4454 Reference alignment style (overrides ``PointerAlignment`` for
4459 * ``RAS_Pointer`` (in configuration: ``Pointer``)
4460 Align reference like ``PointerAlignment``.
4462 * ``RAS_Left`` (in configuration: ``Left``)
4463 Align reference to the left.
4469 * ``RAS_Right`` (in configuration: ``Right``)
4470 Align reference to the right.
4476 * ``RAS_Middle`` (in configuration: ``Middle``)
4477 Align reference in the middle.
4487 **ReflowComments** (``Boolean``) :versionbadge:`clang-format 3.8` :ref:`¶ <ReflowComments>`
4488 If ``true``, clang-format will attempt to re-flow comments. That is it
4489 will touch a comment and *reflow* long comments into new lines, trying to
4490 obey the ``ColumnLimit``.
4495 // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
4496 /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */
4499 // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
4501 /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
4504 .. _RemoveBracesLLVM:
4506 **RemoveBracesLLVM** (``Boolean``) :versionbadge:`clang-format 14` :ref:`¶ <RemoveBracesLLVM>`
4507 Remove optional braces of control statements (``if``, ``else``, ``for``,
4508 and ``while``) in C++ according to the LLVM coding style.
4512 This option will be renamed and expanded to support other styles.
4516 Setting this option to ``true`` could lead to incorrect code formatting
4517 due to clang-format's lack of complete semantic information. As such,
4518 extra care should be taken to review code changes made by this option.
4524 if (isa<FunctionDecl>(D)) { vs. if (isa<FunctionDecl>(D))
4525 handleFunctionDecl(D); handleFunctionDecl(D);
4526 } else if (isa<VarDecl>(D)) { else if (isa<VarDecl>(D))
4527 handleVarDecl(D); handleVarDecl(D);
4530 if (isa<VarDecl>(D)) { vs. if (isa<VarDecl>(D)) {
4531 for (auto *A : D.attrs()) { for (auto *A : D.attrs())
4532 if (shouldProcessAttr(A)) { if (shouldProcessAttr(A))
4533 handleAttr(A); handleAttr(A);
4538 if (isa<FunctionDecl>(D)) { vs. if (isa<FunctionDecl>(D))
4539 for (auto *A : D.attrs()) { for (auto *A : D.attrs())
4540 handleAttr(A); handleAttr(A);
4544 if (auto *D = (T)(D)) { vs. if (auto *D = (T)(D)) {
4545 if (shouldProcess(D)) { if (shouldProcess(D))
4546 handleVarDecl(D); handleVarDecl(D);
4548 markAsIgnored(D); markAsIgnored(D);
4554 } else { else if (c)
4562 .. _RemoveParentheses:
4564 **RemoveParentheses** (``RemoveParenthesesStyle``) :versionbadge:`clang-format 17` :ref:`¶ <RemoveParentheses>`
4565 Remove redundant parentheses.
4569 Setting this option to any value other than ``Leave`` could lead to
4570 incorrect code formatting due to clang-format's lack of complete semantic
4571 information. As such, extra care should be taken to review code changes
4572 made by this option.
4576 * ``RPS_Leave`` (in configuration: ``Leave``)
4577 Do not remove parentheses.
4581 class __declspec((dllimport)) X {};
4583 return ((a + b) - ((c + d)));
4585 * ``RPS_MultipleParentheses`` (in configuration: ``MultipleParentheses``)
4586 Replace multiple parentheses with single parentheses.
4590 class __declspec(dllimport) X {};
4592 return ((a + b) - (c + d));
4594 * ``RPS_ReturnStatement`` (in configuration: ``ReturnStatement``)
4595 Also remove parentheses enclosing the expression in a
4596 ``return``/``co_return`` statement.
4600 class __declspec(dllimport) X {};
4602 return (a + b) - (c + d);
4606 .. _RemoveSemicolon:
4608 **RemoveSemicolon** (``Boolean``) :versionbadge:`clang-format 16` :ref:`¶ <RemoveSemicolon>`
4609 Remove semicolons after the closing brace of a non-empty function.
4613 Setting this option to ``true`` could lead to incorrect code formatting
4614 due to clang-format's lack of complete semantic information. As such,
4615 extra care should be taken to review code changes made by this option.
4621 int max(int a, int b) { int max(int a, int b) {
4622 return a > b ? a : b; return a > b ? a : b;
4625 .. _RequiresClausePosition:
4627 **RequiresClausePosition** (``RequiresClausePositionStyle``) :versionbadge:`clang-format 15` :ref:`¶ <RequiresClausePosition>`
4628 The position of the ``requires`` clause.
4632 * ``RCPS_OwnLine`` (in configuration: ``OwnLine``)
4633 Always put the ``requires`` clause on its own line.
4637 template <typename T>
4641 template <typename T>
4645 template <typename T>
4650 * ``RCPS_WithPreceding`` (in configuration: ``WithPreceding``)
4651 Try to put the clause together with the preceding part of a declaration.
4652 For class templates: stick to the template declaration.
4653 For function templates: stick to the template declaration.
4654 For function declaration followed by a requires clause: stick to the
4659 template <typename T> requires C<T>
4662 template <typename T> requires C<T>
4665 template <typename T>
4666 void baz(T t) requires C<T>
4669 * ``RCPS_WithFollowing`` (in configuration: ``WithFollowing``)
4670 Try to put the ``requires`` clause together with the class or function
4675 template <typename T>
4676 requires C<T> struct Foo {...
4678 template <typename T>
4679 requires C<T> void bar(T t) {...
4681 template <typename T>
4685 * ``RCPS_SingleLine`` (in configuration: ``SingleLine``)
4686 Try to put everything in the same line if possible. Otherwise normal
4687 line breaking rules take over.
4692 template <typename T> requires C<T> struct Foo {...
4694 template <typename T> requires C<T> void bar(T t) {...
4696 template <typename T> void bar(T t) requires C<T> {...
4698 // Not fitting, one possible example:
4699 template <typename LongName>
4700 requires C<LongName>
4703 template <typename LongName>
4704 requires C<LongName>
4705 void bar(LongName ln) {
4707 template <typename LongName>
4708 void bar(LongName ln)
4709 requires C<LongName> {
4713 .. _RequiresExpressionIndentation:
4715 **RequiresExpressionIndentation** (``RequiresExpressionIndentationKind``) :versionbadge:`clang-format 16` :ref:`¶ <RequiresExpressionIndentation>`
4716 The indentation used for requires expression bodies.
4720 * ``REI_OuterScope`` (in configuration: ``OuterScope``)
4721 Align requires expression body relative to the indentation level of the
4722 outer scope the requires expression resides in.
4723 This is the default.
4727 template <typename T>
4728 concept C = requires(T t) {
4732 * ``REI_Keyword`` (in configuration: ``Keyword``)
4733 Align requires expression body relative to the ``requires`` keyword.
4737 template <typename T>
4738 concept C = requires(T t) {
4744 .. _SeparateDefinitionBlocks:
4746 **SeparateDefinitionBlocks** (``SeparateDefinitionStyle``) :versionbadge:`clang-format 14` :ref:`¶ <SeparateDefinitionBlocks>`
4747 Specifies the use of empty lines to separate definition blocks, including
4748 classes, structs, enums, and functions.
4753 #include <cstring> #include <cstring>
4755 int a, b, c; struct Foo {
4759 public: namespace Ns {
4760 struct Foobar { class Bar {
4762 int b; struct Foobar {
4770 ITEM1, int method1() {
4773 template<typename T>
4774 int method2(T x) { enum List {
4778 int method3(int par) {
4779 // ... template<typename T>
4780 } int method2(T x) {
4786 int method3(int par) {
4796 * ``SDS_Leave`` (in configuration: ``Leave``)
4797 Leave definition blocks as they are.
4799 * ``SDS_Always`` (in configuration: ``Always``)
4800 Insert an empty line between definition blocks.
4802 * ``SDS_Never`` (in configuration: ``Never``)
4803 Remove any empty line between definition blocks.
4807 .. _ShortNamespaceLines:
4809 **ShortNamespaceLines** (``Unsigned``) :versionbadge:`clang-format 13` :ref:`¶ <ShortNamespaceLines>`
4810 The maximal number of unwrapped lines that a short namespace spans.
4813 This determines the maximum length of short namespaces by counting
4814 unwrapped lines (i.e. containing neither opening nor closing
4815 namespace brace) and makes "FixNamespaceComments" omit adding
4816 end comments for those.
4820 ShortNamespaceLines: 1 vs. ShortNamespaceLines: 0
4821 namespace a { namespace a {
4825 ShortNamespaceLines: 1 vs. ShortNamespaceLines: 0
4826 namespace b { namespace b {
4829 } // namespace b } // namespace b
4833 **SortIncludes** (``SortIncludesOptions``) :versionbadge:`clang-format 3.8` :ref:`¶ <SortIncludes>`
4834 Controls if and how clang-format will sort ``#includes``.
4838 * ``SI_Never`` (in configuration: ``Never``)
4839 Includes are never sorted.
4849 * ``SI_CaseSensitive`` (in configuration: ``CaseSensitive``)
4850 Includes are sorted in an ASCIIbetical or case sensitive fashion.
4860 * ``SI_CaseInsensitive`` (in configuration: ``CaseInsensitive``)
4861 Includes are sorted in an alphabetical or case insensitive fashion.
4873 .. _SortJavaStaticImport:
4875 **SortJavaStaticImport** (``SortJavaStaticImportOptions``) :versionbadge:`clang-format 12` :ref:`¶ <SortJavaStaticImport>`
4876 When sorting Java imports, by default static imports are placed before
4877 non-static imports. If ``JavaStaticImportAfterImport`` is ``After``,
4878 static imports are placed after non-static imports.
4882 * ``SJSIO_Before`` (in configuration: ``Before``)
4883 Static imports are placed before non-static imports.
4885 .. code-block:: java
4887 import static org.example.function1;
4889 import org.example.ClassA;
4891 * ``SJSIO_After`` (in configuration: ``After``)
4892 Static imports are placed after non-static imports.
4894 .. code-block:: java
4896 import org.example.ClassA;
4898 import static org.example.function1;
4902 .. _SortUsingDeclarations:
4904 **SortUsingDeclarations** (``SortUsingDeclarationsOptions``) :versionbadge:`clang-format 5` :ref:`¶ <SortUsingDeclarations>`
4905 Controls if and how clang-format will sort using declarations.
4909 * ``SUD_Never`` (in configuration: ``Never``)
4910 Using declarations are never sorted.
4914 using std::chrono::duration_cast;
4917 using boost::regex_constants::icase;
4920 * ``SUD_Lexicographic`` (in configuration: ``Lexicographic``)
4921 Using declarations are sorted in the order defined as follows:
4922 Split the strings by "::" and discard any initial empty strings. Sort
4923 the lists of names lexicographically, and within those groups, names are
4924 in case-insensitive lexicographic order.
4929 using boost::regex_constants::icase;
4930 using std::chrono::duration_cast;
4934 * ``SUD_LexicographicNumeric`` (in configuration: ``LexicographicNumeric``)
4935 Using declarations are sorted in the order defined as follows:
4936 Split the strings by "::" and discard any initial empty strings. The
4937 last element of each list is a non-namespace name; all others are
4938 namespace names. Sort the lists of names lexicographically, where the
4939 sort order of individual names is that all non-namespace names come
4940 before all namespace names, and within those groups, names are in
4941 case-insensitive lexicographic order.
4946 using boost::regex_constants::icase;
4949 using std::chrono::duration_cast;
4953 .. _SpaceAfterCStyleCast:
4955 **SpaceAfterCStyleCast** (``Boolean``) :versionbadge:`clang-format 3.5` :ref:`¶ <SpaceAfterCStyleCast>`
4956 If ``true``, a space is inserted after C style casts.
4961 (int) i; vs. (int)i;
4963 .. _SpaceAfterLogicalNot:
4965 **SpaceAfterLogicalNot** (``Boolean``) :versionbadge:`clang-format 9` :ref:`¶ <SpaceAfterLogicalNot>`
4966 If ``true``, a space is inserted after the logical not operator (``!``).
4971 ! someExpression(); vs. !someExpression();
4973 .. _SpaceAfterTemplateKeyword:
4975 **SpaceAfterTemplateKeyword** (``Boolean``) :versionbadge:`clang-format 4` :ref:`¶ <SpaceAfterTemplateKeyword>`
4976 If ``true``, a space will be inserted after the 'template' keyword.
4981 template <int> void foo(); vs. template<int> void foo();
4983 .. _SpaceAroundPointerQualifiers:
4985 **SpaceAroundPointerQualifiers** (``SpaceAroundPointerQualifiersStyle``) :versionbadge:`clang-format 12` :ref:`¶ <SpaceAroundPointerQualifiers>`
4986 Defines in which cases to put a space before or after pointer qualifiers
4990 * ``SAPQ_Default`` (in configuration: ``Default``)
4991 Don't ensure spaces around pointer qualifiers and use PointerAlignment
4996 PointerAlignment: Left PointerAlignment: Right
4997 void* const* x = NULL; vs. void *const *x = NULL;
4999 * ``SAPQ_Before`` (in configuration: ``Before``)
5000 Ensure that there is a space before pointer qualifiers.
5004 PointerAlignment: Left PointerAlignment: Right
5005 void* const* x = NULL; vs. void * const *x = NULL;
5007 * ``SAPQ_After`` (in configuration: ``After``)
5008 Ensure that there is a space after pointer qualifiers.
5012 PointerAlignment: Left PointerAlignment: Right
5013 void* const * x = NULL; vs. void *const *x = NULL;
5015 * ``SAPQ_Both`` (in configuration: ``Both``)
5016 Ensure that there is a space both before and after pointer qualifiers.
5020 PointerAlignment: Left PointerAlignment: Right
5021 void* const * x = NULL; vs. void * const *x = NULL;
5025 .. _SpaceBeforeAssignmentOperators:
5027 **SpaceBeforeAssignmentOperators** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <SpaceBeforeAssignmentOperators>`
5028 If ``false``, spaces will be removed before assignment operators.
5033 int a = 5; vs. int a= 5;
5036 .. _SpaceBeforeCaseColon:
5038 **SpaceBeforeCaseColon** (``Boolean``) :versionbadge:`clang-format 12` :ref:`¶ <SpaceBeforeCaseColon>`
5039 If ``false``, spaces will be removed before case colon.
5044 switch (x) { vs. switch (x) {
5045 case 1 : break; case 1: break;
5048 .. _SpaceBeforeCpp11BracedList:
5050 **SpaceBeforeCpp11BracedList** (``Boolean``) :versionbadge:`clang-format 7` :ref:`¶ <SpaceBeforeCpp11BracedList>`
5051 If ``true``, a space will be inserted before a C++11 braced list
5052 used to initialize an object (after the preceding identifier or type).
5057 Foo foo { bar }; vs. Foo foo{ bar };
5059 vector<int> { 1, 2, 3 }; vector<int>{ 1, 2, 3 };
5060 new int[3] { 1, 2, 3 }; new int[3]{ 1, 2, 3 };
5062 .. _SpaceBeforeCtorInitializerColon:
5064 **SpaceBeforeCtorInitializerColon** (``Boolean``) :versionbadge:`clang-format 7` :ref:`¶ <SpaceBeforeCtorInitializerColon>`
5065 If ``false``, spaces will be removed before constructor initializer
5071 Foo::Foo() : a(a) {} Foo::Foo(): a(a) {}
5073 .. _SpaceBeforeInheritanceColon:
5075 **SpaceBeforeInheritanceColon** (``Boolean``) :versionbadge:`clang-format 7` :ref:`¶ <SpaceBeforeInheritanceColon>`
5076 If ``false``, spaces will be removed before inheritance colon.
5081 class Foo : Bar {} vs. class Foo: Bar {}
5083 .. _SpaceBeforeJsonColon:
5085 **SpaceBeforeJsonColon** (``Boolean``) :versionbadge:`clang-format 17` :ref:`¶ <SpaceBeforeJsonColon>`
5086 If ``true``, a space will be added before a JSON colon. For other
5087 languages, e.g. JavaScript, use ``SpacesInContainerLiterals`` instead.
5093 "key" : "value" vs. "key": "value"
5096 .. _SpaceBeforeParens:
5098 **SpaceBeforeParens** (``SpaceBeforeParensStyle``) :versionbadge:`clang-format 3.5` :ref:`¶ <SpaceBeforeParens>`
5099 Defines in which cases to put a space before opening parentheses.
5103 * ``SBPO_Never`` (in configuration: ``Never``)
5104 Never put a space before opening parentheses.
5114 * ``SBPO_ControlStatements`` (in configuration: ``ControlStatements``)
5115 Put a space before opening parentheses only after control statement
5116 keywords (``for/if/while...``).
5126 * ``SBPO_ControlStatementsExceptControlMacros`` (in configuration: ``ControlStatementsExceptControlMacros``)
5127 Same as ``SBPO_ControlStatements`` except this option doesn't apply to
5128 ForEach and If macros. This is useful in projects where ForEach/If
5129 macros are treated as function calls instead of control statements.
5130 ``SBPO_ControlStatementsExceptForEachMacros`` remains an alias for
5131 backward compatibility.
5141 * ``SBPO_NonEmptyParentheses`` (in configuration: ``NonEmptyParentheses``)
5142 Put a space before opening parentheses only if the parentheses are not
5154 * ``SBPO_Always`` (in configuration: ``Always``)
5155 Always put a space before opening parentheses, except when it's
5156 prohibited by the syntax rules (in function-like macro definitions) or
5157 when determined by other style rules (after unary operators, opening
5168 * ``SBPO_Custom`` (in configuration: ``Custom``)
5169 Configure each individual space before parentheses in
5170 ``SpaceBeforeParensOptions``.
5174 .. _SpaceBeforeParensOptions:
5176 **SpaceBeforeParensOptions** (``SpaceBeforeParensCustom``) :versionbadge:`clang-format 14` :ref:`¶ <SpaceBeforeParensOptions>`
5177 Control of individual space before parentheses.
5179 If ``SpaceBeforeParens`` is set to ``Custom``, use this to specify
5180 how each individual space before parentheses case should be handled.
5181 Otherwise, this is ignored.
5183 .. code-block:: yaml
5186 SpaceBeforeParens: Custom
5187 SpaceBeforeParensOptions:
5188 AfterControlStatements: true
5189 AfterFunctionDefinitionName: true
5191 Nested configuration flags:
5193 Precise control over the spacing before parentheses.
5197 # Should be declared this way:
5198 SpaceBeforeParens: Custom
5199 SpaceBeforeParensOptions:
5200 AfterControlStatements: true
5201 AfterFunctionDefinitionName: true
5203 * ``bool AfterControlStatements`` If ``true``, put space between control statement keywords
5204 (for/if/while...) and opening parentheses.
5209 if (...) {} vs. if(...) {}
5211 * ``bool AfterForeachMacros`` If ``true``, put space between foreach macros and opening parentheses.
5216 FOREACH (...) vs. FOREACH(...)
5217 <loop-body> <loop-body>
5219 * ``bool AfterFunctionDeclarationName`` If ``true``, put a space between function declaration name and opening
5225 void f (); vs. void f();
5227 * ``bool AfterFunctionDefinitionName`` If ``true``, put a space between function definition name and opening
5233 void f () {} vs. void f() {}
5235 * ``bool AfterIfMacros`` If ``true``, put space between if macros and opening parentheses.
5240 IF (...) vs. IF(...)
5241 <conditional-body> <conditional-body>
5243 * ``bool AfterOverloadedOperator`` If ``true``, put a space between operator overloading and opening
5249 void operator++ (int a); vs. void operator++(int a);
5250 object.operator++ (10); object.operator++(10);
5252 * ``AfterPlacementOperatorStyle AfterPlacementOperator`` :versionbadge:`clang-format 18`
5254 Defines in which cases to put a space between ``new/delete`` operators
5255 and opening parentheses.
5259 * ``APO_Never`` (in configuration: ``Never``)
5260 Remove space after ``new/delete`` operators and before ``(``.
5267 * ``APO_Always`` (in configuration: ``Always``)
5268 Always add space after ``new/delete`` operators and before ``(``.
5275 * ``APO_Leave`` (in configuration: ``Leave``)
5276 Leave placement ``new/delete`` expressions as they are.
5279 * ``bool AfterRequiresInClause`` If ``true``, put space between requires keyword in a requires clause and
5280 opening parentheses, if there is one.
5285 template<typename T> vs. template<typename T>
5286 requires (A<T> && B<T>) requires(A<T> && B<T>)
5289 * ``bool AfterRequiresInExpression`` If ``true``, put space between requires keyword in a requires expression
5290 and opening parentheses.
5295 template<typename T> vs. template<typename T>
5296 concept C = requires (T t) { concept C = requires(T t) {
5300 * ``bool BeforeNonEmptyParentheses`` If ``true``, put a space before opening parentheses only if the
5301 parentheses are not empty.
5306 void f (int a); vs. void f();
5310 .. _SpaceBeforeRangeBasedForLoopColon:
5312 **SpaceBeforeRangeBasedForLoopColon** (``Boolean``) :versionbadge:`clang-format 7` :ref:`¶ <SpaceBeforeRangeBasedForLoopColon>`
5313 If ``false``, spaces will be removed before range-based for loop
5319 for (auto v : values) {} vs. for(auto v: values) {}
5321 .. _SpaceBeforeSquareBrackets:
5323 **SpaceBeforeSquareBrackets** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ <SpaceBeforeSquareBrackets>`
5324 If ``true``, spaces will be before ``[``.
5325 Lambdas will not be affected. Only the first ``[`` will get a space added.
5330 int a [5]; vs. int a[5];
5331 int a [5][5]; vs. int a[5][5];
5333 .. _SpaceInEmptyBlock:
5335 **SpaceInEmptyBlock** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ <SpaceInEmptyBlock>`
5336 If ``true``, spaces will be inserted into ``{}``.
5341 void f() { } vs. void f() {}
5342 while (true) { } while (true) {}
5344 .. _SpaceInEmptyParentheses:
5346 **SpaceInEmptyParentheses** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <SpaceInEmptyParentheses>`
5347 If ``true``, spaces may be inserted into ``()``.
5348 This option is **deprecated**. See ``InEmptyParentheses`` of
5349 ``SpacesInParensOptions``.
5351 .. _SpacesBeforeTrailingComments:
5353 **SpacesBeforeTrailingComments** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <SpacesBeforeTrailingComments>`
5354 The number of spaces before trailing line comments
5355 (``//`` - comments).
5357 This does not affect trailing block comments (``/*`` - comments) as those
5358 commonly have different usage patterns and a number of special cases. In
5359 the case of Verilog, it doesn't affect a comment right after the opening
5360 parenthesis in the port or parameter list in a module header, because it
5361 is probably for the port on the following line instead of the parenthesis
5366 SpacesBeforeTrailingComments: 3
5375 **SpacesInAngles** (``SpacesInAnglesStyle``) :versionbadge:`clang-format 3.4` :ref:`¶ <SpacesInAngles>`
5376 The SpacesInAnglesStyle to use for template argument lists.
5380 * ``SIAS_Never`` (in configuration: ``Never``)
5381 Remove spaces after ``<`` and before ``>``.
5385 static_cast<int>(arg);
5386 std::function<void(int)> fct;
5388 * ``SIAS_Always`` (in configuration: ``Always``)
5389 Add spaces after ``<`` and before ``>``.
5393 static_cast< int >(arg);
5394 std::function< void(int) > fct;
5396 * ``SIAS_Leave`` (in configuration: ``Leave``)
5397 Keep a single space after ``<`` and before ``>`` if any spaces were
5398 present. Option ``Standard: Cpp03`` takes precedence.
5402 .. _SpacesInCStyleCastParentheses:
5404 **SpacesInCStyleCastParentheses** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <SpacesInCStyleCastParentheses>`
5405 If ``true``, spaces may be inserted into C style casts.
5406 This option is **deprecated**. See ``InCStyleCasts`` of
5407 ``SpacesInParensOptions``.
5409 .. _SpacesInConditionalStatement:
5411 **SpacesInConditionalStatement** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ <SpacesInConditionalStatement>`
5412 If ``true``, spaces will be inserted around if/for/switch/while
5414 This option is **deprecated**. See ``InConditionalStatements`` of
5415 ``SpacesInParensOptions``.
5417 .. _SpacesInContainerLiterals:
5419 **SpacesInContainerLiterals** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <SpacesInContainerLiterals>`
5420 If ``true``, spaces are inserted inside container literals (e.g. ObjC and
5421 Javascript array and dict literals). For JSON, use
5422 ``SpaceBeforeJsonColon`` instead.
5427 var arr = [ 1, 2, 3 ]; vs. var arr = [1, 2, 3];
5428 f({a : 1, b : 2, c : 3}); f({a: 1, b: 2, c: 3});
5430 .. _SpacesInLineCommentPrefix:
5432 **SpacesInLineCommentPrefix** (``SpacesInLineComment``) :versionbadge:`clang-format 13` :ref:`¶ <SpacesInLineCommentPrefix>`
5433 How many spaces are allowed at the start of a line comment. To disable the
5434 maximum set it to ``-1``, apart from that the maximum takes precedence
5441 // One space is forced
5443 // but more spaces are possible
5447 //Forces to start every comment directly after the slashes
5449 Note that in line comment sections the relative indent of the subsequent
5450 lines is kept, that means the following:
5456 //if (b) { // if (b) {
5457 // return true; // return true;
5465 This option has only effect if ``ReflowComments`` is set to ``true``.
5467 Nested configuration flags:
5469 Control of spaces within a single line comment.
5471 * ``unsigned Minimum`` The minimum number of spaces at the start of the comment.
5473 * ``unsigned Maximum`` The maximum number of spaces at the start of the comment.
5478 **SpacesInParens** (``SpacesInParensStyle``) :versionbadge:`clang-format 17` :ref:`¶ <SpacesInParens>`
5479 Defines in which cases spaces will be inserted after ``(`` and before
5484 * ``SIPO_Never`` (in configuration: ``Never``)
5485 Never put a space in parentheses.
5495 * ``SIPO_Custom`` (in configuration: ``Custom``)
5496 Configure each individual space in parentheses in
5497 `SpacesInParensOptions`.
5501 .. _SpacesInParensOptions:
5503 **SpacesInParensOptions** (``SpacesInParensCustom``) :versionbadge:`clang-format 17` :ref:`¶ <SpacesInParensOptions>`
5504 Control of individual spaces in parentheses.
5506 If ``SpacesInParens`` is set to ``Custom``, use this to specify
5507 how each individual space in parentheses case should be handled.
5508 Otherwise, this is ignored.
5510 .. code-block:: yaml
5513 SpacesInParens: Custom
5514 SpacesInParensOptions:
5515 InConditionalStatements: true
5516 InEmptyParentheses: true
5518 Nested configuration flags:
5520 Precise control over the spacing in parentheses.
5524 # Should be declared this way:
5525 SpacesInParens: Custom
5526 SpacesInParensOptions:
5527 InConditionalStatements: true
5530 * ``bool InConditionalStatements`` Put a space in parentheses only inside conditional statements
5531 (``for/if/while/switch...``).
5536 if ( a ) { ... } vs. if (a) { ... }
5537 while ( i < 5 ) { ... } while (i < 5) { ... }
5539 * ``bool InCStyleCasts`` Put a space in C style casts.
5544 x = ( int32 )y vs. x = (int32)y
5546 * ``bool InEmptyParentheses`` Put a space in parentheses only if the parentheses are empty i.e. '()'
5551 void f( ) { vs. void f() {
5552 int x[] = {foo( ), bar( )}; int x[] = {foo(), bar()};
5553 if (true) { if (true) {
5558 * ``bool Other`` Put a space in parentheses not covered by preceding options.
5563 t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete;
5566 .. _SpacesInParentheses:
5568 **SpacesInParentheses** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <SpacesInParentheses>`
5569 If ``true``, spaces will be inserted after ``(`` and before ``)``.
5570 This option is **deprecated**. The previous behavior is preserved by using
5571 ``SpacesInParens`` with ``Custom`` and by setting all
5572 ``SpacesInParensOptions`` to ``true`` except for ``InCStyleCasts`` and
5573 ``InEmptyParentheses``.
5575 .. _SpacesInSquareBrackets:
5577 **SpacesInSquareBrackets** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <SpacesInSquareBrackets>`
5578 If ``true``, spaces will be inserted after ``[`` and before ``]``.
5579 Lambdas without arguments or unspecified size array declarations will not
5585 int a[ 5 ]; vs. int a[5];
5586 std::unique_ptr<int[]> foo() {} // Won't be affected
5590 **Standard** (``LanguageStandard``) :versionbadge:`clang-format 3.7` :ref:`¶ <Standard>`
5591 Parse and format C++ constructs compatible with this standard.
5596 vector<set<int> > x; vs. vector<set<int>> x;
5600 * ``LS_Cpp03`` (in configuration: ``c++03``)
5601 Parse and format as C++03.
5602 ``Cpp03`` is a deprecated alias for ``c++03``
5604 * ``LS_Cpp11`` (in configuration: ``c++11``)
5605 Parse and format as C++11.
5607 * ``LS_Cpp14`` (in configuration: ``c++14``)
5608 Parse and format as C++14.
5610 * ``LS_Cpp17`` (in configuration: ``c++17``)
5611 Parse and format as C++17.
5613 * ``LS_Cpp20`` (in configuration: ``c++20``)
5614 Parse and format as C++20.
5616 * ``LS_Latest`` (in configuration: ``Latest``)
5617 Parse and format using the latest supported language version.
5618 ``Cpp11`` is a deprecated alias for ``Latest``
5620 * ``LS_Auto`` (in configuration: ``Auto``)
5621 Automatic detection based on the input.
5625 .. _StatementAttributeLikeMacros:
5627 **StatementAttributeLikeMacros** (``List of Strings``) :versionbadge:`clang-format 12` :ref:`¶ <StatementAttributeLikeMacros>`
5628 Macros which are ignored in front of a statement, as if they were an
5629 attribute. So that they are not parsed as identifier, for example for Qts
5634 AlignConsecutiveDeclarations: true
5635 StatementAttributeLikeMacros: []
5636 unsigned char data = 'x';
5637 emit signal(data); // This is parsed as variable declaration.
5639 AlignConsecutiveDeclarations: true
5640 StatementAttributeLikeMacros: [emit]
5641 unsigned char data = 'x';
5642 emit signal(data); // Now it's fine again.
5644 .. _StatementMacros:
5646 **StatementMacros** (``List of Strings``) :versionbadge:`clang-format 8` :ref:`¶ <StatementMacros>`
5647 A vector of macros that should be interpreted as complete
5650 Typical macros are expressions, and require a semi-colon to be
5651 added; sometimes this is not the case, and this allows to make
5652 clang-format aware of such cases.
5654 For example: Q_UNUSED
5658 **TabWidth** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <TabWidth>`
5659 The number of columns used for tab stops.
5663 **TypeNames** (``List of Strings``) :versionbadge:`clang-format 17` :ref:`¶ <TypeNames>`
5664 A vector of non-keyword identifiers that should be interpreted as type
5667 A ``*``, ``&``, or ``&&`` between a type name and another non-keyword
5668 identifier is annotated as a pointer or reference token instead of a
5673 **TypenameMacros** (``List of Strings``) :versionbadge:`clang-format 9` :ref:`¶ <TypenameMacros>`
5674 A vector of macros that should be interpreted as type declarations
5675 instead of as function calls.
5677 These are expected to be macros of the form:
5683 In the .clang-format configuration file, this can be configured like:
5685 .. code-block:: yaml
5687 TypenameMacros: ['STACK_OF', 'LIST']
5689 For example: OpenSSL STACK_OF, BSD LIST_ENTRY.
5693 **UseCRLF** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ <UseCRLF>`
5694 This option is **deprecated**. See ``LF`` and ``CRLF`` of ``LineEnding``.
5698 **UseTab** (``UseTabStyle``) :versionbadge:`clang-format 3.7` :ref:`¶ <UseTab>`
5699 The way to use tab characters in the resulting file.
5703 * ``UT_Never`` (in configuration: ``Never``)
5706 * ``UT_ForIndentation`` (in configuration: ``ForIndentation``)
5707 Use tabs only for indentation.
5709 * ``UT_ForContinuationAndIndentation`` (in configuration: ``ForContinuationAndIndentation``)
5710 Fill all leading whitespace with tabs, and use spaces for alignment that
5711 appears within a line (e.g. consecutive assignments and declarations).
5713 * ``UT_AlignWithSpaces`` (in configuration: ``AlignWithSpaces``)
5714 Use tabs for line continuation and indentation, and spaces for
5717 * ``UT_Always`` (in configuration: ``Always``)
5718 Use tabs whenever we need to fill whitespace that spans at least from
5719 one tab stop to the next one.
5723 .. _VerilogBreakBetweenInstancePorts:
5725 **VerilogBreakBetweenInstancePorts** (``Boolean``) :versionbadge:`clang-format 17` :ref:`¶ <VerilogBreakBetweenInstancePorts>`
5726 For Verilog, put each port on its own line in module instantiations.
5737 ffnand ff1(.q(), .qbar(out1), .clear(in1), .preset(in2));
5739 .. _WhitespaceSensitiveMacros:
5741 **WhitespaceSensitiveMacros** (``List of Strings``) :versionbadge:`clang-format 11` :ref:`¶ <WhitespaceSensitiveMacros>`
5742 A vector of macros which are whitespace-sensitive and should not
5745 These are expected to be macros of the form:
5751 In the .clang-format configuration file, this can be configured like:
5753 .. code-block:: yaml
5755 WhitespaceSensitiveMacros: ['STRINGIZE', 'PP_STRINGIZE']
5757 For example: BOOST_PP_STRINGIZE
5759 .. END_FORMAT_STYLE_OPTIONS
5761 Adding additional style options
5762 ===============================
5764 Each additional style option adds costs to the clang-format project. Some of
5765 these costs affect the clang-format development itself, as we need to make
5766 sure that any given combination of options work and that new features don't
5767 break any of the existing options in any way. There are also costs for end users
5768 as options become less discoverable and people have to think about and make a
5769 decision on options they don't really care about.
5771 The goal of the clang-format project is more on the side of supporting a
5772 limited set of styles really well as opposed to supporting every single style
5773 used by a codebase somewhere in the wild. Of course, we do want to support all
5774 major projects and thus have established the following bar for adding style
5775 options. Each new style option must ..
5777 * be used in a project of significant size (have dozens of contributors)
5778 * have a publicly accessible style guide
5779 * have a person willing to contribute and maintain patches
5784 A style similar to the `Linux Kernel style
5785 <https://www.kernel.org/doc/html/latest/process/coding-style.html>`_:
5787 .. code-block:: yaml
5792 BreakBeforeBraces: Linux
5793 AllowShortIfStatementsOnASingleLine: false
5794 IndentCaseLabels: false
5796 The result is (imagine that tabs are used for indentation here):
5808 do_something_else();
5814 do_something_completely_different();
5825 A style similar to the default Visual Studio formatting style:
5827 .. code-block:: yaml
5831 BreakBeforeBraces: Allman
5832 AllowShortIfStatementsOnASingleLine: false
5833 IndentCaseLabels: false
5849 do_something_else();
5855 do_something_completely_different();