1==========================
2Clang-Format Style Options
3==========================
4
5:doc:`ClangFormatStyleOptions` describes configurable formatting style options
6supported by :doc:`LibFormat` and :doc:`ClangFormat`.
7
8When using :program:`clang-format` command line utility or
9``clang::format::reformat(...)`` functions from code, one can either use one of
10the predefined styles (LLVM, Google, Chromium, Mozilla, WebKit, Microsoft) or
11create a custom style by configuring specific style options.
12
13
14Configuring Style with clang-format
15===================================
16
17:program:`clang-format` supports two ways to provide custom style options:
18directly specify style configuration in the ``-style=`` command line option or
19use ``-style=file`` and put style configuration in the ``.clang-format`` or
20``_clang-format`` file in the project directory.
21
22When using ``-style=file``, :program:`clang-format` for each input file will
23try to find the ``.clang-format`` file located in the closest parent directory
24of the input file. When the standard input is used, the search is started from
25the current directory.
26
27The ``.clang-format`` file uses YAML format:
28
29.. code-block:: yaml
30
31  key1: value1
32  key2: value2
33  # A comment.
34  ...
35
36The configuration file can consist of several sections each having different
37``Language:`` parameter denoting the programming language this section of the
38configuration is targeted at. See the description of the **Language** option
39below for the list of supported languages. The first section may have no
40language set, it will set the default style options for all lanugages.
41Configuration sections for specific language will override options set in the
42default section.
43
44When :program:`clang-format` formats a file, it auto-detects the language using
45the file name. When formatting standard input or a file that doesn't have the
46extension corresponding to its language, ``-assume-filename=`` option can be
47used to override the file name :program:`clang-format` uses to detect the
48language.
49
50An example of a configuration file for multiple languages:
51
52.. code-block:: yaml
53
54  ---
55  # We'll use defaults from the LLVM style, but with 4 columns indentation.
56  BasedOnStyle: LLVM
57  IndentWidth: 4
58  ---
59  Language: Cpp
60  # Force pointers to the type for C++.
61  DerivePointerAlignment: false
62  PointerAlignment: Left
63  ---
64  Language: JavaScript
65  # Use 100 columns for JS.
66  ColumnLimit: 100
67  ---
68  Language: Proto
69  # Don't format .proto files.
70  DisableFormat: true
71  ---
72  Language: CSharp
73  # Use 100 columns for C#.
74  ColumnLimit: 100
75  ...
76
77An easy way to get a valid ``.clang-format`` file containing all configuration
78options of a certain predefined style is:
79
80.. code-block:: console
81
82  clang-format -style=llvm -dump-config > .clang-format
83
84When specifying configuration in the ``-style=`` option, the same configuration
85is applied for all input files. The format of the configuration is:
86
87.. code-block:: console
88
89  -style='{key1: value1, key2: value2, ...}'
90
91
92Disabling Formatting on a Piece of Code
93=======================================
94
95Clang-format understands also special comments that switch formatting in a
96delimited range. The code between a comment ``// clang-format off`` or
97``/* clang-format off */`` up to a comment ``// clang-format on`` or
98``/* clang-format on */`` will not be formatted. The comments themselves
99will be formatted (aligned) normally.
100
101.. code-block:: c++
102
103  int formatted_code;
104  // clang-format off
105      void    unformatted_code  ;
106  // clang-format on
107  void formatted_code_again;
108
109
110Configuring Style in Code
111=========================
112
113When using ``clang::format::reformat(...)`` functions, the format is specified
114by supplying the `clang::format::FormatStyle
115<https://clang.llvm.org/doxygen/structclang_1_1format_1_1FormatStyle.html>`_
116structure.
117
118
119Configurable Format Style Options
120=================================
121
122This section lists the supported style options. Value type is specified for
123each option. For enumeration types possible values are specified both as a C++
124enumeration member (with a prefix, e.g. ``LS_Auto``), and as a value usable in
125the configuration (without a prefix: ``Auto``).
126
127
128**BasedOnStyle** (``string``)
129  The style used for all options not specifically set in the configuration.
130
131  This option is supported only in the :program:`clang-format` configuration
132  (both within ``-style='{...}'`` and the ``.clang-format`` file).
133
134  Possible values:
135
136  * ``LLVM``
137    A style complying with the `LLVM coding standards
138    <https://llvm.org/docs/CodingStandards.html>`_
139  * ``Google``
140    A style complying with `Google's C++ style guide
141    <https://google.github.io/styleguide/cppguide.html>`_
142  * ``Chromium``
143    A style complying with `Chromium's style guide
144    <https://chromium.googlesource.com/chromium/src/+/master/styleguide/styleguide.md>`_
145  * ``Mozilla``
146    A style complying with `Mozilla's style guide
147    <https://developer.mozilla.org/en-US/docs/Developer_Guide/Coding_Style>`_
148  * ``WebKit``
149    A style complying with `WebKit's style guide
150    <https://www.webkit.org/coding/coding-style.html>`_
151  * ``Microsoft``
152    A style complying with `Microsoft's style guide
153    <https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017>`_
154  * ``GNU``
155    A style complying with the `GNU coding standards
156    <https://www.gnu.org/prep/standards/standards.html>`_
157
158.. START_FORMAT_STYLE_OPTIONS
159
160**AccessModifierOffset** (``int``)
161  The extra indent or outdent of access modifiers, e.g. ``public:``.
162
163**AlignAfterOpenBracket** (``BracketAlignmentStyle``)
164  If ``true``, horizontally aligns arguments after an open bracket.
165
166  This applies to round brackets (parentheses), angle brackets and square
167  brackets.
168
169  Possible values:
170
171  * ``BAS_Align`` (in configuration: ``Align``)
172    Align parameters on the open bracket, e.g.:
173
174    .. code-block:: c++
175
176      someLongFunction(argument1,
177                       argument2);
178
179  * ``BAS_DontAlign`` (in configuration: ``DontAlign``)
180    Don't align, instead use ``ContinuationIndentWidth``, e.g.:
181
182    .. code-block:: c++
183
184      someLongFunction(argument1,
185          argument2);
186
187  * ``BAS_AlwaysBreak`` (in configuration: ``AlwaysBreak``)
188    Always break after an open bracket, if the parameters don't fit
189    on a single line, e.g.:
190
191    .. code-block:: c++
192
193      someLongFunction(
194          argument1, argument2);
195
196
197
198**AlignConsecutiveAssignments** (``bool``)
199  If ``true``, aligns consecutive assignments.
200
201  This will align the assignment operators of consecutive lines. This
202  will result in formattings like
203
204  .. code-block:: c++
205
206    int aaaa = 12;
207    int b    = 23;
208    int ccc  = 23;
209
210**AlignConsecutiveBitFields** (``bool``)
211  If ``true``, aligns consecutive bitfield members.
212
213  This will align the bitfield separators of consecutive lines. This
214  will result in formattings like
215
216  .. code-block:: c++
217
218    int aaaa : 1;
219    int b    : 12;
220    int ccc  : 8;
221
222**AlignConsecutiveDeclarations** (``bool``)
223  If ``true``, aligns consecutive declarations.
224
225  This will align the declaration names of consecutive lines. This
226  will result in formattings like
227
228  .. code-block:: c++
229
230    int         aaaa = 12;
231    float       b = 23;
232    std::string ccc = 23;
233
234**AlignConsecutiveMacros** (``bool``)
235  If ``true``, aligns consecutive C/C++ preprocessor macros.
236
237  This will align C/C++ preprocessor macros of consecutive lines.
238  Will result in formattings like
239
240  .. code-block:: c++
241
242    #define SHORT_NAME       42
243    #define LONGER_NAME      0x007f
244    #define EVEN_LONGER_NAME (2)
245    #define foo(x)           (x * x)
246    #define bar(y, z)        (y + z)
247
248**AlignEscapedNewlines** (``EscapedNewlineAlignmentStyle``)
249  Options for aligning backslashes in escaped newlines.
250
251  Possible values:
252
253  * ``ENAS_DontAlign`` (in configuration: ``DontAlign``)
254    Don't align escaped newlines.
255
256    .. code-block:: c++
257
258      #define A \
259        int aaaa; \
260        int b; \
261        int dddddddddd;
262
263  * ``ENAS_Left`` (in configuration: ``Left``)
264    Align escaped newlines as far left as possible.
265
266    .. code-block:: c++
267
268      true:
269      #define A   \
270        int aaaa; \
271        int b;    \
272        int dddddddddd;
273
274      false:
275
276  * ``ENAS_Right`` (in configuration: ``Right``)
277    Align escaped newlines in the right-most column.
278
279    .. code-block:: c++
280
281      #define A                                                                      \
282        int aaaa;                                                                    \
283        int b;                                                                       \
284        int dddddddddd;
285
286
287
288**AlignOperands** (``OperandAlignmentStyle``)
289  If ``true``, horizontally align operands of binary and ternary
290  expressions.
291
292  Possible values:
293
294  * ``OAS_DontAlign`` (in configuration: ``DontAlign``)
295    Do not align operands of binary and ternary expressions.
296    The wrapped lines are indented ``ContinuationIndentWidth`` spaces from
297    the start of the line.
298
299  * ``OAS_Align`` (in configuration: ``Align``)
300    Horizontally align operands of binary and ternary expressions.
301
302    Specifically, this aligns operands of a single expression that needs
303    to be split over multiple lines, e.g.:
304
305    .. code-block:: c++
306
307      int aaa = bbbbbbbbbbbbbbb +
308                ccccccccccccccc;
309
310    When ``BreakBeforeBinaryOperators`` is set, the wrapped operator is
311    aligned with the operand on the first line.
312
313    .. code-block:: c++
314
315      int aaa = bbbbbbbbbbbbbbb
316                + ccccccccccccccc;
317
318  * ``OAS_AlignAfterOperator`` (in configuration: ``AlignAfterOperator``)
319    Horizontally align operands of binary and ternary expressions.
320
321    This is similar to ``AO_Align``, except when
322    ``BreakBeforeBinaryOperators`` is set, the operator is un-indented so
323    that the wrapped operand is aligned with the operand on the first line.
324
325    .. code-block:: c++
326
327      int aaa = bbbbbbbbbbbbbbb
328              + ccccccccccccccc;
329
330
331
332**AlignTrailingComments** (``bool``)
333  If ``true``, aligns trailing comments.
334
335  .. code-block:: c++
336
337    true:                                   false:
338    int a;     // My comment a      vs.     int a; // My comment a
339    int b = 2; // comment  b                int b = 2; // comment about b
340
341**AllowAllArgumentsOnNextLine** (``bool``)
342  If a function call or braced initializer list doesn't fit on a
343  line, allow putting all arguments onto the next line, even if
344  ``BinPackArguments`` is ``false``.
345
346  .. code-block:: c++
347
348    true:
349    callFunction(
350        a, b, c, d);
351
352    false:
353    callFunction(a,
354                 b,
355                 c,
356                 d);
357
358**AllowAllConstructorInitializersOnNextLine** (``bool``)
359  If a constructor definition with a member initializer list doesn't
360  fit on a single line, allow putting all member initializers onto the next
361  line, if ```ConstructorInitializerAllOnOneLineOrOnePerLine``` is true.
362  Note that this parameter has no effect if
363  ```ConstructorInitializerAllOnOneLineOrOnePerLine``` is false.
364
365  .. code-block:: c++
366
367    true:
368    MyClass::MyClass() :
369        member0(0), member1(2) {}
370
371    false:
372    MyClass::MyClass() :
373        member0(0),
374        member1(2) {}
375
376**AllowAllParametersOfDeclarationOnNextLine** (``bool``)
377  If the function declaration doesn't fit on a line,
378  allow putting all parameters of a function declaration onto
379  the next line even if ``BinPackParameters`` is ``false``.
380
381  .. code-block:: c++
382
383    true:
384    void myFunction(
385        int a, int b, int c, int d, int e);
386
387    false:
388    void myFunction(int a,
389                    int b,
390                    int c,
391                    int d,
392                    int e);
393
394**AllowShortBlocksOnASingleLine** (``ShortBlockStyle``)
395  Dependent on the value, ``while (true) { continue; }`` can be put on a
396  single line.
397
398  Possible values:
399
400  * ``SBS_Never`` (in configuration: ``Never``)
401    Never merge blocks into a single line.
402
403    .. code-block:: c++
404
405      while (true) {
406      }
407      while (true) {
408        continue;
409      }
410
411  * ``SBS_Empty`` (in configuration: ``Empty``)
412    Only merge empty blocks.
413
414    .. code-block:: c++
415
416      while (true) {}
417      while (true) {
418        continue;
419      }
420
421  * ``SBS_Always`` (in configuration: ``Always``)
422    Always merge short blocks into a single line.
423
424    .. code-block:: c++
425
426      while (true) {}
427      while (true) { continue; }
428
429
430
431**AllowShortCaseLabelsOnASingleLine** (``bool``)
432  If ``true``, short case labels will be contracted to a single line.
433
434  .. code-block:: c++
435
436    true:                                   false:
437    switch (a) {                    vs.     switch (a) {
438    case 1: x = 1; break;                   case 1:
439    case 2: return;                           x = 1;
440    }                                         break;
441                                            case 2:
442                                              return;
443                                            }
444
445**AllowShortEnumsOnASingleLine** (``bool``)
446  Allow short enums on a single line.
447
448  .. code-block:: c++
449
450    true:
451    enum { A, B } myEnum;
452
453    false:
454    enum
455    {
456      A,
457      B
458    } myEnum;
459
460**AllowShortFunctionsOnASingleLine** (``ShortFunctionStyle``)
461  Dependent on the value, ``int f() { return 0; }`` can be put on a
462  single line.
463
464  Possible values:
465
466  * ``SFS_None`` (in configuration: ``None``)
467    Never merge functions into a single line.
468
469  * ``SFS_InlineOnly`` (in configuration: ``InlineOnly``)
470    Only merge functions defined inside a class. Same as "inline",
471    except it does not implies "empty": i.e. top level empty functions
472    are not merged either.
473
474    .. code-block:: c++
475
476      class Foo {
477        void f() { foo(); }
478      };
479      void f() {
480        foo();
481      }
482      void f() {
483      }
484
485  * ``SFS_Empty`` (in configuration: ``Empty``)
486    Only merge empty functions.
487
488    .. code-block:: c++
489
490      void f() {}
491      void f2() {
492        bar2();
493      }
494
495  * ``SFS_Inline`` (in configuration: ``Inline``)
496    Only merge functions defined inside a class. Implies "empty".
497
498    .. code-block:: c++
499
500      class Foo {
501        void f() { foo(); }
502      };
503      void f() {
504        foo();
505      }
506      void f() {}
507
508  * ``SFS_All`` (in configuration: ``All``)
509    Merge all functions fitting on a single line.
510
511    .. code-block:: c++
512
513      class Foo {
514        void f() { foo(); }
515      };
516      void f() { bar(); }
517
518
519
520**AllowShortIfStatementsOnASingleLine** (``ShortIfStyle``)
521  If ``true``, ``if (a) return;`` can be put on a single line.
522
523  Possible values:
524
525  * ``SIS_Never`` (in configuration: ``Never``)
526    Never put short ifs on the same line.
527
528    .. code-block:: c++
529
530      if (a)
531        return ;
532      else {
533        return;
534      }
535
536  * ``SIS_WithoutElse`` (in configuration: ``WithoutElse``)
537    Without else put short ifs on the same line only if
538    the else is not a compound statement.
539
540    .. code-block:: c++
541
542      if (a) return;
543      else
544        return;
545
546  * ``SIS_Always`` (in configuration: ``Always``)
547    Always put short ifs on the same line if
548    the else is not a compound statement or not.
549
550    .. code-block:: c++
551
552      if (a) return;
553      else {
554        return;
555      }
556
557
558
559**AllowShortLambdasOnASingleLine** (``ShortLambdaStyle``)
560  Dependent on the value, ``auto lambda []() { return 0; }`` can be put on a
561  single line.
562
563  Possible values:
564
565  * ``SLS_None`` (in configuration: ``None``)
566    Never merge lambdas into a single line.
567
568  * ``SLS_Empty`` (in configuration: ``Empty``)
569    Only merge empty lambdas.
570
571    .. code-block:: c++
572
573      auto lambda = [](int a) {}
574      auto lambda2 = [](int a) {
575          return a;
576      };
577
578  * ``SLS_Inline`` (in configuration: ``Inline``)
579    Merge lambda into a single line if argument of a function.
580
581    .. code-block:: c++
582
583      auto lambda = [](int a) {
584          return a;
585      };
586      sort(a.begin(), a.end(), ()[] { return x < y; })
587
588  * ``SLS_All`` (in configuration: ``All``)
589    Merge all lambdas fitting on a single line.
590
591    .. code-block:: c++
592
593      auto lambda = [](int a) {}
594      auto lambda2 = [](int a) { return a; };
595
596
597
598**AllowShortLoopsOnASingleLine** (``bool``)
599  If ``true``, ``while (true) continue;`` can be put on a single
600  line.
601
602**AlwaysBreakAfterDefinitionReturnType** (``DefinitionReturnTypeBreakingStyle``)
603  The function definition return type breaking style to use.  This
604  option is **deprecated** and is retained for backwards compatibility.
605
606  Possible values:
607
608  * ``DRTBS_None`` (in configuration: ``None``)
609    Break after return type automatically.
610    ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
611
612  * ``DRTBS_All`` (in configuration: ``All``)
613    Always break after the return type.
614
615  * ``DRTBS_TopLevel`` (in configuration: ``TopLevel``)
616    Always break after the return types of top-level functions.
617
618
619
620**AlwaysBreakAfterReturnType** (``ReturnTypeBreakingStyle``)
621  The function declaration return type breaking style to use.
622
623  Possible values:
624
625  * ``RTBS_None`` (in configuration: ``None``)
626    Break after return type automatically.
627    ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
628
629    .. code-block:: c++
630
631      class A {
632        int f() { return 0; };
633      };
634      int f();
635      int f() { return 1; }
636
637  * ``RTBS_All`` (in configuration: ``All``)
638    Always break after the return type.
639
640    .. code-block:: c++
641
642      class A {
643        int
644        f() {
645          return 0;
646        };
647      };
648      int
649      f();
650      int
651      f() {
652        return 1;
653      }
654
655  * ``RTBS_TopLevel`` (in configuration: ``TopLevel``)
656    Always break after the return types of top-level functions.
657
658    .. code-block:: c++
659
660      class A {
661        int f() { return 0; };
662      };
663      int
664      f();
665      int
666      f() {
667        return 1;
668      }
669
670  * ``RTBS_AllDefinitions`` (in configuration: ``AllDefinitions``)
671    Always break after the return type of function definitions.
672
673    .. code-block:: c++
674
675      class A {
676        int
677        f() {
678          return 0;
679        };
680      };
681      int f();
682      int
683      f() {
684        return 1;
685      }
686
687  * ``RTBS_TopLevelDefinitions`` (in configuration: ``TopLevelDefinitions``)
688    Always break after the return type of top-level definitions.
689
690    .. code-block:: c++
691
692      class A {
693        int f() { return 0; };
694      };
695      int f();
696      int
697      f() {
698        return 1;
699      }
700
701
702
703**AlwaysBreakBeforeMultilineStrings** (``bool``)
704  If ``true``, always break before multiline string literals.
705
706  This flag is mean to make cases where there are multiple multiline strings
707  in a file look more consistent. Thus, it will only take effect if wrapping
708  the string at that point leads to it being indented
709  ``ContinuationIndentWidth`` spaces from the start of the line.
710
711  .. code-block:: c++
712
713     true:                                  false:
714     aaaa =                         vs.     aaaa = "bbbb"
715         "bbbb"                                    "cccc";
716         "cccc";
717
718**AlwaysBreakTemplateDeclarations** (``BreakTemplateDeclarationsStyle``)
719  The template declaration breaking style to use.
720
721  Possible values:
722
723  * ``BTDS_No`` (in configuration: ``No``)
724    Do not force break before declaration.
725    ``PenaltyBreakTemplateDeclaration`` is taken into account.
726
727    .. code-block:: c++
728
729       template <typename T> T foo() {
730       }
731       template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa,
732                                   int bbbbbbbbbbbbbbbbbbbbb) {
733       }
734
735  * ``BTDS_MultiLine`` (in configuration: ``MultiLine``)
736    Force break after template declaration only when the following
737    declaration spans multiple lines.
738
739    .. code-block:: c++
740
741       template <typename T> T foo() {
742       }
743       template <typename T>
744       T foo(int aaaaaaaaaaaaaaaaaaaaa,
745             int bbbbbbbbbbbbbbbbbbbbb) {
746       }
747
748  * ``BTDS_Yes`` (in configuration: ``Yes``)
749    Always break after template declaration.
750
751    .. code-block:: c++
752
753       template <typename T>
754       T foo() {
755       }
756       template <typename T>
757       T foo(int aaaaaaaaaaaaaaaaaaaaa,
758             int bbbbbbbbbbbbbbbbbbbbb) {
759       }
760
761
762
763**AttributeMacros** (``std::vector<std::string>``)
764  A vector of strings that should be interpreted as attributes/qualifiers
765  instead of identifiers. This can be useful for language extensions or
766  static analyzer annotations.
767
768  For example:
769
770  .. code-block:: c++
771
772    x = (char *__capability)&y;
773    int function(void) __ununsed;
774    void only_writes_to_buffer(char *__output buffer);
775
776  In the .clang-format configuration file, this can be configured like:
777
778  .. code-block:: yaml
779
780    AttributeMacros: ['__capability', '__output', '__ununsed']
781
782**BinPackArguments** (``bool``)
783  If ``false``, a function call's arguments will either be all on the
784  same line or will have one line each.
785
786  .. code-block:: c++
787
788    true:
789    void f() {
790      f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa,
791        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
792    }
793
794    false:
795    void f() {
796      f(aaaaaaaaaaaaaaaaaaaa,
797        aaaaaaaaaaaaaaaaaaaa,
798        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
799    }
800
801**BinPackParameters** (``bool``)
802  If ``false``, a function declaration's or function definition's
803  parameters will either all be on the same line or will have one line each.
804
805  .. code-block:: c++
806
807    true:
808    void f(int aaaaaaaaaaaaaaaaaaaa, int aaaaaaaaaaaaaaaaaaaa,
809           int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
810
811    false:
812    void f(int aaaaaaaaaaaaaaaaaaaa,
813           int aaaaaaaaaaaaaaaaaaaa,
814           int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
815
816**BitFieldColonSpacing** (``BitFieldColonSpacingStyle``)
817  The BitFieldColonSpacingStyle to use for bitfields.
818
819  Possible values:
820
821  * ``BFCS_Both`` (in configuration: ``Both``)
822    Add one space on each side of the ``:``
823
824    .. code-block:: c++
825
826      unsigned bf : 2;
827
828  * ``BFCS_None`` (in configuration: ``None``)
829    Add no space around the ``:`` (except when needed for
830    ``AlignConsecutiveBitFields``).
831
832    .. code-block:: c++
833
834      unsigned bf:2;
835
836  * ``BFCS_Before`` (in configuration: ``Before``)
837    Add space before the ``:`` only
838
839    .. code-block:: c++
840
841      unsigned bf :2;
842
843  * ``BFCS_After`` (in configuration: ``After``)
844    Add space after the ``:`` only (space may be added before if
845    needed for ``AlignConsecutiveBitFields``).
846
847    .. code-block:: c++
848
849      unsigned bf: 2;
850
851
852
853**BraceWrapping** (``BraceWrappingFlags``)
854  Control of individual brace wrapping cases.
855
856  If ``BreakBeforeBraces`` is set to ``BS_Custom``, use this to specify how
857  each individual brace case should be handled. Otherwise, this is ignored.
858
859  .. code-block:: yaml
860
861    # Example of usage:
862    BreakBeforeBraces: Custom
863    BraceWrapping:
864      AfterEnum: true
865      AfterStruct: false
866      SplitEmptyFunction: false
867
868  Nested configuration flags:
869
870
871  * ``bool AfterCaseLabel`` Wrap case labels.
872
873    .. code-block:: c++
874
875      false:                                true:
876      switch (foo) {                vs.     switch (foo) {
877        case 1: {                             case 1:
878          bar();                              {
879          break;                                bar();
880        }                                       break;
881        default: {                            }
882          plop();                             default:
883        }                                     {
884      }                                         plop();
885                                              }
886                                            }
887
888  * ``bool AfterClass`` Wrap class definitions.
889
890    .. code-block:: c++
891
892      true:
893      class foo {};
894
895      false:
896      class foo
897      {};
898
899  * ``BraceWrappingAfterControlStatementStyle AfterControlStatement``
900    Wrap control statements (``if``/``for``/``while``/``switch``/..).
901
902    Possible values:
903
904    * ``BWACS_Never`` (in configuration: ``Never``)
905      Never wrap braces after a control statement.
906
907      .. code-block:: c++
908
909        if (foo()) {
910        } else {
911        }
912        for (int i = 0; i < 10; ++i) {
913        }
914
915    * ``BWACS_MultiLine`` (in configuration: ``MultiLine``)
916      Only wrap braces after a multi-line control statement.
917
918      .. code-block:: c++
919
920        if (foo && bar &&
921            baz)
922        {
923          quux();
924        }
925        while (foo || bar) {
926        }
927
928    * ``BWACS_Always`` (in configuration: ``Always``)
929      Always wrap braces after a control statement.
930
931      .. code-block:: c++
932
933        if (foo())
934        {
935        } else
936        {}
937        for (int i = 0; i < 10; ++i)
938        {}
939
940
941  * ``bool AfterEnum`` Wrap enum definitions.
942
943    .. code-block:: c++
944
945      true:
946      enum X : int
947      {
948        B
949      };
950
951      false:
952      enum X : int { B };
953
954  * ``bool AfterFunction`` Wrap function definitions.
955
956    .. code-block:: c++
957
958      true:
959      void foo()
960      {
961        bar();
962        bar2();
963      }
964
965      false:
966      void foo() {
967        bar();
968        bar2();
969      }
970
971  * ``bool AfterNamespace`` Wrap namespace definitions.
972
973    .. code-block:: c++
974
975      true:
976      namespace
977      {
978      int foo();
979      int bar();
980      }
981
982      false:
983      namespace {
984      int foo();
985      int bar();
986      }
987
988  * ``bool AfterObjCDeclaration`` Wrap ObjC definitions (interfaces, implementations...).
989    @autoreleasepool and @synchronized blocks are wrapped
990    according to `AfterControlStatement` flag.
991
992  * ``bool AfterStruct`` Wrap struct definitions.
993
994    .. code-block:: c++
995
996      true:
997      struct foo
998      {
999        int x;
1000      };
1001
1002      false:
1003      struct foo {
1004        int x;
1005      };
1006
1007  * ``bool AfterUnion`` Wrap union definitions.
1008
1009    .. code-block:: c++
1010
1011      true:
1012      union foo
1013      {
1014        int x;
1015      }
1016
1017      false:
1018      union foo {
1019        int x;
1020      }
1021
1022  * ``bool AfterExternBlock`` Wrap extern blocks.
1023
1024    .. code-block:: c++
1025
1026      true:
1027      extern "C"
1028      {
1029        int foo();
1030      }
1031
1032      false:
1033      extern "C" {
1034      int foo();
1035      }
1036
1037  * ``bool BeforeCatch`` Wrap before ``catch``.
1038
1039    .. code-block:: c++
1040
1041      true:
1042      try {
1043        foo();
1044      }
1045      catch () {
1046      }
1047
1048      false:
1049      try {
1050        foo();
1051      } catch () {
1052      }
1053
1054  * ``bool BeforeElse`` Wrap before ``else``.
1055
1056    .. code-block:: c++
1057
1058      true:
1059      if (foo()) {
1060      }
1061      else {
1062      }
1063
1064      false:
1065      if (foo()) {
1066      } else {
1067      }
1068
1069  * ``bool BeforeLambdaBody`` Wrap lambda block.
1070
1071    .. code-block:: c++
1072
1073      true:
1074      connect(
1075        []()
1076        {
1077          foo();
1078          bar();
1079        });
1080
1081      false:
1082      connect([]() {
1083        foo();
1084        bar();
1085      });
1086
1087  * ``bool BeforeWhile`` Wrap before ``while``.
1088
1089    .. code-block:: c++
1090
1091      true:
1092      do {
1093        foo();
1094      }
1095      while (1);
1096
1097      false:
1098      do {
1099        foo();
1100      } while (1);
1101
1102  * ``bool IndentBraces`` Indent the wrapped braces themselves.
1103
1104  * ``bool SplitEmptyFunction`` If ``false``, empty function body can be put on a single line.
1105    This option is used only if the opening brace of the function has
1106    already been wrapped, i.e. the `AfterFunction` brace wrapping mode is
1107    set, and the function could/should not be put on a single line (as per
1108    `AllowShortFunctionsOnASingleLine` and constructor formatting options).
1109
1110    .. code-block:: c++
1111
1112      int f()   vs.   int f()
1113      {}              {
1114                      }
1115
1116  * ``bool SplitEmptyRecord`` If ``false``, empty record (e.g. class, struct or union) body
1117    can be put on a single line. This option is used only if the opening
1118    brace of the record has already been wrapped, i.e. the `AfterClass`
1119    (for classes) brace wrapping mode is set.
1120
1121    .. code-block:: c++
1122
1123      class Foo   vs.  class Foo
1124      {}               {
1125                       }
1126
1127  * ``bool SplitEmptyNamespace`` If ``false``, empty namespace body can be put on a single line.
1128    This option is used only if the opening brace of the namespace has
1129    already been wrapped, i.e. the `AfterNamespace` brace wrapping mode is
1130    set.
1131
1132    .. code-block:: c++
1133
1134      namespace Foo   vs.  namespace Foo
1135      {}                   {
1136                           }
1137
1138
1139**BreakAfterJavaFieldAnnotations** (``bool``)
1140  Break after each annotation on a field in Java files.
1141
1142  .. code-block:: java
1143
1144     true:                                  false:
1145     @Partial                       vs.     @Partial @Mock DataLoad loader;
1146     @Mock
1147     DataLoad loader;
1148
1149**BreakBeforeBinaryOperators** (``BinaryOperatorStyle``)
1150  The way to wrap binary operators.
1151
1152  Possible values:
1153
1154  * ``BOS_None`` (in configuration: ``None``)
1155    Break after operators.
1156
1157    .. code-block:: c++
1158
1159       LooooooooooongType loooooooooooooooooooooongVariable =
1160           someLooooooooooooooooongFunction();
1161
1162       bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
1163                            aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ==
1164                        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
1165                    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa >
1166                        ccccccccccccccccccccccccccccccccccccccccc;
1167
1168  * ``BOS_NonAssignment`` (in configuration: ``NonAssignment``)
1169    Break before operators that aren't assignments.
1170
1171    .. code-block:: c++
1172
1173       LooooooooooongType loooooooooooooooooooooongVariable =
1174           someLooooooooooooooooongFunction();
1175
1176       bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1177                            + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1178                        == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1179                    && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1180                           > ccccccccccccccccccccccccccccccccccccccccc;
1181
1182  * ``BOS_All`` (in configuration: ``All``)
1183    Break before operators.
1184
1185    .. code-block:: c++
1186
1187       LooooooooooongType loooooooooooooooooooooongVariable
1188           = someLooooooooooooooooongFunction();
1189
1190       bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1191                            + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1192                        == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1193                    && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1194                           > ccccccccccccccccccccccccccccccccccccccccc;
1195
1196
1197
1198**BreakBeforeBraces** (``BraceBreakingStyle``)
1199  The brace breaking style to use.
1200
1201  Possible values:
1202
1203  * ``BS_Attach`` (in configuration: ``Attach``)
1204    Always attach braces to surrounding context.
1205
1206    .. code-block:: c++
1207
1208      namespace N {
1209      enum E {
1210        E1,
1211        E2,
1212      };
1213
1214      class C {
1215      public:
1216        C();
1217      };
1218
1219      bool baz(int i) {
1220        try {
1221          do {
1222            switch (i) {
1223            case 1: {
1224              foobar();
1225              break;
1226            }
1227            default: {
1228              break;
1229            }
1230            }
1231          } while (--i);
1232          return true;
1233        } catch (...) {
1234          handleError();
1235          return false;
1236        }
1237      }
1238
1239      void foo(bool b) {
1240        if (b) {
1241          baz(2);
1242        } else {
1243          baz(5);
1244        }
1245      }
1246
1247      void bar() { foo(true); }
1248      } // namespace N
1249
1250  * ``BS_Linux`` (in configuration: ``Linux``)
1251    Like ``Attach``, but break before braces on function, namespace and
1252    class definitions.
1253
1254    .. code-block:: c++
1255
1256      namespace N
1257      {
1258      enum E {
1259        E1,
1260        E2,
1261      };
1262
1263      class C
1264      {
1265      public:
1266        C();
1267      };
1268
1269      bool baz(int i)
1270      {
1271        try {
1272          do {
1273            switch (i) {
1274            case 1: {
1275              foobar();
1276              break;
1277            }
1278            default: {
1279              break;
1280            }
1281            }
1282          } while (--i);
1283          return true;
1284        } catch (...) {
1285          handleError();
1286          return false;
1287        }
1288      }
1289
1290      void foo(bool b)
1291      {
1292        if (b) {
1293          baz(2);
1294        } else {
1295          baz(5);
1296        }
1297      }
1298
1299      void bar() { foo(true); }
1300      } // namespace N
1301
1302  * ``BS_Mozilla`` (in configuration: ``Mozilla``)
1303    Like ``Attach``, but break before braces on enum, function, and record
1304    definitions.
1305
1306    .. code-block:: c++
1307
1308      namespace N {
1309      enum E
1310      {
1311        E1,
1312        E2,
1313      };
1314
1315      class C
1316      {
1317      public:
1318        C();
1319      };
1320
1321      bool baz(int i)
1322      {
1323        try {
1324          do {
1325            switch (i) {
1326            case 1: {
1327              foobar();
1328              break;
1329            }
1330            default: {
1331              break;
1332            }
1333            }
1334          } while (--i);
1335          return true;
1336        } catch (...) {
1337          handleError();
1338          return false;
1339        }
1340      }
1341
1342      void foo(bool b)
1343      {
1344        if (b) {
1345          baz(2);
1346        } else {
1347          baz(5);
1348        }
1349      }
1350
1351      void bar() { foo(true); }
1352      } // namespace N
1353
1354  * ``BS_Stroustrup`` (in configuration: ``Stroustrup``)
1355    Like ``Attach``, but break before function definitions, ``catch``, and
1356    ``else``.
1357
1358    .. code-block:: c++
1359
1360      namespace N {
1361      enum E {
1362        E1,
1363        E2,
1364      };
1365
1366      class C {
1367      public:
1368        C();
1369      };
1370
1371      bool baz(int i)
1372      {
1373        try {
1374          do {
1375            switch (i) {
1376            case 1: {
1377              foobar();
1378              break;
1379            }
1380            default: {
1381              break;
1382            }
1383            }
1384          } while (--i);
1385          return true;
1386        }
1387        catch (...) {
1388          handleError();
1389          return false;
1390        }
1391      }
1392
1393      void foo(bool b)
1394      {
1395        if (b) {
1396          baz(2);
1397        }
1398        else {
1399          baz(5);
1400        }
1401      }
1402
1403      void bar() { foo(true); }
1404      } // namespace N
1405
1406  * ``BS_Allman`` (in configuration: ``Allman``)
1407    Always break before braces.
1408
1409    .. code-block:: c++
1410
1411      namespace N
1412      {
1413      enum E
1414      {
1415        E1,
1416        E2,
1417      };
1418
1419      class C
1420      {
1421      public:
1422        C();
1423      };
1424
1425      bool baz(int i)
1426      {
1427        try
1428        {
1429          do
1430          {
1431            switch (i)
1432            {
1433            case 1:
1434            {
1435              foobar();
1436              break;
1437            }
1438            default:
1439            {
1440              break;
1441            }
1442            }
1443          } while (--i);
1444          return true;
1445        }
1446        catch (...)
1447        {
1448          handleError();
1449          return false;
1450        }
1451      }
1452
1453      void foo(bool b)
1454      {
1455        if (b)
1456        {
1457          baz(2);
1458        }
1459        else
1460        {
1461          baz(5);
1462        }
1463      }
1464
1465      void bar() { foo(true); }
1466      } // namespace N
1467
1468  * ``BS_Whitesmiths`` (in configuration: ``Whitesmiths``)
1469    Like ``Allman`` but always indent braces and line up code with braces.
1470
1471    .. code-block:: c++
1472
1473      namespace N
1474        {
1475      enum E
1476        {
1477        E1,
1478        E2,
1479        };
1480
1481      class C
1482        {
1483      public:
1484        C();
1485        };
1486
1487      bool baz(int i)
1488        {
1489        try
1490          {
1491          do
1492            {
1493            switch (i)
1494              {
1495              case 1:
1496              {
1497              foobar();
1498              break;
1499              }
1500              default:
1501              {
1502              break;
1503              }
1504              }
1505            } while (--i);
1506          return true;
1507          }
1508        catch (...)
1509          {
1510          handleError();
1511          return false;
1512          }
1513        }
1514
1515      void foo(bool b)
1516        {
1517        if (b)
1518          {
1519          baz(2);
1520          }
1521        else
1522          {
1523          baz(5);
1524          }
1525        }
1526
1527      void bar() { foo(true); }
1528        } // namespace N
1529
1530  * ``BS_GNU`` (in configuration: ``GNU``)
1531    Always break before braces and add an extra level of indentation to
1532    braces of control statements, not to those of class, function
1533    or other definitions.
1534
1535    .. code-block:: c++
1536
1537      namespace N
1538      {
1539      enum E
1540      {
1541        E1,
1542        E2,
1543      };
1544
1545      class C
1546      {
1547      public:
1548        C();
1549      };
1550
1551      bool baz(int i)
1552      {
1553        try
1554          {
1555            do
1556              {
1557                switch (i)
1558                  {
1559                  case 1:
1560                    {
1561                      foobar();
1562                      break;
1563                    }
1564                  default:
1565                    {
1566                      break;
1567                    }
1568                  }
1569              }
1570            while (--i);
1571            return true;
1572          }
1573        catch (...)
1574          {
1575            handleError();
1576            return false;
1577          }
1578      }
1579
1580      void foo(bool b)
1581      {
1582        if (b)
1583          {
1584            baz(2);
1585          }
1586        else
1587          {
1588            baz(5);
1589          }
1590      }
1591
1592      void bar() { foo(true); }
1593      } // namespace N
1594
1595  * ``BS_WebKit`` (in configuration: ``WebKit``)
1596    Like ``Attach``, but break before functions.
1597
1598    .. code-block:: c++
1599
1600      namespace N {
1601      enum E {
1602        E1,
1603        E2,
1604      };
1605
1606      class C {
1607      public:
1608        C();
1609      };
1610
1611      bool baz(int i)
1612      {
1613        try {
1614          do {
1615            switch (i) {
1616            case 1: {
1617              foobar();
1618              break;
1619            }
1620            default: {
1621              break;
1622            }
1623            }
1624          } while (--i);
1625          return true;
1626        } catch (...) {
1627          handleError();
1628          return false;
1629        }
1630      }
1631
1632      void foo(bool b)
1633      {
1634        if (b) {
1635          baz(2);
1636        } else {
1637          baz(5);
1638        }
1639      }
1640
1641      void bar() { foo(true); }
1642      } // namespace N
1643
1644  * ``BS_Custom`` (in configuration: ``Custom``)
1645    Configure each individual brace in `BraceWrapping`.
1646
1647
1648
1649**BreakBeforeConceptDeclarations** (``bool``)
1650  If ``true``, concept will be placed on a new line.
1651
1652  .. code-block:: c++
1653
1654    true:
1655     template<typename T>
1656     concept ...
1657
1658    false:
1659     template<typename T> concept ...
1660
1661**BreakBeforeTernaryOperators** (``bool``)
1662  If ``true``, ternary operators will be placed after line breaks.
1663
1664  .. code-block:: c++
1665
1666     true:
1667     veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription
1668         ? firstValue
1669         : SecondValueVeryVeryVeryVeryLong;
1670
1671     false:
1672     veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ?
1673         firstValue :
1674         SecondValueVeryVeryVeryVeryLong;
1675
1676**BreakConstructorInitializers** (``BreakConstructorInitializersStyle``)
1677  The constructor initializers style to use.
1678
1679  Possible values:
1680
1681  * ``BCIS_BeforeColon`` (in configuration: ``BeforeColon``)
1682    Break constructor initializers before the colon and after the commas.
1683
1684    .. code-block:: c++
1685
1686       Constructor()
1687           : initializer1(),
1688             initializer2()
1689
1690  * ``BCIS_BeforeComma`` (in configuration: ``BeforeComma``)
1691    Break constructor initializers before the colon and commas, and align
1692    the commas with the colon.
1693
1694    .. code-block:: c++
1695
1696       Constructor()
1697           : initializer1()
1698           , initializer2()
1699
1700  * ``BCIS_AfterColon`` (in configuration: ``AfterColon``)
1701    Break constructor initializers after the colon and commas.
1702
1703    .. code-block:: c++
1704
1705       Constructor() :
1706           initializer1(),
1707           initializer2()
1708
1709
1710
1711**BreakInheritanceList** (``BreakInheritanceListStyle``)
1712  The inheritance list style to use.
1713
1714  Possible values:
1715
1716  * ``BILS_BeforeColon`` (in configuration: ``BeforeColon``)
1717    Break inheritance list before the colon and after the commas.
1718
1719    .. code-block:: c++
1720
1721       class Foo
1722           : Base1,
1723             Base2
1724       {};
1725
1726  * ``BILS_BeforeComma`` (in configuration: ``BeforeComma``)
1727    Break inheritance list before the colon and commas, and align
1728    the commas with the colon.
1729
1730    .. code-block:: c++
1731
1732       class Foo
1733           : Base1
1734           , Base2
1735       {};
1736
1737  * ``BILS_AfterColon`` (in configuration: ``AfterColon``)
1738    Break inheritance list after the colon and commas.
1739
1740    .. code-block:: c++
1741
1742       class Foo :
1743           Base1,
1744           Base2
1745       {};
1746
1747
1748
1749**BreakStringLiterals** (``bool``)
1750  Allow breaking string literals when formatting.
1751
1752  .. code-block:: c++
1753
1754     true:
1755     const char* x = "veryVeryVeryVeryVeryVe"
1756                     "ryVeryVeryVeryVeryVery"
1757                     "VeryLongString";
1758
1759     false:
1760     const char* x =
1761       "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
1762
1763**ColumnLimit** (``unsigned``)
1764  The column limit.
1765
1766  A column limit of ``0`` means that there is no column limit. In this case,
1767  clang-format will respect the input's line breaking decisions within
1768  statements unless they contradict other rules.
1769
1770**CommentPragmas** (``std::string``)
1771  A regular expression that describes comments with special meaning,
1772  which should not be split into lines or otherwise changed.
1773
1774  .. code-block:: c++
1775
1776     // CommentPragmas: '^ FOOBAR pragma:'
1777     // Will leave the following line unaffected
1778     #include <vector> // FOOBAR pragma: keep
1779
1780**CompactNamespaces** (``bool``)
1781  If ``true``, consecutive namespace declarations will be on the same
1782  line. If ``false``, each namespace is declared on a new line.
1783
1784  .. code-block:: c++
1785
1786    true:
1787    namespace Foo { namespace Bar {
1788    }}
1789
1790    false:
1791    namespace Foo {
1792    namespace Bar {
1793    }
1794    }
1795
1796  If it does not fit on a single line, the overflowing namespaces get
1797  wrapped:
1798
1799  .. code-block:: c++
1800
1801    namespace Foo { namespace Bar {
1802    namespace Extra {
1803    }}}
1804
1805**ConstructorInitializerAllOnOneLineOrOnePerLine** (``bool``)
1806  If the constructor initializers don't fit on a line, put each
1807  initializer on its own line.
1808
1809  .. code-block:: c++
1810
1811    true:
1812    SomeClass::Constructor()
1813        : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) {
1814      return 0;
1815    }
1816
1817    false:
1818    SomeClass::Constructor()
1819        : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa),
1820          aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) {
1821      return 0;
1822    }
1823
1824**ConstructorInitializerIndentWidth** (``unsigned``)
1825  The number of characters to use for indentation of constructor
1826  initializer lists as well as inheritance lists.
1827
1828**ContinuationIndentWidth** (``unsigned``)
1829  Indent width for line continuations.
1830
1831  .. code-block:: c++
1832
1833     ContinuationIndentWidth: 2
1834
1835     int i =         //  VeryVeryVeryVeryVeryLongComment
1836       longFunction( // Again a long comment
1837         arg);
1838
1839**Cpp11BracedListStyle** (``bool``)
1840  If ``true``, format braced lists as best suited for C++11 braced
1841  lists.
1842
1843  Important differences:
1844  - No spaces inside the braced list.
1845  - No line break before the closing brace.
1846  - Indentation with the continuation indent, not with the block indent.
1847
1848  Fundamentally, C++11 braced lists are formatted exactly like function
1849  calls would be formatted in their place. If the braced list follows a name
1850  (e.g. a type or variable name), clang-format formats as if the ``{}`` were
1851  the parentheses of a function call with that name. If there is no name,
1852  a zero-length name is assumed.
1853
1854  .. code-block:: c++
1855
1856     true:                                  false:
1857     vector<int> x{1, 2, 3, 4};     vs.     vector<int> x{ 1, 2, 3, 4 };
1858     vector<T> x{{}, {}, {}, {}};           vector<T> x{ {}, {}, {}, {} };
1859     f(MyMap[{composite, key}]);            f(MyMap[{ composite, key }]);
1860     new int[3]{1, 2, 3};                   new int[3]{ 1, 2, 3 };
1861
1862**DeriveLineEnding** (``bool``)
1863  Analyze the formatted file for the most used line ending (``\r\n``
1864  or ``\n``). ``UseCRLF`` is only used as a fallback if none can be derived.
1865
1866**DerivePointerAlignment** (``bool``)
1867  If ``true``, analyze the formatted file for the most common
1868  alignment of ``&`` and ``*``.
1869  Pointer and reference alignment styles are going to be updated according
1870  to the preferences found in the file.
1871  ``PointerAlignment`` is then used only as fallback.
1872
1873**DisableFormat** (``bool``)
1874  Disables formatting completely.
1875
1876**ExperimentalAutoDetectBinPacking** (``bool``)
1877  If ``true``, clang-format detects whether function calls and
1878  definitions are formatted with one parameter per line.
1879
1880  Each call can be bin-packed, one-per-line or inconclusive. If it is
1881  inconclusive, e.g. completely on one line, but a decision needs to be
1882  made, clang-format analyzes whether there are other bin-packed cases in
1883  the input file and act accordingly.
1884
1885  NOTE: This is an experimental flag, that might go away or be renamed. Do
1886  not use this in config files, etc. Use at your own risk.
1887
1888**FixNamespaceComments** (``bool``)
1889  If ``true``, clang-format adds missing namespace end comments and
1890  fixes invalid existing ones.
1891
1892  .. code-block:: c++
1893
1894     true:                                  false:
1895     namespace a {                  vs.     namespace a {
1896     foo();                                 foo();
1897     } // namespace a                       }
1898
1899**ForEachMacros** (``std::vector<std::string>``)
1900  A vector of macros that should be interpreted as foreach loops
1901  instead of as function calls.
1902
1903  These are expected to be macros of the form:
1904
1905  .. code-block:: c++
1906
1907    FOREACH(<variable-declaration>, ...)
1908      <loop-body>
1909
1910  In the .clang-format configuration file, this can be configured like:
1911
1912  .. code-block:: yaml
1913
1914    ForEachMacros: ['RANGES_FOR', 'FOREACH']
1915
1916  For example: BOOST_FOREACH.
1917
1918**IncludeBlocks** (``IncludeBlocksStyle``)
1919  Dependent on the value, multiple ``#include`` blocks can be sorted
1920  as one and divided based on category.
1921
1922  Possible values:
1923
1924  * ``IBS_Preserve`` (in configuration: ``Preserve``)
1925    Sort each ``#include`` block separately.
1926
1927    .. code-block:: c++
1928
1929       #include "b.h"               into      #include "b.h"
1930
1931       #include <lib/main.h>                  #include "a.h"
1932       #include "a.h"                         #include <lib/main.h>
1933
1934  * ``IBS_Merge`` (in configuration: ``Merge``)
1935    Merge multiple ``#include`` blocks together and sort as one.
1936
1937    .. code-block:: c++
1938
1939       #include "b.h"               into      #include "a.h"
1940                                              #include "b.h"
1941       #include <lib/main.h>                  #include <lib/main.h>
1942       #include "a.h"
1943
1944  * ``IBS_Regroup`` (in configuration: ``Regroup``)
1945    Merge multiple ``#include`` blocks together and sort as one.
1946    Then split into groups based on category priority. See
1947    ``IncludeCategories``.
1948
1949    .. code-block:: c++
1950
1951       #include "b.h"               into      #include "a.h"
1952                                              #include "b.h"
1953       #include <lib/main.h>
1954       #include "a.h"                         #include <lib/main.h>
1955
1956
1957
1958**IncludeCategories** (``std::vector<IncludeCategory>``)
1959  Regular expressions denoting the different ``#include`` categories
1960  used for ordering ``#includes``.
1961
1962  `POSIX extended
1963  <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html>`_
1964  regular expressions are supported.
1965
1966  These regular expressions are matched against the filename of an include
1967  (including the <> or "") in order. The value belonging to the first
1968  matching regular expression is assigned and ``#includes`` are sorted first
1969  according to increasing category number and then alphabetically within
1970  each category.
1971
1972  If none of the regular expressions match, INT_MAX is assigned as
1973  category. The main header for a source file automatically gets category 0.
1974  so that it is generally kept at the beginning of the ``#includes``
1975  (https://llvm.org/docs/CodingStandards.html#include-style). However, you
1976  can also assign negative priorities if you have certain headers that
1977  always need to be first.
1978
1979  There is a third and optional field ``SortPriority`` which can used while
1980  ``IncludeBlocks = IBS_Regroup`` to define the priority in which
1981  ``#includes`` should be ordered. The value of ``Priority`` defines the
1982  order of ``#include blocks`` and also allows the grouping of ``#includes``
1983  of different priority. ``SortPriority`` is set to the value of
1984  ``Priority`` as default if it is not assigned.
1985
1986  Each regular expression can be marked as case sensitive with the field
1987  ``CaseSensitive``, per default it is not.
1988
1989  To configure this in the .clang-format file, use:
1990
1991  .. code-block:: yaml
1992
1993    IncludeCategories:
1994      - Regex:           '^"(llvm|llvm-c|clang|clang-c)/'
1995        Priority:        2
1996        SortPriority:    2
1997        CaseSensitive:   true
1998      - Regex:           '^(<|"(gtest|gmock|isl|json)/)'
1999        Priority:        3
2000      - Regex:           '<[[:alnum:].]+>'
2001        Priority:        4
2002      - Regex:           '.*'
2003        Priority:        1
2004        SortPriority:    0
2005
2006**IncludeIsMainRegex** (``std::string``)
2007  Specify a regular expression of suffixes that are allowed in the
2008  file-to-main-include mapping.
2009
2010  When guessing whether a #include is the "main" include (to assign
2011  category 0, see above), use this regex of allowed suffixes to the header
2012  stem. A partial match is done, so that:
2013  - "" means "arbitrary suffix"
2014  - "$" means "no suffix"
2015
2016  For example, if configured to "(_test)?$", then a header a.h would be seen
2017  as the "main" include in both a.cc and a_test.cc.
2018
2019**IncludeIsMainSourceRegex** (``std::string``)
2020  Specify a regular expression for files being formatted
2021  that are allowed to be considered "main" in the
2022  file-to-main-include mapping.
2023
2024  By default, clang-format considers files as "main" only when they end
2025  with: ``.c``, ``.cc``, ``.cpp``, ``.c++``, ``.cxx``, ``.m`` or ``.mm``
2026  extensions.
2027  For these files a guessing of "main" include takes place
2028  (to assign category 0, see above). This config option allows for
2029  additional suffixes and extensions for files to be considered as "main".
2030
2031  For example, if this option is configured to ``(Impl\.hpp)$``,
2032  then a file ``ClassImpl.hpp`` is considered "main" (in addition to
2033  ``Class.c``, ``Class.cc``, ``Class.cpp`` and so on) and "main
2034  include file" logic will be executed (with *IncludeIsMainRegex* setting
2035  also being respected in later phase). Without this option set,
2036  ``ClassImpl.hpp`` would not have the main include file put on top
2037  before any other include.
2038
2039**IndentCaseBlocks** (``bool``)
2040  Indent case label blocks one level from the case label.
2041
2042  When ``false``, the block following the case label uses the same
2043  indentation level as for the case label, treating the case label the same
2044  as an if-statement.
2045  When ``true``, the block gets indented as a scope block.
2046
2047  .. code-block:: c++
2048
2049     false:                                 true:
2050     switch (fool) {                vs.     switch (fool) {
2051     case 1: {                              case 1:
2052       bar();                                 {
2053     } break;                                   bar();
2054     default: {                               }
2055       plop();                                break;
2056     }                                      default:
2057     }                                        {
2058                                                plop();
2059                                              }
2060                                            }
2061
2062**IndentCaseLabels** (``bool``)
2063  Indent case labels one level from the switch statement.
2064
2065  When ``false``, use the same indentation level as for the switch
2066  statement. Switch statement body is always indented one level more than
2067  case labels (except the first block following the case label, which
2068  itself indents the code - unless IndentCaseBlocks is enabled).
2069
2070  .. code-block:: c++
2071
2072     false:                                 true:
2073     switch (fool) {                vs.     switch (fool) {
2074     case 1:                                  case 1:
2075       bar();                                   bar();
2076       break;                                   break;
2077     default:                                 default:
2078       plop();                                  plop();
2079     }                                      }
2080
2081**IndentExternBlock** (``IndentExternBlockStyle``)
2082  IndentExternBlockStyle is the type of indenting of extern blocks.
2083
2084  Possible values:
2085
2086  * ``IEBS_AfterExternBlock`` (in configuration: ``AfterExternBlock``)
2087    Backwards compatible with AfterExternBlock's indenting.
2088
2089    .. code-block:: c++
2090
2091       IndentExternBlock: AfterExternBlock
2092       BraceWrapping.AfterExternBlock: true
2093       extern "C"
2094       {
2095           void foo();
2096       }
2097
2098
2099    .. code-block:: c++
2100
2101       IndentExternBlock: AfterExternBlock
2102       BraceWrapping.AfterExternBlock: false
2103       extern "C" {
2104       void foo();
2105       }
2106
2107  * ``IEBS_NoIndent`` (in configuration: ``NoIndent``)
2108    Does not indent extern blocks.
2109
2110    .. code-block:: c++
2111
2112        extern "C" {
2113        void foo();
2114        }
2115
2116  * ``IEBS_Indent`` (in configuration: ``Indent``)
2117    Indents extern blocks.
2118
2119    .. code-block:: c++
2120
2121        extern "C" {
2122          void foo();
2123        }
2124
2125
2126
2127**IndentGotoLabels** (``bool``)
2128  Indent goto labels.
2129
2130  When ``false``, goto labels are flushed left.
2131
2132  .. code-block:: c++
2133
2134     true:                                  false:
2135     int f() {                      vs.     int f() {
2136       if (foo()) {                           if (foo()) {
2137       label1:                              label1:
2138         bar();                                 bar();
2139       }                                      }
2140     label2:                                label2:
2141       return 1;                              return 1;
2142     }                                      }
2143
2144**IndentPPDirectives** (``PPDirectiveIndentStyle``)
2145  The preprocessor directive indenting style to use.
2146
2147  Possible values:
2148
2149  * ``PPDIS_None`` (in configuration: ``None``)
2150    Does not indent any directives.
2151
2152    .. code-block:: c++
2153
2154       #if FOO
2155       #if BAR
2156       #include <foo>
2157       #endif
2158       #endif
2159
2160  * ``PPDIS_AfterHash`` (in configuration: ``AfterHash``)
2161    Indents directives after the hash.
2162
2163    .. code-block:: c++
2164
2165       #if FOO
2166       #  if BAR
2167       #    include <foo>
2168       #  endif
2169       #endif
2170
2171  * ``PPDIS_BeforeHash`` (in configuration: ``BeforeHash``)
2172    Indents directives before the hash.
2173
2174    .. code-block:: c++
2175
2176       #if FOO
2177         #if BAR
2178           #include <foo>
2179         #endif
2180       #endif
2181
2182
2183
2184**IndentRequires** (``bool``)
2185  Indent the requires clause in a template
2186
2187  .. code-block:: c++
2188
2189     true:
2190     template <typename It>
2191       requires Iterator<It>
2192     void sort(It begin, It end) {
2193       //....
2194     }
2195
2196     false:
2197     template <typename It>
2198     requires Iterator<It>
2199     void sort(It begin, It end) {
2200       //....
2201     }
2202
2203**IndentWidth** (``unsigned``)
2204  The number of columns to use for indentation.
2205
2206  .. code-block:: c++
2207
2208     IndentWidth: 3
2209
2210     void f() {
2211        someFunction();
2212        if (true, false) {
2213           f();
2214        }
2215     }
2216
2217**IndentWrappedFunctionNames** (``bool``)
2218  Indent if a function definition or declaration is wrapped after the
2219  type.
2220
2221  .. code-block:: c++
2222
2223     true:
2224     LoooooooooooooooooooooooooooooooooooooooongReturnType
2225         LoooooooooooooooooooooooooooooooongFunctionDeclaration();
2226
2227     false:
2228     LoooooooooooooooooooooooooooooooooooooooongReturnType
2229     LoooooooooooooooooooooooooooooooongFunctionDeclaration();
2230
2231**InsertTrailingCommas** (``TrailingCommaStyle``)
2232  If set to ``TCS_Wrapped`` will insert trailing commas in container
2233  literals (arrays and objects) that wrap across multiple lines.
2234  It is currently only available for JavaScript
2235  and disabled by default ``TCS_None``.
2236  ``InsertTrailingCommas`` cannot be used together with ``BinPackArguments``
2237  as inserting the comma disables bin-packing.
2238
2239  .. code-block:: c++
2240
2241    TSC_Wrapped:
2242    const someArray = [
2243    aaaaaaaaaaaaaaaaaaaaaaaaaa,
2244    aaaaaaaaaaaaaaaaaaaaaaaaaa,
2245    aaaaaaaaaaaaaaaaaaaaaaaaaa,
2246    //                        ^ inserted
2247    ]
2248
2249  Possible values:
2250
2251  * ``TCS_None`` (in configuration: ``None``)
2252    Do not insert trailing commas.
2253
2254  * ``TCS_Wrapped`` (in configuration: ``Wrapped``)
2255    Insert trailing commas in container literals that were wrapped over
2256    multiple lines. Note that this is conceptually incompatible with
2257    bin-packing, because the trailing comma is used as an indicator
2258    that a container should be formatted one-per-line (i.e. not bin-packed).
2259    So inserting a trailing comma counteracts bin-packing.
2260
2261
2262
2263**JavaImportGroups** (``std::vector<std::string>``)
2264  A vector of prefixes ordered by the desired groups for Java imports.
2265
2266  One group's prefix can be a subset of another - the longest prefix is
2267  always matched. Within a group, the imports are ordered lexicographically.
2268  Static imports are grouped separately and follow the same group rules.
2269  By default, static imports are placed before non-static imports,
2270  but this behavior is changed by another option,
2271  ``SortJavaStaticImport``.
2272
2273  In the .clang-format configuration file, this can be configured like
2274  in the following yaml example. This will result in imports being
2275  formatted as in the Java example below.
2276
2277  .. code-block:: yaml
2278
2279    JavaImportGroups: ['com.example', 'com', 'org']
2280
2281
2282  .. code-block:: java
2283
2284     import static com.example.function1;
2285
2286     import static com.test.function2;
2287
2288     import static org.example.function3;
2289
2290     import com.example.ClassA;
2291     import com.example.Test;
2292     import com.example.a.ClassB;
2293
2294     import com.test.ClassC;
2295
2296     import org.example.ClassD;
2297
2298**JavaScriptQuotes** (``JavaScriptQuoteStyle``)
2299  The JavaScriptQuoteStyle to use for JavaScript strings.
2300
2301  Possible values:
2302
2303  * ``JSQS_Leave`` (in configuration: ``Leave``)
2304    Leave string quotes as they are.
2305
2306    .. code-block:: js
2307
2308       string1 = "foo";
2309       string2 = 'bar';
2310
2311  * ``JSQS_Single`` (in configuration: ``Single``)
2312    Always use single quotes.
2313
2314    .. code-block:: js
2315
2316       string1 = 'foo';
2317       string2 = 'bar';
2318
2319  * ``JSQS_Double`` (in configuration: ``Double``)
2320    Always use double quotes.
2321
2322    .. code-block:: js
2323
2324       string1 = "foo";
2325       string2 = "bar";
2326
2327
2328
2329**JavaScriptWrapImports** (``bool``)
2330  Whether to wrap JavaScript import/export statements.
2331
2332  .. code-block:: js
2333
2334     true:
2335     import {
2336         VeryLongImportsAreAnnoying,
2337         VeryLongImportsAreAnnoying,
2338         VeryLongImportsAreAnnoying,
2339     } from 'some/module.js'
2340
2341     false:
2342     import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js"
2343
2344**KeepEmptyLinesAtTheStartOfBlocks** (``bool``)
2345  If true, the empty line at the start of blocks is kept.
2346
2347  .. code-block:: c++
2348
2349     true:                                  false:
2350     if (foo) {                     vs.     if (foo) {
2351                                              bar();
2352       bar();                               }
2353     }
2354
2355**Language** (``LanguageKind``)
2356  Language, this format style is targeted at.
2357
2358  Possible values:
2359
2360  * ``LK_None`` (in configuration: ``None``)
2361    Do not use.
2362
2363  * ``LK_Cpp`` (in configuration: ``Cpp``)
2364    Should be used for C, C++.
2365
2366  * ``LK_CSharp`` (in configuration: ``CSharp``)
2367    Should be used for C#.
2368
2369  * ``LK_Java`` (in configuration: ``Java``)
2370    Should be used for Java.
2371
2372  * ``LK_JavaScript`` (in configuration: ``JavaScript``)
2373    Should be used for JavaScript.
2374
2375  * ``LK_ObjC`` (in configuration: ``ObjC``)
2376    Should be used for Objective-C, Objective-C++.
2377
2378  * ``LK_Proto`` (in configuration: ``Proto``)
2379    Should be used for Protocol Buffers
2380    (https://developers.google.com/protocol-buffers/).
2381
2382  * ``LK_TableGen`` (in configuration: ``TableGen``)
2383    Should be used for TableGen code.
2384
2385  * ``LK_TextProto`` (in configuration: ``TextProto``)
2386    Should be used for Protocol Buffer messages in text format
2387    (https://developers.google.com/protocol-buffers/).
2388
2389
2390
2391**MacroBlockBegin** (``std::string``)
2392  A regular expression matching macros that start a block.
2393
2394  .. code-block:: c++
2395
2396     # With:
2397     MacroBlockBegin: "^NS_MAP_BEGIN|\
2398     NS_TABLE_HEAD$"
2399     MacroBlockEnd: "^\
2400     NS_MAP_END|\
2401     NS_TABLE_.*_END$"
2402
2403     NS_MAP_BEGIN
2404       foo();
2405     NS_MAP_END
2406
2407     NS_TABLE_HEAD
2408       bar();
2409     NS_TABLE_FOO_END
2410
2411     # Without:
2412     NS_MAP_BEGIN
2413     foo();
2414     NS_MAP_END
2415
2416     NS_TABLE_HEAD
2417     bar();
2418     NS_TABLE_FOO_END
2419
2420**MacroBlockEnd** (``std::string``)
2421  A regular expression matching macros that end a block.
2422
2423**MaxEmptyLinesToKeep** (``unsigned``)
2424  The maximum number of consecutive empty lines to keep.
2425
2426  .. code-block:: c++
2427
2428     MaxEmptyLinesToKeep: 1         vs.     MaxEmptyLinesToKeep: 0
2429     int f() {                              int f() {
2430       int = 1;                                 int i = 1;
2431                                                i = foo();
2432       i = foo();                               return i;
2433                                            }
2434       return i;
2435     }
2436
2437**NamespaceIndentation** (``NamespaceIndentationKind``)
2438  The indentation used for namespaces.
2439
2440  Possible values:
2441
2442  * ``NI_None`` (in configuration: ``None``)
2443    Don't indent in namespaces.
2444
2445    .. code-block:: c++
2446
2447       namespace out {
2448       int i;
2449       namespace in {
2450       int i;
2451       }
2452       }
2453
2454  * ``NI_Inner`` (in configuration: ``Inner``)
2455    Indent only in inner namespaces (nested in other namespaces).
2456
2457    .. code-block:: c++
2458
2459       namespace out {
2460       int i;
2461       namespace in {
2462         int i;
2463       }
2464       }
2465
2466  * ``NI_All`` (in configuration: ``All``)
2467    Indent in all namespaces.
2468
2469    .. code-block:: c++
2470
2471       namespace out {
2472         int i;
2473         namespace in {
2474           int i;
2475         }
2476       }
2477
2478
2479
2480**NamespaceMacros** (``std::vector<std::string>``)
2481  A vector of macros which are used to open namespace blocks.
2482
2483  These are expected to be macros of the form:
2484
2485  .. code-block:: c++
2486
2487    NAMESPACE(<namespace-name>, ...) {
2488      <namespace-content>
2489    }
2490
2491  For example: TESTSUITE
2492
2493**ObjCBinPackProtocolList** (``BinPackStyle``)
2494  Controls bin-packing Objective-C protocol conformance list
2495  items into as few lines as possible when they go over ``ColumnLimit``.
2496
2497  If ``Auto`` (the default), delegates to the value in
2498  ``BinPackParameters``. If that is ``true``, bin-packs Objective-C
2499  protocol conformance list items into as few lines as possible
2500  whenever they go over ``ColumnLimit``.
2501
2502  If ``Always``, always bin-packs Objective-C protocol conformance
2503  list items into as few lines as possible whenever they go over
2504  ``ColumnLimit``.
2505
2506  If ``Never``, lays out Objective-C protocol conformance list items
2507  onto individual lines whenever they go over ``ColumnLimit``.
2508
2509
2510  .. code-block:: objc
2511
2512     Always (or Auto, if BinPackParameters=true):
2513     @interface ccccccccccccc () <
2514         ccccccccccccc, ccccccccccccc,
2515         ccccccccccccc, ccccccccccccc> {
2516     }
2517
2518     Never (or Auto, if BinPackParameters=false):
2519     @interface ddddddddddddd () <
2520         ddddddddddddd,
2521         ddddddddddddd,
2522         ddddddddddddd,
2523         ddddddddddddd> {
2524     }
2525
2526  Possible values:
2527
2528  * ``BPS_Auto`` (in configuration: ``Auto``)
2529    Automatically determine parameter bin-packing behavior.
2530
2531  * ``BPS_Always`` (in configuration: ``Always``)
2532    Always bin-pack parameters.
2533
2534  * ``BPS_Never`` (in configuration: ``Never``)
2535    Never bin-pack parameters.
2536
2537
2538
2539**ObjCBlockIndentWidth** (``unsigned``)
2540  The number of characters to use for indentation of ObjC blocks.
2541
2542  .. code-block:: objc
2543
2544     ObjCBlockIndentWidth: 4
2545
2546     [operation setCompletionBlock:^{
2547         [self onOperationDone];
2548     }];
2549
2550**ObjCBreakBeforeNestedBlockParam** (``bool``)
2551  Break parameters list into lines when there is nested block
2552  parameters in a function call.
2553
2554  .. code-block:: c++
2555
2556    false:
2557     - (void)_aMethod
2558     {
2559         [self.test1 t:self w:self callback:^(typeof(self) self, NSNumber
2560         *u, NSNumber *v) {
2561             u = c;
2562         }]
2563     }
2564     true:
2565     - (void)_aMethod
2566     {
2567        [self.test1 t:self
2568                     w:self
2569            callback:^(typeof(self) self, NSNumber *u, NSNumber *v) {
2570                 u = c;
2571             }]
2572     }
2573
2574**ObjCSpaceAfterProperty** (``bool``)
2575  Add a space after ``@property`` in Objective-C, i.e. use
2576  ``@property (readonly)`` instead of ``@property(readonly)``.
2577
2578**ObjCSpaceBeforeProtocolList** (``bool``)
2579  Add a space in front of an Objective-C protocol list, i.e. use
2580  ``Foo <Protocol>`` instead of ``Foo<Protocol>``.
2581
2582**PenaltyBreakAssignment** (``unsigned``)
2583  The penalty for breaking around an assignment operator.
2584
2585**PenaltyBreakBeforeFirstCallParameter** (``unsigned``)
2586  The penalty for breaking a function call after ``call(``.
2587
2588**PenaltyBreakComment** (``unsigned``)
2589  The penalty for each line break introduced inside a comment.
2590
2591**PenaltyBreakFirstLessLess** (``unsigned``)
2592  The penalty for breaking before the first ``<<``.
2593
2594**PenaltyBreakString** (``unsigned``)
2595  The penalty for each line break introduced inside a string literal.
2596
2597**PenaltyBreakTemplateDeclaration** (``unsigned``)
2598  The penalty for breaking after template declaration.
2599
2600**PenaltyExcessCharacter** (``unsigned``)
2601  The penalty for each character outside of the column limit.
2602
2603**PenaltyIndentedWhitespace** (``unsigned``)
2604  Penalty for each character of whitespace indentation
2605  (counted relative to leading non-whitespace column).
2606
2607**PenaltyReturnTypeOnItsOwnLine** (``unsigned``)
2608  Penalty for putting the return type of a function onto its own
2609  line.
2610
2611**PointerAlignment** (``PointerAlignmentStyle``)
2612  Pointer and reference alignment style.
2613
2614  Possible values:
2615
2616  * ``PAS_Left`` (in configuration: ``Left``)
2617    Align pointer to the left.
2618
2619    .. code-block:: c++
2620
2621      int* a;
2622
2623  * ``PAS_Right`` (in configuration: ``Right``)
2624    Align pointer to the right.
2625
2626    .. code-block:: c++
2627
2628      int *a;
2629
2630  * ``PAS_Middle`` (in configuration: ``Middle``)
2631    Align pointer in the middle.
2632
2633    .. code-block:: c++
2634
2635      int * a;
2636
2637
2638
2639**RawStringFormats** (``std::vector<RawStringFormat>``)
2640  Defines hints for detecting supported languages code blocks in raw
2641  strings.
2642
2643  A raw string with a matching delimiter or a matching enclosing function
2644  name will be reformatted assuming the specified language based on the
2645  style for that language defined in the .clang-format file. If no style has
2646  been defined in the .clang-format file for the specific language, a
2647  predefined style given by 'BasedOnStyle' is used. If 'BasedOnStyle' is not
2648  found, the formatting is based on llvm style. A matching delimiter takes
2649  precedence over a matching enclosing function name for determining the
2650  language of the raw string contents.
2651
2652  If a canonical delimiter is specified, occurrences of other delimiters for
2653  the same language will be updated to the canonical if possible.
2654
2655  There should be at most one specification per language and each delimiter
2656  and enclosing function should not occur in multiple specifications.
2657
2658  To configure this in the .clang-format file, use:
2659
2660  .. code-block:: yaml
2661
2662    RawStringFormats:
2663      - Language: TextProto
2664          Delimiters:
2665            - 'pb'
2666            - 'proto'
2667          EnclosingFunctions:
2668            - 'PARSE_TEXT_PROTO'
2669          BasedOnStyle: google
2670      - Language: Cpp
2671          Delimiters:
2672            - 'cc'
2673            - 'cpp'
2674          BasedOnStyle: llvm
2675          CanonicalDelimiter: 'cc'
2676
2677**ReflowComments** (``bool``)
2678  If ``true``, clang-format will attempt to re-flow comments.
2679
2680  .. code-block:: c++
2681
2682     false:
2683     // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
2684     /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */
2685
2686     true:
2687     // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
2688     // information
2689     /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
2690      * information */
2691
2692**SortIncludes** (``bool``)
2693  If ``true``, clang-format will sort ``#includes``.
2694
2695  .. code-block:: c++
2696
2697     false:                                 true:
2698     #include "b.h"                 vs.     #include "a.h"
2699     #include "a.h"                         #include "b.h"
2700
2701**SortJavaStaticImport** (``SortJavaStaticImportOptions``)
2702  When sorting Java imports, by default static imports are placed before
2703  non-static imports. If ``JavaStaticImportAfterImport`` is ``After``,
2704  static imports are placed after non-static imports.
2705
2706  Possible values:
2707
2708  * ``SJSIO_Before`` (in configuration: ``Before``)
2709    Static imports are placed before non-static imports.
2710
2711    .. code-block:: java
2712
2713      import static org.example.function1;
2714
2715      import org.example.ClassA;
2716
2717  * ``SJSIO_After`` (in configuration: ``After``)
2718    Static imports are placed after non-static imports.
2719
2720    .. code-block:: java
2721
2722      import org.example.ClassA;
2723
2724      import static org.example.function1;
2725
2726
2727
2728**SortUsingDeclarations** (``bool``)
2729  If ``true``, clang-format will sort using declarations.
2730
2731  The order of using declarations is defined as follows:
2732  Split the strings by "::" and discard any initial empty strings. The last
2733  element of each list is a non-namespace name; all others are namespace
2734  names. Sort the lists of names lexicographically, where the sort order of
2735  individual names is that all non-namespace names come before all namespace
2736  names, and within those groups, names are in case-insensitive
2737  lexicographic order.
2738
2739  .. code-block:: c++
2740
2741     false:                                 true:
2742     using std::cout;               vs.     using std::cin;
2743     using std::cin;                        using std::cout;
2744
2745**SpaceAfterCStyleCast** (``bool``)
2746  If ``true``, a space is inserted after C style casts.
2747
2748  .. code-block:: c++
2749
2750     true:                                  false:
2751     (int) i;                       vs.     (int)i;
2752
2753**SpaceAfterLogicalNot** (``bool``)
2754  If ``true``, a space is inserted after the logical not operator (``!``).
2755
2756  .. code-block:: c++
2757
2758     true:                                  false:
2759     ! someExpression();            vs.     !someExpression();
2760
2761**SpaceAfterTemplateKeyword** (``bool``)
2762  If ``true``, a space will be inserted after the 'template' keyword.
2763
2764  .. code-block:: c++
2765
2766     true:                                  false:
2767     template <int> void foo();     vs.     template<int> void foo();
2768
2769**SpaceAroundPointerQualifiers** (``SpaceAroundPointerQualifiersStyle``)
2770  Defines in which cases to put a space before or after pointer qualifiers
2771
2772  Possible values:
2773
2774  * ``SAPQ_Default`` (in configuration: ``Default``)
2775    Don't ensure spaces around pointer qualifiers and use PointerAlignment
2776    instead.
2777
2778    .. code-block:: c++
2779
2780       PointerAlignment: Left                 PointerAlignment: Right
2781       void* const* x = NULL;         vs.     void *const *x = NULL;
2782
2783  * ``SAPQ_Before`` (in configuration: ``Before``)
2784    Ensure that there is a space before pointer qualifiers.
2785
2786    .. code-block:: c++
2787
2788       PointerAlignment: Left                 PointerAlignment: Right
2789       void* const* x = NULL;         vs.     void * const *x = NULL;
2790
2791  * ``SAPQ_After`` (in configuration: ``After``)
2792    Ensure that there is a space after pointer qualifiers.
2793
2794    .. code-block:: c++
2795
2796       PointerAlignment: Left                 PointerAlignment: Right
2797       void* const * x = NULL;         vs.     void *const *x = NULL;
2798
2799  * ``SAPQ_Both`` (in configuration: ``Both``)
2800    Ensure that there is a space both before and after pointer qualifiers.
2801
2802    .. code-block:: c++
2803
2804       PointerAlignment: Left                 PointerAlignment: Right
2805       void* const * x = NULL;         vs.     void * const *x = NULL;
2806
2807
2808
2809**SpaceBeforeAssignmentOperators** (``bool``)
2810  If ``false``, spaces will be removed before assignment operators.
2811
2812  .. code-block:: c++
2813
2814     true:                                  false:
2815     int a = 5;                     vs.     int a= 5;
2816     a += 42;                               a+= 42;
2817
2818**SpaceBeforeCaseColon** (``bool``)
2819  If ``false``, spaces will be removed before case colon.
2820
2821  .. code-block:: c++
2822
2823    true:                                   false
2824    switch (x) {                    vs.     switch (x) {
2825      case 1 : break;                         case 1: break;
2826    }                                       }
2827
2828**SpaceBeforeCpp11BracedList** (``bool``)
2829  If ``true``, a space will be inserted before a C++11 braced list
2830  used to initialize an object (after the preceding identifier or type).
2831
2832  .. code-block:: c++
2833
2834     true:                                  false:
2835     Foo foo { bar };               vs.     Foo foo{ bar };
2836     Foo {};                                Foo{};
2837     vector<int> { 1, 2, 3 };               vector<int>{ 1, 2, 3 };
2838     new int[3] { 1, 2, 3 };                new int[3]{ 1, 2, 3 };
2839
2840**SpaceBeforeCtorInitializerColon** (``bool``)
2841  If ``false``, spaces will be removed before constructor initializer
2842  colon.
2843
2844  .. code-block:: c++
2845
2846     true:                                  false:
2847     Foo::Foo() : a(a) {}                   Foo::Foo(): a(a) {}
2848
2849**SpaceBeforeInheritanceColon** (``bool``)
2850  If ``false``, spaces will be removed before inheritance colon.
2851
2852  .. code-block:: c++
2853
2854     true:                                  false:
2855     class Foo : Bar {}             vs.     class Foo: Bar {}
2856
2857**SpaceBeforeParens** (``SpaceBeforeParensOptions``)
2858  Defines in which cases to put a space before opening parentheses.
2859
2860  Possible values:
2861
2862  * ``SBPO_Never`` (in configuration: ``Never``)
2863    Never put a space before opening parentheses.
2864
2865    .. code-block:: c++
2866
2867       void f() {
2868         if(true) {
2869           f();
2870         }
2871       }
2872
2873  * ``SBPO_ControlStatements`` (in configuration: ``ControlStatements``)
2874    Put a space before opening parentheses only after control statement
2875    keywords (``for/if/while...``).
2876
2877    .. code-block:: c++
2878
2879       void f() {
2880         if (true) {
2881           f();
2882         }
2883       }
2884
2885  * ``SBPO_ControlStatementsExceptForEachMacros`` (in configuration: ``ControlStatementsExceptForEachMacros``)
2886    Same as ``SBPO_ControlStatements`` except this option doesn't apply to
2887    ForEach macros. This is useful in projects where ForEach macros are
2888    treated as function calls instead of control statements.
2889
2890    .. code-block:: c++
2891
2892       void f() {
2893         Q_FOREACH(...) {
2894           f();
2895         }
2896       }
2897
2898  * ``SBPO_NonEmptyParentheses`` (in configuration: ``NonEmptyParentheses``)
2899    Put a space before opening parentheses only if the parentheses are not
2900    empty i.e. '()'
2901
2902    .. code-block:: c++
2903
2904      void() {
2905        if (true) {
2906          f();
2907          g (x, y, z);
2908        }
2909      }
2910
2911  * ``SBPO_Always`` (in configuration: ``Always``)
2912    Always put a space before opening parentheses, except when it's
2913    prohibited by the syntax rules (in function-like macro definitions) or
2914    when determined by other style rules (after unary operators, opening
2915    parentheses, etc.)
2916
2917    .. code-block:: c++
2918
2919       void f () {
2920         if (true) {
2921           f ();
2922         }
2923       }
2924
2925
2926
2927**SpaceBeforeRangeBasedForLoopColon** (``bool``)
2928  If ``false``, spaces will be removed before range-based for loop
2929  colon.
2930
2931  .. code-block:: c++
2932
2933     true:                                  false:
2934     for (auto v : values) {}       vs.     for(auto v: values) {}
2935
2936**SpaceBeforeSquareBrackets** (``bool``)
2937  If ``true``, spaces will be before  ``[``.
2938  Lambdas will not be affected. Only the first ``[`` will get a space added.
2939
2940  .. code-block:: c++
2941
2942     true:                                  false:
2943     int a [5];                    vs.      int a[5];
2944     int a [5][5];                 vs.      int a[5][5];
2945
2946**SpaceInEmptyBlock** (``bool``)
2947  If ``true``, spaces will be inserted into ``{}``.
2948
2949  .. code-block:: c++
2950
2951     true:                                false:
2952     void f() { }                   vs.   void f() {}
2953     while (true) { }                     while (true) {}
2954
2955**SpaceInEmptyParentheses** (``bool``)
2956  If ``true``, spaces may be inserted into ``()``.
2957
2958  .. code-block:: c++
2959
2960     true:                                false:
2961     void f( ) {                    vs.   void f() {
2962       int x[] = {foo( ), bar( )};          int x[] = {foo(), bar()};
2963       if (true) {                          if (true) {
2964         f( );                                f();
2965       }                                    }
2966     }                                    }
2967
2968**SpacesBeforeTrailingComments** (``unsigned``)
2969  The number of spaces before trailing line comments
2970  (``//`` - comments).
2971
2972  This does not affect trailing block comments (``/*`` - comments) as
2973  those commonly have different usage patterns and a number of special
2974  cases.
2975
2976  .. code-block:: c++
2977
2978     SpacesBeforeTrailingComments: 3
2979     void f() {
2980       if (true) {   // foo1
2981         f();        // bar
2982       }             // foo
2983     }
2984
2985**SpacesInAngles** (``bool``)
2986  If ``true``, spaces will be inserted after ``<`` and before ``>``
2987  in template argument lists.
2988
2989  .. code-block:: c++
2990
2991     true:                                  false:
2992     static_cast< int >(arg);       vs.     static_cast<int>(arg);
2993     std::function< void(int) > fct;        std::function<void(int)> fct;
2994
2995**SpacesInCStyleCastParentheses** (``bool``)
2996  If ``true``, spaces may be inserted into C style casts.
2997
2998  .. code-block:: c++
2999
3000     true:                                  false:
3001     x = ( int32 )y                 vs.     x = (int32)y
3002
3003**SpacesInConditionalStatement** (``bool``)
3004  If ``true``, spaces will be inserted around if/for/switch/while
3005  conditions.
3006
3007  .. code-block:: c++
3008
3009     true:                                  false:
3010     if ( a )  { ... }              vs.     if (a) { ... }
3011     while ( i < 5 )  { ... }               while (i < 5) { ... }
3012
3013**SpacesInContainerLiterals** (``bool``)
3014  If ``true``, spaces are inserted inside container literals (e.g.
3015  ObjC and Javascript array and dict literals).
3016
3017  .. code-block:: js
3018
3019     true:                                  false:
3020     var arr = [ 1, 2, 3 ];         vs.     var arr = [1, 2, 3];
3021     f({a : 1, b : 2, c : 3});              f({a: 1, b: 2, c: 3});
3022
3023**SpacesInParentheses** (``bool``)
3024  If ``true``, spaces will be inserted after ``(`` and before ``)``.
3025
3026  .. code-block:: c++
3027
3028     true:                                  false:
3029     t f( Deleted & ) & = delete;   vs.     t f(Deleted &) & = delete;
3030
3031**SpacesInSquareBrackets** (``bool``)
3032  If ``true``, spaces will be inserted after ``[`` and before ``]``.
3033  Lambdas without arguments or unspecified size array declarations will not
3034  be affected.
3035
3036  .. code-block:: c++
3037
3038     true:                                  false:
3039     int a[ 5 ];                    vs.     int a[5];
3040     std::unique_ptr<int[]> foo() {} // Won't be affected
3041
3042**Standard** (``LanguageStandard``)
3043  Parse and format C++ constructs compatible with this standard.
3044
3045  .. code-block:: c++
3046
3047     c++03:                                 latest:
3048     vector<set<int> > x;           vs.     vector<set<int>> x;
3049
3050  Possible values:
3051
3052  * ``LS_Cpp03`` (in configuration: ``c++03``)
3053    Parse and format as C++03.
3054    ``Cpp03`` is a deprecated alias for ``c++03``
3055
3056  * ``LS_Cpp11`` (in configuration: ``c++11``)
3057    Parse and format as C++11.
3058
3059  * ``LS_Cpp14`` (in configuration: ``c++14``)
3060    Parse and format as C++14.
3061
3062  * ``LS_Cpp17`` (in configuration: ``c++17``)
3063    Parse and format as C++17.
3064
3065  * ``LS_Cpp20`` (in configuration: ``c++20``)
3066    Parse and format as C++20.
3067
3068  * ``LS_Latest`` (in configuration: ``Latest``)
3069    Parse and format using the latest supported language version.
3070    ``Cpp11`` is a deprecated alias for ``Latest``
3071
3072  * ``LS_Auto`` (in configuration: ``Auto``)
3073    Automatic detection based on the input.
3074
3075
3076
3077**StatementAttributeLikeMacros** (``std::vector<std::string>``)
3078  Macros which are ignored in front of a statement, as if they were an
3079  attribute. So that they are not parsed as identifier, for example for Qts
3080  emit.
3081
3082  .. code-block:: c++
3083
3084    AlignConsecutiveDeclarations: true
3085    StatementAttributeLikeMacros: []
3086    unsigned char data = 'x';
3087    emit          signal(data); // This is parsed as variable declaration.
3088
3089    AlignConsecutiveDeclarations: true
3090    StatementAttributeLikeMacros: [emit]
3091    unsigned char data = 'x';
3092    emit signal(data); // Now it's fine again.
3093
3094**StatementMacros** (``std::vector<std::string>``)
3095  A vector of macros that should be interpreted as complete
3096  statements.
3097
3098  Typical macros are expressions, and require a semi-colon to be
3099  added; sometimes this is not the case, and this allows to make
3100  clang-format aware of such cases.
3101
3102  For example: Q_UNUSED
3103
3104**TabWidth** (``unsigned``)
3105  The number of columns used for tab stops.
3106
3107**TypenameMacros** (``std::vector<std::string>``)
3108  A vector of macros that should be interpreted as type declarations
3109  instead of as function calls.
3110
3111  These are expected to be macros of the form:
3112
3113  .. code-block:: c++
3114
3115    STACK_OF(...)
3116
3117  In the .clang-format configuration file, this can be configured like:
3118
3119  .. code-block:: yaml
3120
3121    TypenameMacros: ['STACK_OF', 'LIST']
3122
3123  For example: OpenSSL STACK_OF, BSD LIST_ENTRY.
3124
3125**UseCRLF** (``bool``)
3126  Use ``\r\n`` instead of ``\n`` for line breaks.
3127  Also used as fallback if ``DeriveLineEnding`` is true.
3128
3129**UseTab** (``UseTabStyle``)
3130  The way to use tab characters in the resulting file.
3131
3132  Possible values:
3133
3134  * ``UT_Never`` (in configuration: ``Never``)
3135    Never use tab.
3136
3137  * ``UT_ForIndentation`` (in configuration: ``ForIndentation``)
3138    Use tabs only for indentation.
3139
3140  * ``UT_ForContinuationAndIndentation`` (in configuration: ``ForContinuationAndIndentation``)
3141    Fill all leading whitespace with tabs, and use spaces for alignment that
3142    appears within a line (e.g. consecutive assignments and declarations).
3143
3144  * ``UT_AlignWithSpaces`` (in configuration: ``AlignWithSpaces``)
3145    Use tabs for line continuation and indentation, and spaces for
3146    alignment.
3147
3148  * ``UT_Always`` (in configuration: ``Always``)
3149    Use tabs whenever we need to fill whitespace that spans at least from
3150    one tab stop to the next one.
3151
3152
3153
3154**WhitespaceSensitiveMacros** (``std::vector<std::string>``)
3155  A vector of macros which are whitespace-sensitive and should not
3156  be touched.
3157
3158  These are expected to be macros of the form:
3159
3160  .. code-block:: c++
3161
3162    STRINGIZE(...)
3163
3164  In the .clang-format configuration file, this can be configured like:
3165
3166  .. code-block:: yaml
3167
3168    WhitespaceSensitiveMacros: ['STRINGIZE', 'PP_STRINGIZE']
3169
3170  For example: BOOST_PP_STRINGIZE
3171
3172.. END_FORMAT_STYLE_OPTIONS
3173
3174Adding additional style options
3175===============================
3176
3177Each additional style option adds costs to the clang-format project. Some of
3178these costs affect the clang-format development itself, as we need to make
3179sure that any given combination of options work and that new features don't
3180break any of the existing options in any way. There are also costs for end users
3181as options become less discoverable and people have to think about and make a
3182decision on options they don't really care about.
3183
3184The goal of the clang-format project is more on the side of supporting a
3185limited set of styles really well as opposed to supporting every single style
3186used by a codebase somewhere in the wild. Of course, we do want to support all
3187major projects and thus have established the following bar for adding style
3188options. Each new style option must ..
3189
3190  * be used in a project of significant size (have dozens of contributors)
3191  * have a publicly accessible style guide
3192  * have a person willing to contribute and maintain patches
3193
3194Examples
3195========
3196
3197A style similar to the `Linux Kernel style
3198<https://www.kernel.org/doc/Documentation/CodingStyle>`_:
3199
3200.. code-block:: yaml
3201
3202  BasedOnStyle: LLVM
3203  IndentWidth: 8
3204  UseTab: Always
3205  BreakBeforeBraces: Linux
3206  AllowShortIfStatementsOnASingleLine: false
3207  IndentCaseLabels: false
3208
3209The result is (imagine that tabs are used for indentation here):
3210
3211.. code-block:: c++
3212
3213  void test()
3214  {
3215          switch (x) {
3216          case 0:
3217          case 1:
3218                  do_something();
3219                  break;
3220          case 2:
3221                  do_something_else();
3222                  break;
3223          default:
3224                  break;
3225          }
3226          if (condition)
3227                  do_something_completely_different();
3228
3229          if (x == y) {
3230                  q();
3231          } else if (x > y) {
3232                  w();
3233          } else {
3234                  r();
3235          }
3236  }
3237
3238A style similar to the default Visual Studio formatting style:
3239
3240.. code-block:: yaml
3241
3242  UseTab: Never
3243  IndentWidth: 4
3244  BreakBeforeBraces: Allman
3245  AllowShortIfStatementsOnASingleLine: false
3246  IndentCaseLabels: false
3247  ColumnLimit: 0
3248
3249The result is:
3250
3251.. code-block:: c++
3252
3253  void test()
3254  {
3255      switch (suffix)
3256      {
3257      case 0:
3258      case 1:
3259          do_something();
3260          break;
3261      case 2:
3262          do_something_else();
3263          break;
3264      default:
3265          break;
3266      }
3267      if (condition)
3268          do_somthing_completely_different();
3269
3270      if (x == y)
3271      {
3272          q();
3273      }
3274      else if (x > y)
3275      {
3276          w();
3277      }
3278      else
3279      {
3280          r();
3281      }
3282  }
3283