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://www.chromium.org/developers/coding-style>`_
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
155.. START_FORMAT_STYLE_OPTIONS
156
157**AccessModifierOffset** (``int``)
158  The extra indent or outdent of access modifiers, e.g. ``public:``.
159
160**AlignAfterOpenBracket** (``BracketAlignmentStyle``)
161  If ``true``, horizontally aligns arguments after an open bracket.
162
163  This applies to round brackets (parentheses), angle brackets and square
164  brackets.
165
166  Possible values:
167
168  * ``BAS_Align`` (in configuration: ``Align``)
169    Align parameters on the open bracket, e.g.:
170
171    .. code-block:: c++
172
173      someLongFunction(argument1,
174                       argument2);
175
176  * ``BAS_DontAlign`` (in configuration: ``DontAlign``)
177    Don't align, instead use ``ContinuationIndentWidth``, e.g.:
178
179    .. code-block:: c++
180
181      someLongFunction(argument1,
182          argument2);
183
184  * ``BAS_AlwaysBreak`` (in configuration: ``AlwaysBreak``)
185    Always break after an open bracket, if the parameters don't fit
186    on a single line, e.g.:
187
188    .. code-block:: c++
189
190      someLongFunction(
191          argument1, argument2);
192
193
194
195**AlignConsecutiveMacros** (``bool``)
196  If ``true``, aligns consecutive C/C++ preprocessor macros.
197
198  This will align the C/C++ preprocessor macros of consecutive lines. This
199  will result in formattings like
200
201  .. code-block:: c++
202
203    #define SHORT_NAME       42
204    #define LONGER_NAME      0x007f
205    #define EVEN_LONGER_NAME (2)
206    #define foo(x)           (x * x)
207    #define bar(y, z)        (y + z)
208
209**AlignConsecutiveAssignments** (``bool``)
210  If ``true``, aligns consecutive assignments.
211
212  This will align the assignment operators of consecutive lines. This
213  will result in formattings like
214
215  .. code-block:: c++
216
217    int aaaa = 12;
218    int b    = 23;
219    int ccc  = 23;
220
221**AlignConsecutiveDeclarations** (``bool``)
222  If ``true``, aligns consecutive declarations.
223
224  This will align the declaration names of consecutive lines. This
225  will result in formattings like
226
227  .. code-block:: c++
228
229    int         aaaa = 12;
230    float       b = 23;
231    std::string ccc = 23;
232
233**AlignEscapedNewlines** (``EscapedNewlineAlignmentStyle``)
234  Options for aligning backslashes in escaped newlines.
235
236  Possible values:
237
238  * ``ENAS_DontAlign`` (in configuration: ``DontAlign``)
239    Don't align escaped newlines.
240
241    .. code-block:: c++
242
243      #define A \
244        int aaaa; \
245        int b; \
246        int dddddddddd;
247
248  * ``ENAS_Left`` (in configuration: ``Left``)
249    Align escaped newlines as far left as possible.
250
251    .. code-block:: c++
252
253      true:
254      #define A   \
255        int aaaa; \
256        int b;    \
257        int dddddddddd;
258
259      false:
260
261  * ``ENAS_Right`` (in configuration: ``Right``)
262    Align escaped newlines in the right-most column.
263
264    .. code-block:: c++
265
266      #define A                                                                      \
267        int aaaa;                                                                    \
268        int b;                                                                       \
269        int dddddddddd;
270
271
272
273**AlignOperands** (``bool``)
274  If ``true``, horizontally align operands of binary and ternary
275  expressions.
276
277  Specifically, this aligns operands of a single expression that needs to be
278  split over multiple lines, e.g.:
279
280  .. code-block:: c++
281
282    int aaa = bbbbbbbbbbbbbbb +
283              ccccccccccccccc;
284
285**AlignTrailingComments** (``bool``)
286  If ``true``, aligns trailing comments.
287
288  .. code-block:: c++
289
290    true:                                   false:
291    int a;     // My comment a      vs.     int a; // My comment a
292    int b = 2; // comment  b                int b = 2; // comment about b
293
294**AllowAllArgumentsOnNextLine** (``bool``)
295  If a function call or braced initializer list doesn't fit on a
296  line, allow putting all arguments onto the next line, even if
297  ``BinPackArguments`` is ``false``.
298
299  .. code-block:: c++
300
301    true:
302    callFunction(
303        a, b, c, d);
304
305    false:
306    callFunction(a,
307                 b,
308                 c,
309                 d);
310
311**AllowAllConstructorInitializersOnNextLine** (``bool``)
312  If a constructor definition with a member initializer list doesn't
313  fit on a single line, allow putting all member initializers onto the next
314  line, if ```ConstructorInitializerAllOnOneLineOrOnePerLine``` is true.
315  Note that this parameter has no effect if
316  ```ConstructorInitializerAllOnOneLineOrOnePerLine``` is false.
317
318  .. code-block:: c++
319
320    true:
321    MyClass::MyClass() :
322        member0(0), member1(2) {}
323
324    false:
325    MyClass::MyClass() :
326        member0(0),
327        member1(2) {}
328
329**AllowAllParametersOfDeclarationOnNextLine** (``bool``)
330  If the function declaration doesn't fit on a line,
331  allow putting all parameters of a function declaration onto
332  the next line even if ``BinPackParameters`` is ``false``.
333
334  .. code-block:: c++
335
336    true:
337    void myFunction(
338        int a, int b, int c, int d, int e);
339
340    false:
341    void myFunction(int a,
342                    int b,
343                    int c,
344                    int d,
345                    int e);
346
347**AllowShortBlocksOnASingleLine** (``bool``)
348  Allows contracting simple braced statements to a single line.
349
350  E.g., this allows ``if (a) { return; }`` to be put on a single line.
351
352**AllowShortCaseLabelsOnASingleLine** (``bool``)
353  If ``true``, short case labels will be contracted to a single line.
354
355  .. code-block:: c++
356
357    true:                                   false:
358    switch (a) {                    vs.     switch (a) {
359    case 1: x = 1; break;                   case 1:
360    case 2: return;                           x = 1;
361    }                                         break;
362                                            case 2:
363                                              return;
364                                            }
365
366**AllowShortFunctionsOnASingleLine** (``ShortFunctionStyle``)
367  Dependent on the value, ``int f() { return 0; }`` can be put on a
368  single line.
369
370  Possible values:
371
372  * ``SFS_None`` (in configuration: ``None``)
373    Never merge functions into a single line.
374
375  * ``SFS_InlineOnly`` (in configuration: ``InlineOnly``)
376    Only merge functions defined inside a class. Same as "inline",
377    except it does not implies "empty": i.e. top level empty functions
378    are not merged either.
379
380    .. code-block:: c++
381
382      class Foo {
383        void f() { foo(); }
384      };
385      void f() {
386        foo();
387      }
388      void f() {
389      }
390
391  * ``SFS_Empty`` (in configuration: ``Empty``)
392    Only merge empty functions.
393
394    .. code-block:: c++
395
396      void f() {}
397      void f2() {
398        bar2();
399      }
400
401  * ``SFS_Inline`` (in configuration: ``Inline``)
402    Only merge functions defined inside a class. Implies "empty".
403
404    .. code-block:: c++
405
406      class Foo {
407        void f() { foo(); }
408      };
409      void f() {
410        foo();
411      }
412      void f() {}
413
414  * ``SFS_All`` (in configuration: ``All``)
415    Merge all functions fitting on a single line.
416
417    .. code-block:: c++
418
419      class Foo {
420        void f() { foo(); }
421      };
422      void f() { bar(); }
423
424
425
426**AllowShortIfStatementsOnASingleLine** (``ShortIfStyle``)
427  If ``true``, ``if (a) return;`` can be put on a single line.
428
429  Possible values:
430
431  * ``SIS_Never`` (in configuration: ``Never``)
432    Never put short ifs on the same line.
433
434    .. code-block:: c++
435
436      if (a)
437        return ;
438      else {
439        return;
440      }
441
442  * ``SIS_WithoutElse`` (in configuration: ``WithoutElse``)
443    Without else put short ifs on the same line only if
444    the else is not a compound statement.
445
446    .. code-block:: c++
447
448      if (a) return;
449      else
450        return;
451
452  * ``SIS_Always`` (in configuration: ``Always``)
453    Always put short ifs on the same line if
454    the else is not a compound statement or not.
455
456    .. code-block:: c++
457
458      if (a) return;
459      else {
460        return;
461      }
462
463
464
465**AllowShortLambdasOnASingleLine** (``ShortLambdaStyle``)
466  Dependent on the value, ``auto lambda []() { return 0; }`` can be put on a
467  single line.
468
469  Possible values:
470
471  * ``SLS_None`` (in configuration: ``None``)
472    Never merge lambdas into a single line.
473
474  * ``SLS_Empty`` (in configuration: ``Empty``)
475    Only merge empty lambdas.
476
477    .. code-block:: c++
478
479      auto lambda = [](int a) {}
480      auto lambda2 = [](int a) {
481          return a;
482      };
483
484  * ``SLS_Inline`` (in configuration: ``Inline``)
485    Merge lambda into a single line if argument of a function.
486
487    .. code-block:: c++
488
489      auto lambda = [](int a) {
490          return a;
491      };
492      sort(a.begin(), a.end(), ()[] { return x < y; })
493
494  * ``SLS_All`` (in configuration: ``All``)
495    Merge all lambdas fitting on a single line.
496
497    .. code-block:: c++
498
499      auto lambda = [](int a) {}
500      auto lambda2 = [](int a) { return a; };
501
502
503
504**AllowShortLoopsOnASingleLine** (``bool``)
505  If ``true``, ``while (true) continue;`` can be put on a single
506  line.
507
508**AlwaysBreakAfterDefinitionReturnType** (``DefinitionReturnTypeBreakingStyle``)
509  The function definition return type breaking style to use.  This
510  option is **deprecated** and is retained for backwards compatibility.
511
512  Possible values:
513
514  * ``DRTBS_None`` (in configuration: ``None``)
515    Break after return type automatically.
516    ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
517
518  * ``DRTBS_All`` (in configuration: ``All``)
519    Always break after the return type.
520
521  * ``DRTBS_TopLevel`` (in configuration: ``TopLevel``)
522    Always break after the return types of top-level functions.
523
524
525
526**AlwaysBreakAfterReturnType** (``ReturnTypeBreakingStyle``)
527  The function declaration return type breaking style to use.
528
529  Possible values:
530
531  * ``RTBS_None`` (in configuration: ``None``)
532    Break after return type automatically.
533    ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
534
535    .. code-block:: c++
536
537      class A {
538        int f() { return 0; };
539      };
540      int f();
541      int f() { return 1; }
542
543  * ``RTBS_All`` (in configuration: ``All``)
544    Always break after the return type.
545
546    .. code-block:: c++
547
548      class A {
549        int
550        f() {
551          return 0;
552        };
553      };
554      int
555      f();
556      int
557      f() {
558        return 1;
559      }
560
561  * ``RTBS_TopLevel`` (in configuration: ``TopLevel``)
562    Always break after the return types of top-level functions.
563
564    .. code-block:: c++
565
566      class A {
567        int f() { return 0; };
568      };
569      int
570      f();
571      int
572      f() {
573        return 1;
574      }
575
576  * ``RTBS_AllDefinitions`` (in configuration: ``AllDefinitions``)
577    Always break after the return type of function definitions.
578
579    .. code-block:: c++
580
581      class A {
582        int
583        f() {
584          return 0;
585        };
586      };
587      int f();
588      int
589      f() {
590        return 1;
591      }
592
593  * ``RTBS_TopLevelDefinitions`` (in configuration: ``TopLevelDefinitions``)
594    Always break after the return type of top-level definitions.
595
596    .. code-block:: c++
597
598      class A {
599        int f() { return 0; };
600      };
601      int f();
602      int
603      f() {
604        return 1;
605      }
606
607
608
609**AlwaysBreakBeforeMultilineStrings** (``bool``)
610  If ``true``, always break before multiline string literals.
611
612  This flag is mean to make cases where there are multiple multiline strings
613  in a file look more consistent. Thus, it will only take effect if wrapping
614  the string at that point leads to it being indented
615  ``ContinuationIndentWidth`` spaces from the start of the line.
616
617  .. code-block:: c++
618
619     true:                                  false:
620     aaaa =                         vs.     aaaa = "bbbb"
621         "bbbb"                                    "cccc";
622         "cccc";
623
624**AlwaysBreakTemplateDeclarations** (``BreakTemplateDeclarationsStyle``)
625  The template declaration breaking style to use.
626
627  Possible values:
628
629  * ``BTDS_No`` (in configuration: ``No``)
630    Do not force break before declaration.
631    ``PenaltyBreakTemplateDeclaration`` is taken into account.
632
633    .. code-block:: c++
634
635       template <typename T> T foo() {
636       }
637       template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa,
638                                   int bbbbbbbbbbbbbbbbbbbbb) {
639       }
640
641  * ``BTDS_MultiLine`` (in configuration: ``MultiLine``)
642    Force break after template declaration only when the following
643    declaration spans multiple lines.
644
645    .. code-block:: c++
646
647       template <typename T> T foo() {
648       }
649       template <typename T>
650       T foo(int aaaaaaaaaaaaaaaaaaaaa,
651             int bbbbbbbbbbbbbbbbbbbbb) {
652       }
653
654  * ``BTDS_Yes`` (in configuration: ``Yes``)
655    Always break after template declaration.
656
657    .. code-block:: c++
658
659       template <typename T>
660       T foo() {
661       }
662       template <typename T>
663       T foo(int aaaaaaaaaaaaaaaaaaaaa,
664             int bbbbbbbbbbbbbbbbbbbbb) {
665       }
666
667
668
669**BinPackArguments** (``bool``)
670  If ``false``, a function call's arguments will either be all on the
671  same line or will have one line each.
672
673  .. code-block:: c++
674
675    true:
676    void f() {
677      f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa,
678        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
679    }
680
681    false:
682    void f() {
683      f(aaaaaaaaaaaaaaaaaaaa,
684        aaaaaaaaaaaaaaaaaaaa,
685        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
686    }
687
688**BinPackParameters** (``bool``)
689  If ``false``, a function declaration's or function definition's
690  parameters will either all be on the same line or will have one line each.
691
692  .. code-block:: c++
693
694    true:
695    void f(int aaaaaaaaaaaaaaaaaaaa, int aaaaaaaaaaaaaaaaaaaa,
696           int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
697
698    false:
699    void f(int aaaaaaaaaaaaaaaaaaaa,
700           int aaaaaaaaaaaaaaaaaaaa,
701           int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
702
703**BraceWrapping** (``BraceWrappingFlags``)
704  Control of individual brace wrapping cases.
705
706  If ``BreakBeforeBraces`` is set to ``BS_Custom``, use this to specify how
707  each individual brace case should be handled. Otherwise, this is ignored.
708
709  .. code-block:: yaml
710
711    # Example of usage:
712    BreakBeforeBraces: Custom
713    BraceWrapping:
714      AfterEnum: true
715      AfterStruct: false
716      SplitEmptyFunction: false
717
718  Nested configuration flags:
719
720
721  * ``bool AfterCaseLabel`` Wrap case labels.
722
723    .. code-block:: c++
724
725      false:                                true:
726      switch (foo) {                vs.     switch (foo) {
727        case 1: {                             case 1:
728          bar();                              {
729          break;                                bar();
730        }                                       break;
731        default: {                            }
732          plop();                             default:
733        }                                     {
734      }                                         plop();
735                                              }
736                                            }
737
738  * ``bool AfterClass`` Wrap class definitions.
739
740    .. code-block:: c++
741
742      true:
743      class foo {};
744
745      false:
746      class foo
747      {};
748
749  * ``bool AfterControlStatement`` Wrap control statements (``if``/``for``/``while``/``switch``/..).
750
751    .. code-block:: c++
752
753      true:
754      if (foo())
755      {
756      } else
757      {}
758      for (int i = 0; i < 10; ++i)
759      {}
760
761      false:
762      if (foo()) {
763      } else {
764      }
765      for (int i = 0; i < 10; ++i) {
766      }
767
768  * ``bool AfterEnum`` Wrap enum definitions.
769
770    .. code-block:: c++
771
772      true:
773      enum X : int
774      {
775        B
776      };
777
778      false:
779      enum X : int { B };
780
781  * ``bool AfterFunction`` Wrap function definitions.
782
783    .. code-block:: c++
784
785      true:
786      void foo()
787      {
788        bar();
789        bar2();
790      }
791
792      false:
793      void foo() {
794        bar();
795        bar2();
796      }
797
798  * ``bool AfterNamespace`` Wrap namespace definitions.
799
800    .. code-block:: c++
801
802      true:
803      namespace
804      {
805      int foo();
806      int bar();
807      }
808
809      false:
810      namespace {
811      int foo();
812      int bar();
813      }
814
815  * ``bool AfterObjCDeclaration`` Wrap ObjC definitions (interfaces, implementations...).
816    @autoreleasepool and @synchronized blocks are wrapped
817    according to `AfterControlStatement` flag.
818
819  * ``bool AfterStruct`` Wrap struct definitions.
820
821    .. code-block:: c++
822
823      true:
824      struct foo
825      {
826        int x;
827      };
828
829      false:
830      struct foo {
831        int x;
832      };
833
834  * ``bool AfterUnion`` Wrap union definitions.
835
836    .. code-block:: c++
837
838      true:
839      union foo
840      {
841        int x;
842      }
843
844      false:
845      union foo {
846        int x;
847      }
848
849  * ``bool AfterExternBlock`` Wrap extern blocks.
850
851    .. code-block:: c++
852
853      true:
854      extern "C"
855      {
856        int foo();
857      }
858
859      false:
860      extern "C" {
861      int foo();
862      }
863
864  * ``bool BeforeCatch`` Wrap before ``catch``.
865
866    .. code-block:: c++
867
868      true:
869      try {
870        foo();
871      }
872      catch () {
873      }
874
875      false:
876      try {
877        foo();
878      } catch () {
879      }
880
881  * ``bool BeforeElse`` Wrap before ``else``.
882
883    .. code-block:: c++
884
885      true:
886      if (foo()) {
887      }
888      else {
889      }
890
891      false:
892      if (foo()) {
893      } else {
894      }
895
896  * ``bool IndentBraces`` Indent the wrapped braces themselves.
897
898  * ``bool SplitEmptyFunction`` If ``false``, empty function body can be put on a single line.
899    This option is used only if the opening brace of the function has
900    already been wrapped, i.e. the `AfterFunction` brace wrapping mode is
901    set, and the function could/should not be put on a single line (as per
902    `AllowShortFunctionsOnASingleLine` and constructor formatting options).
903
904    .. code-block:: c++
905
906      int f()   vs.   inf f()
907      {}              {
908                      }
909
910  * ``bool SplitEmptyRecord`` If ``false``, empty record (e.g. class, struct or union) body
911    can be put on a single line. This option is used only if the opening
912    brace of the record has already been wrapped, i.e. the `AfterClass`
913    (for classes) brace wrapping mode is set.
914
915    .. code-block:: c++
916
917      class Foo   vs.  class Foo
918      {}               {
919                       }
920
921  * ``bool SplitEmptyNamespace`` If ``false``, empty namespace body can be put on a single line.
922    This option is used only if the opening brace of the namespace has
923    already been wrapped, i.e. the `AfterNamespace` brace wrapping mode is
924    set.
925
926    .. code-block:: c++
927
928      namespace Foo   vs.  namespace Foo
929      {}                   {
930                           }
931
932
933**BreakAfterJavaFieldAnnotations** (``bool``)
934  Break after each annotation on a field in Java files.
935
936  .. code-block:: java
937
938     true:                                  false:
939     @Partial                       vs.     @Partial @Mock DataLoad loader;
940     @Mock
941     DataLoad loader;
942
943**BreakBeforeBinaryOperators** (``BinaryOperatorStyle``)
944  The way to wrap binary operators.
945
946  Possible values:
947
948  * ``BOS_None`` (in configuration: ``None``)
949    Break after operators.
950
951    .. code-block:: c++
952
953       LooooooooooongType loooooooooooooooooooooongVariable =
954           someLooooooooooooooooongFunction();
955
956       bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
957                            aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ==
958                        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
959                    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa >
960                        ccccccccccccccccccccccccccccccccccccccccc;
961
962  * ``BOS_NonAssignment`` (in configuration: ``NonAssignment``)
963    Break before operators that aren't assignments.
964
965    .. code-block:: c++
966
967       LooooooooooongType loooooooooooooooooooooongVariable =
968           someLooooooooooooooooongFunction();
969
970       bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
971                            + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
972                        == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
973                    && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
974                           > ccccccccccccccccccccccccccccccccccccccccc;
975
976  * ``BOS_All`` (in configuration: ``All``)
977    Break before operators.
978
979    .. code-block:: c++
980
981       LooooooooooongType loooooooooooooooooooooongVariable
982           = someLooooooooooooooooongFunction();
983
984       bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
985                            + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
986                        == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
987                    && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
988                           > ccccccccccccccccccccccccccccccccccccccccc;
989
990
991
992**BreakBeforeBraces** (``BraceBreakingStyle``)
993  The brace breaking style to use.
994
995  Possible values:
996
997  * ``BS_Attach`` (in configuration: ``Attach``)
998    Always attach braces to surrounding context.
999
1000    .. code-block:: c++
1001
1002      try {
1003        foo();
1004      } catch () {
1005      }
1006      void foo() { bar(); }
1007      class foo {};
1008      if (foo()) {
1009      } else {
1010      }
1011      enum X : int { A, B };
1012
1013  * ``BS_Linux`` (in configuration: ``Linux``)
1014    Like ``Attach``, but break before braces on function, namespace and
1015    class definitions.
1016
1017    .. code-block:: c++
1018
1019      try {
1020        foo();
1021      } catch () {
1022      }
1023      void foo() { bar(); }
1024      class foo
1025      {
1026      };
1027      if (foo()) {
1028      } else {
1029      }
1030      enum X : int { A, B };
1031
1032  * ``BS_Mozilla`` (in configuration: ``Mozilla``)
1033    Like ``Attach``, but break before braces on enum, function, and record
1034    definitions.
1035
1036    .. code-block:: c++
1037
1038      try {
1039        foo();
1040      } catch () {
1041      }
1042      void foo() { bar(); }
1043      class foo
1044      {
1045      };
1046      if (foo()) {
1047      } else {
1048      }
1049      enum X : int { A, B };
1050
1051  * ``BS_Stroustrup`` (in configuration: ``Stroustrup``)
1052    Like ``Attach``, but break before function definitions, ``catch``, and
1053    ``else``.
1054
1055    .. code-block:: c++
1056
1057      try {
1058        foo();
1059      }
1060      catch () {
1061      }
1062      void foo() { bar(); }
1063      class foo {
1064      };
1065      if (foo()) {
1066      }
1067      else {
1068      }
1069      enum X : int { A, B };
1070
1071  * ``BS_Allman`` (in configuration: ``Allman``)
1072    Always break before braces.
1073
1074    .. code-block:: c++
1075
1076      try
1077      {
1078        foo();
1079      }
1080      catch ()
1081      {
1082      }
1083      void foo() { bar(); }
1084      class foo
1085      {
1086      };
1087      if (foo())
1088      {
1089      }
1090      else
1091      {
1092      }
1093      enum X : int
1094      {
1095        A,
1096        B
1097      };
1098
1099  * ``BS_GNU`` (in configuration: ``GNU``)
1100    Always break before braces and add an extra level of indentation to
1101    braces of control statements, not to those of class, function
1102    or other definitions.
1103
1104    .. code-block:: c++
1105
1106      try
1107        {
1108          foo();
1109        }
1110      catch ()
1111        {
1112        }
1113      void foo() { bar(); }
1114      class foo
1115      {
1116      };
1117      if (foo())
1118        {
1119        }
1120      else
1121        {
1122        }
1123      enum X : int
1124      {
1125        A,
1126        B
1127      };
1128
1129  * ``BS_WebKit`` (in configuration: ``WebKit``)
1130    Like ``Attach``, but break before functions.
1131
1132    .. code-block:: c++
1133
1134      try {
1135        foo();
1136      } catch () {
1137      }
1138      void foo() { bar(); }
1139      class foo {
1140      };
1141      if (foo()) {
1142      } else {
1143      }
1144      enum X : int { A, B };
1145
1146  * ``BS_Custom`` (in configuration: ``Custom``)
1147    Configure each individual brace in `BraceWrapping`.
1148
1149
1150
1151**BreakBeforeTernaryOperators** (``bool``)
1152  If ``true``, ternary operators will be placed after line breaks.
1153
1154  .. code-block:: c++
1155
1156     true:
1157     veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription
1158         ? firstValue
1159         : SecondValueVeryVeryVeryVeryLong;
1160
1161     false:
1162     veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ?
1163         firstValue :
1164         SecondValueVeryVeryVeryVeryLong;
1165
1166**BreakConstructorInitializers** (``BreakConstructorInitializersStyle``)
1167  The constructor initializers style to use.
1168
1169  Possible values:
1170
1171  * ``BCIS_BeforeColon`` (in configuration: ``BeforeColon``)
1172    Break constructor initializers before the colon and after the commas.
1173
1174    .. code-block:: c++
1175
1176       Constructor()
1177           : initializer1(),
1178             initializer2()
1179
1180  * ``BCIS_BeforeComma`` (in configuration: ``BeforeComma``)
1181    Break constructor initializers before the colon and commas, and align
1182    the commas with the colon.
1183
1184    .. code-block:: c++
1185
1186       Constructor()
1187           : initializer1()
1188           , initializer2()
1189
1190  * ``BCIS_AfterColon`` (in configuration: ``AfterColon``)
1191    Break constructor initializers after the colon and commas.
1192
1193    .. code-block:: c++
1194
1195       Constructor() :
1196           initializer1(),
1197           initializer2()
1198
1199
1200
1201**BreakInheritanceList** (``BreakInheritanceListStyle``)
1202  The inheritance list style to use.
1203
1204  Possible values:
1205
1206  * ``BILS_BeforeColon`` (in configuration: ``BeforeColon``)
1207    Break inheritance list before the colon and after the commas.
1208
1209    .. code-block:: c++
1210
1211       class Foo
1212           : Base1,
1213             Base2
1214       {};
1215
1216  * ``BILS_BeforeComma`` (in configuration: ``BeforeComma``)
1217    Break inheritance list before the colon and commas, and align
1218    the commas with the colon.
1219
1220    .. code-block:: c++
1221
1222       class Foo
1223           : Base1
1224           , Base2
1225       {};
1226
1227  * ``BILS_AfterColon`` (in configuration: ``AfterColon``)
1228    Break inheritance list after the colon and commas.
1229
1230    .. code-block:: c++
1231
1232       class Foo :
1233           Base1,
1234           Base2
1235       {};
1236
1237
1238
1239**BreakStringLiterals** (``bool``)
1240  Allow breaking string literals when formatting.
1241
1242**ColumnLimit** (``unsigned``)
1243  The column limit.
1244
1245  A column limit of ``0`` means that there is no column limit. In this case,
1246  clang-format will respect the input's line breaking decisions within
1247  statements unless they contradict other rules.
1248
1249**CommentPragmas** (``std::string``)
1250  A regular expression that describes comments with special meaning,
1251  which should not be split into lines or otherwise changed.
1252
1253  .. code-block:: c++
1254
1255     // CommentPragmas: '^ FOOBAR pragma:'
1256     // Will leave the following line unaffected
1257     #include <vector> // FOOBAR pragma: keep
1258
1259**CompactNamespaces** (``bool``)
1260  If ``true``, consecutive namespace declarations will be on the same
1261  line. If ``false``, each namespace is declared on a new line.
1262
1263  .. code-block:: c++
1264
1265    true:
1266    namespace Foo { namespace Bar {
1267    }}
1268
1269    false:
1270    namespace Foo {
1271    namespace Bar {
1272    }
1273    }
1274
1275  If it does not fit on a single line, the overflowing namespaces get
1276  wrapped:
1277
1278  .. code-block:: c++
1279
1280    namespace Foo { namespace Bar {
1281    namespace Extra {
1282    }}}
1283
1284**ConstructorInitializerAllOnOneLineOrOnePerLine** (``bool``)
1285  If the constructor initializers don't fit on a line, put each
1286  initializer on its own line.
1287
1288  .. code-block:: c++
1289
1290    true:
1291    SomeClass::Constructor()
1292        : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) {
1293      return 0;
1294    }
1295
1296    false:
1297    SomeClass::Constructor()
1298        : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa),
1299          aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) {
1300      return 0;
1301    }
1302
1303**ConstructorInitializerIndentWidth** (``unsigned``)
1304  The number of characters to use for indentation of constructor
1305  initializer lists as well as inheritance lists.
1306
1307**ContinuationIndentWidth** (``unsigned``)
1308  Indent width for line continuations.
1309
1310  .. code-block:: c++
1311
1312     ContinuationIndentWidth: 2
1313
1314     int i =         //  VeryVeryVeryVeryVeryLongComment
1315       longFunction( // Again a long comment
1316         arg);
1317
1318**Cpp11BracedListStyle** (``bool``)
1319  If ``true``, format braced lists as best suited for C++11 braced
1320  lists.
1321
1322  Important differences:
1323  - No spaces inside the braced list.
1324  - No line break before the closing brace.
1325  - Indentation with the continuation indent, not with the block indent.
1326
1327  Fundamentally, C++11 braced lists are formatted exactly like function
1328  calls would be formatted in their place. If the braced list follows a name
1329  (e.g. a type or variable name), clang-format formats as if the ``{}`` were
1330  the parentheses of a function call with that name. If there is no name,
1331  a zero-length name is assumed.
1332
1333  .. code-block:: c++
1334
1335     true:                                  false:
1336     vector<int> x{1, 2, 3, 4};     vs.     vector<int> x{ 1, 2, 3, 4 };
1337     vector<T> x{{}, {}, {}, {}};           vector<T> x{ {}, {}, {}, {} };
1338     f(MyMap[{composite, key}]);            f(MyMap[{ composite, key }]);
1339     new int[3]{1, 2, 3};                   new int[3]{ 1, 2, 3 };
1340
1341**DerivePointerAlignment** (``bool``)
1342  If ``true``, analyze the formatted file for the most common
1343  alignment of ``&`` and ``*``.
1344  Pointer and reference alignment styles are going to be updated according
1345  to the preferences found in the file.
1346  ``PointerAlignment`` is then used only as fallback.
1347
1348**DisableFormat** (``bool``)
1349  Disables formatting completely.
1350
1351**ExperimentalAutoDetectBinPacking** (``bool``)
1352  If ``true``, clang-format detects whether function calls and
1353  definitions are formatted with one parameter per line.
1354
1355  Each call can be bin-packed, one-per-line or inconclusive. If it is
1356  inconclusive, e.g. completely on one line, but a decision needs to be
1357  made, clang-format analyzes whether there are other bin-packed cases in
1358  the input file and act accordingly.
1359
1360  NOTE: This is an experimental flag, that might go away or be renamed. Do
1361  not use this in config files, etc. Use at your own risk.
1362
1363**FixNamespaceComments** (``bool``)
1364  If ``true``, clang-format adds missing namespace end comments and
1365  fixes invalid existing ones.
1366
1367  .. code-block:: c++
1368
1369     true:                                  false:
1370     namespace a {                  vs.     namespace a {
1371     foo();                                 foo();
1372     } // namespace a                       }
1373
1374**ForEachMacros** (``std::vector<std::string>``)
1375  A vector of macros that should be interpreted as foreach loops
1376  instead of as function calls.
1377
1378  These are expected to be macros of the form:
1379
1380  .. code-block:: c++
1381
1382    FOREACH(<variable-declaration>, ...)
1383      <loop-body>
1384
1385  In the .clang-format configuration file, this can be configured like:
1386
1387  .. code-block:: yaml
1388
1389    ForEachMacros: ['RANGES_FOR', 'FOREACH']
1390
1391  For example: BOOST_FOREACH.
1392
1393**TypenameMacros** (``std::vector<std::string>``)
1394  A vector of macros that should be interpreted as type declarations
1395  instead of as function calls.
1396
1397  These are expected to be macros of the form:
1398
1399  .. code-block: c++
1400
1401    STACK_OF(...)
1402
1403  In the .clang-format configuration file, this can be configured like:
1404
1405  .. code-block: yaml
1406
1407    TypenameMacros: ['STACK_OF', 'LIST']
1408
1409  For example: OpenSSL STACK_OF, BSD LIST_ENTRY.
1410
1411**IncludeBlocks** (``IncludeBlocksStyle``)
1412  Dependent on the value, multiple ``#include`` blocks can be sorted
1413  as one and divided based on category.
1414
1415  Possible values:
1416
1417  * ``IBS_Preserve`` (in configuration: ``Preserve``)
1418    Sort each ``#include`` block separately.
1419
1420    .. code-block:: c++
1421
1422       #include "b.h"               into      #include "b.h"
1423
1424       #include <lib/main.h>                  #include "a.h"
1425       #include "a.h"                         #include <lib/main.h>
1426
1427  * ``IBS_Merge`` (in configuration: ``Merge``)
1428    Merge multiple ``#include`` blocks together and sort as one.
1429
1430    .. code-block:: c++
1431
1432       #include "b.h"               into      #include "a.h"
1433                                              #include "b.h"
1434       #include <lib/main.h>                  #include <lib/main.h>
1435       #include "a.h"
1436
1437  * ``IBS_Regroup`` (in configuration: ``Regroup``)
1438    Merge multiple ``#include`` blocks together and sort as one.
1439    Then split into groups based on category priority. See
1440    ``IncludeCategories``.
1441
1442    .. code-block:: c++
1443
1444       #include "b.h"               into      #include "a.h"
1445                                              #include "b.h"
1446       #include <lib/main.h>
1447       #include "a.h"                         #include <lib/main.h>
1448
1449
1450
1451**IncludeCategories** (``std::vector<IncludeCategory>``)
1452  Regular expressions denoting the different ``#include`` categories
1453  used for ordering ``#includes``.
1454
1455  `POSIX extended
1456  <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html>`_
1457  regular expressions are supported.
1458
1459  These regular expressions are matched against the filename of an include
1460  (including the <> or "") in order. The value belonging to the first
1461  matching regular expression is assigned and ``#includes`` are sorted first
1462  according to increasing category number and then alphabetically within
1463  each category.
1464
1465  If none of the regular expressions match, INT_MAX is assigned as
1466  category. The main header for a source file automatically gets category 0.
1467  so that it is generally kept at the beginning of the ``#includes``
1468  (https://llvm.org/docs/CodingStandards.html#include-style). However, you
1469  can also assign negative priorities if you have certain headers that
1470  always need to be first.
1471
1472  To configure this in the .clang-format file, use:
1473
1474  .. code-block:: yaml
1475
1476    IncludeCategories:
1477      - Regex:           '^"(llvm|llvm-c|clang|clang-c)/'
1478        Priority:        2
1479      - Regex:           '^(<|"(gtest|gmock|isl|json)/)'
1480        Priority:        3
1481      - Regex:           '<[[:alnum:].]+>'
1482        Priority:        4
1483      - Regex:           '.*'
1484        Priority:        1
1485
1486**IncludeIsMainRegex** (``std::string``)
1487  Specify a regular expression of suffixes that are allowed in the
1488  file-to-main-include mapping.
1489
1490  When guessing whether a #include is the "main" include (to assign
1491  category 0, see above), use this regex of allowed suffixes to the header
1492  stem. A partial match is done, so that:
1493  - "" means "arbitrary suffix"
1494  - "$" means "no suffix"
1495
1496  For example, if configured to "(_test)?$", then a header a.h would be seen
1497  as the "main" include in both a.cc and a_test.cc.
1498
1499**IndentCaseLabels** (``bool``)
1500  Indent case labels one level from the switch statement.
1501
1502  When ``false``, use the same indentation level as for the switch statement.
1503  Switch statement body is always indented one level more than case labels.
1504
1505  .. code-block:: c++
1506
1507     false:                                 true:
1508     switch (fool) {                vs.     switch (fool) {
1509     case 1:                                  case 1:
1510       bar();                                   bar();
1511       break;                                   break;
1512     default:                                 default:
1513       plop();                                  plop();
1514     }                                      }
1515
1516**IndentPPDirectives** (``PPDirectiveIndentStyle``)
1517  The preprocessor directive indenting style to use.
1518
1519  Possible values:
1520
1521  * ``PPDIS_None`` (in configuration: ``None``)
1522    Does not indent any directives.
1523
1524    .. code-block:: c++
1525
1526       #if FOO
1527       #if BAR
1528       #include <foo>
1529       #endif
1530       #endif
1531
1532  * ``PPDIS_AfterHash`` (in configuration: ``AfterHash``)
1533    Indents directives after the hash.
1534
1535    .. code-block:: c++
1536
1537       #if FOO
1538       #  if BAR
1539       #    include <foo>
1540       #  endif
1541       #endif
1542
1543  * ``PPDIS_BeforeHash`` (in configuration: ``BeforeHash``)
1544    Indents directives before the hash.
1545
1546    .. code-block:: c++
1547
1548       #if FOO
1549         #if BAR
1550           #include <foo>
1551         #endif
1552       #endif
1553
1554
1555
1556**IndentWidth** (``unsigned``)
1557  The number of columns to use for indentation.
1558
1559  .. code-block:: c++
1560
1561     IndentWidth: 3
1562
1563     void f() {
1564        someFunction();
1565        if (true, false) {
1566           f();
1567        }
1568     }
1569
1570**IndentWrappedFunctionNames** (``bool``)
1571  Indent if a function definition or declaration is wrapped after the
1572  type.
1573
1574  .. code-block:: c++
1575
1576     true:
1577     LoooooooooooooooooooooooooooooooooooooooongReturnType
1578         LoooooooooooooooooooooooooooooooongFunctionDeclaration();
1579
1580     false:
1581     LoooooooooooooooooooooooooooooooooooooooongReturnType
1582     LoooooooooooooooooooooooooooooooongFunctionDeclaration();
1583
1584**JavaImportGroups** (``std::vector<std::string>``)
1585  A vector of prefixes ordered by the desired groups for Java imports.
1586
1587  Each group is separated by a newline. Static imports will also follow the
1588  same grouping convention above all non-static imports. One group's prefix
1589  can be a subset of another - the longest prefix is always matched. Within
1590  a group, the imports are ordered lexicographically.
1591
1592  In the .clang-format configuration file, this can be configured like
1593  in the following yaml example. This will result in imports being
1594  formatted as in the Java example below.
1595
1596  .. code-block:: yaml
1597
1598    JavaImportGroups: ['com.example', 'com', 'org']
1599
1600
1601  .. code-block:: java
1602
1603     import static com.example.function1;
1604
1605     import static com.test.function2;
1606
1607     import static org.example.function3;
1608
1609     import com.example.ClassA;
1610     import com.example.Test;
1611     import com.example.a.ClassB;
1612
1613     import com.test.ClassC;
1614
1615     import org.example.ClassD;
1616
1617**JavaScriptQuotes** (``JavaScriptQuoteStyle``)
1618  The JavaScriptQuoteStyle to use for JavaScript strings.
1619
1620  Possible values:
1621
1622  * ``JSQS_Leave`` (in configuration: ``Leave``)
1623    Leave string quotes as they are.
1624
1625    .. code-block:: js
1626
1627       string1 = "foo";
1628       string2 = 'bar';
1629
1630  * ``JSQS_Single`` (in configuration: ``Single``)
1631    Always use single quotes.
1632
1633    .. code-block:: js
1634
1635       string1 = 'foo';
1636       string2 = 'bar';
1637
1638  * ``JSQS_Double`` (in configuration: ``Double``)
1639    Always use double quotes.
1640
1641    .. code-block:: js
1642
1643       string1 = "foo";
1644       string2 = "bar";
1645
1646
1647
1648**JavaScriptWrapImports** (``bool``)
1649  Whether to wrap JavaScript import/export statements.
1650
1651  .. code-block:: js
1652
1653     true:
1654     import {
1655         VeryLongImportsAreAnnoying,
1656         VeryLongImportsAreAnnoying,
1657         VeryLongImportsAreAnnoying,
1658     } from 'some/module.js'
1659
1660     false:
1661     import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js"
1662
1663**KeepEmptyLinesAtTheStartOfBlocks** (``bool``)
1664  If true, the empty line at the start of blocks is kept.
1665
1666  .. code-block:: c++
1667
1668     true:                                  false:
1669     if (foo) {                     vs.     if (foo) {
1670                                              bar();
1671       bar();                               }
1672     }
1673
1674**Language** (``LanguageKind``)
1675  Language, this format style is targeted at.
1676
1677  Possible values:
1678
1679  * ``LK_None`` (in configuration: ``None``)
1680    Do not use.
1681
1682  * ``LK_Cpp`` (in configuration: ``Cpp``)
1683    Should be used for C, C++.
1684
1685  * ``LK_CSharp`` (in configuration: ``CSharp``)
1686    Should be used for C#.
1687
1688  * ``LK_Java`` (in configuration: ``Java``)
1689    Should be used for Java.
1690
1691  * ``LK_JavaScript`` (in configuration: ``JavaScript``)
1692    Should be used for JavaScript.
1693
1694  * ``LK_ObjC`` (in configuration: ``ObjC``)
1695    Should be used for Objective-C, Objective-C++.
1696
1697  * ``LK_Proto`` (in configuration: ``Proto``)
1698    Should be used for Protocol Buffers
1699    (https://developers.google.com/protocol-buffers/).
1700
1701  * ``LK_TableGen`` (in configuration: ``TableGen``)
1702    Should be used for TableGen code.
1703
1704  * ``LK_TextProto`` (in configuration: ``TextProto``)
1705    Should be used for Protocol Buffer messages in text format
1706    (https://developers.google.com/protocol-buffers/).
1707
1708
1709
1710**MacroBlockBegin** (``std::string``)
1711  A regular expression matching macros that start a block.
1712
1713  .. code-block:: c++
1714
1715     # With:
1716     MacroBlockBegin: "^NS_MAP_BEGIN|\
1717     NS_TABLE_HEAD$"
1718     MacroBlockEnd: "^\
1719     NS_MAP_END|\
1720     NS_TABLE_.*_END$"
1721
1722     NS_MAP_BEGIN
1723       foo();
1724     NS_MAP_END
1725
1726     NS_TABLE_HEAD
1727       bar();
1728     NS_TABLE_FOO_END
1729
1730     # Without:
1731     NS_MAP_BEGIN
1732     foo();
1733     NS_MAP_END
1734
1735     NS_TABLE_HEAD
1736     bar();
1737     NS_TABLE_FOO_END
1738
1739**MacroBlockEnd** (``std::string``)
1740  A regular expression matching macros that end a block.
1741
1742**MaxEmptyLinesToKeep** (``unsigned``)
1743  The maximum number of consecutive empty lines to keep.
1744
1745  .. code-block:: c++
1746
1747     MaxEmptyLinesToKeep: 1         vs.     MaxEmptyLinesToKeep: 0
1748     int f() {                              int f() {
1749       int = 1;                                 int i = 1;
1750                                                i = foo();
1751       i = foo();                               return i;
1752                                            }
1753       return i;
1754     }
1755
1756**NamespaceIndentation** (``NamespaceIndentationKind``)
1757  The indentation used for namespaces.
1758
1759  Possible values:
1760
1761  * ``NI_None`` (in configuration: ``None``)
1762    Don't indent in namespaces.
1763
1764    .. code-block:: c++
1765
1766       namespace out {
1767       int i;
1768       namespace in {
1769       int i;
1770       }
1771       }
1772
1773  * ``NI_Inner`` (in configuration: ``Inner``)
1774    Indent only in inner namespaces (nested in other namespaces).
1775
1776    .. code-block:: c++
1777
1778       namespace out {
1779       int i;
1780       namespace in {
1781         int i;
1782       }
1783       }
1784
1785  * ``NI_All`` (in configuration: ``All``)
1786    Indent in all namespaces.
1787
1788    .. code-block:: c++
1789
1790       namespace out {
1791         int i;
1792         namespace in {
1793           int i;
1794         }
1795       }
1796
1797
1798
1799**NamespaceMacros** (``std::vector<std::string>``)
1800  A vector of macros which are used to open namespace blocks.
1801
1802  These are expected to be macros of the form:
1803
1804  .. code-block:: c++
1805
1806    NAMESPACE(<namespace-name>, ...) {
1807      <namespace-content>
1808    }
1809
1810  For example: TESTSUITE
1811
1812**ObjCBinPackProtocolList** (``BinPackStyle``)
1813  Controls bin-packing Objective-C protocol conformance list
1814  items into as few lines as possible when they go over ``ColumnLimit``.
1815
1816  If ``Auto`` (the default), delegates to the value in
1817  ``BinPackParameters``. If that is ``true``, bin-packs Objective-C
1818  protocol conformance list items into as few lines as possible
1819  whenever they go over ``ColumnLimit``.
1820
1821  If ``Always``, always bin-packs Objective-C protocol conformance
1822  list items into as few lines as possible whenever they go over
1823  ``ColumnLimit``.
1824
1825  If ``Never``, lays out Objective-C protocol conformance list items
1826  onto individual lines whenever they go over ``ColumnLimit``.
1827
1828
1829  .. code-block:: objc
1830
1831     Always (or Auto, if BinPackParameters=true):
1832     @interface ccccccccccccc () <
1833         ccccccccccccc, ccccccccccccc,
1834         ccccccccccccc, ccccccccccccc> {
1835     }
1836
1837     Never (or Auto, if BinPackParameters=false):
1838     @interface ddddddddddddd () <
1839         ddddddddddddd,
1840         ddddddddddddd,
1841         ddddddddddddd,
1842         ddddddddddddd> {
1843     }
1844
1845  Possible values:
1846
1847  * ``BPS_Auto`` (in configuration: ``Auto``)
1848    Automatically determine parameter bin-packing behavior.
1849
1850  * ``BPS_Always`` (in configuration: ``Always``)
1851    Always bin-pack parameters.
1852
1853  * ``BPS_Never`` (in configuration: ``Never``)
1854    Never bin-pack parameters.
1855
1856
1857
1858**ObjCBlockIndentWidth** (``unsigned``)
1859  The number of characters to use for indentation of ObjC blocks.
1860
1861  .. code-block:: objc
1862
1863     ObjCBlockIndentWidth: 4
1864
1865     [operation setCompletionBlock:^{
1866         [self onOperationDone];
1867     }];
1868
1869**ObjCSpaceAfterProperty** (``bool``)
1870  Add a space after ``@property`` in Objective-C, i.e. use
1871  ``@property (readonly)`` instead of ``@property(readonly)``.
1872
1873**ObjCSpaceBeforeProtocolList** (``bool``)
1874  Add a space in front of an Objective-C protocol list, i.e. use
1875  ``Foo <Protocol>`` instead of ``Foo<Protocol>``.
1876
1877**PenaltyBreakAssignment** (``unsigned``)
1878  The penalty for breaking around an assignment operator.
1879
1880**PenaltyBreakBeforeFirstCallParameter** (``unsigned``)
1881  The penalty for breaking a function call after ``call(``.
1882
1883**PenaltyBreakComment** (``unsigned``)
1884  The penalty for each line break introduced inside a comment.
1885
1886**PenaltyBreakFirstLessLess** (``unsigned``)
1887  The penalty for breaking before the first ``<<``.
1888
1889**PenaltyBreakString** (``unsigned``)
1890  The penalty for each line break introduced inside a string literal.
1891
1892**PenaltyBreakTemplateDeclaration** (``unsigned``)
1893  The penalty for breaking after template declaration.
1894
1895**PenaltyExcessCharacter** (``unsigned``)
1896  The penalty for each character outside of the column limit.
1897
1898**PenaltyReturnTypeOnItsOwnLine** (``unsigned``)
1899  Penalty for putting the return type of a function onto its own
1900  line.
1901
1902**PointerAlignment** (``PointerAlignmentStyle``)
1903  Pointer and reference alignment style.
1904
1905  Possible values:
1906
1907  * ``PAS_Left`` (in configuration: ``Left``)
1908    Align pointer to the left.
1909
1910    .. code-block:: c++
1911
1912      int* a;
1913
1914  * ``PAS_Right`` (in configuration: ``Right``)
1915    Align pointer to the right.
1916
1917    .. code-block:: c++
1918
1919      int *a;
1920
1921  * ``PAS_Middle`` (in configuration: ``Middle``)
1922    Align pointer in the middle.
1923
1924    .. code-block:: c++
1925
1926      int * a;
1927
1928
1929
1930**RawStringFormats** (``std::vector<RawStringFormat>``)
1931  Defines hints for detecting supported languages code blocks in raw
1932  strings.
1933
1934  A raw string with a matching delimiter or a matching enclosing function
1935  name will be reformatted assuming the specified language based on the
1936  style for that language defined in the .clang-format file. If no style has
1937  been defined in the .clang-format file for the specific language, a
1938  predefined style given by 'BasedOnStyle' is used. If 'BasedOnStyle' is not
1939  found, the formatting is based on llvm style. A matching delimiter takes
1940  precedence over a matching enclosing function name for determining the
1941  language of the raw string contents.
1942
1943  If a canonical delimiter is specified, occurrences of other delimiters for
1944  the same language will be updated to the canonical if possible.
1945
1946  There should be at most one specification per language and each delimiter
1947  and enclosing function should not occur in multiple specifications.
1948
1949  To configure this in the .clang-format file, use:
1950
1951  .. code-block:: yaml
1952
1953    RawStringFormats:
1954      - Language: TextProto
1955          Delimiters:
1956            - 'pb'
1957            - 'proto'
1958          EnclosingFunctions:
1959            - 'PARSE_TEXT_PROTO'
1960          BasedOnStyle: google
1961      - Language: Cpp
1962          Delimiters:
1963            - 'cc'
1964            - 'cpp'
1965          BasedOnStyle: llvm
1966          CanonicalDelimiter: 'cc'
1967
1968**ReflowComments** (``bool``)
1969  If ``true``, clang-format will attempt to re-flow comments.
1970
1971  .. code-block:: c++
1972
1973     false:
1974     // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
1975     /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */
1976
1977     true:
1978     // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
1979     // information
1980     /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
1981      * information */
1982
1983**SortIncludes** (``bool``)
1984  If ``true``, clang-format will sort ``#includes``.
1985
1986  .. code-block:: c++
1987
1988     false:                                 true:
1989     #include "b.h"                 vs.     #include "a.h"
1990     #include "a.h"                         #include "b.h"
1991
1992**SortUsingDeclarations** (``bool``)
1993  If ``true``, clang-format will sort using declarations.
1994
1995  The order of using declarations is defined as follows:
1996  Split the strings by "::" and discard any initial empty strings. The last
1997  element of each list is a non-namespace name; all others are namespace
1998  names. Sort the lists of names lexicographically, where the sort order of
1999  individual names is that all non-namespace names come before all namespace
2000  names, and within those groups, names are in case-insensitive
2001  lexicographic order.
2002
2003  .. code-block:: c++
2004
2005     false:                                 true:
2006     using std::cout;               vs.     using std::cin;
2007     using std::cin;                        using std::cout;
2008
2009**SpaceAfterCStyleCast** (``bool``)
2010  If ``true``, a space is inserted after C style casts.
2011
2012  .. code-block:: c++
2013
2014     true:                                  false:
2015     (int) i;                       vs.     (int)i;
2016
2017**SpaceAfterLogicalNot** (``bool``)
2018  If ``true``, a space is inserted after the logical not operator (``!``).
2019
2020  .. code-block:: c++
2021
2022     true:                                  false:
2023     ! someExpression();            vs.     !someExpression();
2024
2025**SpaceAfterTemplateKeyword** (``bool``)
2026  If ``true``, a space will be inserted after the 'template' keyword.
2027
2028  .. code-block:: c++
2029
2030     true:                                  false:
2031     template <int> void foo();     vs.     template<int> void foo();
2032
2033**SpaceBeforeAssignmentOperators** (``bool``)
2034  If ``false``, spaces will be removed before assignment operators.
2035
2036  .. code-block:: c++
2037
2038     true:                                  false:
2039     int a = 5;                     vs.     int a=5;
2040     a += 42                                a+=42;
2041
2042**SpaceBeforeCpp11BracedList** (``bool``)
2043  If ``true``, a space will be inserted before a C++11 braced list
2044  used to initialize an object (after the preceding identifier or type).
2045
2046  .. code-block:: c++
2047
2048     true:                                  false:
2049     Foo foo { bar };               vs.     Foo foo{ bar };
2050     Foo {};                                Foo{};
2051     vector<int> { 1, 2, 3 };               vector<int>{ 1, 2, 3 };
2052     new int[3] { 1, 2, 3 };                new int[3]{ 1, 2, 3 };
2053
2054**SpaceBeforeCtorInitializerColon** (``bool``)
2055  If ``false``, spaces will be removed before constructor initializer
2056  colon.
2057
2058  .. code-block:: c++
2059
2060     true:                                  false:
2061     Foo::Foo() : a(a) {}                   Foo::Foo(): a(a) {}
2062
2063**SpaceBeforeInheritanceColon** (``bool``)
2064  If ``false``, spaces will be removed before inheritance colon.
2065
2066  .. code-block:: c++
2067
2068     true:                                  false:
2069     class Foo : Bar {}             vs.     class Foo: Bar {}
2070
2071**SpaceBeforeParens** (``SpaceBeforeParensOptions``)
2072  Defines in which cases to put a space before opening parentheses.
2073
2074  Possible values:
2075
2076  * ``SBPO_Never`` (in configuration: ``Never``)
2077    Never put a space before opening parentheses.
2078
2079    .. code-block:: c++
2080
2081       void f() {
2082         if(true) {
2083           f();
2084         }
2085       }
2086
2087  * ``SBPO_ControlStatements`` (in configuration: ``ControlStatements``)
2088    Put a space before opening parentheses only after control statement
2089    keywords (``for/if/while...``).
2090
2091    .. code-block:: c++
2092
2093       void f() {
2094         if (true) {
2095           f();
2096         }
2097       }
2098
2099  * ``SBPO_NonEmptyParentheses`` (in configuration: ``NonEmptyParentheses``)
2100    Put a space before opening parentheses only if the parentheses are not
2101    empty i.e. '()'
2102
2103    .. code-block:: c++
2104
2105      void() {
2106        if (true) {
2107          f();
2108          g (x, y, z);
2109        }
2110      }
2111
2112  * ``SBPO_Always`` (in configuration: ``Always``)
2113    Always put a space before opening parentheses, except when it's
2114    prohibited by the syntax rules (in function-like macro definitions) or
2115    when determined by other style rules (after unary operators, opening
2116    parentheses, etc.)
2117
2118    .. code-block:: c++
2119
2120       void f () {
2121         if (true) {
2122           f ();
2123         }
2124       }
2125
2126
2127
2128**SpaceBeforeRangeBasedForLoopColon** (``bool``)
2129  If ``false``, spaces will be removed before range-based for loop
2130  colon.
2131
2132  .. code-block:: c++
2133
2134     true:                                  false:
2135     for (auto v : values) {}       vs.     for(auto v: values) {}
2136
2137**SpaceInEmptyParentheses** (``bool``)
2138  If ``true``, spaces may be inserted into ``()``.
2139
2140  .. code-block:: c++
2141
2142     true:                                false:
2143     void f( ) {                    vs.   void f() {
2144       int x[] = {foo( ), bar( )};          int x[] = {foo(), bar()};
2145       if (true) {                          if (true) {
2146         f( );                                f();
2147       }                                    }
2148     }                                    }
2149
2150**SpacesBeforeTrailingComments** (``unsigned``)
2151  The number of spaces before trailing line comments
2152  (``//`` - comments).
2153
2154  This does not affect trailing block comments (``/*`` - comments) as
2155  those commonly have different usage patterns and a number of special
2156  cases.
2157
2158  .. code-block:: c++
2159
2160     SpacesBeforeTrailingComments: 3
2161     void f() {
2162       if (true) {   // foo1
2163         f();        // bar
2164       }             // foo
2165     }
2166
2167**SpacesInAngles** (``bool``)
2168  If ``true``, spaces will be inserted after ``<`` and before ``>``
2169  in template argument lists.
2170
2171  .. code-block:: c++
2172
2173     true:                                  false:
2174     static_cast< int >(arg);       vs.     static_cast<int>(arg);
2175     std::function< void(int) > fct;        std::function<void(int)> fct;
2176
2177**SpacesInCStyleCastParentheses** (``bool``)
2178  If ``true``, spaces may be inserted into C style casts.
2179
2180  .. code-block:: c++
2181
2182     true:                                  false:
2183     x = ( int32 )y                 vs.     x = (int32)y
2184
2185**SpacesInContainerLiterals** (``bool``)
2186  If ``true``, spaces are inserted inside container literals (e.g.
2187  ObjC and Javascript array and dict literals).
2188
2189  .. code-block:: js
2190
2191     true:                                  false:
2192     var arr = [ 1, 2, 3 ];         vs.     var arr = [1, 2, 3];
2193     f({a : 1, b : 2, c : 3});              f({a: 1, b: 2, c: 3});
2194
2195**SpacesInParentheses** (``bool``)
2196  If ``true``, spaces will be inserted after ``(`` and before ``)``.
2197
2198  .. code-block:: c++
2199
2200     true:                                  false:
2201     t f( Deleted & ) & = delete;   vs.     t f(Deleted &) & = delete;
2202
2203**SpacesInSquareBrackets** (``bool``)
2204  If ``true``, spaces will be inserted after ``[`` and before ``]``.
2205  Lambdas or unspecified size array declarations will not be affected.
2206
2207  .. code-block:: c++
2208
2209     true:                                  false:
2210     int a[ 5 ];                    vs.     int a[5];
2211     std::unique_ptr<int[]> foo() {} // Won't be affected
2212
2213**Standard** (``LanguageStandard``)
2214  Format compatible with this standard, e.g. use ``A<A<int> >``
2215  instead of ``A<A<int>>`` for ``LS_Cpp03``.
2216
2217  Possible values:
2218
2219  * ``LS_Cpp03`` (in configuration: ``Cpp03``)
2220    Use C++03-compatible syntax.
2221
2222  * ``LS_Cpp11`` (in configuration: ``Cpp11``)
2223    Use features of C++11, C++14 and C++1z (e.g. ``A<A<int>>`` instead of
2224    ``A<A<int> >``).
2225
2226  * ``LS_Auto`` (in configuration: ``Auto``)
2227    Automatic detection based on the input.
2228
2229
2230
2231**StatementMacros** (``std::vector<std::string>``)
2232  A vector of macros that should be interpreted as complete
2233  statements.
2234
2235  Typical macros are expressions, and require a semi-colon to be
2236  added; sometimes this is not the case, and this allows to make
2237  clang-format aware of such cases.
2238
2239  For example: Q_UNUSED
2240
2241**TabWidth** (``unsigned``)
2242  The number of columns used for tab stops.
2243
2244**UseTab** (``UseTabStyle``)
2245  The way to use tab characters in the resulting file.
2246
2247  Possible values:
2248
2249  * ``UT_Never`` (in configuration: ``Never``)
2250    Never use tab.
2251
2252  * ``UT_ForIndentation`` (in configuration: ``ForIndentation``)
2253    Use tabs only for indentation.
2254
2255  * ``UT_ForContinuationAndIndentation`` (in configuration: ``ForContinuationAndIndentation``)
2256    Use tabs only for line continuation and indentation.
2257
2258  * ``UT_Always`` (in configuration: ``Always``)
2259    Use tabs whenever we need to fill whitespace that spans at least from
2260    one tab stop to the next one.
2261
2262
2263
2264.. END_FORMAT_STYLE_OPTIONS
2265
2266Adding additional style options
2267===============================
2268
2269Each additional style option adds costs to the clang-format project. Some of
2270these costs affect the clang-format development itself, as we need to make
2271sure that any given combination of options work and that new features don't
2272break any of the existing options in any way. There are also costs for end users
2273as options become less discoverable and people have to think about and make a
2274decision on options they don't really care about.
2275
2276The goal of the clang-format project is more on the side of supporting a
2277limited set of styles really well as opposed to supporting every single style
2278used by a codebase somewhere in the wild. Of course, we do want to support all
2279major projects and thus have established the following bar for adding style
2280options. Each new style option must ..
2281
2282  * be used in a project of significant size (have dozens of contributors)
2283  * have a publicly accessible style guide
2284  * have a person willing to contribute and maintain patches
2285
2286Examples
2287========
2288
2289A style similar to the `Linux Kernel style
2290<https://www.kernel.org/doc/Documentation/CodingStyle>`_:
2291
2292.. code-block:: yaml
2293
2294  BasedOnStyle: LLVM
2295  IndentWidth: 8
2296  UseTab: Always
2297  BreakBeforeBraces: Linux
2298  AllowShortIfStatementsOnASingleLine: false
2299  IndentCaseLabels: false
2300
2301The result is (imagine that tabs are used for indentation here):
2302
2303.. code-block:: c++
2304
2305  void test()
2306  {
2307          switch (x) {
2308          case 0:
2309          case 1:
2310                  do_something();
2311                  break;
2312          case 2:
2313                  do_something_else();
2314                  break;
2315          default:
2316                  break;
2317          }
2318          if (condition)
2319                  do_something_completely_different();
2320
2321          if (x == y) {
2322                  q();
2323          } else if (x > y) {
2324                  w();
2325          } else {
2326                  r();
2327          }
2328  }
2329
2330A style similar to the default Visual Studio formatting style:
2331
2332.. code-block:: yaml
2333
2334  UseTab: Never
2335  IndentWidth: 4
2336  BreakBeforeBraces: Allman
2337  AllowShortIfStatementsOnASingleLine: false
2338  IndentCaseLabels: false
2339  ColumnLimit: 0
2340
2341The result is:
2342
2343.. code-block:: c++
2344
2345  void test()
2346  {
2347      switch (suffix)
2348      {
2349      case 0:
2350      case 1:
2351          do_something();
2352          break;
2353      case 2:
2354          do_something_else();
2355          break;
2356      default:
2357          break;
2358      }
2359      if (condition)
2360          do_somthing_completely_different();
2361
2362      if (x == y)
2363      {
2364          q();
2365      }
2366      else if (x > y)
2367      {
2368          w();
2369      }
2370      else
2371      {
2372          r();
2373      }
2374  }
2375