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) or create a
11custom 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
73An easy way to get a valid ``.clang-format`` file containing all configuration
74options of a certain predefined style is:
75
76.. code-block:: console
77
78  clang-format -style=llvm -dump-config > .clang-format
79
80When specifying configuration in the ``-style=`` option, the same configuration
81is applied for all input files. The format of the configuration is:
82
83.. code-block:: console
84
85  -style='{key1: value1, key2: value2, ...}'
86
87
88Disabling Formatting on a Piece of Code
89=======================================
90
91Clang-format understands also special comments that switch formatting in a
92delimited range. The code between a comment ``// clang-format off`` or
93``/* clang-format off */`` up to a comment ``// clang-format on`` or
94``/* clang-format on */`` will not be formatted. The comments themselves
95will be formatted (aligned) normally.
96
97.. code-block:: c++
98
99  int formatted_code;
100  // clang-format off
101      void    unformatted_code  ;
102  // clang-format on
103  void formatted_code_again;
104
105
106Configuring Style in Code
107=========================
108
109When using ``clang::format::reformat(...)`` functions, the format is specified
110by supplying the `clang::format::FormatStyle
111<http://clang.llvm.org/doxygen/structclang_1_1format_1_1FormatStyle.html>`_
112structure.
113
114
115Configurable Format Style Options
116=================================
117
118This section lists the supported style options. Value type is specified for
119each option. For enumeration types possible values are specified both as a C++
120enumeration member (with a prefix, e.g. ``LS_Auto``), and as a value usable in
121the configuration (without a prefix: ``Auto``).
122
123
124**BasedOnStyle** (``string``)
125  The style used for all options not specifically set in the configuration.
126
127  This option is supported only in the :program:`clang-format` configuration
128  (both within ``-style='{...}'`` and the ``.clang-format`` file).
129
130  Possible values:
131
132  * ``LLVM``
133    A style complying with the `LLVM coding standards
134    <http://llvm.org/docs/CodingStandards.html>`_
135  * ``Google``
136    A style complying with `Google's C++ style guide
137    <http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml>`_
138  * ``Chromium``
139    A style complying with `Chromium's style guide
140    <http://www.chromium.org/developers/coding-style>`_
141  * ``Mozilla``
142    A style complying with `Mozilla's style guide
143    <https://developer.mozilla.org/en-US/docs/Developer_Guide/Coding_Style>`_
144  * ``WebKit``
145    A style complying with `WebKit's style guide
146    <http://www.webkit.org/coding/coding-style.html>`_
147
148.. START_FORMAT_STYLE_OPTIONS
149
150**AccessModifierOffset** (``int``)
151  The extra indent or outdent of access modifiers, e.g. ``public:``.
152
153**AlignAfterOpenBracket** (``BracketAlignmentStyle``)
154  If ``true``, horizontally aligns arguments after an open bracket.
155
156  This applies to round brackets (parentheses), angle brackets and square
157  brackets.
158
159  Possible values:
160
161  * ``BAS_Align`` (in configuration: ``Align``)
162    Align parameters on the open bracket, e.g.:
163
164    .. code-block:: c++
165
166      someLongFunction(argument1,
167                       argument2);
168
169  * ``BAS_DontAlign`` (in configuration: ``DontAlign``)
170    Don't align, instead use ``ContinuationIndentWidth``, e.g.:
171
172    .. code-block:: c++
173
174      someLongFunction(argument1,
175          argument2);
176
177  * ``BAS_AlwaysBreak`` (in configuration: ``AlwaysBreak``)
178    Always break after an open bracket, if the parameters don't fit
179    on a single line, e.g.:
180
181    .. code-block:: c++
182
183      someLongFunction(
184          argument1, argument2);
185
186
187
188**AlignConsecutiveAssignments** (``bool``)
189  If ``true``, aligns consecutive assignments.
190
191  This will align the assignment operators of consecutive lines. This
192  will result in formattings like
193
194  .. code-block:: c++
195
196    int aaaa = 12;
197    int b    = 23;
198    int ccc  = 23;
199
200**AlignConsecutiveDeclarations** (``bool``)
201  If ``true``, aligns consecutive declarations.
202
203  This will align the declaration names of consecutive lines. This
204  will result in formattings like
205
206  .. code-block:: c++
207
208    int         aaaa = 12;
209    float       b = 23;
210    std::string ccc = 23;
211
212**AlignEscapedNewlines** (``EscapedNewlineAlignmentStyle``)
213  Options for aligning backslashes in escaped newlines.
214
215  Possible values:
216
217  * ``ENAS_DontAlign`` (in configuration: ``DontAlign``)
218    Don't align escaped newlines.
219
220    .. code-block:: c++
221
222      #define A \
223        int aaaa; \
224        int b; \
225        int dddddddddd;
226
227  * ``ENAS_Left`` (in configuration: ``Left``)
228    Align escaped newlines as far left as possible.
229
230    .. code-block:: c++
231
232      true:
233      #define A   \
234        int aaaa; \
235        int b;    \
236        int dddddddddd;
237
238      false:
239
240  * ``ENAS_Right`` (in configuration: ``Right``)
241    Align escaped newlines in the right-most column.
242
243    .. code-block:: c++
244
245      #define A                                                                      \
246        int aaaa;                                                                    \
247        int b;                                                                       \
248        int dddddddddd;
249
250
251
252**AlignOperands** (``bool``)
253  If ``true``, horizontally align operands of binary and ternary
254  expressions.
255
256  Specifically, this aligns operands of a single expression that needs to be
257  split over multiple lines, e.g.:
258
259  .. code-block:: c++
260
261    int aaa = bbbbbbbbbbbbbbb +
262              ccccccccccccccc;
263
264**AlignTrailingComments** (``bool``)
265  If ``true``, aligns trailing comments.
266
267  .. code-block:: c++
268
269    true:
270    int a;     // My comment a
271    int b = 2; // comment  b
272
273    false:
274    int a; // My comment a
275    int b = 2; // comment about b
276
277**AllowAllParametersOfDeclarationOnNextLine** (``bool``)
278  If the function declaration doesn't fit on a line,
279  allow putting all parameters of a function declaration onto
280  the next line even if ``BinPackParameters`` is ``false``.
281
282  .. code-block:: c++
283
284    true:
285    void myFunction(
286        int a, int b, int c, int d, int e);
287
288    false:
289    void myFunction(int a,
290                    int b,
291                    int c,
292                    int d,
293                    int e);
294
295**AllowShortBlocksOnASingleLine** (``bool``)
296  Allows contracting simple braced statements to a single line.
297
298  E.g., this allows ``if (a) { return; }`` to be put on a single line.
299
300**AllowShortCaseLabelsOnASingleLine** (``bool``)
301  If ``true``, short case labels will be contracted to a single line.
302
303  .. code-block:: c++
304
305    true:                                   false:
306    switch (a) {                    vs.     switch (a) {
307    case 1: x = 1; break;                   case 1:
308    case 2: return;                           x = 1;
309    }                                         break;
310                                            case 2:
311                                              return;
312                                            }
313
314**AllowShortFunctionsOnASingleLine** (``ShortFunctionStyle``)
315  Dependent on the value, ``int f() { return 0; }`` can be put on a
316  single line.
317
318  Possible values:
319
320  * ``SFS_None`` (in configuration: ``None``)
321    Never merge functions into a single line.
322
323  * ``SFS_InlineOnly`` (in configuration: ``InlineOnly``)
324    Only merge functions defined inside a class. Same as "inline",
325    except it does not implies "empty": i.e. top level empty functions
326    are not merged either.
327
328    .. code-block:: c++
329
330      class Foo {
331        void f() { foo(); }
332      };
333      void f() {
334        foo();
335      }
336      void f() {
337      }
338
339  * ``SFS_Empty`` (in configuration: ``Empty``)
340    Only merge empty functions.
341
342    .. code-block:: c++
343
344      void f() {}
345      void f2() {
346        bar2();
347      }
348
349  * ``SFS_Inline`` (in configuration: ``Inline``)
350    Only merge functions defined inside a class. Implies "empty".
351
352    .. code-block:: c++
353
354      class Foo {
355        void f() { foo(); }
356      };
357      void f() {
358        foo();
359      }
360      void f() {}
361
362  * ``SFS_All`` (in configuration: ``All``)
363    Merge all functions fitting on a single line.
364
365    .. code-block:: c++
366
367      class Foo {
368        void f() { foo(); }
369      };
370      void f() { bar(); }
371
372
373
374**AllowShortIfStatementsOnASingleLine** (``bool``)
375  If ``true``, ``if (a) return;`` can be put on a single line.
376
377**AllowShortLoopsOnASingleLine** (``bool``)
378  If ``true``, ``while (true) continue;`` can be put on a single
379  line.
380
381**AlwaysBreakAfterDefinitionReturnType** (``DefinitionReturnTypeBreakingStyle``)
382  The function definition return type breaking style to use.  This
383  option is **deprecated** and is retained for backwards compatibility.
384
385  Possible values:
386
387  * ``DRTBS_None`` (in configuration: ``None``)
388    Break after return type automatically.
389    ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
390
391  * ``DRTBS_All`` (in configuration: ``All``)
392    Always break after the return type.
393
394  * ``DRTBS_TopLevel`` (in configuration: ``TopLevel``)
395    Always break after the return types of top-level functions.
396
397
398
399**AlwaysBreakAfterReturnType** (``ReturnTypeBreakingStyle``)
400  The function declaration return type breaking style to use.
401
402  Possible values:
403
404  * ``RTBS_None`` (in configuration: ``None``)
405    Break after return type automatically.
406    ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
407
408    .. code-block:: c++
409
410      class A {
411        int f() { return 0; };
412      };
413      int f();
414      int f() { return 1; }
415
416  * ``RTBS_All`` (in configuration: ``All``)
417    Always break after the return type.
418
419    .. code-block:: c++
420
421      class A {
422        int
423        f() {
424          return 0;
425        };
426      };
427      int
428      f();
429      int
430      f() {
431        return 1;
432      }
433
434  * ``RTBS_TopLevel`` (in configuration: ``TopLevel``)
435    Always break after the return types of top-level functions.
436
437    .. code-block:: c++
438
439      class A {
440        int f() { return 0; };
441      };
442      int
443      f();
444      int
445      f() {
446        return 1;
447      }
448
449  * ``RTBS_AllDefinitions`` (in configuration: ``AllDefinitions``)
450    Always break after the return type of function definitions.
451
452    .. code-block:: c++
453
454      class A {
455        int
456        f() {
457          return 0;
458        };
459      };
460      int f();
461      int
462      f() {
463        return 1;
464      }
465
466  * ``RTBS_TopLevelDefinitions`` (in configuration: ``TopLevelDefinitions``)
467    Always break after the return type of top-level definitions.
468
469    .. code-block:: c++
470
471      class A {
472        int f() { return 0; };
473      };
474      int f();
475      int
476      f() {
477        return 1;
478      }
479
480
481
482**AlwaysBreakBeforeMultilineStrings** (``bool``)
483  If ``true``, always break before multiline string literals.
484
485  This flag is mean to make cases where there are multiple multiline strings
486  in a file look more consistent. Thus, it will only take effect if wrapping
487  the string at that point leads to it being indented
488  ``ContinuationIndentWidth`` spaces from the start of the line.
489
490  .. code-block:: c++
491
492     true:                                  false:
493     aaaa =                         vs.     aaaa = "bbbb"
494         "bbbb"                                    "cccc";
495         "cccc";
496
497**AlwaysBreakTemplateDeclarations** (``bool``)
498  If ``true``, always break after the ``template<...>`` of a template
499  declaration.
500
501  .. code-block:: c++
502
503     true:                                  false:
504     template <typename T>          vs.     template <typename T> class C {};
505     class C {};
506
507**BinPackArguments** (``bool``)
508  If ``false``, a function call's arguments will either be all on the
509  same line or will have one line each.
510
511  .. code-block:: c++
512
513    true:
514    void f() {
515      f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa,
516        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
517    }
518
519    false:
520    void f() {
521      f(aaaaaaaaaaaaaaaaaaaa,
522        aaaaaaaaaaaaaaaaaaaa,
523        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
524    }
525
526**BinPackParameters** (``bool``)
527  If ``false``, a function declaration's or function definition's
528  parameters will either all be on the same line or will have one line each.
529
530  .. code-block:: c++
531
532    true:
533    void f(int aaaaaaaaaaaaaaaaaaaa, int aaaaaaaaaaaaaaaaaaaa,
534           int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
535
536    false:
537    void f(int aaaaaaaaaaaaaaaaaaaa,
538           int aaaaaaaaaaaaaaaaaaaa,
539           int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
540
541**BraceWrapping** (``BraceWrappingFlags``)
542  Control of individual brace wrapping cases.
543
544  If ``BreakBeforeBraces`` is set to ``BS_Custom``, use this to specify how
545  each individual brace case should be handled. Otherwise, this is ignored.
546
547  .. code-block:: yaml
548
549    # Example of usage:
550    BreakBeforeBraces: Custom
551    BraceWrapping:
552      AfterEnum: true
553      AfterStruct: false
554      SplitEmptyFunction: false
555
556  Nested configuration flags:
557
558
559  * ``bool AfterClass`` Wrap class definitions.
560
561    .. code-block:: c++
562
563      true:
564      class foo {};
565
566      false:
567      class foo
568      {};
569
570  * ``bool AfterControlStatement`` Wrap control statements (``if``/``for``/``while``/``switch``/..).
571
572    .. code-block:: c++
573
574      true:
575      if (foo())
576      {
577      } else
578      {}
579      for (int i = 0; i < 10; ++i)
580      {}
581
582      false:
583      if (foo()) {
584      } else {
585      }
586      for (int i = 0; i < 10; ++i) {
587      }
588
589  * ``bool AfterEnum`` Wrap enum definitions.
590
591    .. code-block:: c++
592
593      true:
594      enum X : int
595      {
596        B
597      };
598
599      false:
600      enum X : int { B };
601
602  * ``bool AfterFunction`` Wrap function definitions.
603
604    .. code-block:: c++
605
606      true:
607      void foo()
608      {
609        bar();
610        bar2();
611      }
612
613      false:
614      void foo() {
615        bar();
616        bar2();
617      }
618
619  * ``bool AfterNamespace`` Wrap namespace definitions.
620
621    .. code-block:: c++
622
623      true:
624      namespace
625      {
626      int foo();
627      int bar();
628      }
629
630      false:
631      namespace {
632      int foo();
633      int bar();
634      }
635
636  * ``bool AfterObjCDeclaration`` Wrap ObjC definitions (``@autoreleasepool``, interfaces, ..).
637
638  * ``bool AfterStruct`` Wrap struct definitions.
639
640    .. code-block:: c++
641
642      true:
643      struct foo
644      {
645        int x;
646      };
647
648      false:
649      struct foo {
650        int x;
651      };
652
653  * ``bool AfterUnion`` Wrap union definitions.
654
655    .. code-block:: c++
656
657      true:
658      union foo
659      {
660        int x;
661      }
662
663      false:
664      union foo {
665        int x;
666      }
667
668  * ``bool AfterExternBlock`` Wrap extern blocks.
669
670    .. code-block:: c++
671
672      true:
673      extern "C"
674      {
675        int foo();
676      }
677
678      false:
679      extern "C" {
680      int foo();
681      }
682
683  * ``bool BeforeCatch`` Wrap before ``catch``.
684
685    .. code-block:: c++
686
687      true:
688      try {
689        foo();
690      }
691      catch () {
692      }
693
694      false:
695      try {
696        foo();
697      } catch () {
698      }
699
700  * ``bool BeforeElse`` Wrap before ``else``.
701
702    .. code-block:: c++
703
704      true:
705      if (foo()) {
706      }
707      else {
708      }
709
710      false:
711      if (foo()) {
712      } else {
713      }
714
715  * ``bool IndentBraces`` Indent the wrapped braces themselves.
716
717  * ``bool SplitEmptyFunction`` If ``false``, empty function body can be put on a single line.
718    This option is used only if the opening brace of the function has
719    already been wrapped, i.e. the `AfterFunction` brace wrapping mode is
720    set, and the function could/should not be put on a single line (as per
721    `AllowShortFunctionsOnASingleLine` and constructor formatting options).
722
723    .. code-block:: c++
724
725      int f()   vs.   inf f()
726      {}              {
727                      }
728
729  * ``bool SplitEmptyRecord`` If ``false``, empty record (e.g. class, struct or union) body
730    can be put on a single line. This option is used only if the opening
731    brace of the record has already been wrapped, i.e. the `AfterClass`
732    (for classes) brace wrapping mode is set.
733
734    .. code-block:: c++
735
736      class Foo   vs.  class Foo
737      {}               {
738                       }
739
740  * ``bool SplitEmptyNamespace`` If ``false``, empty namespace body can be put on a single line.
741    This option is used only if the opening brace of the namespace has
742    already been wrapped, i.e. the `AfterNamespace` brace wrapping mode is
743    set.
744
745    .. code-block:: c++
746
747      namespace Foo   vs.  namespace Foo
748      {}                   {
749                           }
750
751
752**BreakAfterJavaFieldAnnotations** (``bool``)
753  Break after each annotation on a field in Java files.
754
755  .. code-block:: java
756
757     true:                                  false:
758     @Partial                       vs.     @Partial @Mock DataLoad loader;
759     @Mock
760     DataLoad loader;
761
762**BreakBeforeBinaryOperators** (``BinaryOperatorStyle``)
763  The way to wrap binary operators.
764
765  Possible values:
766
767  * ``BOS_None`` (in configuration: ``None``)
768    Break after operators.
769
770    .. code-block:: c++
771
772       LooooooooooongType loooooooooooooooooooooongVariable =
773           someLooooooooooooooooongFunction();
774
775       bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
776                            aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ==
777                        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
778                    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa >
779                        ccccccccccccccccccccccccccccccccccccccccc;
780
781  * ``BOS_NonAssignment`` (in configuration: ``NonAssignment``)
782    Break before operators that aren't assignments.
783
784    .. code-block:: c++
785
786       LooooooooooongType loooooooooooooooooooooongVariable =
787           someLooooooooooooooooongFunction();
788
789       bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
790                            + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
791                        == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
792                    && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
793                           > ccccccccccccccccccccccccccccccccccccccccc;
794
795  * ``BOS_All`` (in configuration: ``All``)
796    Break before operators.
797
798    .. code-block:: c++
799
800       LooooooooooongType loooooooooooooooooooooongVariable
801           = someLooooooooooooooooongFunction();
802
803       bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
804                            + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
805                        == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
806                    && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
807                           > ccccccccccccccccccccccccccccccccccccccccc;
808
809
810
811**BreakBeforeBraces** (``BraceBreakingStyle``)
812  The brace breaking style to use.
813
814  Possible values:
815
816  * ``BS_Attach`` (in configuration: ``Attach``)
817    Always attach braces to surrounding context.
818
819    .. code-block:: c++
820
821      try {
822        foo();
823      } catch () {
824      }
825      void foo() { bar(); }
826      class foo {};
827      if (foo()) {
828      } else {
829      }
830      enum X : int { A, B };
831
832  * ``BS_Linux`` (in configuration: ``Linux``)
833    Like ``Attach``, but break before braces on function, namespace and
834    class definitions.
835
836    .. code-block:: c++
837
838      try {
839        foo();
840      } catch () {
841      }
842      void foo() { bar(); }
843      class foo
844      {
845      };
846      if (foo()) {
847      } else {
848      }
849      enum X : int { A, B };
850
851  * ``BS_Mozilla`` (in configuration: ``Mozilla``)
852    Like ``Attach``, but break before braces on enum, function, and record
853    definitions.
854
855    .. code-block:: c++
856
857      try {
858        foo();
859      } catch () {
860      }
861      void foo() { bar(); }
862      class foo
863      {
864      };
865      if (foo()) {
866      } else {
867      }
868      enum X : int { A, B };
869
870  * ``BS_Stroustrup`` (in configuration: ``Stroustrup``)
871    Like ``Attach``, but break before function definitions, ``catch``, and
872    ``else``.
873
874    .. code-block:: c++
875
876      try {
877        foo();
878      } catch () {
879      }
880      void foo() { bar(); }
881      class foo
882      {
883      };
884      if (foo()) {
885      } else {
886      }
887      enum X : int
888      {
889        A,
890        B
891      };
892
893  * ``BS_Allman`` (in configuration: ``Allman``)
894    Always break before braces.
895
896    .. code-block:: c++
897
898      try {
899        foo();
900      }
901      catch () {
902      }
903      void foo() { bar(); }
904      class foo {
905      };
906      if (foo()) {
907      }
908      else {
909      }
910      enum X : int { A, B };
911
912  * ``BS_GNU`` (in configuration: ``GNU``)
913    Always break before braces and add an extra level of indentation to
914    braces of control statements, not to those of class, function
915    or other definitions.
916
917    .. code-block:: c++
918
919      try
920        {
921          foo();
922        }
923      catch ()
924        {
925        }
926      void foo() { bar(); }
927      class foo
928      {
929      };
930      if (foo())
931        {
932        }
933      else
934        {
935        }
936      enum X : int
937      {
938        A,
939        B
940      };
941
942  * ``BS_WebKit`` (in configuration: ``WebKit``)
943    Like ``Attach``, but break before functions.
944
945    .. code-block:: c++
946
947      try {
948        foo();
949      } catch () {
950      }
951      void foo() { bar(); }
952      class foo {
953      };
954      if (foo()) {
955      } else {
956      }
957      enum X : int { A, B };
958
959  * ``BS_Custom`` (in configuration: ``Custom``)
960    Configure each individual brace in `BraceWrapping`.
961
962
963
964**BreakBeforeInheritanceComma** (``bool``)
965  If ``true``, in the class inheritance expression clang-format will
966  break before ``:`` and ``,`` if there is multiple inheritance.
967
968  .. code-block:: c++
969
970     true:                                  false:
971     class MyClass                  vs.     class MyClass : public X, public Y {
972         : public X                         };
973         , public Y {
974     };
975
976**BreakBeforeTernaryOperators** (``bool``)
977  If ``true``, ternary operators will be placed after line breaks.
978
979  .. code-block:: c++
980
981     true:
982     veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription
983         ? firstValue
984         : SecondValueVeryVeryVeryVeryLong;
985
986     false:
987     veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ?
988         firstValue :
989         SecondValueVeryVeryVeryVeryLong;
990
991**BreakConstructorInitializers** (``BreakConstructorInitializersStyle``)
992  The constructor initializers style to use.
993
994  Possible values:
995
996  * ``BCIS_BeforeColon`` (in configuration: ``BeforeColon``)
997    Break constructor initializers before the colon and after the commas.
998
999    .. code-block:: c++
1000
1001    Constructor()
1002        : initializer1(),
1003          initializer2()
1004
1005  * ``BCIS_BeforeComma`` (in configuration: ``BeforeComma``)
1006    Break constructor initializers before the colon and commas, and align
1007    the commas with the colon.
1008
1009    .. code-block:: c++
1010
1011    Constructor()
1012        : initializer1()
1013        , initializer2()
1014
1015  * ``BCIS_AfterColon`` (in configuration: ``AfterColon``)
1016    Break constructor initializers after the colon and commas.
1017
1018    .. code-block:: c++
1019
1020    Constructor() :
1021        initializer1(),
1022        initializer2()
1023
1024
1025
1026**BreakStringLiterals** (``bool``)
1027  Allow breaking string literals when formatting.
1028
1029**ColumnLimit** (``unsigned``)
1030  The column limit.
1031
1032  A column limit of ``0`` means that there is no column limit. In this case,
1033  clang-format will respect the input's line breaking decisions within
1034  statements unless they contradict other rules.
1035
1036**CommentPragmas** (``std::string``)
1037  A regular expression that describes comments with special meaning,
1038  which should not be split into lines or otherwise changed.
1039
1040  .. code-block:: c++
1041
1042     // CommentPragmas: '^ FOOBAR pragma:'
1043     // Will leave the following line unaffected
1044     #include <vector> // FOOBAR pragma: keep
1045
1046**CompactNamespaces** (``bool``)
1047  If ``true``, consecutive namespace declarations will be on the same
1048  line. If ``false``, each namespace is declared on a new line.
1049
1050  .. code-block:: c++
1051
1052    true:
1053    namespace Foo { namespace Bar {
1054    }}
1055
1056    false:
1057    namespace Foo {
1058    namespace Bar {
1059    }
1060    }
1061
1062  If it does not fit on a single line, the overflowing namespaces get
1063  wrapped:
1064
1065  .. code-block:: c++
1066
1067    namespace Foo { namespace Bar {
1068    namespace Extra {
1069    }}}
1070
1071**ConstructorInitializerAllOnOneLineOrOnePerLine** (``bool``)
1072  If the constructor initializers don't fit on a line, put each
1073  initializer on its own line.
1074
1075  .. code-block:: c++
1076
1077    true:
1078    SomeClass::Constructor()
1079        : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) {
1080      return 0;
1081    }
1082
1083    false:
1084    SomeClass::Constructor()
1085        : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa),
1086          aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) {
1087      return 0;
1088    }
1089
1090**ConstructorInitializerIndentWidth** (``unsigned``)
1091  The number of characters to use for indentation of constructor
1092  initializer lists.
1093
1094**ContinuationIndentWidth** (``unsigned``)
1095  Indent width for line continuations.
1096
1097  .. code-block:: c++
1098
1099     ContinuationIndentWidth: 2
1100
1101     int i =         //  VeryVeryVeryVeryVeryLongComment
1102       longFunction( // Again a long comment
1103         arg);
1104
1105**Cpp11BracedListStyle** (``bool``)
1106  If ``true``, format braced lists as best suited for C++11 braced
1107  lists.
1108
1109  Important differences:
1110  - No spaces inside the braced list.
1111  - No line break before the closing brace.
1112  - Indentation with the continuation indent, not with the block indent.
1113
1114  Fundamentally, C++11 braced lists are formatted exactly like function
1115  calls would be formatted in their place. If the braced list follows a name
1116  (e.g. a type or variable name), clang-format formats as if the ``{}`` were
1117  the parentheses of a function call with that name. If there is no name,
1118  a zero-length name is assumed.
1119
1120  .. code-block:: c++
1121
1122     true:                                  false:
1123     vector<int> x{1, 2, 3, 4};     vs.     vector<int> x{ 1, 2, 3, 4 };
1124     vector<T> x{{}, {}, {}, {}};           vector<T> x{ {}, {}, {}, {} };
1125     f(MyMap[{composite, key}]);            f(MyMap[{ composite, key }]);
1126     new int[3]{1, 2, 3};                   new int[3]{ 1, 2, 3 };
1127
1128**DerivePointerAlignment** (``bool``)
1129  If ``true``, analyze the formatted file for the most common
1130  alignment of ``&`` and ``*``.
1131  Pointer and reference alignment styles are going to be updated according
1132  to the preferences found in the file.
1133  ``PointerAlignment`` is then used only as fallback.
1134
1135**DisableFormat** (``bool``)
1136  Disables formatting completely.
1137
1138**ExperimentalAutoDetectBinPacking** (``bool``)
1139  If ``true``, clang-format detects whether function calls and
1140  definitions are formatted with one parameter per line.
1141
1142  Each call can be bin-packed, one-per-line or inconclusive. If it is
1143  inconclusive, e.g. completely on one line, but a decision needs to be
1144  made, clang-format analyzes whether there are other bin-packed cases in
1145  the input file and act accordingly.
1146
1147  NOTE: This is an experimental flag, that might go away or be renamed. Do
1148  not use this in config files, etc. Use at your own risk.
1149
1150**FixNamespaceComments** (``bool``)
1151  If ``true``, clang-format adds missing namespace end comments and
1152  fixes invalid existing ones.
1153
1154  .. code-block:: c++
1155
1156     true:                                  false:
1157     namespace a {                  vs.     namespace a {
1158     foo();                                 foo();
1159     } // namespace a;                      }
1160
1161**ForEachMacros** (``std::vector<std::string>``)
1162  A vector of macros that should be interpreted as foreach loops
1163  instead of as function calls.
1164
1165  These are expected to be macros of the form:
1166
1167  .. code-block:: c++
1168
1169    FOREACH(<variable-declaration>, ...)
1170      <loop-body>
1171
1172  In the .clang-format configuration file, this can be configured like:
1173
1174  .. code-block:: yaml
1175
1176    ForEachMacros: ['RANGES_FOR', 'FOREACH']
1177
1178  For example: BOOST_FOREACH.
1179
1180**IncludeCategories** (``std::vector<IncludeCategory>``)
1181  Regular expressions denoting the different ``#include`` categories
1182  used for ordering ``#includes``.
1183
1184  These regular expressions are matched against the filename of an include
1185  (including the <> or "") in order. The value belonging to the first
1186  matching regular expression is assigned and ``#includes`` are sorted first
1187  according to increasing category number and then alphabetically within
1188  each category.
1189
1190  If none of the regular expressions match, INT_MAX is assigned as
1191  category. The main header for a source file automatically gets category 0.
1192  so that it is generally kept at the beginning of the ``#includes``
1193  (http://llvm.org/docs/CodingStandards.html#include-style). However, you
1194  can also assign negative priorities if you have certain headers that
1195  always need to be first.
1196
1197  To configure this in the .clang-format file, use:
1198
1199  .. code-block:: yaml
1200
1201    IncludeCategories:
1202      - Regex:           '^"(llvm|llvm-c|clang|clang-c)/'
1203        Priority:        2
1204      - Regex:           '^(<|"(gtest|gmock|isl|json)/)'
1205        Priority:        3
1206      - Regex:           '.*'
1207        Priority:        1
1208
1209**IncludeIsMainRegex** (``std::string``)
1210  Specify a regular expression of suffixes that are allowed in the
1211  file-to-main-include mapping.
1212
1213  When guessing whether a #include is the "main" include (to assign
1214  category 0, see above), use this regex of allowed suffixes to the header
1215  stem. A partial match is done, so that:
1216  - "" means "arbitrary suffix"
1217  - "$" means "no suffix"
1218
1219  For example, if configured to "(_test)?$", then a header a.h would be seen
1220  as the "main" include in both a.cc and a_test.cc.
1221
1222**IndentCaseLabels** (``bool``)
1223  Indent case labels one level from the switch statement.
1224
1225  When ``false``, use the same indentation level as for the switch statement.
1226  Switch statement body is always indented one level more than case labels.
1227
1228  .. code-block:: c++
1229
1230     false:                                 true:
1231     switch (fool) {                vs.     switch (fool) {
1232     case 1:                                  case 1:
1233       bar();                                   bar();
1234       break;                                   break;
1235     default:                                 default:
1236       plop();                                  plop();
1237     }                                      }
1238
1239**IndentPPDirectives** (``PPDirectiveIndentStyle``)
1240  The preprocessor directive indenting style to use.
1241
1242  Possible values:
1243
1244  * ``PPDIS_None`` (in configuration: ``None``)
1245    Does not indent any directives.
1246
1247    .. code-block:: c++
1248
1249       #if FOO
1250       #if BAR
1251       #include <foo>
1252       #endif
1253       #endif
1254
1255  * ``PPDIS_AfterHash`` (in configuration: ``AfterHash``)
1256    Indents directives after the hash.
1257
1258    .. code-block:: c++
1259
1260       #if FOO
1261       #  if BAR
1262       #    include <foo>
1263       #  endif
1264       #endif
1265
1266
1267
1268**IndentWidth** (``unsigned``)
1269  The number of columns to use for indentation.
1270
1271  .. code-block:: c++
1272
1273     IndentWidth: 3
1274
1275     void f() {
1276        someFunction();
1277        if (true, false) {
1278           f();
1279        }
1280     }
1281
1282**IndentWrappedFunctionNames** (``bool``)
1283  Indent if a function definition or declaration is wrapped after the
1284  type.
1285
1286  .. code-block:: c++
1287
1288     true:
1289     LoooooooooooooooooooooooooooooooooooooooongReturnType
1290         LoooooooooooooooooooooooooooooooongFunctionDeclaration();
1291
1292     false:
1293     LoooooooooooooooooooooooooooooooooooooooongReturnType
1294     LoooooooooooooooooooooooooooooooongFunctionDeclaration();
1295
1296**JavaScriptQuotes** (``JavaScriptQuoteStyle``)
1297  The JavaScriptQuoteStyle to use for JavaScript strings.
1298
1299  Possible values:
1300
1301  * ``JSQS_Leave`` (in configuration: ``Leave``)
1302    Leave string quotes as they are.
1303
1304    .. code-block:: js
1305
1306       string1 = "foo";
1307       string2 = 'bar';
1308
1309  * ``JSQS_Single`` (in configuration: ``Single``)
1310    Always use single quotes.
1311
1312    .. code-block:: js
1313
1314       string1 = 'foo';
1315       string2 = 'bar';
1316
1317  * ``JSQS_Double`` (in configuration: ``Double``)
1318    Always use double quotes.
1319
1320    .. code-block:: js
1321
1322       string1 = "foo";
1323       string2 = "bar";
1324
1325
1326
1327**JavaScriptWrapImports** (``bool``)
1328  Whether to wrap JavaScript import/export statements.
1329
1330  .. code-block:: js
1331
1332     true:
1333     import {
1334         VeryLongImportsAreAnnoying,
1335         VeryLongImportsAreAnnoying,
1336         VeryLongImportsAreAnnoying,
1337     } from 'some/module.js'
1338
1339     false:
1340     import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js"
1341
1342**KeepEmptyLinesAtTheStartOfBlocks** (``bool``)
1343  If true, the empty line at the start of blocks is kept.
1344
1345  .. code-block:: c++
1346
1347     true:                                  false:
1348     if (foo) {                     vs.     if (foo) {
1349                                              bar();
1350       bar();                               }
1351     }
1352
1353**Language** (``LanguageKind``)
1354  Language, this format style is targeted at.
1355
1356  Possible values:
1357
1358  * ``LK_None`` (in configuration: ``None``)
1359    Do not use.
1360
1361  * ``LK_Cpp`` (in configuration: ``Cpp``)
1362    Should be used for C, C++.
1363
1364  * ``LK_Java`` (in configuration: ``Java``)
1365    Should be used for Java.
1366
1367  * ``LK_JavaScript`` (in configuration: ``JavaScript``)
1368    Should be used for JavaScript.
1369
1370  * ``LK_ObjC`` (in configuration: ``ObjC``)
1371    Should be used for Objective-C, Objective-C++.
1372
1373  * ``LK_Proto`` (in configuration: ``Proto``)
1374    Should be used for Protocol Buffers
1375    (https://developers.google.com/protocol-buffers/).
1376
1377  * ``LK_TableGen`` (in configuration: ``TableGen``)
1378    Should be used for TableGen code.
1379
1380  * ``LK_TextProto`` (in configuration: ``TextProto``)
1381    Should be used for Protocol Buffer messages in text format
1382    (https://developers.google.com/protocol-buffers/).
1383
1384
1385
1386**MacroBlockBegin** (``std::string``)
1387  A regular expression matching macros that start a block.
1388
1389  .. code-block:: c++
1390
1391     # With:
1392     MacroBlockBegin: "^NS_MAP_BEGIN|\
1393     NS_TABLE_HEAD$"
1394     MacroBlockEnd: "^\
1395     NS_MAP_END|\
1396     NS_TABLE_.*_END$"
1397
1398     NS_MAP_BEGIN
1399       foo();
1400     NS_MAP_END
1401
1402     NS_TABLE_HEAD
1403       bar();
1404     NS_TABLE_FOO_END
1405
1406     # Without:
1407     NS_MAP_BEGIN
1408     foo();
1409     NS_MAP_END
1410
1411     NS_TABLE_HEAD
1412     bar();
1413     NS_TABLE_FOO_END
1414
1415**MacroBlockEnd** (``std::string``)
1416  A regular expression matching macros that end a block.
1417
1418**MaxEmptyLinesToKeep** (``unsigned``)
1419  The maximum number of consecutive empty lines to keep.
1420
1421  .. code-block:: c++
1422
1423     MaxEmptyLinesToKeep: 1         vs.     MaxEmptyLinesToKeep: 0
1424     int f() {                              int f() {
1425       int = 1;                                 int i = 1;
1426                                                i = foo();
1427       i = foo();                               return i;
1428                                            }
1429       return i;
1430     }
1431
1432**NamespaceIndentation** (``NamespaceIndentationKind``)
1433  The indentation used for namespaces.
1434
1435  Possible values:
1436
1437  * ``NI_None`` (in configuration: ``None``)
1438    Don't indent in namespaces.
1439
1440    .. code-block:: c++
1441
1442       namespace out {
1443       int i;
1444       namespace in {
1445       int i;
1446       }
1447       }
1448
1449  * ``NI_Inner`` (in configuration: ``Inner``)
1450    Indent only in inner namespaces (nested in other namespaces).
1451
1452    .. code-block:: c++
1453
1454       namespace out {
1455       int i;
1456       namespace in {
1457         int i;
1458       }
1459       }
1460
1461  * ``NI_All`` (in configuration: ``All``)
1462    Indent in all namespaces.
1463
1464    .. code-block:: c++
1465
1466       namespace out {
1467         int i;
1468         namespace in {
1469           int i;
1470         }
1471       }
1472
1473
1474
1475**ObjCBlockIndentWidth** (``unsigned``)
1476  The number of characters to use for indentation of ObjC blocks.
1477
1478  .. code-block:: objc
1479
1480     ObjCBlockIndentWidth: 4
1481
1482     [operation setCompletionBlock:^{
1483         [self onOperationDone];
1484     }];
1485
1486**ObjCSpaceAfterProperty** (``bool``)
1487  Add a space after ``@property`` in Objective-C, i.e. use
1488  ``@property (readonly)`` instead of ``@property(readonly)``.
1489
1490**ObjCSpaceBeforeProtocolList** (``bool``)
1491  Add a space in front of an Objective-C protocol list, i.e. use
1492  ``Foo <Protocol>`` instead of ``Foo<Protocol>``.
1493
1494**PenaltyBreakAssignment** (``unsigned``)
1495  The penalty for breaking around an assignment operator.
1496
1497**PenaltyBreakBeforeFirstCallParameter** (``unsigned``)
1498  The penalty for breaking a function call after ``call(``.
1499
1500**PenaltyBreakComment** (``unsigned``)
1501  The penalty for each line break introduced inside a comment.
1502
1503**PenaltyBreakFirstLessLess** (``unsigned``)
1504  The penalty for breaking before the first ``<<``.
1505
1506**PenaltyBreakString** (``unsigned``)
1507  The penalty for each line break introduced inside a string literal.
1508
1509**PenaltyExcessCharacter** (``unsigned``)
1510  The penalty for each character outside of the column limit.
1511
1512**PenaltyReturnTypeOnItsOwnLine** (``unsigned``)
1513  Penalty for putting the return type of a function onto its own
1514  line.
1515
1516**PointerAlignment** (``PointerAlignmentStyle``)
1517  Pointer and reference alignment style.
1518
1519  Possible values:
1520
1521  * ``PAS_Left`` (in configuration: ``Left``)
1522    Align pointer to the left.
1523
1524    .. code-block:: c++
1525
1526      int* a;
1527
1528  * ``PAS_Right`` (in configuration: ``Right``)
1529    Align pointer to the right.
1530
1531    .. code-block:: c++
1532
1533      int *a;
1534
1535  * ``PAS_Middle`` (in configuration: ``Middle``)
1536    Align pointer in the middle.
1537
1538    .. code-block:: c++
1539
1540      int * a;
1541
1542
1543
1544**ReflowComments** (``bool``)
1545  If ``true``, clang-format will attempt to re-flow comments.
1546
1547  .. code-block:: c++
1548
1549     false:
1550     // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
1551     /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */
1552
1553     true:
1554     // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
1555     // information
1556     /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
1557      * information */
1558
1559**SortIncludes** (``bool``)
1560  If ``true``, clang-format will sort ``#includes``.
1561
1562  .. code-block:: c++
1563
1564     false:                                 true:
1565     #include "b.h"                 vs.     #include "a.h"
1566     #include "a.h"                         #include "b.h"
1567
1568**SortUsingDeclarations** (``bool``)
1569  If ``true``, clang-format will sort using declarations.
1570
1571  .. code-block:: c++
1572
1573     false:                                 true:
1574     using std::cout;               vs.     using std::cin;
1575     using std::cin;                        using std::cout;
1576
1577**SpaceAfterCStyleCast** (``bool``)
1578  If ``true``, a space is inserted after C style casts.
1579
1580  .. code-block:: c++
1581
1582     true:                                  false:
1583     (int)i;                        vs.     (int) i;
1584
1585**SpaceAfterTemplateKeyword** (``bool``)
1586  If ``true``, a space will be inserted after the 'template' keyword.
1587
1588  .. code-block:: c++
1589
1590     true:                                  false:
1591     template <int> void foo();     vs.     template<int> void foo();
1592
1593**SpaceBeforeAssignmentOperators** (``bool``)
1594  If ``false``, spaces will be removed before assignment operators.
1595
1596  .. code-block:: c++
1597
1598     true:                                  false:
1599     int a = 5;                     vs.     int a=5;
1600     a += 42                                a+=42;
1601
1602**SpaceBeforeParens** (``SpaceBeforeParensOptions``)
1603  Defines in which cases to put a space before opening parentheses.
1604
1605  Possible values:
1606
1607  * ``SBPO_Never`` (in configuration: ``Never``)
1608    Never put a space before opening parentheses.
1609
1610    .. code-block:: c++
1611
1612       void f() {
1613         if(true) {
1614           f();
1615         }
1616       }
1617
1618  * ``SBPO_ControlStatements`` (in configuration: ``ControlStatements``)
1619    Put a space before opening parentheses only after control statement
1620    keywords (``for/if/while...``).
1621
1622    .. code-block:: c++
1623
1624       void f() {
1625         if (true) {
1626           f();
1627         }
1628       }
1629
1630  * ``SBPO_Always`` (in configuration: ``Always``)
1631    Always put a space before opening parentheses, except when it's
1632    prohibited by the syntax rules (in function-like macro definitions) or
1633    when determined by other style rules (after unary operators, opening
1634    parentheses, etc.)
1635
1636    .. code-block:: c++
1637
1638       void f () {
1639         if (true) {
1640           f ();
1641         }
1642       }
1643
1644
1645
1646**SpaceInEmptyParentheses** (``bool``)
1647  If ``true``, spaces may be inserted into ``()``.
1648
1649  .. code-block:: c++
1650
1651     true:                                false:
1652     void f( ) {                    vs.   void f() {
1653       int x[] = {foo( ), bar( )};          int x[] = {foo(), bar()};
1654       if (true) {                          if (true) {
1655         f( );                                f();
1656       }                                    }
1657     }                                    }
1658
1659**SpacesBeforeTrailingComments** (``unsigned``)
1660  The number of spaces before trailing line comments
1661  (``//`` - comments).
1662
1663  This does not affect trailing block comments (``/*`` - comments) as
1664  those commonly have different usage patterns and a number of special
1665  cases.
1666
1667  .. code-block:: c++
1668
1669     SpacesBeforeTrailingComments: 3
1670     void f() {
1671       if (true) {   // foo1
1672         f();        // bar
1673       }             // foo
1674     }
1675
1676**SpacesInAngles** (``bool``)
1677  If ``true``, spaces will be inserted after ``<`` and before ``>``
1678  in template argument lists.
1679
1680  .. code-block:: c++
1681
1682     true:                                  false:
1683     static_cast< int >(arg);       vs.     static_cast<int>(arg);
1684     std::function< void(int) > fct;        std::function<void(int)> fct;
1685
1686**SpacesInCStyleCastParentheses** (``bool``)
1687  If ``true``, spaces may be inserted into C style casts.
1688
1689  .. code-block:: c++
1690
1691     true:                                  false:
1692     x = ( int32 )y                 vs.     x = (int32)y
1693
1694**SpacesInContainerLiterals** (``bool``)
1695  If ``true``, spaces are inserted inside container literals (e.g.
1696  ObjC and Javascript array and dict literals).
1697
1698  .. code-block:: js
1699
1700     true:                                  false:
1701     var arr = [ 1, 2, 3 ];         vs.     var arr = [1, 2, 3];
1702     f({a : 1, b : 2, c : 3});              f({a: 1, b: 2, c: 3});
1703
1704**SpacesInParentheses** (``bool``)
1705  If ``true``, spaces will be inserted after ``(`` and before ``)``.
1706
1707  .. code-block:: c++
1708
1709     true:                                  false:
1710     t f( Deleted & ) & = delete;   vs.     t f(Deleted &) & = delete;
1711
1712**SpacesInSquareBrackets** (``bool``)
1713  If ``true``, spaces will be inserted after ``[`` and before ``]``.
1714  Lambdas or unspecified size array declarations will not be affected.
1715
1716  .. code-block:: c++
1717
1718     true:                                  false:
1719     int a[ 5 ];                    vs.     int a[5];
1720     std::unique_ptr<int[]> foo() {} // Won't be affected
1721
1722**Standard** (``LanguageStandard``)
1723  Format compatible with this standard, e.g. use ``A<A<int> >``
1724  instead of ``A<A<int>>`` for ``LS_Cpp03``.
1725
1726  Possible values:
1727
1728  * ``LS_Cpp03`` (in configuration: ``Cpp03``)
1729    Use C++03-compatible syntax.
1730
1731  * ``LS_Cpp11`` (in configuration: ``Cpp11``)
1732    Use features of C++11, C++14 and C++1z (e.g. ``A<A<int>>`` instead of
1733    ``A<A<int> >``).
1734
1735  * ``LS_Auto`` (in configuration: ``Auto``)
1736    Automatic detection based on the input.
1737
1738
1739
1740**TabWidth** (``unsigned``)
1741  The number of columns used for tab stops.
1742
1743**UseTab** (``UseTabStyle``)
1744  The way to use tab characters in the resulting file.
1745
1746  Possible values:
1747
1748  * ``UT_Never`` (in configuration: ``Never``)
1749    Never use tab.
1750
1751  * ``UT_ForIndentation`` (in configuration: ``ForIndentation``)
1752    Use tabs only for indentation.
1753
1754  * ``UT_ForContinuationAndIndentation`` (in configuration: ``ForContinuationAndIndentation``)
1755    Use tabs only for line continuation and indentation.
1756
1757  * ``UT_Always`` (in configuration: ``Always``)
1758    Use tabs whenever we need to fill whitespace that spans at least from
1759    one tab stop to the next one.
1760
1761
1762
1763.. END_FORMAT_STYLE_OPTIONS
1764
1765Adding additional style options
1766===============================
1767
1768Each additional style option adds costs to the clang-format project. Some of
1769these costs affect the clang-format development itself, as we need to make
1770sure that any given combination of options work and that new features don't
1771break any of the existing options in any way. There are also costs for end users
1772as options become less discoverable and people have to think about and make a
1773decision on options they don't really care about.
1774
1775The goal of the clang-format project is more on the side of supporting a
1776limited set of styles really well as opposed to supporting every single style
1777used by a codebase somewhere in the wild. Of course, we do want to support all
1778major projects and thus have established the following bar for adding style
1779options. Each new style option must ..
1780
1781  * be used in a project of significant size (have dozens of contributors)
1782  * have a publicly accessible style guide
1783  * have a person willing to contribute and maintain patches
1784
1785Examples
1786========
1787
1788A style similar to the `Linux Kernel style
1789<https://www.kernel.org/doc/Documentation/CodingStyle>`_:
1790
1791.. code-block:: yaml
1792
1793  BasedOnStyle: LLVM
1794  IndentWidth: 8
1795  UseTab: Always
1796  BreakBeforeBraces: Linux
1797  AllowShortIfStatementsOnASingleLine: false
1798  IndentCaseLabels: false
1799
1800The result is (imagine that tabs are used for indentation here):
1801
1802.. code-block:: c++
1803
1804  void test()
1805  {
1806          switch (x) {
1807          case 0:
1808          case 1:
1809                  do_something();
1810                  break;
1811          case 2:
1812                  do_something_else();
1813                  break;
1814          default:
1815                  break;
1816          }
1817          if (condition)
1818                  do_something_completely_different();
1819
1820          if (x == y) {
1821                  q();
1822          } else if (x > y) {
1823                  w();
1824          } else {
1825                  r();
1826          }
1827  }
1828
1829A style similar to the default Visual Studio formatting style:
1830
1831.. code-block:: yaml
1832
1833  UseTab: Never
1834  IndentWidth: 4
1835  BreakBeforeBraces: Allman
1836  AllowShortIfStatementsOnASingleLine: false
1837  IndentCaseLabels: false
1838  ColumnLimit: 0
1839
1840The result is:
1841
1842.. code-block:: c++
1843
1844  void test()
1845  {
1846      switch (suffix)
1847      {
1848      case 0:
1849      case 1:
1850          do_something();
1851          break;
1852      case 2:
1853          do_something_else();
1854          break;
1855      default:
1856          break;
1857      }
1858      if (condition)
1859          do_somthing_completely_different();
1860
1861      if (x == y)
1862      {
1863          q();
1864      }
1865      else if (x > y)
1866      {
1867          w();
1868      }
1869      else
1870      {
1871          r();
1872      }
1873  }
1874