1..
2  !!!!NOTE!!!!
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.
6
7.. raw:: html
8
9      <style type="text/css">
10        .versionbadge { background-color: #1c913d; height: 20px; display: inline-block; width: 120px; text-align: center; border-radius: 5px; color: #FFFFFF; font-family: "Verdana,Geneva,DejaVu Sans,sans-serif"; }
11      </style>
12
13.. role:: versionbadge
14
15==========================
16Clang-Format Style Options
17==========================
18
19:doc:`ClangFormatStyleOptions` describes configurable formatting style options
20supported by :doc:`LibFormat` and :doc:`ClangFormat`.
21
22When using :program:`clang-format` command line utility or
23``clang::format::reformat(...)`` functions from code, one can either use one of
24the predefined styles (LLVM, Google, Chromium, Mozilla, WebKit, Microsoft) or
25create a custom style by configuring specific style options.
26
27
28Configuring Style with clang-format
29===================================
30
31:program:`clang-format` supports two ways to provide custom style options:
32directly specify style configuration in the ``-style=`` command line option or
33use ``-style=file`` and put style configuration in the ``.clang-format`` or
34``_clang-format`` file in the project directory.
35
36When using ``-style=file``, :program:`clang-format` for each input file will
37try to find the ``.clang-format`` file located in the closest parent directory
38of the input file. When the standard input is used, the search is started from
39the current directory.
40
41When using ``-style=file:<format_file_path>``, :program:`clang-format` for
42each input file will use the format file located at `<format_file_path>`.
43The path may be absolute or relative to the working directory.
44
45The ``.clang-format`` file uses YAML format:
46
47.. code-block:: yaml
48
49  key1: value1
50  key2: value2
51  # A comment.
52  ...
53
54The configuration file can consist of several sections each having different
55``Language:`` parameter denoting the programming language this section of the
56configuration is targeted at. See the description of the **Language** option
57below for the list of supported languages. The first section may have no
58language set, it will set the default style options for all languages.
59Configuration sections for specific language will override options set in the
60default section.
61
62When :program:`clang-format` formats a file, it auto-detects the language using
63the file name. When formatting standard input or a file that doesn't have the
64extension corresponding to its language, ``-assume-filename=`` option can be
65used to override the file name :program:`clang-format` uses to detect the
66language.
67
68An example of a configuration file for multiple languages:
69
70.. code-block:: yaml
71
72  ---
73  # We'll use defaults from the LLVM style, but with 4 columns indentation.
74  BasedOnStyle: LLVM
75  IndentWidth: 4
76  ---
77  Language: Cpp
78  # Force pointers to the type for C++.
79  DerivePointerAlignment: false
80  PointerAlignment: Left
81  ---
82  Language: JavaScript
83  # Use 100 columns for JS.
84  ColumnLimit: 100
85  ---
86  Language: Proto
87  # Don't format .proto files.
88  DisableFormat: true
89  ---
90  Language: CSharp
91  # Use 100 columns for C#.
92  ColumnLimit: 100
93  ...
94
95An easy way to get a valid ``.clang-format`` file containing all configuration
96options of a certain predefined style is:
97
98.. code-block:: console
99
100  clang-format -style=llvm -dump-config > .clang-format
101
102When specifying configuration in the ``-style=`` option, the same configuration
103is applied for all input files. The format of the configuration is:
104
105.. code-block:: console
106
107  -style='{key1: value1, key2: value2, ...}'
108
109
110Disabling Formatting on a Piece of Code
111=======================================
112
113Clang-format understands also special comments that switch formatting in a
114delimited 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
117will be formatted (aligned) normally.
118
119.. code-block:: c++
120
121  int formatted_code;
122  // clang-format off
123      void    unformatted_code  ;
124  // clang-format on
125  void formatted_code_again;
126
127
128Configuring Style in Code
129=========================
130
131When using ``clang::format::reformat(...)`` functions, the format is specified
132by supplying the `clang::format::FormatStyle
133<https://clang.llvm.org/doxygen/structclang_1_1format_1_1FormatStyle.html>`_
134structure.
135
136
137Configurable Format Style Options
138=================================
139
140This section lists the supported style options. Value type is specified for
141each option. For enumeration types possible values are specified both as a C++
142enumeration member (with a prefix, e.g. ``LS_Auto``), and as a value usable in
143the configuration (without a prefix: ``Auto``).
144
145.. _BasedOnStyle:
146
147**BasedOnStyle** (``String``) :ref:`¶ <BasedOnStyle>`
148  The style used for all options not specifically set in the configuration.
149
150  This option is supported only in the :program:`clang-format` configuration
151  (both within ``-style='{...}'`` and the ``.clang-format`` file).
152
153  Possible values:
154
155  * ``LLVM``
156    A style complying with the `LLVM coding standards
157    <https://llvm.org/docs/CodingStandards.html>`_
158  * ``Google``
159    A style complying with `Google's C++ style guide
160    <https://google.github.io/styleguide/cppguide.html>`_
161  * ``Chromium``
162    A style complying with `Chromium's style guide
163    <https://chromium.googlesource.com/chromium/src/+/refs/heads/main/styleguide/styleguide.md>`_
164  * ``Mozilla``
165    A style complying with `Mozilla's style guide
166    <https://firefox-source-docs.mozilla.org/code-quality/coding-style/index.html>`_
167  * ``WebKit``
168    A style complying with `WebKit's style guide
169    <https://www.webkit.org/coding/coding-style.html>`_
170  * ``Microsoft``
171    A style complying with `Microsoft's style guide
172    <https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference>`_
173  * ``GNU``
174    A style complying with the `GNU coding standards
175    <https://www.gnu.org/prep/standards/standards.html>`_
176  * ``InheritParentConfig``
177    Not a real style, but allows to use the ``.clang-format`` file from the
178    parent directory (or its parent if there is none). If there is no parent
179    file found it falls back to the ``fallback`` style, and applies the changes
180    to that.
181
182    With this option you can overwrite some parts of your main style for your
183    subdirectories. This is also possible through the command line, e.g.:
184    ``--style={BasedOnStyle: InheritParentConfig, ColumnLimit: 20}``
185
186.. START_FORMAT_STYLE_OPTIONS
187
188.. _AccessModifierOffset:
189
190**AccessModifierOffset** (``Integer``) :versionbadge:`clang-format 3.3` :ref:`¶ <AccessModifierOffset>`
191  The extra indent or outdent of access modifiers, e.g. ``public:``.
192
193.. _AlignAfterOpenBracket:
194
195**AlignAfterOpenBracket** (``BracketAlignmentStyle``) :versionbadge:`clang-format 3.8` :ref:`¶ <AlignAfterOpenBracket>`
196  If ``true``, horizontally aligns arguments after an open bracket.
197
198  This applies to round brackets (parentheses), angle brackets and square
199  brackets.
200
201  Possible values:
202
203  * ``BAS_Align`` (in configuration: ``Align``)
204    Align parameters on the open bracket, e.g.:
205
206    .. code-block:: c++
207
208      someLongFunction(argument1,
209                       argument2);
210
211  * ``BAS_DontAlign`` (in configuration: ``DontAlign``)
212    Don't align, instead use ``ContinuationIndentWidth``, e.g.:
213
214    .. code-block:: c++
215
216      someLongFunction(argument1,
217          argument2);
218
219  * ``BAS_AlwaysBreak`` (in configuration: ``AlwaysBreak``)
220    Always break after an open bracket, if the parameters don't fit
221    on a single line, e.g.:
222
223    .. code-block:: c++
224
225      someLongFunction(
226          argument1, argument2);
227
228  * ``BAS_BlockIndent`` (in configuration: ``BlockIndent``)
229    Always break after an open bracket, if the parameters don't fit
230    on a single line. Closing brackets will be placed on a new line.
231    E.g.:
232
233    .. code-block:: c++
234
235      someLongFunction(
236          argument1, argument2
237      )
238
239
240    .. warning::
241
242     Note: This currently only applies to parentheses.
243
244
245
246.. _AlignArrayOfStructures:
247
248**AlignArrayOfStructures** (``ArrayInitializerAlignmentStyle``) :versionbadge:`clang-format 13` :ref:`¶ <AlignArrayOfStructures>`
249  if not ``None``, when using initialization for an array of structs
250  aligns the fields into columns.
251
252  NOTE: As of clang-format 15 this option only applied to arrays with equal
253  number of columns per row.
254
255  Possible values:
256
257  * ``AIAS_Left`` (in configuration: ``Left``)
258    Align array column and left justify the columns e.g.:
259
260    .. code-block:: c++
261
262      struct test demo[] =
263      {
264          {56, 23,    "hello"},
265          {-1, 93463, "world"},
266          {7,  5,     "!!"   }
267      };
268
269  * ``AIAS_Right`` (in configuration: ``Right``)
270    Align array column and right justify the columns e.g.:
271
272    .. code-block:: c++
273
274      struct test demo[] =
275      {
276          {56,    23, "hello"},
277          {-1, 93463, "world"},
278          { 7,     5,    "!!"}
279      };
280
281  * ``AIAS_None`` (in configuration: ``None``)
282    Don't align array initializer columns.
283
284
285
286.. _AlignConsecutiveAssignments:
287
288**AlignConsecutiveAssignments** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 3.8` :ref:`¶ <AlignConsecutiveAssignments>`
289  Style of aligning consecutive assignments.
290
291  ``Consecutive`` will result in formattings like:
292
293  .. code-block:: c++
294
295    int a            = 1;
296    int somelongname = 2;
297    double c         = 3;
298
299  Nested configuration flags:
300
301  Alignment options.
302
303  They can also be read as a whole for compatibility. The choices are:
304  - None
305  - Consecutive
306  - AcrossEmptyLines
307  - AcrossComments
308  - AcrossEmptyLinesAndComments
309
310  For example, to align across empty lines and not across comments, either
311  of these work.
312
313  .. code-block:: c++
314
315    AlignConsecutiveMacros: AcrossEmptyLines
316
317    AlignConsecutiveMacros:
318      Enabled: true
319      AcrossEmptyLines: true
320      AcrossComments: false
321
322  * ``bool Enabled`` Whether aligning is enabled.
323
324    .. code-block:: c++
325
326      #define SHORT_NAME       42
327      #define LONGER_NAME      0x007f
328      #define EVEN_LONGER_NAME (2)
329      #define foo(x)           (x * x)
330      #define bar(y, z)        (y + z)
331
332      int a            = 1;
333      int somelongname = 2;
334      double c         = 3;
335
336      int aaaa : 1;
337      int b    : 12;
338      int ccc  : 8;
339
340      int         aaaa = 12;
341      float       b = 23;
342      std::string ccc;
343
344  * ``bool AcrossEmptyLines`` Whether to align across empty lines.
345
346    .. code-block:: c++
347
348      true:
349      int a            = 1;
350      int somelongname = 2;
351      double c         = 3;
352
353      int d            = 3;
354
355      false:
356      int a            = 1;
357      int somelongname = 2;
358      double c         = 3;
359
360      int d = 3;
361
362  * ``bool AcrossComments`` Whether to align across comments.
363
364    .. code-block:: c++
365
366      true:
367      int d    = 3;
368      /* A comment. */
369      double e = 4;
370
371      false:
372      int d = 3;
373      /* A comment. */
374      double e = 4;
375
376  * ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``.  Whether compound assignments
377    like ``+=`` are aligned along with ``=``.
378
379    .. code-block:: c++
380
381      true:
382      a   &= 2;
383      bbb  = 2;
384
385      false:
386      a &= 2;
387      bbb = 2;
388
389  * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``.  Whether short assignment
390    operators are left-padded to the same length as long ones in order to
391    put all assignment operators to the right of the left hand side.
392
393    .. code-block:: c++
394
395      true:
396      a   >>= 2;
397      bbb   = 2;
398
399      a     = 2;
400      bbb >>= 2;
401
402      false:
403      a >>= 2;
404      bbb = 2;
405
406      a     = 2;
407      bbb >>= 2;
408
409
410.. _AlignConsecutiveBitFields:
411
412**AlignConsecutiveBitFields** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 11` :ref:`¶ <AlignConsecutiveBitFields>`
413  Style of aligning consecutive bit fields.
414
415  ``Consecutive`` will align the bitfield separators of consecutive lines.
416  This will result in formattings like:
417
418  .. code-block:: c++
419
420    int aaaa : 1;
421    int b    : 12;
422    int ccc  : 8;
423
424  Nested configuration flags:
425
426  Alignment options.
427
428  They can also be read as a whole for compatibility. The choices are:
429  - None
430  - Consecutive
431  - AcrossEmptyLines
432  - AcrossComments
433  - AcrossEmptyLinesAndComments
434
435  For example, to align across empty lines and not across comments, either
436  of these work.
437
438  .. code-block:: c++
439
440    AlignConsecutiveMacros: AcrossEmptyLines
441
442    AlignConsecutiveMacros:
443      Enabled: true
444      AcrossEmptyLines: true
445      AcrossComments: false
446
447  * ``bool Enabled`` Whether aligning is enabled.
448
449    .. code-block:: c++
450
451      #define SHORT_NAME       42
452      #define LONGER_NAME      0x007f
453      #define EVEN_LONGER_NAME (2)
454      #define foo(x)           (x * x)
455      #define bar(y, z)        (y + z)
456
457      int a            = 1;
458      int somelongname = 2;
459      double c         = 3;
460
461      int aaaa : 1;
462      int b    : 12;
463      int ccc  : 8;
464
465      int         aaaa = 12;
466      float       b = 23;
467      std::string ccc;
468
469  * ``bool AcrossEmptyLines`` Whether to align across empty lines.
470
471    .. code-block:: c++
472
473      true:
474      int a            = 1;
475      int somelongname = 2;
476      double c         = 3;
477
478      int d            = 3;
479
480      false:
481      int a            = 1;
482      int somelongname = 2;
483      double c         = 3;
484
485      int d = 3;
486
487  * ``bool AcrossComments`` Whether to align across comments.
488
489    .. code-block:: c++
490
491      true:
492      int d    = 3;
493      /* A comment. */
494      double e = 4;
495
496      false:
497      int d = 3;
498      /* A comment. */
499      double e = 4;
500
501  * ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``.  Whether compound assignments
502    like ``+=`` are aligned along with ``=``.
503
504    .. code-block:: c++
505
506      true:
507      a   &= 2;
508      bbb  = 2;
509
510      false:
511      a &= 2;
512      bbb = 2;
513
514  * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``.  Whether short assignment
515    operators are left-padded to the same length as long ones in order to
516    put all assignment operators to the right of the left hand side.
517
518    .. code-block:: c++
519
520      true:
521      a   >>= 2;
522      bbb   = 2;
523
524      a     = 2;
525      bbb >>= 2;
526
527      false:
528      a >>= 2;
529      bbb = 2;
530
531      a     = 2;
532      bbb >>= 2;
533
534
535.. _AlignConsecutiveDeclarations:
536
537**AlignConsecutiveDeclarations** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 3.8` :ref:`¶ <AlignConsecutiveDeclarations>`
538  Style of aligning consecutive declarations.
539
540  ``Consecutive`` will align the declaration names of consecutive lines.
541  This will result in formattings like:
542
543  .. code-block:: c++
544
545    int         aaaa = 12;
546    float       b = 23;
547    std::string ccc;
548
549  Nested configuration flags:
550
551  Alignment options.
552
553  They can also be read as a whole for compatibility. The choices are:
554  - None
555  - Consecutive
556  - AcrossEmptyLines
557  - AcrossComments
558  - AcrossEmptyLinesAndComments
559
560  For example, to align across empty lines and not across comments, either
561  of these work.
562
563  .. code-block:: c++
564
565    AlignConsecutiveMacros: AcrossEmptyLines
566
567    AlignConsecutiveMacros:
568      Enabled: true
569      AcrossEmptyLines: true
570      AcrossComments: false
571
572  * ``bool Enabled`` Whether aligning is enabled.
573
574    .. code-block:: c++
575
576      #define SHORT_NAME       42
577      #define LONGER_NAME      0x007f
578      #define EVEN_LONGER_NAME (2)
579      #define foo(x)           (x * x)
580      #define bar(y, z)        (y + z)
581
582      int a            = 1;
583      int somelongname = 2;
584      double c         = 3;
585
586      int aaaa : 1;
587      int b    : 12;
588      int ccc  : 8;
589
590      int         aaaa = 12;
591      float       b = 23;
592      std::string ccc;
593
594  * ``bool AcrossEmptyLines`` Whether to align across empty lines.
595
596    .. code-block:: c++
597
598      true:
599      int a            = 1;
600      int somelongname = 2;
601      double c         = 3;
602
603      int d            = 3;
604
605      false:
606      int a            = 1;
607      int somelongname = 2;
608      double c         = 3;
609
610      int d = 3;
611
612  * ``bool AcrossComments`` Whether to align across comments.
613
614    .. code-block:: c++
615
616      true:
617      int d    = 3;
618      /* A comment. */
619      double e = 4;
620
621      false:
622      int d = 3;
623      /* A comment. */
624      double e = 4;
625
626  * ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``.  Whether compound assignments
627    like ``+=`` are aligned along with ``=``.
628
629    .. code-block:: c++
630
631      true:
632      a   &= 2;
633      bbb  = 2;
634
635      false:
636      a &= 2;
637      bbb = 2;
638
639  * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``.  Whether short assignment
640    operators are left-padded to the same length as long ones in order to
641    put all assignment operators to the right of the left hand side.
642
643    .. code-block:: c++
644
645      true:
646      a   >>= 2;
647      bbb   = 2;
648
649      a     = 2;
650      bbb >>= 2;
651
652      false:
653      a >>= 2;
654      bbb = 2;
655
656      a     = 2;
657      bbb >>= 2;
658
659
660.. _AlignConsecutiveMacros:
661
662**AlignConsecutiveMacros** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 9` :ref:`¶ <AlignConsecutiveMacros>`
663  Style of aligning consecutive macro definitions.
664
665  ``Consecutive`` will result in formattings like:
666
667  .. code-block:: c++
668
669    #define SHORT_NAME       42
670    #define LONGER_NAME      0x007f
671    #define EVEN_LONGER_NAME (2)
672    #define foo(x)           (x * x)
673    #define bar(y, z)        (y + z)
674
675  Nested configuration flags:
676
677  Alignment options.
678
679  They can also be read as a whole for compatibility. The choices are:
680  - None
681  - Consecutive
682  - AcrossEmptyLines
683  - AcrossComments
684  - AcrossEmptyLinesAndComments
685
686  For example, to align across empty lines and not across comments, either
687  of these work.
688
689  .. code-block:: c++
690
691    AlignConsecutiveMacros: AcrossEmptyLines
692
693    AlignConsecutiveMacros:
694      Enabled: true
695      AcrossEmptyLines: true
696      AcrossComments: false
697
698  * ``bool Enabled`` Whether aligning is enabled.
699
700    .. code-block:: c++
701
702      #define SHORT_NAME       42
703      #define LONGER_NAME      0x007f
704      #define EVEN_LONGER_NAME (2)
705      #define foo(x)           (x * x)
706      #define bar(y, z)        (y + z)
707
708      int a            = 1;
709      int somelongname = 2;
710      double c         = 3;
711
712      int aaaa : 1;
713      int b    : 12;
714      int ccc  : 8;
715
716      int         aaaa = 12;
717      float       b = 23;
718      std::string ccc;
719
720  * ``bool AcrossEmptyLines`` Whether to align across empty lines.
721
722    .. code-block:: c++
723
724      true:
725      int a            = 1;
726      int somelongname = 2;
727      double c         = 3;
728
729      int d            = 3;
730
731      false:
732      int a            = 1;
733      int somelongname = 2;
734      double c         = 3;
735
736      int d = 3;
737
738  * ``bool AcrossComments`` Whether to align across comments.
739
740    .. code-block:: c++
741
742      true:
743      int d    = 3;
744      /* A comment. */
745      double e = 4;
746
747      false:
748      int d = 3;
749      /* A comment. */
750      double e = 4;
751
752  * ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``.  Whether compound assignments
753    like ``+=`` are aligned along with ``=``.
754
755    .. code-block:: c++
756
757      true:
758      a   &= 2;
759      bbb  = 2;
760
761      false:
762      a &= 2;
763      bbb = 2;
764
765  * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``.  Whether short assignment
766    operators are left-padded to the same length as long ones in order to
767    put all assignment operators to the right of the left hand side.
768
769    .. code-block:: c++
770
771      true:
772      a   >>= 2;
773      bbb   = 2;
774
775      a     = 2;
776      bbb >>= 2;
777
778      false:
779      a >>= 2;
780      bbb = 2;
781
782      a     = 2;
783      bbb >>= 2;
784
785
786.. _AlignEscapedNewlines:
787
788**AlignEscapedNewlines** (``EscapedNewlineAlignmentStyle``) :versionbadge:`clang-format 5` :ref:`¶ <AlignEscapedNewlines>`
789  Options for aligning backslashes in escaped newlines.
790
791  Possible values:
792
793  * ``ENAS_DontAlign`` (in configuration: ``DontAlign``)
794    Don't align escaped newlines.
795
796    .. code-block:: c++
797
798      #define A \
799        int aaaa; \
800        int b; \
801        int dddddddddd;
802
803  * ``ENAS_Left`` (in configuration: ``Left``)
804    Align escaped newlines as far left as possible.
805
806    .. code-block:: c++
807
808      true:
809      #define A   \
810        int aaaa; \
811        int b;    \
812        int dddddddddd;
813
814      false:
815
816  * ``ENAS_Right`` (in configuration: ``Right``)
817    Align escaped newlines in the right-most column.
818
819    .. code-block:: c++
820
821      #define A                                                                      \
822        int aaaa;                                                                    \
823        int b;                                                                       \
824        int dddddddddd;
825
826
827
828.. _AlignOperands:
829
830**AlignOperands** (``OperandAlignmentStyle``) :versionbadge:`clang-format 3.5` :ref:`¶ <AlignOperands>`
831  If ``true``, horizontally align operands of binary and ternary
832  expressions.
833
834  Possible values:
835
836  * ``OAS_DontAlign`` (in configuration: ``DontAlign``)
837    Do not align operands of binary and ternary expressions.
838    The wrapped lines are indented ``ContinuationIndentWidth`` spaces from
839    the start of the line.
840
841  * ``OAS_Align`` (in configuration: ``Align``)
842    Horizontally align operands of binary and ternary expressions.
843
844    Specifically, this aligns operands of a single expression that needs
845    to be split over multiple lines, e.g.:
846
847    .. code-block:: c++
848
849      int aaa = bbbbbbbbbbbbbbb +
850                ccccccccccccccc;
851
852    When ``BreakBeforeBinaryOperators`` is set, the wrapped operator is
853    aligned with the operand on the first line.
854
855    .. code-block:: c++
856
857      int aaa = bbbbbbbbbbbbbbb
858                + ccccccccccccccc;
859
860  * ``OAS_AlignAfterOperator`` (in configuration: ``AlignAfterOperator``)
861    Horizontally align operands of binary and ternary expressions.
862
863    This is similar to ``AO_Align``, except when
864    ``BreakBeforeBinaryOperators`` is set, the operator is un-indented so
865    that the wrapped operand is aligned with the operand on the first line.
866
867    .. code-block:: c++
868
869      int aaa = bbbbbbbbbbbbbbb
870              + ccccccccccccccc;
871
872
873
874.. _AlignTrailingComments:
875
876**AlignTrailingComments** (``TrailingCommentsAlignmentStyle``) :versionbadge:`clang-format 3.7` :ref:`¶ <AlignTrailingComments>`
877  Control of trailing comments.
878
879  NOTE: As of clang-format 16 this option is not a bool but can be set
880  to the options. Conventional bool options still can be parsed as before.
881
882
883  .. code-block:: yaml
884
885    # Example of usage:
886    AlignTrailingComments:
887      Kind: Always
888      OverEmptyLines: 2
889
890  Nested configuration flags:
891
892  Alignment options
893
894  * ``TrailingCommentsAlignmentKinds Kind``
895    Specifies the way to align trailing comments.
896
897    Possible values:
898
899    * ``TCAS_Leave`` (in configuration: ``Leave``)
900      Leave trailing comments as they are.
901
902      .. code-block:: c++
903
904        int a;    // comment
905        int ab;       // comment
906
907        int abc;  // comment
908        int abcd;     // comment
909
910    * ``TCAS_Always`` (in configuration: ``Always``)
911      Align trailing comments.
912
913      .. code-block:: c++
914
915        int a;  // comment
916        int ab; // comment
917
918        int abc;  // comment
919        int abcd; // comment
920
921    * ``TCAS_Never`` (in configuration: ``Never``)
922      Don't align trailing comments but other formatter applies.
923
924      .. code-block:: c++
925
926        int a; // comment
927        int ab; // comment
928
929        int abc; // comment
930        int abcd; // comment
931
932
933  * ``unsigned OverEmptyLines`` How many empty lines to apply alignment.
934    When both ``MaxEmptyLinesToKeep`` and ``OverEmptyLines`` are set to 2,
935    it formats like below.
936
937    .. code-block:: c++
938
939      int a;      // all these
940
941      int ab;     // comments are
942
943
944      int abcdef; // aligned
945
946    When ``MaxEmptyLinesToKeep`` is set to 2 and ``OverEmptyLines`` is set
947    to 1, it formats like below.
948
949    .. code-block:: c++
950
951      int a;  // these are
952
953      int ab; // aligned
954
955
956      int abcdef; // but this isn't
957
958
959.. _AllowAllArgumentsOnNextLine:
960
961**AllowAllArgumentsOnNextLine** (``Boolean``) :versionbadge:`clang-format 9` :ref:`¶ <AllowAllArgumentsOnNextLine>`
962  If a function call or braced initializer list doesn't fit on a
963  line, allow putting all arguments onto the next line, even if
964  ``BinPackArguments`` is ``false``.
965
966  .. code-block:: c++
967
968    true:
969    callFunction(
970        a, b, c, d);
971
972    false:
973    callFunction(a,
974                 b,
975                 c,
976                 d);
977
978.. _AllowAllConstructorInitializersOnNextLine:
979
980**AllowAllConstructorInitializersOnNextLine** (``Boolean``) :versionbadge:`clang-format 9` :ref:`¶ <AllowAllConstructorInitializersOnNextLine>`
981  This option is **deprecated**. See ``NextLine`` of
982  ``PackConstructorInitializers``.
983
984.. _AllowAllParametersOfDeclarationOnNextLine:
985
986**AllowAllParametersOfDeclarationOnNextLine** (``Boolean``) :versionbadge:`clang-format 3.3` :ref:`¶ <AllowAllParametersOfDeclarationOnNextLine>`
987  If the function declaration doesn't fit on a line,
988  allow putting all parameters of a function declaration onto
989  the next line even if ``BinPackParameters`` is ``false``.
990
991  .. code-block:: c++
992
993    true:
994    void myFunction(
995        int a, int b, int c, int d, int e);
996
997    false:
998    void myFunction(int a,
999                    int b,
1000                    int c,
1001                    int d,
1002                    int e);
1003
1004.. _AllowShortBlocksOnASingleLine:
1005
1006**AllowShortBlocksOnASingleLine** (``ShortBlockStyle``) :versionbadge:`clang-format 3.5` :ref:`¶ <AllowShortBlocksOnASingleLine>`
1007  Dependent on the value, ``while (true) { continue; }`` can be put on a
1008  single line.
1009
1010  Possible values:
1011
1012  * ``SBS_Never`` (in configuration: ``Never``)
1013    Never merge blocks into a single line.
1014
1015    .. code-block:: c++
1016
1017      while (true) {
1018      }
1019      while (true) {
1020        continue;
1021      }
1022
1023  * ``SBS_Empty`` (in configuration: ``Empty``)
1024    Only merge empty blocks.
1025
1026    .. code-block:: c++
1027
1028      while (true) {}
1029      while (true) {
1030        continue;
1031      }
1032
1033  * ``SBS_Always`` (in configuration: ``Always``)
1034    Always merge short blocks into a single line.
1035
1036    .. code-block:: c++
1037
1038      while (true) {}
1039      while (true) { continue; }
1040
1041
1042
1043.. _AllowShortCaseLabelsOnASingleLine:
1044
1045**AllowShortCaseLabelsOnASingleLine** (``Boolean``) :versionbadge:`clang-format 3.6` :ref:`¶ <AllowShortCaseLabelsOnASingleLine>`
1046  If ``true``, short case labels will be contracted to a single line.
1047
1048  .. code-block:: c++
1049
1050    true:                                   false:
1051    switch (a) {                    vs.     switch (a) {
1052    case 1: x = 1; break;                   case 1:
1053    case 2: return;                           x = 1;
1054    }                                         break;
1055                                            case 2:
1056                                              return;
1057                                            }
1058
1059.. _AllowShortEnumsOnASingleLine:
1060
1061**AllowShortEnumsOnASingleLine** (``Boolean``) :versionbadge:`clang-format 11` :ref:`¶ <AllowShortEnumsOnASingleLine>`
1062  Allow short enums on a single line.
1063
1064  .. code-block:: c++
1065
1066    true:
1067    enum { A, B } myEnum;
1068
1069    false:
1070    enum {
1071      A,
1072      B
1073    } myEnum;
1074
1075.. _AllowShortFunctionsOnASingleLine:
1076
1077**AllowShortFunctionsOnASingleLine** (``ShortFunctionStyle``) :versionbadge:`clang-format 3.5` :ref:`¶ <AllowShortFunctionsOnASingleLine>`
1078  Dependent on the value, ``int f() { return 0; }`` can be put on a
1079  single line.
1080
1081  Possible values:
1082
1083  * ``SFS_None`` (in configuration: ``None``)
1084    Never merge functions into a single line.
1085
1086  * ``SFS_InlineOnly`` (in configuration: ``InlineOnly``)
1087    Only merge functions defined inside a class. Same as "inline",
1088    except it does not implies "empty": i.e. top level empty functions
1089    are not merged either.
1090
1091    .. code-block:: c++
1092
1093      class Foo {
1094        void f() { foo(); }
1095      };
1096      void f() {
1097        foo();
1098      }
1099      void f() {
1100      }
1101
1102  * ``SFS_Empty`` (in configuration: ``Empty``)
1103    Only merge empty functions.
1104
1105    .. code-block:: c++
1106
1107      void f() {}
1108      void f2() {
1109        bar2();
1110      }
1111
1112  * ``SFS_Inline`` (in configuration: ``Inline``)
1113    Only merge functions defined inside a class. Implies "empty".
1114
1115    .. code-block:: c++
1116
1117      class Foo {
1118        void f() { foo(); }
1119      };
1120      void f() {
1121        foo();
1122      }
1123      void f() {}
1124
1125  * ``SFS_All`` (in configuration: ``All``)
1126    Merge all functions fitting on a single line.
1127
1128    .. code-block:: c++
1129
1130      class Foo {
1131        void f() { foo(); }
1132      };
1133      void f() { bar(); }
1134
1135
1136
1137.. _AllowShortIfStatementsOnASingleLine:
1138
1139**AllowShortIfStatementsOnASingleLine** (``ShortIfStyle``) :versionbadge:`clang-format 3.3` :ref:`¶ <AllowShortIfStatementsOnASingleLine>`
1140  Dependent on the value, ``if (a) return;`` can be put on a single line.
1141
1142  Possible values:
1143
1144  * ``SIS_Never`` (in configuration: ``Never``)
1145    Never put short ifs on the same line.
1146
1147    .. code-block:: c++
1148
1149      if (a)
1150        return;
1151
1152      if (b)
1153        return;
1154      else
1155        return;
1156
1157      if (c)
1158        return;
1159      else {
1160        return;
1161      }
1162
1163  * ``SIS_WithoutElse`` (in configuration: ``WithoutElse``)
1164    Put short ifs on the same line only if there is no else statement.
1165
1166    .. code-block:: c++
1167
1168      if (a) return;
1169
1170      if (b)
1171        return;
1172      else
1173        return;
1174
1175      if (c)
1176        return;
1177      else {
1178        return;
1179      }
1180
1181  * ``SIS_OnlyFirstIf`` (in configuration: ``OnlyFirstIf``)
1182    Put short ifs, but not else ifs nor else statements, on the same line.
1183
1184    .. code-block:: c++
1185
1186      if (a) return;
1187
1188      if (b) return;
1189      else if (b)
1190        return;
1191      else
1192        return;
1193
1194      if (c) return;
1195      else {
1196        return;
1197      }
1198
1199  * ``SIS_AllIfsAndElse`` (in configuration: ``AllIfsAndElse``)
1200    Always put short ifs, else ifs and else statements on the same
1201    line.
1202
1203    .. code-block:: c++
1204
1205      if (a) return;
1206
1207      if (b) return;
1208      else return;
1209
1210      if (c) return;
1211      else {
1212        return;
1213      }
1214
1215
1216
1217.. _AllowShortLambdasOnASingleLine:
1218
1219**AllowShortLambdasOnASingleLine** (``ShortLambdaStyle``) :versionbadge:`clang-format 9` :ref:`¶ <AllowShortLambdasOnASingleLine>`
1220  Dependent on the value, ``auto lambda []() { return 0; }`` can be put on a
1221  single line.
1222
1223  Possible values:
1224
1225  * ``SLS_None`` (in configuration: ``None``)
1226    Never merge lambdas into a single line.
1227
1228  * ``SLS_Empty`` (in configuration: ``Empty``)
1229    Only merge empty lambdas.
1230
1231    .. code-block:: c++
1232
1233      auto lambda = [](int a) {};
1234      auto lambda2 = [](int a) {
1235          return a;
1236      };
1237
1238  * ``SLS_Inline`` (in configuration: ``Inline``)
1239    Merge lambda into a single line if the lambda is argument of a function.
1240
1241    .. code-block:: c++
1242
1243      auto lambda = [](int x, int y) {
1244          return x < y;
1245      };
1246      sort(a.begin(), a.end(), [](int x, int y) { return x < y; });
1247
1248  * ``SLS_All`` (in configuration: ``All``)
1249    Merge all lambdas fitting on a single line.
1250
1251    .. code-block:: c++
1252
1253      auto lambda = [](int a) {};
1254      auto lambda2 = [](int a) { return a; };
1255
1256
1257
1258.. _AllowShortLoopsOnASingleLine:
1259
1260**AllowShortLoopsOnASingleLine** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <AllowShortLoopsOnASingleLine>`
1261  If ``true``, ``while (true) continue;`` can be put on a single
1262  line.
1263
1264.. _AlwaysBreakAfterDefinitionReturnType:
1265
1266**AlwaysBreakAfterDefinitionReturnType** (``DefinitionReturnTypeBreakingStyle``) :versionbadge:`clang-format 3.7` :ref:`¶ <AlwaysBreakAfterDefinitionReturnType>`
1267  The function definition return type breaking style to use.  This
1268  option is **deprecated** and is retained for backwards compatibility.
1269
1270  Possible values:
1271
1272  * ``DRTBS_None`` (in configuration: ``None``)
1273    Break after return type automatically.
1274    ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
1275
1276  * ``DRTBS_All`` (in configuration: ``All``)
1277    Always break after the return type.
1278
1279  * ``DRTBS_TopLevel`` (in configuration: ``TopLevel``)
1280    Always break after the return types of top-level functions.
1281
1282
1283
1284.. _AlwaysBreakAfterReturnType:
1285
1286**AlwaysBreakAfterReturnType** (``ReturnTypeBreakingStyle``) :versionbadge:`clang-format 3.8` :ref:`¶ <AlwaysBreakAfterReturnType>`
1287  The function declaration return type breaking style to use.
1288
1289  Possible values:
1290
1291  * ``RTBS_None`` (in configuration: ``None``)
1292    Break after return type automatically.
1293    ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
1294
1295    .. code-block:: c++
1296
1297      class A {
1298        int f() { return 0; };
1299      };
1300      int f();
1301      int f() { return 1; }
1302
1303  * ``RTBS_All`` (in configuration: ``All``)
1304    Always break after the return type.
1305
1306    .. code-block:: c++
1307
1308      class A {
1309        int
1310        f() {
1311          return 0;
1312        };
1313      };
1314      int
1315      f();
1316      int
1317      f() {
1318        return 1;
1319      }
1320
1321  * ``RTBS_TopLevel`` (in configuration: ``TopLevel``)
1322    Always break after the return types of top-level functions.
1323
1324    .. code-block:: c++
1325
1326      class A {
1327        int f() { return 0; };
1328      };
1329      int
1330      f();
1331      int
1332      f() {
1333        return 1;
1334      }
1335
1336  * ``RTBS_AllDefinitions`` (in configuration: ``AllDefinitions``)
1337    Always break after the return type of function definitions.
1338
1339    .. code-block:: c++
1340
1341      class A {
1342        int
1343        f() {
1344          return 0;
1345        };
1346      };
1347      int f();
1348      int
1349      f() {
1350        return 1;
1351      }
1352
1353  * ``RTBS_TopLevelDefinitions`` (in configuration: ``TopLevelDefinitions``)
1354    Always break after the return type of top-level definitions.
1355
1356    .. code-block:: c++
1357
1358      class A {
1359        int f() { return 0; };
1360      };
1361      int f();
1362      int
1363      f() {
1364        return 1;
1365      }
1366
1367
1368
1369.. _AlwaysBreakBeforeMultilineStrings:
1370
1371**AlwaysBreakBeforeMultilineStrings** (``Boolean``) :versionbadge:`clang-format 3.4` :ref:`¶ <AlwaysBreakBeforeMultilineStrings>`
1372  If ``true``, always break before multiline string literals.
1373
1374  This flag is mean to make cases where there are multiple multiline strings
1375  in a file look more consistent. Thus, it will only take effect if wrapping
1376  the string at that point leads to it being indented
1377  ``ContinuationIndentWidth`` spaces from the start of the line.
1378
1379  .. code-block:: c++
1380
1381     true:                                  false:
1382     aaaa =                         vs.     aaaa = "bbbb"
1383         "bbbb"                                    "cccc";
1384         "cccc";
1385
1386.. _AlwaysBreakTemplateDeclarations:
1387
1388**AlwaysBreakTemplateDeclarations** (``BreakTemplateDeclarationsStyle``) :versionbadge:`clang-format 3.4` :ref:`¶ <AlwaysBreakTemplateDeclarations>`
1389  The template declaration breaking style to use.
1390
1391  Possible values:
1392
1393  * ``BTDS_No`` (in configuration: ``No``)
1394    Do not force break before declaration.
1395    ``PenaltyBreakTemplateDeclaration`` is taken into account.
1396
1397    .. code-block:: c++
1398
1399       template <typename T> T foo() {
1400       }
1401       template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa,
1402                                   int bbbbbbbbbbbbbbbbbbbbb) {
1403       }
1404
1405  * ``BTDS_MultiLine`` (in configuration: ``MultiLine``)
1406    Force break after template declaration only when the following
1407    declaration spans multiple lines.
1408
1409    .. code-block:: c++
1410
1411       template <typename T> T foo() {
1412       }
1413       template <typename T>
1414       T foo(int aaaaaaaaaaaaaaaaaaaaa,
1415             int bbbbbbbbbbbbbbbbbbbbb) {
1416       }
1417
1418  * ``BTDS_Yes`` (in configuration: ``Yes``)
1419    Always break after template declaration.
1420
1421    .. code-block:: c++
1422
1423       template <typename T>
1424       T foo() {
1425       }
1426       template <typename T>
1427       T foo(int aaaaaaaaaaaaaaaaaaaaa,
1428             int bbbbbbbbbbbbbbbbbbbbb) {
1429       }
1430
1431
1432
1433.. _AttributeMacros:
1434
1435**AttributeMacros** (``List of Strings``) :versionbadge:`clang-format 12` :ref:`¶ <AttributeMacros>`
1436  A vector of strings that should be interpreted as attributes/qualifiers
1437  instead of identifiers. This can be useful for language extensions or
1438  static analyzer annotations.
1439
1440  For example:
1441
1442  .. code-block:: c++
1443
1444    x = (char *__capability)&y;
1445    int function(void) __ununsed;
1446    void only_writes_to_buffer(char *__output buffer);
1447
1448  In the .clang-format configuration file, this can be configured like:
1449
1450  .. code-block:: yaml
1451
1452    AttributeMacros: ['__capability', '__output', '__ununsed']
1453
1454.. _BinPackArguments:
1455
1456**BinPackArguments** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <BinPackArguments>`
1457  If ``false``, a function call's arguments will either be all on the
1458  same line or will have one line each.
1459
1460  .. code-block:: c++
1461
1462    true:
1463    void f() {
1464      f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa,
1465        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
1466    }
1467
1468    false:
1469    void f() {
1470      f(aaaaaaaaaaaaaaaaaaaa,
1471        aaaaaaaaaaaaaaaaaaaa,
1472        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
1473    }
1474
1475.. _BinPackParameters:
1476
1477**BinPackParameters** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <BinPackParameters>`
1478  If ``false``, a function declaration's or function definition's
1479  parameters will either all be on the same line or will have one line each.
1480
1481  .. code-block:: c++
1482
1483    true:
1484    void f(int aaaaaaaaaaaaaaaaaaaa, int aaaaaaaaaaaaaaaaaaaa,
1485           int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
1486
1487    false:
1488    void f(int aaaaaaaaaaaaaaaaaaaa,
1489           int aaaaaaaaaaaaaaaaaaaa,
1490           int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
1491
1492.. _BitFieldColonSpacing:
1493
1494**BitFieldColonSpacing** (``BitFieldColonSpacingStyle``) :versionbadge:`clang-format 12` :ref:`¶ <BitFieldColonSpacing>`
1495  The BitFieldColonSpacingStyle to use for bitfields.
1496
1497  Possible values:
1498
1499  * ``BFCS_Both`` (in configuration: ``Both``)
1500    Add one space on each side of the ``:``
1501
1502    .. code-block:: c++
1503
1504      unsigned bf : 2;
1505
1506  * ``BFCS_None`` (in configuration: ``None``)
1507    Add no space around the ``:`` (except when needed for
1508    ``AlignConsecutiveBitFields``).
1509
1510    .. code-block:: c++
1511
1512      unsigned bf:2;
1513
1514  * ``BFCS_Before`` (in configuration: ``Before``)
1515    Add space before the ``:`` only
1516
1517    .. code-block:: c++
1518
1519      unsigned bf :2;
1520
1521  * ``BFCS_After`` (in configuration: ``After``)
1522    Add space after the ``:`` only (space may be added before if
1523    needed for ``AlignConsecutiveBitFields``).
1524
1525    .. code-block:: c++
1526
1527      unsigned bf: 2;
1528
1529
1530
1531.. _BraceWrapping:
1532
1533**BraceWrapping** (``BraceWrappingFlags``) :versionbadge:`clang-format 3.8` :ref:`¶ <BraceWrapping>`
1534  Control of individual brace wrapping cases.
1535
1536  If ``BreakBeforeBraces`` is set to ``BS_Custom``, use this to specify how
1537  each individual brace case should be handled. Otherwise, this is ignored.
1538
1539  .. code-block:: yaml
1540
1541    # Example of usage:
1542    BreakBeforeBraces: Custom
1543    BraceWrapping:
1544      AfterEnum: true
1545      AfterStruct: false
1546      SplitEmptyFunction: false
1547
1548  Nested configuration flags:
1549
1550  Precise control over the wrapping of braces.
1551
1552  .. code-block:: c++
1553
1554    # Should be declared this way:
1555    BreakBeforeBraces: Custom
1556    BraceWrapping:
1557        AfterClass: true
1558
1559  * ``bool AfterCaseLabel`` Wrap case labels.
1560
1561    .. code-block:: c++
1562
1563      false:                                true:
1564      switch (foo) {                vs.     switch (foo) {
1565        case 1: {                             case 1:
1566          bar();                              {
1567          break;                                bar();
1568        }                                       break;
1569        default: {                            }
1570          plop();                             default:
1571        }                                     {
1572      }                                         plop();
1573                                              }
1574                                            }
1575
1576  * ``bool AfterClass`` Wrap class definitions.
1577
1578    .. code-block:: c++
1579
1580      true:
1581      class foo
1582      {};
1583
1584      false:
1585      class foo {};
1586
1587  * ``BraceWrappingAfterControlStatementStyle AfterControlStatement``
1588    Wrap control statements (``if``/``for``/``while``/``switch``/..).
1589
1590    Possible values:
1591
1592    * ``BWACS_Never`` (in configuration: ``Never``)
1593      Never wrap braces after a control statement.
1594
1595      .. code-block:: c++
1596
1597        if (foo()) {
1598        } else {
1599        }
1600        for (int i = 0; i < 10; ++i) {
1601        }
1602
1603    * ``BWACS_MultiLine`` (in configuration: ``MultiLine``)
1604      Only wrap braces after a multi-line control statement.
1605
1606      .. code-block:: c++
1607
1608        if (foo && bar &&
1609            baz)
1610        {
1611          quux();
1612        }
1613        while (foo || bar) {
1614        }
1615
1616    * ``BWACS_Always`` (in configuration: ``Always``)
1617      Always wrap braces after a control statement.
1618
1619      .. code-block:: c++
1620
1621        if (foo())
1622        {
1623        } else
1624        {}
1625        for (int i = 0; i < 10; ++i)
1626        {}
1627
1628
1629  * ``bool AfterEnum`` Wrap enum definitions.
1630
1631    .. code-block:: c++
1632
1633      true:
1634      enum X : int
1635      {
1636        B
1637      };
1638
1639      false:
1640      enum X : int { B };
1641
1642  * ``bool AfterFunction`` Wrap function definitions.
1643
1644    .. code-block:: c++
1645
1646      true:
1647      void foo()
1648      {
1649        bar();
1650        bar2();
1651      }
1652
1653      false:
1654      void foo() {
1655        bar();
1656        bar2();
1657      }
1658
1659  * ``bool AfterNamespace`` Wrap namespace definitions.
1660
1661    .. code-block:: c++
1662
1663      true:
1664      namespace
1665      {
1666      int foo();
1667      int bar();
1668      }
1669
1670      false:
1671      namespace {
1672      int foo();
1673      int bar();
1674      }
1675
1676  * ``bool AfterObjCDeclaration`` Wrap ObjC definitions (interfaces, implementations...).
1677    @autoreleasepool and @synchronized blocks are wrapped
1678    according to `AfterControlStatement` flag.
1679
1680  * ``bool AfterStruct`` Wrap struct definitions.
1681
1682    .. code-block:: c++
1683
1684      true:
1685      struct foo
1686      {
1687        int x;
1688      };
1689
1690      false:
1691      struct foo {
1692        int x;
1693      };
1694
1695  * ``bool AfterUnion`` Wrap union definitions.
1696
1697    .. code-block:: c++
1698
1699      true:
1700      union foo
1701      {
1702        int x;
1703      }
1704
1705      false:
1706      union foo {
1707        int x;
1708      }
1709
1710  * ``bool AfterExternBlock`` Wrap extern blocks.
1711
1712    .. code-block:: c++
1713
1714      true:
1715      extern "C"
1716      {
1717        int foo();
1718      }
1719
1720      false:
1721      extern "C" {
1722      int foo();
1723      }
1724
1725  * ``bool BeforeCatch`` Wrap before ``catch``.
1726
1727    .. code-block:: c++
1728
1729      true:
1730      try {
1731        foo();
1732      }
1733      catch () {
1734      }
1735
1736      false:
1737      try {
1738        foo();
1739      } catch () {
1740      }
1741
1742  * ``bool BeforeElse`` Wrap before ``else``.
1743
1744    .. code-block:: c++
1745
1746      true:
1747      if (foo()) {
1748      }
1749      else {
1750      }
1751
1752      false:
1753      if (foo()) {
1754      } else {
1755      }
1756
1757  * ``bool BeforeLambdaBody`` Wrap lambda block.
1758
1759    .. code-block:: c++
1760
1761      true:
1762      connect(
1763        []()
1764        {
1765          foo();
1766          bar();
1767        });
1768
1769      false:
1770      connect([]() {
1771        foo();
1772        bar();
1773      });
1774
1775  * ``bool BeforeWhile`` Wrap before ``while``.
1776
1777    .. code-block:: c++
1778
1779      true:
1780      do {
1781        foo();
1782      }
1783      while (1);
1784
1785      false:
1786      do {
1787        foo();
1788      } while (1);
1789
1790  * ``bool IndentBraces`` Indent the wrapped braces themselves.
1791
1792  * ``bool SplitEmptyFunction`` If ``false``, empty function body can be put on a single line.
1793    This option is used only if the opening brace of the function has
1794    already been wrapped, i.e. the `AfterFunction` brace wrapping mode is
1795    set, and the function could/should not be put on a single line (as per
1796    `AllowShortFunctionsOnASingleLine` and constructor formatting options).
1797
1798    .. code-block:: c++
1799
1800      false:          true:
1801      int f()   vs.   int f()
1802      {}              {
1803                      }
1804
1805  * ``bool SplitEmptyRecord`` If ``false``, empty record (e.g. class, struct or union) body
1806    can be put on a single line. This option is used only if the opening
1807    brace of the record has already been wrapped, i.e. the `AfterClass`
1808    (for classes) brace wrapping mode is set.
1809
1810    .. code-block:: c++
1811
1812      false:           true:
1813      class Foo   vs.  class Foo
1814      {}               {
1815                       }
1816
1817  * ``bool SplitEmptyNamespace`` If ``false``, empty namespace body can be put on a single line.
1818    This option is used only if the opening brace of the namespace has
1819    already been wrapped, i.e. the `AfterNamespace` brace wrapping mode is
1820    set.
1821
1822    .. code-block:: c++
1823
1824      false:               true:
1825      namespace Foo   vs.  namespace Foo
1826      {}                   {
1827                           }
1828
1829
1830.. _BreakAfterAttributes:
1831
1832**BreakAfterAttributes** (``AttributeBreakingStyle``) :versionbadge:`clang-format 16` :ref:`¶ <BreakAfterAttributes>`
1833  Break after a group of C++11 attributes before a function
1834  declaration/definition name.
1835
1836  Possible values:
1837
1838  * ``ABS_Always`` (in configuration: ``Always``)
1839    Always break after attributes.
1840
1841    .. code-block:: c++
1842
1843      [[nodiscard]]
1844      inline int f();
1845      [[gnu::const]] [[nodiscard]]
1846      int g();
1847
1848  * ``ABS_Leave`` (in configuration: ``Leave``)
1849    Leave the line breaking after attributes as is.
1850
1851    .. code-block:: c++
1852
1853      [[nodiscard]] inline int f();
1854      [[gnu::const]] [[nodiscard]]
1855      int g();
1856
1857  * ``ABS_Never`` (in configuration: ``Never``)
1858    Never break after attributes.
1859
1860    .. code-block:: c++
1861
1862      [[nodiscard]] inline int f();
1863      [[gnu::const]] [[nodiscard]] int g();
1864
1865
1866
1867.. _BreakAfterJavaFieldAnnotations:
1868
1869**BreakAfterJavaFieldAnnotations** (``Boolean``) :versionbadge:`clang-format 3.8` :ref:`¶ <BreakAfterJavaFieldAnnotations>`
1870  Break after each annotation on a field in Java files.
1871
1872  .. code-block:: java
1873
1874     true:                                  false:
1875     @Partial                       vs.     @Partial @Mock DataLoad loader;
1876     @Mock
1877     DataLoad loader;
1878
1879.. _BreakArrays:
1880
1881**BreakArrays** (``Boolean``) :versionbadge:`clang-format 16` :ref:`¶ <BreakArrays>`
1882  If ``true``, clang-format will always break after a Json array `[`
1883  otherwise it will scan until the closing `]` to determine if it should add
1884  newlines between elements (prettier compatible).
1885
1886  NOTE: This is currently only for formatting JSON.
1887
1888  .. code-block:: c++
1889
1890     true:                                  false:
1891     [                          vs.      [1, 2, 3, 4]
1892       1,
1893       2,
1894       3,
1895       4
1896     ]
1897
1898.. _BreakBeforeBinaryOperators:
1899
1900**BreakBeforeBinaryOperators** (``BinaryOperatorStyle``) :versionbadge:`clang-format 3.6` :ref:`¶ <BreakBeforeBinaryOperators>`
1901  The way to wrap binary operators.
1902
1903  Possible values:
1904
1905  * ``BOS_None`` (in configuration: ``None``)
1906    Break after operators.
1907
1908    .. code-block:: c++
1909
1910       LooooooooooongType loooooooooooooooooooooongVariable =
1911           someLooooooooooooooooongFunction();
1912
1913       bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
1914                            aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ==
1915                        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
1916                    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa >
1917                        ccccccccccccccccccccccccccccccccccccccccc;
1918
1919  * ``BOS_NonAssignment`` (in configuration: ``NonAssignment``)
1920    Break before operators that aren't assignments.
1921
1922    .. code-block:: c++
1923
1924       LooooooooooongType loooooooooooooooooooooongVariable =
1925           someLooooooooooooooooongFunction();
1926
1927       bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1928                            + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1929                        == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1930                    && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1931                           > ccccccccccccccccccccccccccccccccccccccccc;
1932
1933  * ``BOS_All`` (in configuration: ``All``)
1934    Break before operators.
1935
1936    .. code-block:: c++
1937
1938       LooooooooooongType loooooooooooooooooooooongVariable
1939           = someLooooooooooooooooongFunction();
1940
1941       bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1942                            + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1943                        == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1944                    && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1945                           > ccccccccccccccccccccccccccccccccccccccccc;
1946
1947
1948
1949.. _BreakBeforeBraces:
1950
1951**BreakBeforeBraces** (``BraceBreakingStyle``) :versionbadge:`clang-format 3.7` :ref:`¶ <BreakBeforeBraces>`
1952  The brace breaking style to use.
1953
1954  Possible values:
1955
1956  * ``BS_Attach`` (in configuration: ``Attach``)
1957    Always attach braces to surrounding context.
1958
1959    .. code-block:: c++
1960
1961      namespace N {
1962      enum E {
1963        E1,
1964        E2,
1965      };
1966
1967      class C {
1968      public:
1969        C();
1970      };
1971
1972      bool baz(int i) {
1973        try {
1974          do {
1975            switch (i) {
1976            case 1: {
1977              foobar();
1978              break;
1979            }
1980            default: {
1981              break;
1982            }
1983            }
1984          } while (--i);
1985          return true;
1986        } catch (...) {
1987          handleError();
1988          return false;
1989        }
1990      }
1991
1992      void foo(bool b) {
1993        if (b) {
1994          baz(2);
1995        } else {
1996          baz(5);
1997        }
1998      }
1999
2000      void bar() { foo(true); }
2001      } // namespace N
2002
2003  * ``BS_Linux`` (in configuration: ``Linux``)
2004    Like ``Attach``, but break before braces on function, namespace and
2005    class definitions.
2006
2007    .. code-block:: c++
2008
2009      namespace N
2010      {
2011      enum E {
2012        E1,
2013        E2,
2014      };
2015
2016      class C
2017      {
2018      public:
2019        C();
2020      };
2021
2022      bool baz(int i)
2023      {
2024        try {
2025          do {
2026            switch (i) {
2027            case 1: {
2028              foobar();
2029              break;
2030            }
2031            default: {
2032              break;
2033            }
2034            }
2035          } while (--i);
2036          return true;
2037        } catch (...) {
2038          handleError();
2039          return false;
2040        }
2041      }
2042
2043      void foo(bool b)
2044      {
2045        if (b) {
2046          baz(2);
2047        } else {
2048          baz(5);
2049        }
2050      }
2051
2052      void bar() { foo(true); }
2053      } // namespace N
2054
2055  * ``BS_Mozilla`` (in configuration: ``Mozilla``)
2056    Like ``Attach``, but break before braces on enum, function, and record
2057    definitions.
2058
2059    .. code-block:: c++
2060
2061      namespace N {
2062      enum E
2063      {
2064        E1,
2065        E2,
2066      };
2067
2068      class C
2069      {
2070      public:
2071        C();
2072      };
2073
2074      bool baz(int i)
2075      {
2076        try {
2077          do {
2078            switch (i) {
2079            case 1: {
2080              foobar();
2081              break;
2082            }
2083            default: {
2084              break;
2085            }
2086            }
2087          } while (--i);
2088          return true;
2089        } catch (...) {
2090          handleError();
2091          return false;
2092        }
2093      }
2094
2095      void foo(bool b)
2096      {
2097        if (b) {
2098          baz(2);
2099        } else {
2100          baz(5);
2101        }
2102      }
2103
2104      void bar() { foo(true); }
2105      } // namespace N
2106
2107  * ``BS_Stroustrup`` (in configuration: ``Stroustrup``)
2108    Like ``Attach``, but break before function definitions, ``catch``, and
2109    ``else``.
2110
2111    .. code-block:: c++
2112
2113      namespace N {
2114      enum E {
2115        E1,
2116        E2,
2117      };
2118
2119      class C {
2120      public:
2121        C();
2122      };
2123
2124      bool baz(int i)
2125      {
2126        try {
2127          do {
2128            switch (i) {
2129            case 1: {
2130              foobar();
2131              break;
2132            }
2133            default: {
2134              break;
2135            }
2136            }
2137          } while (--i);
2138          return true;
2139        }
2140        catch (...) {
2141          handleError();
2142          return false;
2143        }
2144      }
2145
2146      void foo(bool b)
2147      {
2148        if (b) {
2149          baz(2);
2150        }
2151        else {
2152          baz(5);
2153        }
2154      }
2155
2156      void bar() { foo(true); }
2157      } // namespace N
2158
2159  * ``BS_Allman`` (in configuration: ``Allman``)
2160    Always break before braces.
2161
2162    .. code-block:: c++
2163
2164      namespace N
2165      {
2166      enum E
2167      {
2168        E1,
2169        E2,
2170      };
2171
2172      class C
2173      {
2174      public:
2175        C();
2176      };
2177
2178      bool baz(int i)
2179      {
2180        try
2181        {
2182          do
2183          {
2184            switch (i)
2185            {
2186            case 1:
2187            {
2188              foobar();
2189              break;
2190            }
2191            default:
2192            {
2193              break;
2194            }
2195            }
2196          } while (--i);
2197          return true;
2198        }
2199        catch (...)
2200        {
2201          handleError();
2202          return false;
2203        }
2204      }
2205
2206      void foo(bool b)
2207      {
2208        if (b)
2209        {
2210          baz(2);
2211        }
2212        else
2213        {
2214          baz(5);
2215        }
2216      }
2217
2218      void bar() { foo(true); }
2219      } // namespace N
2220
2221  * ``BS_Whitesmiths`` (in configuration: ``Whitesmiths``)
2222    Like ``Allman`` but always indent braces and line up code with braces.
2223
2224    .. code-block:: c++
2225
2226      namespace N
2227        {
2228      enum E
2229        {
2230        E1,
2231        E2,
2232        };
2233
2234      class C
2235        {
2236      public:
2237        C();
2238        };
2239
2240      bool baz(int i)
2241        {
2242        try
2243          {
2244          do
2245            {
2246            switch (i)
2247              {
2248              case 1:
2249              {
2250              foobar();
2251              break;
2252              }
2253              default:
2254              {
2255              break;
2256              }
2257              }
2258            } while (--i);
2259          return true;
2260          }
2261        catch (...)
2262          {
2263          handleError();
2264          return false;
2265          }
2266        }
2267
2268      void foo(bool b)
2269        {
2270        if (b)
2271          {
2272          baz(2);
2273          }
2274        else
2275          {
2276          baz(5);
2277          }
2278        }
2279
2280      void bar() { foo(true); }
2281        } // namespace N
2282
2283  * ``BS_GNU`` (in configuration: ``GNU``)
2284    Always break before braces and add an extra level of indentation to
2285    braces of control statements, not to those of class, function
2286    or other definitions.
2287
2288    .. code-block:: c++
2289
2290      namespace N
2291      {
2292      enum E
2293      {
2294        E1,
2295        E2,
2296      };
2297
2298      class C
2299      {
2300      public:
2301        C();
2302      };
2303
2304      bool baz(int i)
2305      {
2306        try
2307          {
2308            do
2309              {
2310                switch (i)
2311                  {
2312                  case 1:
2313                    {
2314                      foobar();
2315                      break;
2316                    }
2317                  default:
2318                    {
2319                      break;
2320                    }
2321                  }
2322              }
2323            while (--i);
2324            return true;
2325          }
2326        catch (...)
2327          {
2328            handleError();
2329            return false;
2330          }
2331      }
2332
2333      void foo(bool b)
2334      {
2335        if (b)
2336          {
2337            baz(2);
2338          }
2339        else
2340          {
2341            baz(5);
2342          }
2343      }
2344
2345      void bar() { foo(true); }
2346      } // namespace N
2347
2348  * ``BS_WebKit`` (in configuration: ``WebKit``)
2349    Like ``Attach``, but break before functions.
2350
2351    .. code-block:: c++
2352
2353      namespace N {
2354      enum E {
2355        E1,
2356        E2,
2357      };
2358
2359      class C {
2360      public:
2361        C();
2362      };
2363
2364      bool baz(int i)
2365      {
2366        try {
2367          do {
2368            switch (i) {
2369            case 1: {
2370              foobar();
2371              break;
2372            }
2373            default: {
2374              break;
2375            }
2376            }
2377          } while (--i);
2378          return true;
2379        } catch (...) {
2380          handleError();
2381          return false;
2382        }
2383      }
2384
2385      void foo(bool b)
2386      {
2387        if (b) {
2388          baz(2);
2389        } else {
2390          baz(5);
2391        }
2392      }
2393
2394      void bar() { foo(true); }
2395      } // namespace N
2396
2397  * ``BS_Custom`` (in configuration: ``Custom``)
2398    Configure each individual brace in `BraceWrapping`.
2399
2400
2401
2402.. _BreakBeforeConceptDeclarations:
2403
2404**BreakBeforeConceptDeclarations** (``BreakBeforeConceptDeclarationsStyle``) :versionbadge:`clang-format 12` :ref:`¶ <BreakBeforeConceptDeclarations>`
2405  The concept declaration style to use.
2406
2407  Possible values:
2408
2409  * ``BBCDS_Never`` (in configuration: ``Never``)
2410    Keep the template declaration line together with ``concept``.
2411
2412    .. code-block:: c++
2413
2414      template <typename T> concept C = ...;
2415
2416  * ``BBCDS_Allowed`` (in configuration: ``Allowed``)
2417    Breaking between template declaration and ``concept`` is allowed. The
2418    actual behavior depends on the content and line breaking rules and
2419    penalities.
2420
2421  * ``BBCDS_Always`` (in configuration: ``Always``)
2422    Always break before ``concept``, putting it in the line after the
2423    template declaration.
2424
2425    .. code-block:: c++
2426
2427      template <typename T>
2428      concept C = ...;
2429
2430
2431
2432.. _BreakBeforeInlineASMColon:
2433
2434**BreakBeforeInlineASMColon** (``BreakBeforeInlineASMColonStyle``) :versionbadge:`clang-format 16` :ref:`¶ <BreakBeforeInlineASMColon>`
2435  The inline ASM colon style to use.
2436
2437  Possible values:
2438
2439  * ``BBIAS_Never`` (in configuration: ``Never``)
2440    No break before inline ASM colon.
2441
2442    .. code-block:: c++
2443
2444       asm volatile("string", : : val);
2445
2446  * ``BBIAS_OnlyMultiline`` (in configuration: ``OnlyMultiline``)
2447    Break before inline ASM colon if the line length is longer than column
2448    limit.
2449
2450    .. code-block:: c++
2451
2452       asm volatile("string", : : val);
2453       asm("cmoveq %1, %2, %[result]"
2454           : [result] "=r"(result)
2455           : "r"(test), "r"(new), "[result]"(old));
2456
2457  * ``BBIAS_Always`` (in configuration: ``Always``)
2458    Always break before inline ASM colon.
2459
2460    .. code-block:: c++
2461
2462       asm volatile("string",
2463                    :
2464                    : val);
2465
2466
2467
2468.. _BreakBeforeTernaryOperators:
2469
2470**BreakBeforeTernaryOperators** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <BreakBeforeTernaryOperators>`
2471  If ``true``, ternary operators will be placed after line breaks.
2472
2473  .. code-block:: c++
2474
2475     true:
2476     veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription
2477         ? firstValue
2478         : SecondValueVeryVeryVeryVeryLong;
2479
2480     false:
2481     veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ?
2482         firstValue :
2483         SecondValueVeryVeryVeryVeryLong;
2484
2485.. _BreakConstructorInitializers:
2486
2487**BreakConstructorInitializers** (``BreakConstructorInitializersStyle``) :versionbadge:`clang-format 5` :ref:`¶ <BreakConstructorInitializers>`
2488  The break constructor initializers style to use.
2489
2490  Possible values:
2491
2492  * ``BCIS_BeforeColon`` (in configuration: ``BeforeColon``)
2493    Break constructor initializers before the colon and after the commas.
2494
2495    .. code-block:: c++
2496
2497       Constructor()
2498           : initializer1(),
2499             initializer2()
2500
2501  * ``BCIS_BeforeComma`` (in configuration: ``BeforeComma``)
2502    Break constructor initializers before the colon and commas, and align
2503    the commas with the colon.
2504
2505    .. code-block:: c++
2506
2507       Constructor()
2508           : initializer1()
2509           , initializer2()
2510
2511  * ``BCIS_AfterColon`` (in configuration: ``AfterColon``)
2512    Break constructor initializers after the colon and commas.
2513
2514    .. code-block:: c++
2515
2516       Constructor() :
2517           initializer1(),
2518           initializer2()
2519
2520
2521
2522.. _BreakInheritanceList:
2523
2524**BreakInheritanceList** (``BreakInheritanceListStyle``) :versionbadge:`clang-format 7` :ref:`¶ <BreakInheritanceList>`
2525  The inheritance list style to use.
2526
2527  Possible values:
2528
2529  * ``BILS_BeforeColon`` (in configuration: ``BeforeColon``)
2530    Break inheritance list before the colon and after the commas.
2531
2532    .. code-block:: c++
2533
2534       class Foo
2535           : Base1,
2536             Base2
2537       {};
2538
2539  * ``BILS_BeforeComma`` (in configuration: ``BeforeComma``)
2540    Break inheritance list before the colon and commas, and align
2541    the commas with the colon.
2542
2543    .. code-block:: c++
2544
2545       class Foo
2546           : Base1
2547           , Base2
2548       {};
2549
2550  * ``BILS_AfterColon`` (in configuration: ``AfterColon``)
2551    Break inheritance list after the colon and commas.
2552
2553    .. code-block:: c++
2554
2555       class Foo :
2556           Base1,
2557           Base2
2558       {};
2559
2560  * ``BILS_AfterComma`` (in configuration: ``AfterComma``)
2561    Break inheritance list only after the commas.
2562
2563    .. code-block:: c++
2564
2565       class Foo : Base1,
2566                   Base2
2567       {};
2568
2569
2570
2571.. _BreakStringLiterals:
2572
2573**BreakStringLiterals** (``Boolean``) :versionbadge:`clang-format 3.9` :ref:`¶ <BreakStringLiterals>`
2574  Allow breaking string literals when formatting.
2575
2576  .. code-block:: c++
2577
2578     true:
2579     const char* x = "veryVeryVeryVeryVeryVe"
2580                     "ryVeryVeryVeryVeryVery"
2581                     "VeryLongString";
2582
2583     false:
2584     const char* x =
2585       "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
2586
2587.. _ColumnLimit:
2588
2589**ColumnLimit** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <ColumnLimit>`
2590  The column limit.
2591
2592  A column limit of ``0`` means that there is no column limit. In this case,
2593  clang-format will respect the input's line breaking decisions within
2594  statements unless they contradict other rules.
2595
2596.. _CommentPragmas:
2597
2598**CommentPragmas** (``String``) :versionbadge:`clang-format 3.7` :ref:`¶ <CommentPragmas>`
2599  A regular expression that describes comments with special meaning,
2600  which should not be split into lines or otherwise changed.
2601
2602  .. code-block:: c++
2603
2604     // CommentPragmas: '^ FOOBAR pragma:'
2605     // Will leave the following line unaffected
2606     #include <vector> // FOOBAR pragma: keep
2607
2608.. _CompactNamespaces:
2609
2610**CompactNamespaces** (``Boolean``) :versionbadge:`clang-format 5` :ref:`¶ <CompactNamespaces>`
2611  If ``true``, consecutive namespace declarations will be on the same
2612  line. If ``false``, each namespace is declared on a new line.
2613
2614  .. code-block:: c++
2615
2616    true:
2617    namespace Foo { namespace Bar {
2618    }}
2619
2620    false:
2621    namespace Foo {
2622    namespace Bar {
2623    }
2624    }
2625
2626  If it does not fit on a single line, the overflowing namespaces get
2627  wrapped:
2628
2629  .. code-block:: c++
2630
2631    namespace Foo { namespace Bar {
2632    namespace Extra {
2633    }}}
2634
2635.. _ConstructorInitializerAllOnOneLineOrOnePerLine:
2636
2637**ConstructorInitializerAllOnOneLineOrOnePerLine** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <ConstructorInitializerAllOnOneLineOrOnePerLine>`
2638  This option is **deprecated**. See ``CurrentLine`` of
2639  ``PackConstructorInitializers``.
2640
2641.. _ConstructorInitializerIndentWidth:
2642
2643**ConstructorInitializerIndentWidth** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <ConstructorInitializerIndentWidth>`
2644  The number of characters to use for indentation of constructor
2645  initializer lists as well as inheritance lists.
2646
2647.. _ContinuationIndentWidth:
2648
2649**ContinuationIndentWidth** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <ContinuationIndentWidth>`
2650  Indent width for line continuations.
2651
2652  .. code-block:: c++
2653
2654     ContinuationIndentWidth: 2
2655
2656     int i =         //  VeryVeryVeryVeryVeryLongComment
2657       longFunction( // Again a long comment
2658         arg);
2659
2660.. _Cpp11BracedListStyle:
2661
2662**Cpp11BracedListStyle** (``Boolean``) :versionbadge:`clang-format 3.4` :ref:`¶ <Cpp11BracedListStyle>`
2663  If ``true``, format braced lists as best suited for C++11 braced
2664  lists.
2665
2666  Important differences:
2667  - No spaces inside the braced list.
2668  - No line break before the closing brace.
2669  - Indentation with the continuation indent, not with the block indent.
2670
2671  Fundamentally, C++11 braced lists are formatted exactly like function
2672  calls would be formatted in their place. If the braced list follows a name
2673  (e.g. a type or variable name), clang-format formats as if the ``{}`` were
2674  the parentheses of a function call with that name. If there is no name,
2675  a zero-length name is assumed.
2676
2677  .. code-block:: c++
2678
2679     true:                                  false:
2680     vector<int> x{1, 2, 3, 4};     vs.     vector<int> x{ 1, 2, 3, 4 };
2681     vector<T> x{{}, {}, {}, {}};           vector<T> x{ {}, {}, {}, {} };
2682     f(MyMap[{composite, key}]);            f(MyMap[{ composite, key }]);
2683     new int[3]{1, 2, 3};                   new int[3]{ 1, 2, 3 };
2684
2685.. _DeriveLineEnding:
2686
2687**DeriveLineEnding** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ <DeriveLineEnding>`
2688  This option is **deprecated**. See ``DeriveLF`` and ``DeriveCRLF`` of
2689  ``LineEnding``.
2690
2691.. _DerivePointerAlignment:
2692
2693**DerivePointerAlignment** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <DerivePointerAlignment>`
2694  If ``true``, analyze the formatted file for the most common
2695  alignment of ``&`` and ``*``.
2696  Pointer and reference alignment styles are going to be updated according
2697  to the preferences found in the file.
2698  ``PointerAlignment`` is then used only as fallback.
2699
2700.. _DisableFormat:
2701
2702**DisableFormat** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <DisableFormat>`
2703  Disables formatting completely.
2704
2705.. _EmptyLineAfterAccessModifier:
2706
2707**EmptyLineAfterAccessModifier** (``EmptyLineAfterAccessModifierStyle``) :versionbadge:`clang-format 13` :ref:`¶ <EmptyLineAfterAccessModifier>`
2708  Defines when to put an empty line after access modifiers.
2709  ``EmptyLineBeforeAccessModifier`` configuration handles the number of
2710  empty lines between two access modifiers.
2711
2712  Possible values:
2713
2714  * ``ELAAMS_Never`` (in configuration: ``Never``)
2715    Remove all empty lines after access modifiers.
2716
2717    .. code-block:: c++
2718
2719      struct foo {
2720      private:
2721        int i;
2722      protected:
2723        int j;
2724        /* comment */
2725      public:
2726        foo() {}
2727      private:
2728      protected:
2729      };
2730
2731  * ``ELAAMS_Leave`` (in configuration: ``Leave``)
2732    Keep existing empty lines after access modifiers.
2733    MaxEmptyLinesToKeep is applied instead.
2734
2735  * ``ELAAMS_Always`` (in configuration: ``Always``)
2736    Always add empty line after access modifiers if there are none.
2737    MaxEmptyLinesToKeep is applied also.
2738
2739    .. code-block:: c++
2740
2741      struct foo {
2742      private:
2743
2744        int i;
2745      protected:
2746
2747        int j;
2748        /* comment */
2749      public:
2750
2751        foo() {}
2752      private:
2753
2754      protected:
2755
2756      };
2757
2758
2759
2760.. _EmptyLineBeforeAccessModifier:
2761
2762**EmptyLineBeforeAccessModifier** (``EmptyLineBeforeAccessModifierStyle``) :versionbadge:`clang-format 12` :ref:`¶ <EmptyLineBeforeAccessModifier>`
2763  Defines in which cases to put empty line before access modifiers.
2764
2765  Possible values:
2766
2767  * ``ELBAMS_Never`` (in configuration: ``Never``)
2768    Remove all empty lines before access modifiers.
2769
2770    .. code-block:: c++
2771
2772      struct foo {
2773      private:
2774        int i;
2775      protected:
2776        int j;
2777        /* comment */
2778      public:
2779        foo() {}
2780      private:
2781      protected:
2782      };
2783
2784  * ``ELBAMS_Leave`` (in configuration: ``Leave``)
2785    Keep existing empty lines before access modifiers.
2786
2787  * ``ELBAMS_LogicalBlock`` (in configuration: ``LogicalBlock``)
2788    Add empty line only when access modifier starts a new logical block.
2789    Logical block is a group of one or more member fields or functions.
2790
2791    .. code-block:: c++
2792
2793      struct foo {
2794      private:
2795        int i;
2796
2797      protected:
2798        int j;
2799        /* comment */
2800      public:
2801        foo() {}
2802
2803      private:
2804      protected:
2805      };
2806
2807  * ``ELBAMS_Always`` (in configuration: ``Always``)
2808    Always add empty line before access modifiers unless access modifier
2809    is at the start of struct or class definition.
2810
2811    .. code-block:: c++
2812
2813      struct foo {
2814      private:
2815        int i;
2816
2817      protected:
2818        int j;
2819        /* comment */
2820
2821      public:
2822        foo() {}
2823
2824      private:
2825
2826      protected:
2827      };
2828
2829
2830
2831.. _ExperimentalAutoDetectBinPacking:
2832
2833**ExperimentalAutoDetectBinPacking** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <ExperimentalAutoDetectBinPacking>`
2834  If ``true``, clang-format detects whether function calls and
2835  definitions are formatted with one parameter per line.
2836
2837  Each call can be bin-packed, one-per-line or inconclusive. If it is
2838  inconclusive, e.g. completely on one line, but a decision needs to be
2839  made, clang-format analyzes whether there are other bin-packed cases in
2840  the input file and act accordingly.
2841
2842  NOTE: This is an experimental flag, that might go away or be renamed. Do
2843  not use this in config files, etc. Use at your own risk.
2844
2845.. _FixNamespaceComments:
2846
2847**FixNamespaceComments** (``Boolean``) :versionbadge:`clang-format 5` :ref:`¶ <FixNamespaceComments>`
2848  If ``true``, clang-format adds missing namespace end comments for
2849  namespaces and fixes invalid existing ones. This doesn't affect short
2850  namespaces, which are controlled by ``ShortNamespaceLines``.
2851
2852  .. code-block:: c++
2853
2854     true:                                  false:
2855     namespace longNamespace {      vs.     namespace longNamespace {
2856     void foo();                            void foo();
2857     void bar();                            void bar();
2858     } // namespace a                       }
2859     namespace shortNamespace {             namespace shortNamespace {
2860     void baz();                            void baz();
2861     }                                      }
2862
2863.. _ForEachMacros:
2864
2865**ForEachMacros** (``List of Strings``) :versionbadge:`clang-format 3.7` :ref:`¶ <ForEachMacros>`
2866  A vector of macros that should be interpreted as foreach loops
2867  instead of as function calls.
2868
2869  These are expected to be macros of the form:
2870
2871  .. code-block:: c++
2872
2873    FOREACH(<variable-declaration>, ...)
2874      <loop-body>
2875
2876  In the .clang-format configuration file, this can be configured like:
2877
2878  .. code-block:: yaml
2879
2880    ForEachMacros: ['RANGES_FOR', 'FOREACH']
2881
2882  For example: BOOST_FOREACH.
2883
2884.. _IfMacros:
2885
2886**IfMacros** (``List of Strings``) :versionbadge:`clang-format 13` :ref:`¶ <IfMacros>`
2887  A vector of macros that should be interpreted as conditionals
2888  instead of as function calls.
2889
2890  These are expected to be macros of the form:
2891
2892  .. code-block:: c++
2893
2894    IF(...)
2895      <conditional-body>
2896    else IF(...)
2897      <conditional-body>
2898
2899  In the .clang-format configuration file, this can be configured like:
2900
2901  .. code-block:: yaml
2902
2903    IfMacros: ['IF']
2904
2905  For example: `KJ_IF_MAYBE
2906  <https://github.com/capnproto/capnproto/blob/master/kjdoc/tour.md#maybes>`_
2907
2908.. _IncludeBlocks:
2909
2910**IncludeBlocks** (``IncludeBlocksStyle``) :versionbadge:`clang-format 6` :ref:`¶ <IncludeBlocks>`
2911  Dependent on the value, multiple ``#include`` blocks can be sorted
2912  as one and divided based on category.
2913
2914  Possible values:
2915
2916  * ``IBS_Preserve`` (in configuration: ``Preserve``)
2917    Sort each ``#include`` block separately.
2918
2919    .. code-block:: c++
2920
2921       #include "b.h"               into      #include "b.h"
2922
2923       #include <lib/main.h>                  #include "a.h"
2924       #include "a.h"                         #include <lib/main.h>
2925
2926  * ``IBS_Merge`` (in configuration: ``Merge``)
2927    Merge multiple ``#include`` blocks together and sort as one.
2928
2929    .. code-block:: c++
2930
2931       #include "b.h"               into      #include "a.h"
2932                                              #include "b.h"
2933       #include <lib/main.h>                  #include <lib/main.h>
2934       #include "a.h"
2935
2936  * ``IBS_Regroup`` (in configuration: ``Regroup``)
2937    Merge multiple ``#include`` blocks together and sort as one.
2938    Then split into groups based on category priority. See
2939    ``IncludeCategories``.
2940
2941    .. code-block:: c++
2942
2943       #include "b.h"               into      #include "a.h"
2944                                              #include "b.h"
2945       #include <lib/main.h>
2946       #include "a.h"                         #include <lib/main.h>
2947
2948
2949
2950.. _IncludeCategories:
2951
2952**IncludeCategories** (``List of IncludeCategories``) :versionbadge:`clang-format 3.8` :ref:`¶ <IncludeCategories>`
2953  Regular expressions denoting the different ``#include`` categories
2954  used for ordering ``#includes``.
2955
2956  `POSIX extended
2957  <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html>`_
2958  regular expressions are supported.
2959
2960  These regular expressions are matched against the filename of an include
2961  (including the <> or "") in order. The value belonging to the first
2962  matching regular expression is assigned and ``#includes`` are sorted first
2963  according to increasing category number and then alphabetically within
2964  each category.
2965
2966  If none of the regular expressions match, INT_MAX is assigned as
2967  category. The main header for a source file automatically gets category 0.
2968  so that it is generally kept at the beginning of the ``#includes``
2969  (https://llvm.org/docs/CodingStandards.html#include-style). However, you
2970  can also assign negative priorities if you have certain headers that
2971  always need to be first.
2972
2973  There is a third and optional field ``SortPriority`` which can used while
2974  ``IncludeBlocks = IBS_Regroup`` to define the priority in which
2975  ``#includes`` should be ordered. The value of ``Priority`` defines the
2976  order of ``#include blocks`` and also allows the grouping of ``#includes``
2977  of different priority. ``SortPriority`` is set to the value of
2978  ``Priority`` as default if it is not assigned.
2979
2980  Each regular expression can be marked as case sensitive with the field
2981  ``CaseSensitive``, per default it is not.
2982
2983  To configure this in the .clang-format file, use:
2984
2985  .. code-block:: yaml
2986
2987    IncludeCategories:
2988      - Regex:           '^"(llvm|llvm-c|clang|clang-c)/'
2989        Priority:        2
2990        SortPriority:    2
2991        CaseSensitive:   true
2992      - Regex:           '^((<|")(gtest|gmock|isl|json)/)'
2993        Priority:        3
2994      - Regex:           '<[[:alnum:].]+>'
2995        Priority:        4
2996      - Regex:           '.*'
2997        Priority:        1
2998        SortPriority:    0
2999
3000.. _IncludeIsMainRegex:
3001
3002**IncludeIsMainRegex** (``String``) :versionbadge:`clang-format 3.9` :ref:`¶ <IncludeIsMainRegex>`
3003  Specify a regular expression of suffixes that are allowed in the
3004  file-to-main-include mapping.
3005
3006  When guessing whether a #include is the "main" include (to assign
3007  category 0, see above), use this regex of allowed suffixes to the header
3008  stem. A partial match is done, so that:
3009  - "" means "arbitrary suffix"
3010  - "$" means "no suffix"
3011
3012  For example, if configured to "(_test)?$", then a header a.h would be seen
3013  as the "main" include in both a.cc and a_test.cc.
3014
3015.. _IncludeIsMainSourceRegex:
3016
3017**IncludeIsMainSourceRegex** (``String``) :versionbadge:`clang-format 10` :ref:`¶ <IncludeIsMainSourceRegex>`
3018  Specify a regular expression for files being formatted
3019  that are allowed to be considered "main" in the
3020  file-to-main-include mapping.
3021
3022  By default, clang-format considers files as "main" only when they end
3023  with: ``.c``, ``.cc``, ``.cpp``, ``.c++``, ``.cxx``, ``.m`` or ``.mm``
3024  extensions.
3025  For these files a guessing of "main" include takes place
3026  (to assign category 0, see above). This config option allows for
3027  additional suffixes and extensions for files to be considered as "main".
3028
3029  For example, if this option is configured to ``(Impl\.hpp)$``,
3030  then a file ``ClassImpl.hpp`` is considered "main" (in addition to
3031  ``Class.c``, ``Class.cc``, ``Class.cpp`` and so on) and "main
3032  include file" logic will be executed (with *IncludeIsMainRegex* setting
3033  also being respected in later phase). Without this option set,
3034  ``ClassImpl.hpp`` would not have the main include file put on top
3035  before any other include.
3036
3037.. _IndentAccessModifiers:
3038
3039**IndentAccessModifiers** (``Boolean``) :versionbadge:`clang-format 13` :ref:`¶ <IndentAccessModifiers>`
3040  Specify whether access modifiers should have their own indentation level.
3041
3042  When ``false``, access modifiers are indented (or outdented) relative to
3043  the record members, respecting the ``AccessModifierOffset``. Record
3044  members are indented one level below the record.
3045  When ``true``, access modifiers get their own indentation level. As a
3046  consequence, record members are always indented 2 levels below the record,
3047  regardless of the access modifier presence. Value of the
3048  ``AccessModifierOffset`` is ignored.
3049
3050  .. code-block:: c++
3051
3052     false:                                 true:
3053     class C {                      vs.     class C {
3054       class D {                                class D {
3055         void bar();                                void bar();
3056       protected:                                 protected:
3057         D();                                       D();
3058       };                                       };
3059     public:                                  public:
3060       C();                                     C();
3061     };                                     };
3062     void foo() {                           void foo() {
3063       return 1;                              return 1;
3064     }                                      }
3065
3066.. _IndentCaseBlocks:
3067
3068**IndentCaseBlocks** (``Boolean``) :versionbadge:`clang-format 11` :ref:`¶ <IndentCaseBlocks>`
3069  Indent case label blocks one level from the case label.
3070
3071  When ``false``, the block following the case label uses the same
3072  indentation level as for the case label, treating the case label the same
3073  as an if-statement.
3074  When ``true``, the block gets indented as a scope block.
3075
3076  .. code-block:: c++
3077
3078     false:                                 true:
3079     switch (fool) {                vs.     switch (fool) {
3080     case 1: {                              case 1:
3081       bar();                                 {
3082     } break;                                   bar();
3083     default: {                               }
3084       plop();                                break;
3085     }                                      default:
3086     }                                        {
3087                                                plop();
3088                                              }
3089                                            }
3090
3091.. _IndentCaseLabels:
3092
3093**IndentCaseLabels** (``Boolean``) :versionbadge:`clang-format 3.3` :ref:`¶ <IndentCaseLabels>`
3094  Indent case labels one level from the switch statement.
3095
3096  When ``false``, use the same indentation level as for the switch
3097  statement. Switch statement body is always indented one level more than
3098  case labels (except the first block following the case label, which
3099  itself indents the code - unless IndentCaseBlocks is enabled).
3100
3101  .. code-block:: c++
3102
3103     false:                                 true:
3104     switch (fool) {                vs.     switch (fool) {
3105     case 1:                                  case 1:
3106       bar();                                   bar();
3107       break;                                   break;
3108     default:                                 default:
3109       plop();                                  plop();
3110     }                                      }
3111
3112.. _IndentExternBlock:
3113
3114**IndentExternBlock** (``IndentExternBlockStyle``) :versionbadge:`clang-format 11` :ref:`¶ <IndentExternBlock>`
3115  IndentExternBlockStyle is the type of indenting of extern blocks.
3116
3117  Possible values:
3118
3119  * ``IEBS_AfterExternBlock`` (in configuration: ``AfterExternBlock``)
3120    Backwards compatible with AfterExternBlock's indenting.
3121
3122    .. code-block:: c++
3123
3124       IndentExternBlock: AfterExternBlock
3125       BraceWrapping.AfterExternBlock: true
3126       extern "C"
3127       {
3128           void foo();
3129       }
3130
3131
3132    .. code-block:: c++
3133
3134       IndentExternBlock: AfterExternBlock
3135       BraceWrapping.AfterExternBlock: false
3136       extern "C" {
3137       void foo();
3138       }
3139
3140  * ``IEBS_NoIndent`` (in configuration: ``NoIndent``)
3141    Does not indent extern blocks.
3142
3143    .. code-block:: c++
3144
3145        extern "C" {
3146        void foo();
3147        }
3148
3149  * ``IEBS_Indent`` (in configuration: ``Indent``)
3150    Indents extern blocks.
3151
3152    .. code-block:: c++
3153
3154        extern "C" {
3155          void foo();
3156        }
3157
3158
3159
3160.. _IndentGotoLabels:
3161
3162**IndentGotoLabels** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ <IndentGotoLabels>`
3163  Indent goto labels.
3164
3165  When ``false``, goto labels are flushed left.
3166
3167  .. code-block:: c++
3168
3169     true:                                  false:
3170     int f() {                      vs.     int f() {
3171       if (foo()) {                           if (foo()) {
3172       label1:                              label1:
3173         bar();                                 bar();
3174       }                                      }
3175     label2:                                label2:
3176       return 1;                              return 1;
3177     }                                      }
3178
3179.. _IndentPPDirectives:
3180
3181**IndentPPDirectives** (``PPDirectiveIndentStyle``) :versionbadge:`clang-format 6` :ref:`¶ <IndentPPDirectives>`
3182  The preprocessor directive indenting style to use.
3183
3184  Possible values:
3185
3186  * ``PPDIS_None`` (in configuration: ``None``)
3187    Does not indent any directives.
3188
3189    .. code-block:: c++
3190
3191       #if FOO
3192       #if BAR
3193       #include <foo>
3194       #endif
3195       #endif
3196
3197  * ``PPDIS_AfterHash`` (in configuration: ``AfterHash``)
3198    Indents directives after the hash.
3199
3200    .. code-block:: c++
3201
3202       #if FOO
3203       #  if BAR
3204       #    include <foo>
3205       #  endif
3206       #endif
3207
3208  * ``PPDIS_BeforeHash`` (in configuration: ``BeforeHash``)
3209    Indents directives before the hash.
3210
3211    .. code-block:: c++
3212
3213       #if FOO
3214         #if BAR
3215           #include <foo>
3216         #endif
3217       #endif
3218
3219
3220
3221.. _IndentRequiresClause:
3222
3223**IndentRequiresClause** (``Boolean``) :versionbadge:`clang-format 15` :ref:`¶ <IndentRequiresClause>`
3224  Indent the requires clause in a template. This only applies when
3225  ``RequiresClausePosition`` is ``OwnLine``, or ``WithFollowing``.
3226
3227  In clang-format 12, 13 and 14 it was named ``IndentRequires``.
3228
3229  .. code-block:: c++
3230
3231     true:
3232     template <typename It>
3233       requires Iterator<It>
3234     void sort(It begin, It end) {
3235       //....
3236     }
3237
3238     false:
3239     template <typename It>
3240     requires Iterator<It>
3241     void sort(It begin, It end) {
3242       //....
3243     }
3244
3245.. _IndentWidth:
3246
3247**IndentWidth** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <IndentWidth>`
3248  The number of columns to use for indentation.
3249
3250  .. code-block:: c++
3251
3252     IndentWidth: 3
3253
3254     void f() {
3255        someFunction();
3256        if (true, false) {
3257           f();
3258        }
3259     }
3260
3261.. _IndentWrappedFunctionNames:
3262
3263**IndentWrappedFunctionNames** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <IndentWrappedFunctionNames>`
3264  Indent if a function definition or declaration is wrapped after the
3265  type.
3266
3267  .. code-block:: c++
3268
3269     true:
3270     LoooooooooooooooooooooooooooooooooooooooongReturnType
3271         LoooooooooooooooooooooooooooooooongFunctionDeclaration();
3272
3273     false:
3274     LoooooooooooooooooooooooooooooooooooooooongReturnType
3275     LoooooooooooooooooooooooooooooooongFunctionDeclaration();
3276
3277.. _InsertBraces:
3278
3279**InsertBraces** (``Boolean``) :versionbadge:`clang-format 15` :ref:`¶ <InsertBraces>`
3280  Insert braces after control statements (``if``, ``else``, ``for``, ``do``,
3281  and ``while``) in C++ unless the control statements are inside macro
3282  definitions or the braces would enclose preprocessor directives.
3283
3284  .. warning::
3285
3286   Setting this option to `true` could lead to incorrect code formatting due
3287   to clang-format's lack of complete semantic information. As such, extra
3288   care should be taken to review code changes made by this option.
3289
3290  .. code-block:: c++
3291
3292    false:                                    true:
3293
3294    if (isa<FunctionDecl>(D))        vs.      if (isa<FunctionDecl>(D)) {
3295      handleFunctionDecl(D);                    handleFunctionDecl(D);
3296    else if (isa<VarDecl>(D))                 } else if (isa<VarDecl>(D)) {
3297      handleVarDecl(D);                         handleVarDecl(D);
3298    else                                      } else {
3299      return;                                   return;
3300                                              }
3301
3302    while (i--)                      vs.      while (i--) {
3303      for (auto *A : D.attrs())                 for (auto *A : D.attrs()) {
3304        handleAttr(A);                            handleAttr(A);
3305                                                }
3306                                              }
3307
3308    do                               vs.      do {
3309      --i;                                      --i;
3310    while (i);                                } while (i);
3311
3312.. _InsertNewlineAtEOF:
3313
3314**InsertNewlineAtEOF** (``Boolean``) :versionbadge:`clang-format 16` :ref:`¶ <InsertNewlineAtEOF>`
3315  Insert a newline at end of file if missing.
3316
3317.. _InsertTrailingCommas:
3318
3319**InsertTrailingCommas** (``TrailingCommaStyle``) :versionbadge:`clang-format 11` :ref:`¶ <InsertTrailingCommas>`
3320  If set to ``TCS_Wrapped`` will insert trailing commas in container
3321  literals (arrays and objects) that wrap across multiple lines.
3322  It is currently only available for JavaScript
3323  and disabled by default ``TCS_None``.
3324  ``InsertTrailingCommas`` cannot be used together with ``BinPackArguments``
3325  as inserting the comma disables bin-packing.
3326
3327  .. code-block:: c++
3328
3329    TSC_Wrapped:
3330    const someArray = [
3331    aaaaaaaaaaaaaaaaaaaaaaaaaa,
3332    aaaaaaaaaaaaaaaaaaaaaaaaaa,
3333    aaaaaaaaaaaaaaaaaaaaaaaaaa,
3334    //                        ^ inserted
3335    ]
3336
3337  Possible values:
3338
3339  * ``TCS_None`` (in configuration: ``None``)
3340    Do not insert trailing commas.
3341
3342  * ``TCS_Wrapped`` (in configuration: ``Wrapped``)
3343    Insert trailing commas in container literals that were wrapped over
3344    multiple lines. Note that this is conceptually incompatible with
3345    bin-packing, because the trailing comma is used as an indicator
3346    that a container should be formatted one-per-line (i.e. not bin-packed).
3347    So inserting a trailing comma counteracts bin-packing.
3348
3349
3350
3351.. _IntegerLiteralSeparator:
3352
3353**IntegerLiteralSeparator** (``IntegerLiteralSeparatorStyle``) :versionbadge:`clang-format 16` :ref:`¶ <IntegerLiteralSeparator>`
3354  Format integer literal separators (``'`` for C++ and ``_`` for C#, Java,
3355  and JavaScript).
3356
3357  Nested configuration flags:
3358
3359  Separator format of integer literals of different bases.
3360
3361  If negative, remove separators. If  ``0``, leave the literal as is. If
3362  positive, insert separators between digits starting from the rightmost
3363  digit.
3364
3365  For example, the config below will leave separators in binary literals
3366  alone, insert separators in decimal literals to separate the digits into
3367  groups of 3, and remove separators in hexadecimal literals.
3368
3369  .. code-block:: c++
3370
3371    IntegerLiteralSeparator:
3372      Binary: 0
3373      Decimal: 3
3374      Hex: -1
3375
3376  You can also specify a minimum number of digits (``BinaryMinDigits``,
3377  ``DecimalMinDigits``, and ``HexMinDigits``) the integer literal must
3378  have in order for the separators to be inserted.
3379
3380  * ``int8_t Binary`` Format separators in binary literals.
3381
3382    .. code-block:: text
3383
3384      /* -1: */ b = 0b100111101101;
3385      /*  0: */ b = 0b10011'11'0110'1;
3386      /*  3: */ b = 0b100'111'101'101;
3387      /*  4: */ b = 0b1001'1110'1101;
3388
3389  * ``int8_t BinaryMinDigits`` Format separators in binary literals with a minimum number of digits.
3390
3391    .. code-block:: text
3392
3393      // Binary: 3
3394      // BinaryMinDigits: 7
3395      b1 = 0b101101;
3396      b2 = 0b1'101'101;
3397
3398  * ``int8_t Decimal`` Format separators in decimal literals.
3399
3400    .. code-block:: text
3401
3402      /* -1: */ d = 18446744073709550592ull;
3403      /*  0: */ d = 184467'440737'0'95505'92ull;
3404      /*  3: */ d = 18'446'744'073'709'550'592ull;
3405
3406  * ``int8_t DecimalMinDigits`` Format separators in decimal literals with a minimum number of digits.
3407
3408    .. code-block:: text
3409
3410      // Decimal: 3
3411      // DecimalMinDigits: 5
3412      d1 = 2023;
3413      d2 = 10'000;
3414
3415  * ``int8_t Hex`` Format separators in hexadecimal literals.
3416
3417    .. code-block:: text
3418
3419      /* -1: */ h = 0xDEADBEEFDEADBEEFuz;
3420      /*  0: */ h = 0xDEAD'BEEF'DE'AD'BEE'Fuz;
3421      /*  2: */ h = 0xDE'AD'BE'EF'DE'AD'BE'EFuz;
3422
3423  * ``int8_t HexMinDigits`` Format separators in hexadecimal literals with a minimum number of
3424    digits.
3425
3426    .. code-block:: text
3427
3428      // Hex: 2
3429      // HexMinDigits: 6
3430      h1 = 0xABCDE;
3431      h2 = 0xAB'CD'EF;
3432
3433
3434.. _JavaImportGroups:
3435
3436**JavaImportGroups** (``List of Strings``) :versionbadge:`clang-format 8` :ref:`¶ <JavaImportGroups>`
3437  A vector of prefixes ordered by the desired groups for Java imports.
3438
3439  One group's prefix can be a subset of another - the longest prefix is
3440  always matched. Within a group, the imports are ordered lexicographically.
3441  Static imports are grouped separately and follow the same group rules.
3442  By default, static imports are placed before non-static imports,
3443  but this behavior is changed by another option,
3444  ``SortJavaStaticImport``.
3445
3446  In the .clang-format configuration file, this can be configured like
3447  in the following yaml example. This will result in imports being
3448  formatted as in the Java example below.
3449
3450  .. code-block:: yaml
3451
3452    JavaImportGroups: ['com.example', 'com', 'org']
3453
3454
3455  .. code-block:: java
3456
3457     import static com.example.function1;
3458
3459     import static com.test.function2;
3460
3461     import static org.example.function3;
3462
3463     import com.example.ClassA;
3464     import com.example.Test;
3465     import com.example.a.ClassB;
3466
3467     import com.test.ClassC;
3468
3469     import org.example.ClassD;
3470
3471.. _JavaScriptQuotes:
3472
3473**JavaScriptQuotes** (``JavaScriptQuoteStyle``) :versionbadge:`clang-format 3.9` :ref:`¶ <JavaScriptQuotes>`
3474  The JavaScriptQuoteStyle to use for JavaScript strings.
3475
3476  Possible values:
3477
3478  * ``JSQS_Leave`` (in configuration: ``Leave``)
3479    Leave string quotes as they are.
3480
3481    .. code-block:: js
3482
3483       string1 = "foo";
3484       string2 = 'bar';
3485
3486  * ``JSQS_Single`` (in configuration: ``Single``)
3487    Always use single quotes.
3488
3489    .. code-block:: js
3490
3491       string1 = 'foo';
3492       string2 = 'bar';
3493
3494  * ``JSQS_Double`` (in configuration: ``Double``)
3495    Always use double quotes.
3496
3497    .. code-block:: js
3498
3499       string1 = "foo";
3500       string2 = "bar";
3501
3502
3503
3504.. _JavaScriptWrapImports:
3505
3506**JavaScriptWrapImports** (``Boolean``) :versionbadge:`clang-format 3.9` :ref:`¶ <JavaScriptWrapImports>`
3507  Whether to wrap JavaScript import/export statements.
3508
3509  .. code-block:: js
3510
3511     true:
3512     import {
3513         VeryLongImportsAreAnnoying,
3514         VeryLongImportsAreAnnoying,
3515         VeryLongImportsAreAnnoying,
3516     } from 'some/module.js'
3517
3518     false:
3519     import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js"
3520
3521.. _KeepEmptyLinesAtTheStartOfBlocks:
3522
3523**KeepEmptyLinesAtTheStartOfBlocks** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <KeepEmptyLinesAtTheStartOfBlocks>`
3524  If true, the empty line at the start of blocks is kept.
3525
3526  .. code-block:: c++
3527
3528     true:                                  false:
3529     if (foo) {                     vs.     if (foo) {
3530                                              bar();
3531       bar();                               }
3532     }
3533
3534.. _LambdaBodyIndentation:
3535
3536**LambdaBodyIndentation** (``LambdaBodyIndentationKind``) :versionbadge:`clang-format 13` :ref:`¶ <LambdaBodyIndentation>`
3537  The indentation style of lambda bodies. ``Signature`` (the default)
3538  causes the lambda body to be indented one additional level relative to
3539  the indentation level of the signature. ``OuterScope`` forces the lambda
3540  body to be indented one additional level relative to the parent scope
3541  containing the lambda signature. For callback-heavy code, it may improve
3542  readability to have the signature indented two levels and to use
3543  ``OuterScope``. The KJ style guide requires ``OuterScope``.
3544  `KJ style guide
3545  <https://github.com/capnproto/capnproto/blob/master/style-guide.md>`_
3546
3547  Possible values:
3548
3549  * ``LBI_Signature`` (in configuration: ``Signature``)
3550    Align lambda body relative to the lambda signature. This is the default.
3551
3552    .. code-block:: c++
3553
3554       someMethod(
3555           [](SomeReallyLongLambdaSignatureArgument foo) {
3556             return;
3557           });
3558
3559  * ``LBI_OuterScope`` (in configuration: ``OuterScope``)
3560    Align lambda body relative to the indentation level of the outer scope
3561    the lambda signature resides in.
3562
3563    .. code-block:: c++
3564
3565       someMethod(
3566           [](SomeReallyLongLambdaSignatureArgument foo) {
3567         return;
3568       });
3569
3570
3571
3572.. _Language:
3573
3574**Language** (``LanguageKind``) :versionbadge:`clang-format 3.5` :ref:`¶ <Language>`
3575  Language, this format style is targeted at.
3576
3577  Possible values:
3578
3579  * ``LK_None`` (in configuration: ``None``)
3580    Do not use.
3581
3582  * ``LK_Cpp`` (in configuration: ``Cpp``)
3583    Should be used for C, C++.
3584
3585  * ``LK_CSharp`` (in configuration: ``CSharp``)
3586    Should be used for C#.
3587
3588  * ``LK_Java`` (in configuration: ``Java``)
3589    Should be used for Java.
3590
3591  * ``LK_JavaScript`` (in configuration: ``JavaScript``)
3592    Should be used for JavaScript.
3593
3594  * ``LK_Json`` (in configuration: ``Json``)
3595    Should be used for JSON.
3596
3597  * ``LK_ObjC`` (in configuration: ``ObjC``)
3598    Should be used for Objective-C, Objective-C++.
3599
3600  * ``LK_Proto`` (in configuration: ``Proto``)
3601    Should be used for Protocol Buffers
3602    (https://developers.google.com/protocol-buffers/).
3603
3604  * ``LK_TableGen`` (in configuration: ``TableGen``)
3605    Should be used for TableGen code.
3606
3607  * ``LK_TextProto`` (in configuration: ``TextProto``)
3608    Should be used for Protocol Buffer messages in text format
3609    (https://developers.google.com/protocol-buffers/).
3610
3611  * ``LK_Verilog`` (in configuration: ``Verilog``)
3612    Should be used for Verilog and SystemVerilog.
3613    https://standards.ieee.org/ieee/1800/6700/
3614    https://sci-hub.st/10.1109/IEEESTD.2018.8299595
3615
3616
3617
3618.. _LineEnding:
3619
3620**LineEnding** (``LineEndingStyle``) :versionbadge:`clang-format 16` :ref:`¶ <LineEnding>`
3621  Line ending style (``\n`` or ``\r\n``) to use.
3622
3623  Possible values:
3624
3625  * ``LE_LF`` (in configuration: ``LF``)
3626    Use ``\n``.
3627
3628  * ``LE_CRLF`` (in configuration: ``CRLF``)
3629    Use ``\r\n``.
3630
3631  * ``LE_DeriveLF`` (in configuration: ``DeriveLF``)
3632    Use ``\n`` unless the input has more lines ending in ``\r\n``.
3633
3634  * ``LE_DeriveCRLF`` (in configuration: ``DeriveCRLF``)
3635    Use ``\r\n`` unless the input has more lines ending in ``\n``.
3636
3637
3638
3639.. _MacroBlockBegin:
3640
3641**MacroBlockBegin** (``String``) :versionbadge:`clang-format 3.7` :ref:`¶ <MacroBlockBegin>`
3642  A regular expression matching macros that start a block.
3643
3644  .. code-block:: c++
3645
3646     # With:
3647     MacroBlockBegin: "^NS_MAP_BEGIN|\
3648     NS_TABLE_HEAD$"
3649     MacroBlockEnd: "^\
3650     NS_MAP_END|\
3651     NS_TABLE_.*_END$"
3652
3653     NS_MAP_BEGIN
3654       foo();
3655     NS_MAP_END
3656
3657     NS_TABLE_HEAD
3658       bar();
3659     NS_TABLE_FOO_END
3660
3661     # Without:
3662     NS_MAP_BEGIN
3663     foo();
3664     NS_MAP_END
3665
3666     NS_TABLE_HEAD
3667     bar();
3668     NS_TABLE_FOO_END
3669
3670.. _MacroBlockEnd:
3671
3672**MacroBlockEnd** (``String``) :versionbadge:`clang-format 3.7` :ref:`¶ <MacroBlockEnd>`
3673  A regular expression matching macros that end a block.
3674
3675.. _MaxEmptyLinesToKeep:
3676
3677**MaxEmptyLinesToKeep** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <MaxEmptyLinesToKeep>`
3678  The maximum number of consecutive empty lines to keep.
3679
3680  .. code-block:: c++
3681
3682     MaxEmptyLinesToKeep: 1         vs.     MaxEmptyLinesToKeep: 0
3683     int f() {                              int f() {
3684       int = 1;                                 int i = 1;
3685                                                i = foo();
3686       i = foo();                               return i;
3687                                            }
3688       return i;
3689     }
3690
3691.. _NamespaceIndentation:
3692
3693**NamespaceIndentation** (``NamespaceIndentationKind``) :versionbadge:`clang-format 3.7` :ref:`¶ <NamespaceIndentation>`
3694  The indentation used for namespaces.
3695
3696  Possible values:
3697
3698  * ``NI_None`` (in configuration: ``None``)
3699    Don't indent in namespaces.
3700
3701    .. code-block:: c++
3702
3703       namespace out {
3704       int i;
3705       namespace in {
3706       int i;
3707       }
3708       }
3709
3710  * ``NI_Inner`` (in configuration: ``Inner``)
3711    Indent only in inner namespaces (nested in other namespaces).
3712
3713    .. code-block:: c++
3714
3715       namespace out {
3716       int i;
3717       namespace in {
3718         int i;
3719       }
3720       }
3721
3722  * ``NI_All`` (in configuration: ``All``)
3723    Indent in all namespaces.
3724
3725    .. code-block:: c++
3726
3727       namespace out {
3728         int i;
3729         namespace in {
3730           int i;
3731         }
3732       }
3733
3734
3735
3736.. _NamespaceMacros:
3737
3738**NamespaceMacros** (``List of Strings``) :versionbadge:`clang-format 9` :ref:`¶ <NamespaceMacros>`
3739  A vector of macros which are used to open namespace blocks.
3740
3741  These are expected to be macros of the form:
3742
3743  .. code-block:: c++
3744
3745    NAMESPACE(<namespace-name>, ...) {
3746      <namespace-content>
3747    }
3748
3749  For example: TESTSUITE
3750
3751.. _ObjCBinPackProtocolList:
3752
3753**ObjCBinPackProtocolList** (``BinPackStyle``) :versionbadge:`clang-format 7` :ref:`¶ <ObjCBinPackProtocolList>`
3754  Controls bin-packing Objective-C protocol conformance list
3755  items into as few lines as possible when they go over ``ColumnLimit``.
3756
3757  If ``Auto`` (the default), delegates to the value in
3758  ``BinPackParameters``. If that is ``true``, bin-packs Objective-C
3759  protocol conformance list items into as few lines as possible
3760  whenever they go over ``ColumnLimit``.
3761
3762  If ``Always``, always bin-packs Objective-C protocol conformance
3763  list items into as few lines as possible whenever they go over
3764  ``ColumnLimit``.
3765
3766  If ``Never``, lays out Objective-C protocol conformance list items
3767  onto individual lines whenever they go over ``ColumnLimit``.
3768
3769
3770  .. code-block:: objc
3771
3772     Always (or Auto, if BinPackParameters=true):
3773     @interface ccccccccccccc () <
3774         ccccccccccccc, ccccccccccccc,
3775         ccccccccccccc, ccccccccccccc> {
3776     }
3777
3778     Never (or Auto, if BinPackParameters=false):
3779     @interface ddddddddddddd () <
3780         ddddddddddddd,
3781         ddddddddddddd,
3782         ddddddddddddd,
3783         ddddddddddddd> {
3784     }
3785
3786  Possible values:
3787
3788  * ``BPS_Auto`` (in configuration: ``Auto``)
3789    Automatically determine parameter bin-packing behavior.
3790
3791  * ``BPS_Always`` (in configuration: ``Always``)
3792    Always bin-pack parameters.
3793
3794  * ``BPS_Never`` (in configuration: ``Never``)
3795    Never bin-pack parameters.
3796
3797
3798
3799.. _ObjCBlockIndentWidth:
3800
3801**ObjCBlockIndentWidth** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <ObjCBlockIndentWidth>`
3802  The number of characters to use for indentation of ObjC blocks.
3803
3804  .. code-block:: objc
3805
3806     ObjCBlockIndentWidth: 4
3807
3808     [operation setCompletionBlock:^{
3809         [self onOperationDone];
3810     }];
3811
3812.. _ObjCBreakBeforeNestedBlockParam:
3813
3814**ObjCBreakBeforeNestedBlockParam** (``Boolean``) :versionbadge:`clang-format 11` :ref:`¶ <ObjCBreakBeforeNestedBlockParam>`
3815  Break parameters list into lines when there is nested block
3816  parameters in a function call.
3817
3818  .. code-block:: c++
3819
3820    false:
3821     - (void)_aMethod
3822     {
3823         [self.test1 t:self w:self callback:^(typeof(self) self, NSNumber
3824         *u, NSNumber *v) {
3825             u = c;
3826         }]
3827     }
3828     true:
3829     - (void)_aMethod
3830     {
3831        [self.test1 t:self
3832                     w:self
3833            callback:^(typeof(self) self, NSNumber *u, NSNumber *v) {
3834                 u = c;
3835             }]
3836     }
3837
3838.. _ObjCSpaceAfterProperty:
3839
3840**ObjCSpaceAfterProperty** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <ObjCSpaceAfterProperty>`
3841  Add a space after ``@property`` in Objective-C, i.e. use
3842  ``@property (readonly)`` instead of ``@property(readonly)``.
3843
3844.. _ObjCSpaceBeforeProtocolList:
3845
3846**ObjCSpaceBeforeProtocolList** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <ObjCSpaceBeforeProtocolList>`
3847  Add a space in front of an Objective-C protocol list, i.e. use
3848  ``Foo <Protocol>`` instead of ``Foo<Protocol>``.
3849
3850.. _PPIndentWidth:
3851
3852**PPIndentWidth** (``Integer``) :versionbadge:`clang-format 13` :ref:`¶ <PPIndentWidth>`
3853  The number of columns to use for indentation of preprocessor statements.
3854  When set to -1 (default) ``IndentWidth`` is used also for preprocessor
3855  statements.
3856
3857  .. code-block:: c++
3858
3859     PPIndentWidth: 1
3860
3861     #ifdef __linux__
3862     # define FOO
3863     #else
3864     # define BAR
3865     #endif
3866
3867.. _PackConstructorInitializers:
3868
3869**PackConstructorInitializers** (``PackConstructorInitializersStyle``) :versionbadge:`clang-format 14` :ref:`¶ <PackConstructorInitializers>`
3870  The pack constructor initializers style to use.
3871
3872  Possible values:
3873
3874  * ``PCIS_Never`` (in configuration: ``Never``)
3875    Always put each constructor initializer on its own line.
3876
3877    .. code-block:: c++
3878
3879       Constructor()
3880           : a(),
3881             b()
3882
3883  * ``PCIS_BinPack`` (in configuration: ``BinPack``)
3884    Bin-pack constructor initializers.
3885
3886    .. code-block:: c++
3887
3888       Constructor()
3889           : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(),
3890             cccccccccccccccccccc()
3891
3892  * ``PCIS_CurrentLine`` (in configuration: ``CurrentLine``)
3893    Put all constructor initializers on the current line if they fit.
3894    Otherwise, put each one on its own line.
3895
3896    .. code-block:: c++
3897
3898       Constructor() : a(), b()
3899
3900       Constructor()
3901           : aaaaaaaaaaaaaaaaaaaa(),
3902             bbbbbbbbbbbbbbbbbbbb(),
3903             ddddddddddddd()
3904
3905  * ``PCIS_NextLine`` (in configuration: ``NextLine``)
3906    Same as ``PCIS_CurrentLine`` except that if all constructor initializers
3907    do not fit on the current line, try to fit them on the next line.
3908
3909    .. code-block:: c++
3910
3911       Constructor() : a(), b()
3912
3913       Constructor()
3914           : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), ddddddddddddd()
3915
3916       Constructor()
3917           : aaaaaaaaaaaaaaaaaaaa(),
3918             bbbbbbbbbbbbbbbbbbbb(),
3919             cccccccccccccccccccc()
3920
3921
3922
3923.. _PenaltyBreakAssignment:
3924
3925**PenaltyBreakAssignment** (``Unsigned``) :versionbadge:`clang-format 5` :ref:`¶ <PenaltyBreakAssignment>`
3926  The penalty for breaking around an assignment operator.
3927
3928.. _PenaltyBreakBeforeFirstCallParameter:
3929
3930**PenaltyBreakBeforeFirstCallParameter** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <PenaltyBreakBeforeFirstCallParameter>`
3931  The penalty for breaking a function call after ``call(``.
3932
3933.. _PenaltyBreakComment:
3934
3935**PenaltyBreakComment** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <PenaltyBreakComment>`
3936  The penalty for each line break introduced inside a comment.
3937
3938.. _PenaltyBreakFirstLessLess:
3939
3940**PenaltyBreakFirstLessLess** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <PenaltyBreakFirstLessLess>`
3941  The penalty for breaking before the first ``<<``.
3942
3943.. _PenaltyBreakOpenParenthesis:
3944
3945**PenaltyBreakOpenParenthesis** (``Unsigned``) :versionbadge:`clang-format 14` :ref:`¶ <PenaltyBreakOpenParenthesis>`
3946  The penalty for breaking after ``(``.
3947
3948.. _PenaltyBreakString:
3949
3950**PenaltyBreakString** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <PenaltyBreakString>`
3951  The penalty for each line break introduced inside a string literal.
3952
3953.. _PenaltyBreakTemplateDeclaration:
3954
3955**PenaltyBreakTemplateDeclaration** (``Unsigned``) :versionbadge:`clang-format 7` :ref:`¶ <PenaltyBreakTemplateDeclaration>`
3956  The penalty for breaking after template declaration.
3957
3958.. _PenaltyExcessCharacter:
3959
3960**PenaltyExcessCharacter** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <PenaltyExcessCharacter>`
3961  The penalty for each character outside of the column limit.
3962
3963.. _PenaltyIndentedWhitespace:
3964
3965**PenaltyIndentedWhitespace** (``Unsigned``) :versionbadge:`clang-format 12` :ref:`¶ <PenaltyIndentedWhitespace>`
3966  Penalty for each character of whitespace indentation
3967  (counted relative to leading non-whitespace column).
3968
3969.. _PenaltyReturnTypeOnItsOwnLine:
3970
3971**PenaltyReturnTypeOnItsOwnLine** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <PenaltyReturnTypeOnItsOwnLine>`
3972  Penalty for putting the return type of a function onto its own line.
3973
3974.. _PointerAlignment:
3975
3976**PointerAlignment** (``PointerAlignmentStyle``) :versionbadge:`clang-format 3.7` :ref:`¶ <PointerAlignment>`
3977  Pointer and reference alignment style.
3978
3979  Possible values:
3980
3981  * ``PAS_Left`` (in configuration: ``Left``)
3982    Align pointer to the left.
3983
3984    .. code-block:: c++
3985
3986      int* a;
3987
3988  * ``PAS_Right`` (in configuration: ``Right``)
3989    Align pointer to the right.
3990
3991    .. code-block:: c++
3992
3993      int *a;
3994
3995  * ``PAS_Middle`` (in configuration: ``Middle``)
3996    Align pointer in the middle.
3997
3998    .. code-block:: c++
3999
4000      int * a;
4001
4002
4003
4004.. _QualifierAlignment:
4005
4006**QualifierAlignment** (``QualifierAlignmentStyle``) :versionbadge:`clang-format 14` :ref:`¶ <QualifierAlignment>`
4007  Different ways to arrange specifiers and qualifiers (e.g. const/volatile).
4008
4009  .. warning::
4010
4011   Setting ``QualifierAlignment``  to something other than `Leave`, COULD
4012   lead to incorrect code formatting due to incorrect decisions made due to
4013   clang-formats lack of complete semantic information.
4014   As such extra care should be taken to review code changes made by the use
4015   of this option.
4016
4017  Possible values:
4018
4019  * ``QAS_Leave`` (in configuration: ``Leave``)
4020    Don't change specifiers/qualifiers to either Left or Right alignment
4021    (default).
4022
4023    .. code-block:: c++
4024
4025       int const a;
4026       const int *a;
4027
4028  * ``QAS_Left`` (in configuration: ``Left``)
4029    Change specifiers/qualifiers to be left-aligned.
4030
4031    .. code-block:: c++
4032
4033       const int a;
4034       const int *a;
4035
4036  * ``QAS_Right`` (in configuration: ``Right``)
4037    Change specifiers/qualifiers to be right-aligned.
4038
4039    .. code-block:: c++
4040
4041       int const a;
4042       int const *a;
4043
4044  * ``QAS_Custom`` (in configuration: ``Custom``)
4045    Change specifiers/qualifiers to be aligned based on ``QualifierOrder``.
4046    With:
4047
4048    .. code-block:: yaml
4049
4050      QualifierOrder: ['inline', 'static', 'type', 'const']
4051
4052
4053    .. code-block:: c++
4054
4055
4056       int const a;
4057       int const *a;
4058
4059
4060
4061.. _QualifierOrder:
4062
4063**QualifierOrder** (``List of Strings``) :versionbadge:`clang-format 14` :ref:`¶ <QualifierOrder>`
4064  The order in which the qualifiers appear.
4065  Order is an array that can contain any of the following:
4066
4067    * const
4068    * inline
4069    * static
4070    * friend
4071    * constexpr
4072    * volatile
4073    * restrict
4074    * type
4075
4076  Note: it MUST contain 'type'.
4077  Items to the left of 'type' will be placed to the left of the type and
4078  aligned in the order supplied. Items to the right of 'type' will be placed
4079  to the right of the type and aligned in the order supplied.
4080
4081
4082  .. code-block:: yaml
4083
4084    QualifierOrder: ['inline', 'static', 'type', 'const', 'volatile' ]
4085
4086.. _RawStringFormats:
4087
4088**RawStringFormats** (``List of RawStringFormats``) :versionbadge:`clang-format 6` :ref:`¶ <RawStringFormats>`
4089  Defines hints for detecting supported languages code blocks in raw
4090  strings.
4091
4092  A raw string with a matching delimiter or a matching enclosing function
4093  name will be reformatted assuming the specified language based on the
4094  style for that language defined in the .clang-format file. If no style has
4095  been defined in the .clang-format file for the specific language, a
4096  predefined style given by 'BasedOnStyle' is used. If 'BasedOnStyle' is not
4097  found, the formatting is based on llvm style. A matching delimiter takes
4098  precedence over a matching enclosing function name for determining the
4099  language of the raw string contents.
4100
4101  If a canonical delimiter is specified, occurrences of other delimiters for
4102  the same language will be updated to the canonical if possible.
4103
4104  There should be at most one specification per language and each delimiter
4105  and enclosing function should not occur in multiple specifications.
4106
4107  To configure this in the .clang-format file, use:
4108
4109  .. code-block:: yaml
4110
4111    RawStringFormats:
4112      - Language: TextProto
4113          Delimiters:
4114            - 'pb'
4115            - 'proto'
4116          EnclosingFunctions:
4117            - 'PARSE_TEXT_PROTO'
4118          BasedOnStyle: google
4119      - Language: Cpp
4120          Delimiters:
4121            - 'cc'
4122            - 'cpp'
4123          BasedOnStyle: llvm
4124          CanonicalDelimiter: 'cc'
4125
4126.. _ReferenceAlignment:
4127
4128**ReferenceAlignment** (``ReferenceAlignmentStyle``) :versionbadge:`clang-format 13` :ref:`¶ <ReferenceAlignment>`
4129  Reference alignment style (overrides ``PointerAlignment`` for
4130  references).
4131
4132  Possible values:
4133
4134  * ``RAS_Pointer`` (in configuration: ``Pointer``)
4135    Align reference like ``PointerAlignment``.
4136
4137  * ``RAS_Left`` (in configuration: ``Left``)
4138    Align reference to the left.
4139
4140    .. code-block:: c++
4141
4142      int& a;
4143
4144  * ``RAS_Right`` (in configuration: ``Right``)
4145    Align reference to the right.
4146
4147    .. code-block:: c++
4148
4149      int &a;
4150
4151  * ``RAS_Middle`` (in configuration: ``Middle``)
4152    Align reference in the middle.
4153
4154    .. code-block:: c++
4155
4156      int & a;
4157
4158
4159
4160.. _ReflowComments:
4161
4162**ReflowComments** (``Boolean``) :versionbadge:`clang-format 3.8` :ref:`¶ <ReflowComments>`
4163  If ``true``, clang-format will attempt to re-flow comments. That is it
4164  will touch a comment and *reflow* long comments into new lines, trying to
4165  obey the ``ColumnLimit``.
4166
4167  .. code-block:: c++
4168
4169     false:
4170     // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
4171     /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */
4172
4173     true:
4174     // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
4175     // information
4176     /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
4177      * information */
4178
4179.. _RemoveBracesLLVM:
4180
4181**RemoveBracesLLVM** (``Boolean``) :versionbadge:`clang-format 14` :ref:`¶ <RemoveBracesLLVM>`
4182  Remove optional braces of control statements (``if``, ``else``, ``for``,
4183  and ``while``) in C++ according to the LLVM coding style.
4184
4185  .. warning::
4186
4187   This option will be renamed and expanded to support other styles.
4188
4189  .. warning::
4190
4191   Setting this option to `true` could lead to incorrect code formatting due
4192   to clang-format's lack of complete semantic information. As such, extra
4193   care should be taken to review code changes made by this option.
4194
4195  .. code-block:: c++
4196
4197    false:                                     true:
4198
4199    if (isa<FunctionDecl>(D)) {        vs.     if (isa<FunctionDecl>(D))
4200      handleFunctionDecl(D);                     handleFunctionDecl(D);
4201    } else if (isa<VarDecl>(D)) {              else if (isa<VarDecl>(D))
4202      handleVarDecl(D);                          handleVarDecl(D);
4203    }
4204
4205    if (isa<VarDecl>(D)) {             vs.     if (isa<VarDecl>(D)) {
4206      for (auto *A : D.attrs()) {                for (auto *A : D.attrs())
4207        if (shouldProcessAttr(A)) {                if (shouldProcessAttr(A))
4208          handleAttr(A);                             handleAttr(A);
4209        }                                      }
4210      }
4211    }
4212
4213    if (isa<FunctionDecl>(D)) {        vs.     if (isa<FunctionDecl>(D))
4214      for (auto *A : D.attrs()) {                for (auto *A : D.attrs())
4215        handleAttr(A);                             handleAttr(A);
4216      }
4217    }
4218
4219    if (auto *D = (T)(D)) {            vs.     if (auto *D = (T)(D)) {
4220      if (shouldProcess(D)) {                    if (shouldProcess(D))
4221        handleVarDecl(D);                          handleVarDecl(D);
4222      } else {                                   else
4223        markAsIgnored(D);                          markAsIgnored(D);
4224      }                                        }
4225    }
4226
4227    if (a) {                           vs.     if (a)
4228      b();                                       b();
4229    } else {                                   else if (c)
4230      if (c) {                                   d();
4231        d();                                   else
4232      } else {                                   e();
4233        e();
4234      }
4235    }
4236
4237.. _RemoveSemicolon:
4238
4239**RemoveSemicolon** (``Boolean``) :versionbadge:`clang-format 16` :ref:`¶ <RemoveSemicolon>`
4240  Remove semicolons after the closing brace of a non-empty function.
4241
4242  .. warning::
4243
4244   Setting this option to `true` could lead to incorrect code formatting due
4245   to clang-format's lack of complete semantic information. As such, extra
4246   care should be taken to review code changes made by this option.
4247
4248  .. code-block:: c++
4249
4250    false:                                     true:
4251
4252    int max(int a, int b) {                    int max(int a, int b) {
4253      return a > b ? a : b;                      return a > b ? a : b;
4254    };                                         }
4255
4256.. _RequiresClausePosition:
4257
4258**RequiresClausePosition** (``RequiresClausePositionStyle``) :versionbadge:`clang-format 15` :ref:`¶ <RequiresClausePosition>`
4259  The position of the ``requires`` clause.
4260
4261  Possible values:
4262
4263  * ``RCPS_OwnLine`` (in configuration: ``OwnLine``)
4264    Always put the ``requires`` clause on its own line.
4265
4266    .. code-block:: c++
4267
4268      template <typename T>
4269      requires C<T>
4270      struct Foo {...
4271
4272      template <typename T>
4273      requires C<T>
4274      void bar(T t) {...
4275
4276      template <typename T>
4277      void baz(T t)
4278      requires C<T>
4279      {...
4280
4281  * ``RCPS_WithPreceding`` (in configuration: ``WithPreceding``)
4282    Try to put the clause together with the preceding part of a declaration.
4283    For class templates: stick to the template declaration.
4284    For function templates: stick to the template declaration.
4285    For function declaration followed by a requires clause: stick to the
4286    parameter list.
4287
4288    .. code-block:: c++
4289
4290      template <typename T> requires C<T>
4291      struct Foo {...
4292
4293      template <typename T> requires C<T>
4294      void bar(T t) {...
4295
4296      template <typename T>
4297      void baz(T t) requires C<T>
4298      {...
4299
4300  * ``RCPS_WithFollowing`` (in configuration: ``WithFollowing``)
4301    Try to put the ``requires`` clause together with the class or function
4302    declaration.
4303
4304    .. code-block:: c++
4305
4306      template <typename T>
4307      requires C<T> struct Foo {...
4308
4309      template <typename T>
4310      requires C<T> void bar(T t) {...
4311
4312      template <typename T>
4313      void baz(T t)
4314      requires C<T> {...
4315
4316  * ``RCPS_SingleLine`` (in configuration: ``SingleLine``)
4317    Try to put everything in the same line if possible. Otherwise normal
4318    line breaking rules take over.
4319
4320    .. code-block:: c++
4321
4322      // Fitting:
4323      template <typename T> requires C<T> struct Foo {...
4324
4325      template <typename T> requires C<T> void bar(T t) {...
4326
4327      template <typename T> void bar(T t) requires C<T> {...
4328
4329      // Not fitting, one possible example:
4330      template <typename LongName>
4331      requires C<LongName>
4332      struct Foo {...
4333
4334      template <typename LongName>
4335      requires C<LongName>
4336      void bar(LongName ln) {
4337
4338      template <typename LongName>
4339      void bar(LongName ln)
4340          requires C<LongName> {
4341
4342
4343
4344.. _RequiresExpressionIndentation:
4345
4346**RequiresExpressionIndentation** (``RequiresExpressionIndentationKind``) :versionbadge:`clang-format 16` :ref:`¶ <RequiresExpressionIndentation>`
4347  The indentation used for requires expression bodies.
4348
4349  Possible values:
4350
4351  * ``REI_OuterScope`` (in configuration: ``OuterScope``)
4352    Align requires expression body relative to the indentation level of the
4353    outer scope the requires expression resides in.
4354    This is the default.
4355
4356    .. code-block:: c++
4357
4358       template <typename T>
4359       concept C = requires(T t) {
4360         ...
4361       }
4362
4363  * ``REI_Keyword`` (in configuration: ``Keyword``)
4364    Align requires expression body relative to the `requires` keyword.
4365
4366    .. code-block:: c++
4367
4368       template <typename T>
4369       concept C = requires(T t) {
4370                     ...
4371                   }
4372
4373
4374
4375.. _SeparateDefinitionBlocks:
4376
4377**SeparateDefinitionBlocks** (``SeparateDefinitionStyle``) :versionbadge:`clang-format 14` :ref:`¶ <SeparateDefinitionBlocks>`
4378  Specifies the use of empty lines to separate definition blocks, including
4379  classes, structs, enums, and functions.
4380
4381  .. code-block:: c++
4382
4383     Never                  v.s.     Always
4384     #include <cstring>              #include <cstring>
4385     struct Foo {
4386       int a, b, c;                  struct Foo {
4387     };                                int a, b, c;
4388     namespace Ns {                  };
4389     class Bar {
4390     public:                         namespace Ns {
4391       struct Foobar {               class Bar {
4392         int a;                      public:
4393         int b;                        struct Foobar {
4394       };                                int a;
4395     private:                            int b;
4396       int t;                          };
4397       int method1() {
4398         // ...                      private:
4399       }                               int t;
4400       enum List {
4401         ITEM1,                        int method1() {
4402         ITEM2                           // ...
4403       };                              }
4404       template<typename T>
4405       int method2(T x) {              enum List {
4406         // ...                          ITEM1,
4407       }                                 ITEM2
4408       int i, j, k;                    };
4409       int method3(int par) {
4410         // ...                        template<typename T>
4411       }                               int method2(T x) {
4412     };                                  // ...
4413     class C {};                       }
4414     }
4415                                       int i, j, k;
4416
4417                                       int method3(int par) {
4418                                         // ...
4419                                       }
4420                                     };
4421
4422                                     class C {};
4423                                     }
4424
4425  Possible values:
4426
4427  * ``SDS_Leave`` (in configuration: ``Leave``)
4428    Leave definition blocks as they are.
4429
4430  * ``SDS_Always`` (in configuration: ``Always``)
4431    Insert an empty line between definition blocks.
4432
4433  * ``SDS_Never`` (in configuration: ``Never``)
4434    Remove any empty line between definition blocks.
4435
4436
4437
4438.. _ShortNamespaceLines:
4439
4440**ShortNamespaceLines** (``Unsigned``) :versionbadge:`clang-format 13` :ref:`¶ <ShortNamespaceLines>`
4441  The maximal number of unwrapped lines that a short namespace spans.
4442  Defaults to 1.
4443
4444  This determines the maximum length of short namespaces by counting
4445  unwrapped lines (i.e. containing neither opening nor closing
4446  namespace brace) and makes "FixNamespaceComments" omit adding
4447  end comments for those.
4448
4449  .. code-block:: c++
4450
4451     ShortNamespaceLines: 1     vs.     ShortNamespaceLines: 0
4452     namespace a {                      namespace a {
4453       int foo;                           int foo;
4454     }                                  } // namespace a
4455
4456     ShortNamespaceLines: 1     vs.     ShortNamespaceLines: 0
4457     namespace b {                      namespace b {
4458       int foo;                           int foo;
4459       int bar;                           int bar;
4460     } // namespace b                   } // namespace b
4461
4462.. _SortIncludes:
4463
4464**SortIncludes** (``SortIncludesOptions``) :versionbadge:`clang-format 3.8` :ref:`¶ <SortIncludes>`
4465  Controls if and how clang-format will sort ``#includes``.
4466  If ``Never``, includes are never sorted.
4467  If ``CaseInsensitive``, includes are sorted in an ASCIIbetical or case
4468  insensitive fashion.
4469  If ``CaseSensitive``, includes are sorted in an alphabetical or case
4470  sensitive fashion.
4471
4472  Possible values:
4473
4474  * ``SI_Never`` (in configuration: ``Never``)
4475    Includes are never sorted.
4476
4477    .. code-block:: c++
4478
4479       #include "B/A.h"
4480       #include "A/B.h"
4481       #include "a/b.h"
4482       #include "A/b.h"
4483       #include "B/a.h"
4484
4485  * ``SI_CaseSensitive`` (in configuration: ``CaseSensitive``)
4486    Includes are sorted in an ASCIIbetical or case sensitive fashion.
4487
4488    .. code-block:: c++
4489
4490       #include "A/B.h"
4491       #include "A/b.h"
4492       #include "B/A.h"
4493       #include "B/a.h"
4494       #include "a/b.h"
4495
4496  * ``SI_CaseInsensitive`` (in configuration: ``CaseInsensitive``)
4497    Includes are sorted in an alphabetical or case insensitive fashion.
4498
4499    .. code-block:: c++
4500
4501       #include "A/B.h"
4502       #include "A/b.h"
4503       #include "a/b.h"
4504       #include "B/A.h"
4505       #include "B/a.h"
4506
4507
4508
4509.. _SortJavaStaticImport:
4510
4511**SortJavaStaticImport** (``SortJavaStaticImportOptions``) :versionbadge:`clang-format 12` :ref:`¶ <SortJavaStaticImport>`
4512  When sorting Java imports, by default static imports are placed before
4513  non-static imports. If ``JavaStaticImportAfterImport`` is ``After``,
4514  static imports are placed after non-static imports.
4515
4516  Possible values:
4517
4518  * ``SJSIO_Before`` (in configuration: ``Before``)
4519    Static imports are placed before non-static imports.
4520
4521    .. code-block:: java
4522
4523      import static org.example.function1;
4524
4525      import org.example.ClassA;
4526
4527  * ``SJSIO_After`` (in configuration: ``After``)
4528    Static imports are placed after non-static imports.
4529
4530    .. code-block:: java
4531
4532      import org.example.ClassA;
4533
4534      import static org.example.function1;
4535
4536
4537
4538.. _SortUsingDeclarations:
4539
4540**SortUsingDeclarations** (``SortUsingDeclarationsOptions``) :versionbadge:`clang-format 5` :ref:`¶ <SortUsingDeclarations>`
4541  Controls if and how clang-format will sort using declarations.
4542
4543  Possible values:
4544
4545  * ``SUD_Never`` (in configuration: ``Never``)
4546    Using declarations are never sorted.
4547
4548    .. code-block:: c++
4549
4550       using std::chrono::duration_cast;
4551       using std::move;
4552       using boost::regex;
4553       using boost::regex_constants::icase;
4554       using std::string;
4555
4556  * ``SUD_Lexicographic`` (in configuration: ``Lexicographic``)
4557    Using declarations are sorted in the order defined as follows:
4558    Split the strings by "::" and discard any initial empty strings. Sort
4559    the lists of names lexicographically, and within those groups, names are
4560    in case-insensitive lexicographic order.
4561
4562    .. code-block:: c++
4563
4564       using boost::regex;
4565       using boost::regex_constants::icase;
4566       using std::chrono::duration_cast;
4567       using std::move;
4568       using std::string;
4569
4570  * ``SUD_LexicographicNumeric`` (in configuration: ``LexicographicNumeric``)
4571    Using declarations are sorted in the order defined as follows:
4572    Split the strings by "::" and discard any initial empty strings. The
4573    last element of each list is a non-namespace name; all others are
4574    namespace names. Sort the lists of names lexicographically, where the
4575    sort order of individual names is that all non-namespace names come
4576    before all namespace names, and within those groups, names are in
4577    case-insensitive lexicographic order.
4578
4579    .. code-block:: c++
4580
4581       using boost::regex;
4582       using boost::regex_constants::icase;
4583       using std::move;
4584       using std::string;
4585       using std::chrono::duration_cast;
4586
4587
4588
4589.. _SpaceAfterCStyleCast:
4590
4591**SpaceAfterCStyleCast** (``Boolean``) :versionbadge:`clang-format 3.5` :ref:`¶ <SpaceAfterCStyleCast>`
4592  If ``true``, a space is inserted after C style casts.
4593
4594  .. code-block:: c++
4595
4596     true:                                  false:
4597     (int) i;                       vs.     (int)i;
4598
4599.. _SpaceAfterLogicalNot:
4600
4601**SpaceAfterLogicalNot** (``Boolean``) :versionbadge:`clang-format 9` :ref:`¶ <SpaceAfterLogicalNot>`
4602  If ``true``, a space is inserted after the logical not operator (``!``).
4603
4604  .. code-block:: c++
4605
4606     true:                                  false:
4607     ! someExpression();            vs.     !someExpression();
4608
4609.. _SpaceAfterTemplateKeyword:
4610
4611**SpaceAfterTemplateKeyword** (``Boolean``) :versionbadge:`clang-format 4` :ref:`¶ <SpaceAfterTemplateKeyword>`
4612  If ``true``, a space will be inserted after the 'template' keyword.
4613
4614  .. code-block:: c++
4615
4616     true:                                  false:
4617     template <int> void foo();     vs.     template<int> void foo();
4618
4619.. _SpaceAroundPointerQualifiers:
4620
4621**SpaceAroundPointerQualifiers** (``SpaceAroundPointerQualifiersStyle``) :versionbadge:`clang-format 12` :ref:`¶ <SpaceAroundPointerQualifiers>`
4622  Defines in which cases to put a space before or after pointer qualifiers
4623
4624  Possible values:
4625
4626  * ``SAPQ_Default`` (in configuration: ``Default``)
4627    Don't ensure spaces around pointer qualifiers and use PointerAlignment
4628    instead.
4629
4630    .. code-block:: c++
4631
4632       PointerAlignment: Left                 PointerAlignment: Right
4633       void* const* x = NULL;         vs.     void *const *x = NULL;
4634
4635  * ``SAPQ_Before`` (in configuration: ``Before``)
4636    Ensure that there is a space before pointer qualifiers.
4637
4638    .. code-block:: c++
4639
4640       PointerAlignment: Left                 PointerAlignment: Right
4641       void* const* x = NULL;         vs.     void * const *x = NULL;
4642
4643  * ``SAPQ_After`` (in configuration: ``After``)
4644    Ensure that there is a space after pointer qualifiers.
4645
4646    .. code-block:: c++
4647
4648       PointerAlignment: Left                 PointerAlignment: Right
4649       void* const * x = NULL;         vs.     void *const *x = NULL;
4650
4651  * ``SAPQ_Both`` (in configuration: ``Both``)
4652    Ensure that there is a space both before and after pointer qualifiers.
4653
4654    .. code-block:: c++
4655
4656       PointerAlignment: Left                 PointerAlignment: Right
4657       void* const * x = NULL;         vs.     void * const *x = NULL;
4658
4659
4660
4661.. _SpaceBeforeAssignmentOperators:
4662
4663**SpaceBeforeAssignmentOperators** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <SpaceBeforeAssignmentOperators>`
4664  If ``false``, spaces will be removed before assignment operators.
4665
4666  .. code-block:: c++
4667
4668     true:                                  false:
4669     int a = 5;                     vs.     int a= 5;
4670     a += 42;                               a+= 42;
4671
4672.. _SpaceBeforeCaseColon:
4673
4674**SpaceBeforeCaseColon** (``Boolean``) :versionbadge:`clang-format 12` :ref:`¶ <SpaceBeforeCaseColon>`
4675  If ``false``, spaces will be removed before case colon.
4676
4677  .. code-block:: c++
4678
4679    true:                                   false
4680    switch (x) {                    vs.     switch (x) {
4681      case 1 : break;                         case 1: break;
4682    }                                       }
4683
4684.. _SpaceBeforeCpp11BracedList:
4685
4686**SpaceBeforeCpp11BracedList** (``Boolean``) :versionbadge:`clang-format 7` :ref:`¶ <SpaceBeforeCpp11BracedList>`
4687  If ``true``, a space will be inserted before a C++11 braced list
4688  used to initialize an object (after the preceding identifier or type).
4689
4690  .. code-block:: c++
4691
4692     true:                                  false:
4693     Foo foo { bar };               vs.     Foo foo{ bar };
4694     Foo {};                                Foo{};
4695     vector<int> { 1, 2, 3 };               vector<int>{ 1, 2, 3 };
4696     new int[3] { 1, 2, 3 };                new int[3]{ 1, 2, 3 };
4697
4698.. _SpaceBeforeCtorInitializerColon:
4699
4700**SpaceBeforeCtorInitializerColon** (``Boolean``) :versionbadge:`clang-format 7` :ref:`¶ <SpaceBeforeCtorInitializerColon>`
4701  If ``false``, spaces will be removed before constructor initializer
4702  colon.
4703
4704  .. code-block:: c++
4705
4706     true:                                  false:
4707     Foo::Foo() : a(a) {}                   Foo::Foo(): a(a) {}
4708
4709.. _SpaceBeforeInheritanceColon:
4710
4711**SpaceBeforeInheritanceColon** (``Boolean``) :versionbadge:`clang-format 7` :ref:`¶ <SpaceBeforeInheritanceColon>`
4712  If ``false``, spaces will be removed before inheritance colon.
4713
4714  .. code-block:: c++
4715
4716     true:                                  false:
4717     class Foo : Bar {}             vs.     class Foo: Bar {}
4718
4719.. _SpaceBeforeParens:
4720
4721**SpaceBeforeParens** (``SpaceBeforeParensStyle``) :versionbadge:`clang-format 3.5` :ref:`¶ <SpaceBeforeParens>`
4722  Defines in which cases to put a space before opening parentheses.
4723
4724  Possible values:
4725
4726  * ``SBPO_Never`` (in configuration: ``Never``)
4727    Never put a space before opening parentheses.
4728
4729    .. code-block:: c++
4730
4731       void f() {
4732         if(true) {
4733           f();
4734         }
4735       }
4736
4737  * ``SBPO_ControlStatements`` (in configuration: ``ControlStatements``)
4738    Put a space before opening parentheses only after control statement
4739    keywords (``for/if/while...``).
4740
4741    .. code-block:: c++
4742
4743       void f() {
4744         if (true) {
4745           f();
4746         }
4747       }
4748
4749  * ``SBPO_ControlStatementsExceptControlMacros`` (in configuration: ``ControlStatementsExceptControlMacros``)
4750    Same as ``SBPO_ControlStatements`` except this option doesn't apply to
4751    ForEach and If macros. This is useful in projects where ForEach/If
4752    macros are treated as function calls instead of control statements.
4753    ``SBPO_ControlStatementsExceptForEachMacros`` remains an alias for
4754    backward compatibility.
4755
4756    .. code-block:: c++
4757
4758       void f() {
4759         Q_FOREACH(...) {
4760           f();
4761         }
4762       }
4763
4764  * ``SBPO_NonEmptyParentheses`` (in configuration: ``NonEmptyParentheses``)
4765    Put a space before opening parentheses only if the parentheses are not
4766    empty i.e. '()'
4767
4768    .. code-block:: c++
4769
4770      void() {
4771        if (true) {
4772          f();
4773          g (x, y, z);
4774        }
4775      }
4776
4777  * ``SBPO_Always`` (in configuration: ``Always``)
4778    Always put a space before opening parentheses, except when it's
4779    prohibited by the syntax rules (in function-like macro definitions) or
4780    when determined by other style rules (after unary operators, opening
4781    parentheses, etc.)
4782
4783    .. code-block:: c++
4784
4785       void f () {
4786         if (true) {
4787           f ();
4788         }
4789       }
4790
4791  * ``SBPO_Custom`` (in configuration: ``Custom``)
4792    Configure each individual space before parentheses in
4793    `SpaceBeforeParensOptions`.
4794
4795
4796
4797.. _SpaceBeforeParensOptions:
4798
4799**SpaceBeforeParensOptions** (``SpaceBeforeParensCustom``) :versionbadge:`clang-format 14` :ref:`¶ <SpaceBeforeParensOptions>`
4800  Control of individual space before parentheses.
4801
4802  If ``SpaceBeforeParens`` is set to ``Custom``, use this to specify
4803  how each individual space before parentheses case should be handled.
4804  Otherwise, this is ignored.
4805
4806  .. code-block:: yaml
4807
4808    # Example of usage:
4809    SpaceBeforeParens: Custom
4810    SpaceBeforeParensOptions:
4811      AfterControlStatements: true
4812      AfterFunctionDefinitionName: true
4813
4814  Nested configuration flags:
4815
4816  Precise control over the spacing before parentheses.
4817
4818  .. code-block:: c++
4819
4820    # Should be declared this way:
4821    SpaceBeforeParens: Custom
4822    SpaceBeforeParensOptions:
4823      AfterControlStatements: true
4824      AfterFunctionDefinitionName: true
4825
4826  * ``bool AfterControlStatements`` If ``true``, put space betwee control statement keywords
4827    (for/if/while...) and opening parentheses.
4828
4829    .. code-block:: c++
4830
4831       true:                                  false:
4832       if (...) {}                     vs.    if(...) {}
4833
4834  * ``bool AfterForeachMacros`` If ``true``, put space between foreach macros and opening parentheses.
4835
4836    .. code-block:: c++
4837
4838       true:                                  false:
4839       FOREACH (...)                   vs.    FOREACH(...)
4840         <loop-body>                            <loop-body>
4841
4842  * ``bool AfterFunctionDeclarationName`` If ``true``, put a space between function declaration name and opening
4843    parentheses.
4844
4845    .. code-block:: c++
4846
4847       true:                                  false:
4848       void f ();                      vs.    void f();
4849
4850  * ``bool AfterFunctionDefinitionName`` If ``true``, put a space between function definition name and opening
4851    parentheses.
4852
4853    .. code-block:: c++
4854
4855       true:                                  false:
4856       void f () {}                    vs.    void f() {}
4857
4858  * ``bool AfterIfMacros`` If ``true``, put space between if macros and opening parentheses.
4859
4860    .. code-block:: c++
4861
4862       true:                                  false:
4863       IF (...)                        vs.    IF(...)
4864         <conditional-body>                     <conditional-body>
4865
4866  * ``bool AfterOverloadedOperator`` If ``true``, put a space between operator overloading and opening
4867    parentheses.
4868
4869    .. code-block:: c++
4870
4871       true:                                  false:
4872       void operator++ (int a);        vs.    void operator++(int a);
4873       object.operator++ (10);                object.operator++(10);
4874
4875  * ``bool AfterRequiresInClause`` If ``true``, put space between requires keyword in a requires clause and
4876    opening parentheses, if there is one.
4877
4878    .. code-block:: c++
4879
4880       true:                                  false:
4881       template<typename T>            vs.    template<typename T>
4882       requires (A<T> && B<T>)                requires(A<T> && B<T>)
4883       ...                                    ...
4884
4885  * ``bool AfterRequiresInExpression`` If ``true``, put space between requires keyword in a requires expression
4886    and opening parentheses.
4887
4888    .. code-block:: c++
4889
4890       true:                                  false:
4891       template<typename T>            vs.    template<typename T>
4892       concept C = requires (T t) {           concept C = requires(T t) {
4893                     ...                                    ...
4894                   }                                      }
4895
4896  * ``bool BeforeNonEmptyParentheses`` If ``true``, put a space before opening parentheses only if the
4897    parentheses are not empty.
4898
4899    .. code-block:: c++
4900
4901       true:                                  false:
4902       void f (int a);                 vs.    void f();
4903       f (a);                                 f();
4904
4905
4906.. _SpaceBeforeRangeBasedForLoopColon:
4907
4908**SpaceBeforeRangeBasedForLoopColon** (``Boolean``) :versionbadge:`clang-format 7` :ref:`¶ <SpaceBeforeRangeBasedForLoopColon>`
4909  If ``false``, spaces will be removed before range-based for loop
4910  colon.
4911
4912  .. code-block:: c++
4913
4914     true:                                  false:
4915     for (auto v : values) {}       vs.     for(auto v: values) {}
4916
4917.. _SpaceBeforeSquareBrackets:
4918
4919**SpaceBeforeSquareBrackets** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ <SpaceBeforeSquareBrackets>`
4920  If ``true``, spaces will be before  ``[``.
4921  Lambdas will not be affected. Only the first ``[`` will get a space added.
4922
4923  .. code-block:: c++
4924
4925     true:                                  false:
4926     int a [5];                    vs.      int a[5];
4927     int a [5][5];                 vs.      int a[5][5];
4928
4929.. _SpaceInEmptyBlock:
4930
4931**SpaceInEmptyBlock** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ <SpaceInEmptyBlock>`
4932  If ``true``, spaces will be inserted into ``{}``.
4933
4934  .. code-block:: c++
4935
4936     true:                                false:
4937     void f() { }                   vs.   void f() {}
4938     while (true) { }                     while (true) {}
4939
4940.. _SpaceInEmptyParentheses:
4941
4942**SpaceInEmptyParentheses** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <SpaceInEmptyParentheses>`
4943  If ``true``, spaces may be inserted into ``()``.
4944
4945  .. code-block:: c++
4946
4947     true:                                false:
4948     void f( ) {                    vs.   void f() {
4949       int x[] = {foo( ), bar( )};          int x[] = {foo(), bar()};
4950       if (true) {                          if (true) {
4951         f( );                                f();
4952       }                                    }
4953     }                                    }
4954
4955.. _SpacesBeforeTrailingComments:
4956
4957**SpacesBeforeTrailingComments** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <SpacesBeforeTrailingComments>`
4958  The number of spaces before trailing line comments
4959  (``//`` - comments).
4960
4961  This does not affect trailing block comments (``/*`` - comments) as
4962  those commonly have different usage patterns and a number of special
4963  cases.
4964
4965  .. code-block:: c++
4966
4967     SpacesBeforeTrailingComments: 3
4968     void f() {
4969       if (true) {   // foo1
4970         f();        // bar
4971       }             // foo
4972     }
4973
4974.. _SpacesInAngles:
4975
4976**SpacesInAngles** (``SpacesInAnglesStyle``) :versionbadge:`clang-format 3.4` :ref:`¶ <SpacesInAngles>`
4977  The SpacesInAnglesStyle to use for template argument lists.
4978
4979  Possible values:
4980
4981  * ``SIAS_Never`` (in configuration: ``Never``)
4982    Remove spaces after ``<`` and before ``>``.
4983
4984    .. code-block:: c++
4985
4986       static_cast<int>(arg);
4987       std::function<void(int)> fct;
4988
4989  * ``SIAS_Always`` (in configuration: ``Always``)
4990    Add spaces after ``<`` and before ``>``.
4991
4992    .. code-block:: c++
4993
4994       static_cast< int >(arg);
4995       std::function< void(int) > fct;
4996
4997  * ``SIAS_Leave`` (in configuration: ``Leave``)
4998    Keep a single space after ``<`` and before ``>`` if any spaces were
4999    present. Option ``Standard: Cpp03`` takes precedence.
5000
5001
5002
5003.. _SpacesInCStyleCastParentheses:
5004
5005**SpacesInCStyleCastParentheses** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <SpacesInCStyleCastParentheses>`
5006  If ``true``, spaces may be inserted into C style casts.
5007
5008  .. code-block:: c++
5009
5010     true:                                  false:
5011     x = ( int32 )y                 vs.     x = (int32)y
5012
5013.. _SpacesInConditionalStatement:
5014
5015**SpacesInConditionalStatement** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ <SpacesInConditionalStatement>`
5016  If ``true``, spaces will be inserted around if/for/switch/while
5017  conditions.
5018
5019  .. code-block:: c++
5020
5021     true:                                  false:
5022     if ( a )  { ... }              vs.     if (a) { ... }
5023     while ( i < 5 )  { ... }               while (i < 5) { ... }
5024
5025.. _SpacesInContainerLiterals:
5026
5027**SpacesInContainerLiterals** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <SpacesInContainerLiterals>`
5028  If ``true``, spaces are inserted inside container literals (e.g.
5029  ObjC and Javascript array and dict literals).
5030
5031  .. code-block:: js
5032
5033     true:                                  false:
5034     var arr = [ 1, 2, 3 ];         vs.     var arr = [1, 2, 3];
5035     f({a : 1, b : 2, c : 3});              f({a: 1, b: 2, c: 3});
5036
5037.. _SpacesInLineCommentPrefix:
5038
5039**SpacesInLineCommentPrefix** (``SpacesInLineComment``) :versionbadge:`clang-format 13` :ref:`¶ <SpacesInLineCommentPrefix>`
5040  How many spaces are allowed at the start of a line comment. To disable the
5041  maximum set it to ``-1``, apart from that the maximum takes precedence
5042  over the minimum.
5043
5044  .. code-block:: c++
5045
5046    Minimum = 1
5047    Maximum = -1
5048    // One space is forced
5049
5050    //  but more spaces are possible
5051
5052    Minimum = 0
5053    Maximum = 0
5054    //Forces to start every comment directly after the slashes
5055
5056  Note that in line comment sections the relative indent of the subsequent
5057  lines is kept, that means the following:
5058
5059  .. code-block:: c++
5060
5061    before:                                   after:
5062    Minimum: 1
5063    //if (b) {                                // if (b) {
5064    //  return true;                          //   return true;
5065    //}                                       // }
5066
5067    Maximum: 0
5068    /// List:                                 ///List:
5069    ///  - Foo                                /// - Foo
5070    ///    - Bar                              ///   - Bar
5071
5072  This option has only effect if ``ReflowComments`` is set to ``true``.
5073
5074  Nested configuration flags:
5075
5076  Control of spaces within a single line comment.
5077
5078  * ``unsigned Minimum`` The minimum number of spaces at the start of the comment.
5079
5080  * ``unsigned Maximum`` The maximum number of spaces at the start of the comment.
5081
5082
5083.. _SpacesInParentheses:
5084
5085**SpacesInParentheses** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <SpacesInParentheses>`
5086  If ``true``, spaces will be inserted after ``(`` and before ``)``.
5087
5088  .. code-block:: c++
5089
5090     true:                                  false:
5091     t f( Deleted & ) & = delete;   vs.     t f(Deleted &) & = delete;
5092
5093.. _SpacesInSquareBrackets:
5094
5095**SpacesInSquareBrackets** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <SpacesInSquareBrackets>`
5096  If ``true``, spaces will be inserted after ``[`` and before ``]``.
5097  Lambdas without arguments or unspecified size array declarations will not
5098  be affected.
5099
5100  .. code-block:: c++
5101
5102     true:                                  false:
5103     int a[ 5 ];                    vs.     int a[5];
5104     std::unique_ptr<int[]> foo() {} // Won't be affected
5105
5106.. _Standard:
5107
5108**Standard** (``LanguageStandard``) :versionbadge:`clang-format 3.7` :ref:`¶ <Standard>`
5109  Parse and format C++ constructs compatible with this standard.
5110
5111  .. code-block:: c++
5112
5113     c++03:                                 latest:
5114     vector<set<int> > x;           vs.     vector<set<int>> x;
5115
5116  Possible values:
5117
5118  * ``LS_Cpp03`` (in configuration: ``c++03``)
5119    Parse and format as C++03.
5120    ``Cpp03`` is a deprecated alias for ``c++03``
5121
5122  * ``LS_Cpp11`` (in configuration: ``c++11``)
5123    Parse and format as C++11.
5124
5125  * ``LS_Cpp14`` (in configuration: ``c++14``)
5126    Parse and format as C++14.
5127
5128  * ``LS_Cpp17`` (in configuration: ``c++17``)
5129    Parse and format as C++17.
5130
5131  * ``LS_Cpp20`` (in configuration: ``c++20``)
5132    Parse and format as C++20.
5133
5134  * ``LS_Latest`` (in configuration: ``Latest``)
5135    Parse and format using the latest supported language version.
5136    ``Cpp11`` is a deprecated alias for ``Latest``
5137
5138  * ``LS_Auto`` (in configuration: ``Auto``)
5139    Automatic detection based on the input.
5140
5141
5142
5143.. _StatementAttributeLikeMacros:
5144
5145**StatementAttributeLikeMacros** (``List of Strings``) :versionbadge:`clang-format 12` :ref:`¶ <StatementAttributeLikeMacros>`
5146  Macros which are ignored in front of a statement, as if they were an
5147  attribute. So that they are not parsed as identifier, for example for Qts
5148  emit.
5149
5150  .. code-block:: c++
5151
5152    AlignConsecutiveDeclarations: true
5153    StatementAttributeLikeMacros: []
5154    unsigned char data = 'x';
5155    emit          signal(data); // This is parsed as variable declaration.
5156
5157    AlignConsecutiveDeclarations: true
5158    StatementAttributeLikeMacros: [emit]
5159    unsigned char data = 'x';
5160    emit signal(data); // Now it's fine again.
5161
5162.. _StatementMacros:
5163
5164**StatementMacros** (``List of Strings``) :versionbadge:`clang-format 8` :ref:`¶ <StatementMacros>`
5165  A vector of macros that should be interpreted as complete
5166  statements.
5167
5168  Typical macros are expressions, and require a semi-colon to be
5169  added; sometimes this is not the case, and this allows to make
5170  clang-format aware of such cases.
5171
5172  For example: Q_UNUSED
5173
5174.. _TabWidth:
5175
5176**TabWidth** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <TabWidth>`
5177  The number of columns used for tab stops.
5178
5179.. _TypenameMacros:
5180
5181**TypenameMacros** (``List of Strings``) :versionbadge:`clang-format 9` :ref:`¶ <TypenameMacros>`
5182  A vector of macros that should be interpreted as type declarations
5183  instead of as function calls.
5184
5185  These are expected to be macros of the form:
5186
5187  .. code-block:: c++
5188
5189    STACK_OF(...)
5190
5191  In the .clang-format configuration file, this can be configured like:
5192
5193  .. code-block:: yaml
5194
5195    TypenameMacros: ['STACK_OF', 'LIST']
5196
5197  For example: OpenSSL STACK_OF, BSD LIST_ENTRY.
5198
5199.. _UseCRLF:
5200
5201**UseCRLF** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ <UseCRLF>`
5202  This option is **deprecated**. See ``LF`` and ``CRLF`` of ``LineEnding``.
5203
5204.. _UseTab:
5205
5206**UseTab** (``UseTabStyle``) :versionbadge:`clang-format 3.7` :ref:`¶ <UseTab>`
5207  The way to use tab characters in the resulting file.
5208
5209  Possible values:
5210
5211  * ``UT_Never`` (in configuration: ``Never``)
5212    Never use tab.
5213
5214  * ``UT_ForIndentation`` (in configuration: ``ForIndentation``)
5215    Use tabs only for indentation.
5216
5217  * ``UT_ForContinuationAndIndentation`` (in configuration: ``ForContinuationAndIndentation``)
5218    Fill all leading whitespace with tabs, and use spaces for alignment that
5219    appears within a line (e.g. consecutive assignments and declarations).
5220
5221  * ``UT_AlignWithSpaces`` (in configuration: ``AlignWithSpaces``)
5222    Use tabs for line continuation and indentation, and spaces for
5223    alignment.
5224
5225  * ``UT_Always`` (in configuration: ``Always``)
5226    Use tabs whenever we need to fill whitespace that spans at least from
5227    one tab stop to the next one.
5228
5229
5230
5231.. _WhitespaceSensitiveMacros:
5232
5233**WhitespaceSensitiveMacros** (``List of Strings``) :versionbadge:`clang-format 11` :ref:`¶ <WhitespaceSensitiveMacros>`
5234  A vector of macros which are whitespace-sensitive and should not
5235  be touched.
5236
5237  These are expected to be macros of the form:
5238
5239  .. code-block:: c++
5240
5241    STRINGIZE(...)
5242
5243  In the .clang-format configuration file, this can be configured like:
5244
5245  .. code-block:: yaml
5246
5247    WhitespaceSensitiveMacros: ['STRINGIZE', 'PP_STRINGIZE']
5248
5249  For example: BOOST_PP_STRINGIZE
5250
5251.. END_FORMAT_STYLE_OPTIONS
5252
5253Adding additional style options
5254===============================
5255
5256Each additional style option adds costs to the clang-format project. Some of
5257these costs affect the clang-format development itself, as we need to make
5258sure that any given combination of options work and that new features don't
5259break any of the existing options in any way. There are also costs for end users
5260as options become less discoverable and people have to think about and make a
5261decision on options they don't really care about.
5262
5263The goal of the clang-format project is more on the side of supporting a
5264limited set of styles really well as opposed to supporting every single style
5265used by a codebase somewhere in the wild. Of course, we do want to support all
5266major projects and thus have established the following bar for adding style
5267options. Each new style option must ..
5268
5269  * be used in a project of significant size (have dozens of contributors)
5270  * have a publicly accessible style guide
5271  * have a person willing to contribute and maintain patches
5272
5273Examples
5274========
5275
5276A style similar to the `Linux Kernel style
5277<https://www.kernel.org/doc/Documentation/CodingStyle>`_:
5278
5279.. code-block:: yaml
5280
5281  BasedOnStyle: LLVM
5282  IndentWidth: 8
5283  UseTab: Always
5284  BreakBeforeBraces: Linux
5285  AllowShortIfStatementsOnASingleLine: false
5286  IndentCaseLabels: false
5287
5288The result is (imagine that tabs are used for indentation here):
5289
5290.. code-block:: c++
5291
5292  void test()
5293  {
5294          switch (x) {
5295          case 0:
5296          case 1:
5297                  do_something();
5298                  break;
5299          case 2:
5300                  do_something_else();
5301                  break;
5302          default:
5303                  break;
5304          }
5305          if (condition)
5306                  do_something_completely_different();
5307
5308          if (x == y) {
5309                  q();
5310          } else if (x > y) {
5311                  w();
5312          } else {
5313                  r();
5314          }
5315  }
5316
5317A style similar to the default Visual Studio formatting style:
5318
5319.. code-block:: yaml
5320
5321  UseTab: Never
5322  IndentWidth: 4
5323  BreakBeforeBraces: Allman
5324  AllowShortIfStatementsOnASingleLine: false
5325  IndentCaseLabels: false
5326  ColumnLimit: 0
5327
5328The result is:
5329
5330.. code-block:: c++
5331
5332  void test()
5333  {
5334      switch (suffix)
5335      {
5336      case 0:
5337      case 1:
5338          do_something();
5339          break;
5340      case 2:
5341          do_something_else();
5342          break;
5343      default:
5344          break;
5345      }
5346      if (condition)
5347          do_something_completely_different();
5348
5349      if (x == y)
5350      {
5351          q();
5352      }
5353      else if (x > y)
5354      {
5355          w();
5356      }
5357      else
5358      {
5359          r();
5360      }
5361  }
5362