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