blob: 816b39f06f3e1de4ccc158f0cf0f2721dcb64d7a [file] [log] [blame]
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001==========================
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
Hans Wennborg9f6581b2013-09-10 15:41:12 +000019use ``-style=file`` and put style configuration in the ``.clang-format`` or
20``_clang-format`` file in the project directory.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +000021
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
Alexander Kornienko092cb212014-08-12 13:34:22 +000036The 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
Alexander Kornienkod278e0e2013-09-04 15:09:13 +000073An 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
Daniel Jasperd8b4ec02014-10-07 12:15:15 +000088Disabling 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
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000106Configuring 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++
Alexander Kornienko472d27a2013-09-04 15:14:18 +0000120enumeration member (with a prefix, e.g. ``LS_Auto``), and as a value usable in
121the configuration (without a prefix: ``Auto``).
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000122
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``)
Alexander Kornienkoe99a3a32016-02-23 16:12:08 +0000151 The extra indent or outdent of access modifiers, e.g. ``public:``.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000152
Daniel Jasper6501f7e2015-10-27 12:38:37 +0000153**AlignAfterOpenBracket** (``BracketAlignmentStyle``)
Daniel Jasper3219e432014-12-02 13:24:51 +0000154 If ``true``, horizontally aligns arguments after an open bracket.
155
156 This applies to round brackets (parentheses), angle brackets and square
Alexander Kornienko1e048232016-02-23 16:11:51 +0000157 brackets.
Daniel Jasperb5bda7c2015-10-06 12:11:51 +0000158
Daniel Jasper6501f7e2015-10-27 12:38:37 +0000159 Possible values:
Daniel Jasper8e1ecca2015-10-07 13:02:45 +0000160
Daniel Jasper6501f7e2015-10-27 12:38:37 +0000161 * ``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);
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000168
Daniel Jasper6501f7e2015-10-27 12:38:37 +0000169 * ``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);
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000176
Daniel Jasper6501f7e2015-10-27 12:38:37 +0000177 * ``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
Daniel Jasper3219e432014-12-02 13:24:51 +0000186
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000187
Daniel Jaspera44991332015-04-29 13:06:49 +0000188**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
Daniel Jasperb5bda7c2015-10-06 12:11:51 +0000193
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +0000194 .. code-block:: c++
Daniel Jasper8e1ecca2015-10-07 13:02:45 +0000195
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +0000196 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
Daniel Jasperb5bda7c2015-10-06 12:11:51 +0000205
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +0000206 .. code-block:: c++
Daniel Jasper8e1ecca2015-10-07 13:02:45 +0000207
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +0000208 int aaaa = 12;
209 float b = 23;
210 std::string ccc = 23;
Daniel Jaspera44991332015-04-29 13:06:49 +0000211
Daniel Jasper7fdbb3f2017-05-08 15:08:00 +0000212**AlignEscapedNewlines** (``EscapedNewlineAlignmentStyle``)
213 Options for aligning backslashes in escaped newlines.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000214
Daniel Jasper7fdbb3f2017-05-08 15:08:00 +0000215 Possible values:
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000216
Daniel Jasper7fdbb3f2017-05-08 15:08:00 +0000217 * ``ENAS_DontAlign`` (in configuration: ``DontAlign``)
218 Don't align escaped newlines.
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000219
Daniel Jasper7fdbb3f2017-05-08 15:08:00 +0000220 .. 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
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000251
Daniel Jasper3219e432014-12-02 13:24:51 +0000252**AlignOperands** (``bool``)
253 If ``true``, horizontally align operands of binary and ternary
254 expressions.
255
Alexander Kornienko1e048232016-02-23 16:11:51 +0000256 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
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000264**AlignTrailingComments** (``bool``)
265 If ``true``, aligns trailing comments.
266
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000267 .. code-block:: c++
268
Krasimir Georgiev818da9b2017-11-09 15:41:23 +0000269 true: false:
270 int a; // My comment a vs. int a; // My comment a
271 int b = 2; // comment b int b = 2; // comment about b
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000272
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000273**AllowAllParametersOfDeclarationOnNextLine** (``bool``)
Daniel Jasper392c2ba2017-09-07 13:45:41 +0000274 If the function declaration doesn't fit on a line,
275 allow putting all parameters of a function declaration onto
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000276 the next line even if ``BinPackParameters`` is ``false``.
277
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000278 .. code-block:: c++
279
Daniel Jasper392c2ba2017-09-07 13:45:41 +0000280 true:
281 void myFunction(
282 int a, int b, int c, int d, int e);
283
284 false:
285 void myFunction(int a,
286 int b,
287 int c,
288 int d,
289 int e);
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000290
Daniel Jasper17605d32014-05-14 09:33:35 +0000291**AllowShortBlocksOnASingleLine** (``bool``)
292 Allows contracting simple braced statements to a single line.
293
294 E.g., this allows ``if (a) { return; }`` to be put on a single line.
295
Daniel Jasperb87899b2014-09-10 13:11:45 +0000296**AllowShortCaseLabelsOnASingleLine** (``bool``)
297 If ``true``, short case labels will be contracted to a single line.
298
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000299 .. code-block:: c++
300
301 true: false:
302 switch (a) { vs. switch (a) {
303 case 1: x = 1; break; case 1:
304 case 2: return; x = 1;
305 } break;
306 case 2:
307 return;
308 }
309
Daniel Jasperb5524822014-04-09 14:05:49 +0000310**AllowShortFunctionsOnASingleLine** (``ShortFunctionStyle``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000311 Dependent on the value, ``int f() { return 0; }`` can be put on a
312 single line.
Daniel Jasperb5524822014-04-09 14:05:49 +0000313
314 Possible values:
315
316 * ``SFS_None`` (in configuration: ``None``)
317 Never merge functions into a single line.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000318
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000319 * ``SFS_InlineOnly`` (in configuration: ``InlineOnly``)
320 Only merge functions defined inside a class. Same as "inline",
321 except it does not implies "empty": i.e. top level empty functions
322 are not merged either.
323
324 .. code-block:: c++
325
326 class Foo {
327 void f() { foo(); }
328 };
329 void f() {
330 foo();
331 }
332 void f() {
333 }
334
Daniel Jasper3219e432014-12-02 13:24:51 +0000335 * ``SFS_Empty`` (in configuration: ``Empty``)
336 Only merge empty functions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000337
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000338 .. code-block:: c++
339
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000340 void f() {}
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000341 void f2() {
342 bar2();
343 }
344
Daniel Jasper20580fd2015-06-11 13:31:45 +0000345 * ``SFS_Inline`` (in configuration: ``Inline``)
346 Only merge functions defined inside a class. Implies "empty".
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000347
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000348 .. code-block:: c++
349
Jonathan Roelofs335777b2017-03-20 17:07:49 +0000350 class Foo {
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000351 void f() { foo(); }
352 };
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000353 void f() {
354 foo();
355 }
356 void f() {}
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000357
Daniel Jasperb5524822014-04-09 14:05:49 +0000358 * ``SFS_All`` (in configuration: ``All``)
359 Merge all functions fitting on a single line.
360
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000361 .. code-block:: c++
362
Jonathan Roelofs335777b2017-03-20 17:07:49 +0000363 class Foo {
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000364 void f() { foo(); }
365 };
366 void f() { bar(); }
367
Alexander Kornienkofdca83d2013-12-10 10:18:34 +0000368
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000369
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000370**AllowShortIfStatementsOnASingleLine** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000371 If ``true``, ``if (a) return;`` can be put on a single line.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000372
373**AllowShortLoopsOnASingleLine** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000374 If ``true``, ``while (true) continue;`` can be put on a single
375 line.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000376
Birunthan Mohanathasa0388a82015-06-29 15:30:42 +0000377**AlwaysBreakAfterDefinitionReturnType** (``DefinitionReturnTypeBreakingStyle``)
Zachary Turner448592e2015-12-18 22:20:15 +0000378 The function definition return type breaking style to use. This
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000379 option is **deprecated** and is retained for backwards compatibility.
Daniel Jasperca4ea1c2014-08-05 12:16:31 +0000380
Birunthan Mohanathasa0388a82015-06-29 15:30:42 +0000381 Possible values:
382
383 * ``DRTBS_None`` (in configuration: ``None``)
384 Break after return type automatically.
385 ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000386
Birunthan Mohanathasa0388a82015-06-29 15:30:42 +0000387 * ``DRTBS_All`` (in configuration: ``All``)
388 Always break after the return type.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000389
Birunthan Mohanathasa0388a82015-06-29 15:30:42 +0000390 * ``DRTBS_TopLevel`` (in configuration: ``TopLevel``)
Zachary Turner448592e2015-12-18 22:20:15 +0000391 Always break after the return types of top-level functions.
392
393
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000394
Zachary Turner448592e2015-12-18 22:20:15 +0000395**AlwaysBreakAfterReturnType** (``ReturnTypeBreakingStyle``)
396 The function declaration return type breaking style to use.
397
398 Possible values:
399
400 * ``RTBS_None`` (in configuration: ``None``)
401 Break after return type automatically.
402 ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000403
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000404 .. code-block:: c++
405
406 class A {
407 int f() { return 0; };
408 };
409 int f();
410 int f() { return 1; }
411
Zachary Turner448592e2015-12-18 22:20:15 +0000412 * ``RTBS_All`` (in configuration: ``All``)
413 Always break after the return type.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000414
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000415 .. code-block:: c++
416
417 class A {
418 int
419 f() {
420 return 0;
421 };
422 };
423 int
424 f();
425 int
426 f() {
427 return 1;
428 }
429
Zachary Turner448592e2015-12-18 22:20:15 +0000430 * ``RTBS_TopLevel`` (in configuration: ``TopLevel``)
431 Always break after the return types of top-level functions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000432
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000433 .. code-block:: c++
434
435 class A {
436 int f() { return 0; };
437 };
438 int
439 f();
440 int
441 f() {
442 return 1;
443 }
444
Zachary Turner448592e2015-12-18 22:20:15 +0000445 * ``RTBS_AllDefinitions`` (in configuration: ``AllDefinitions``)
446 Always break after the return type of function definitions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000447
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000448 .. code-block:: c++
449
450 class A {
451 int
452 f() {
453 return 0;
454 };
455 };
456 int f();
457 int
458 f() {
459 return 1;
460 }
461
Zachary Turner448592e2015-12-18 22:20:15 +0000462 * ``RTBS_TopLevelDefinitions`` (in configuration: ``TopLevelDefinitions``)
463 Always break after the return type of top-level definitions.
Birunthan Mohanathasa0388a82015-06-29 15:30:42 +0000464
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000465 .. code-block:: c++
466
467 class A {
468 int f() { return 0; };
469 };
470 int f();
471 int
472 f() {
473 return 1;
474 }
475
Daniel Jasperca4ea1c2014-08-05 12:16:31 +0000476
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000477
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000478**AlwaysBreakBeforeMultilineStrings** (``bool``)
479 If ``true``, always break before multiline string literals.
480
Daniel Jasper2aaedd32015-06-18 09:12:47 +0000481 This flag is mean to make cases where there are multiple multiline strings
482 in a file look more consistent. Thus, it will only take effect if wrapping
483 the string at that point leads to it being indented
484 ``ContinuationIndentWidth`` spaces from the start of the line.
485
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000486 .. code-block:: c++
487
488 true: false:
489 aaaa = vs. aaaa = "bbbb"
490 "bbbb" "cccc";
491 "cccc";
492
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000493**AlwaysBreakTemplateDeclarations** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000494 If ``true``, always break after the ``template<...>`` of a template
495 declaration.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000496
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000497 .. code-block:: c++
498
499 true: false:
500 template <typename T> vs. template <typename T> class C {};
501 class C {};
502
Daniel Jasper18210d72014-10-09 09:52:05 +0000503**BinPackArguments** (``bool``)
504 If ``false``, a function call's arguments will either be all on the
505 same line or will have one line each.
506
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000507 .. code-block:: c++
508
509 true:
510 void f() {
511 f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa,
512 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
513 }
514
515 false:
516 void f() {
517 f(aaaaaaaaaaaaaaaaaaaa,
518 aaaaaaaaaaaaaaaaaaaa,
519 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
520 }
521
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000522**BinPackParameters** (``bool``)
Daniel Jasper18210d72014-10-09 09:52:05 +0000523 If ``false``, a function declaration's or function definition's
524 parameters will either all be on the same line or will have one line each.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000525
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000526 .. code-block:: c++
527
528 true:
529 void f(int aaaaaaaaaaaaaaaaaaaa, int aaaaaaaaaaaaaaaaaaaa,
530 int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
531
532 false:
533 void f(int aaaaaaaaaaaaaaaaaaaa,
534 int aaaaaaaaaaaaaaaaaaaa,
535 int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
536
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000537**BraceWrapping** (``BraceWrappingFlags``)
538 Control of individual brace wrapping cases.
539
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000540 If ``BreakBeforeBraces`` is set to ``BS_Custom``, use this to specify how
541 each individual brace case should be handled. Otherwise, this is ignored.
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000542
Sylvestre Ledru7372d482017-09-07 12:09:14 +0000543 .. code-block:: yaml
544
545 # Example of usage:
546 BreakBeforeBraces: Custom
547 BraceWrapping:
548 AfterEnum: true
549 AfterStruct: false
550 SplitEmptyFunction: false
551
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000552 Nested configuration flags:
553
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000554
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000555 * ``bool AfterClass`` Wrap class definitions.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000556
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000557 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000558
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000559 true:
560 class foo {};
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000561
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000562 false:
563 class foo
564 {};
Eric Fiselier1571fae2017-06-15 03:38:08 +0000565
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000566 * ``bool AfterControlStatement`` Wrap control statements (``if``/``for``/``while``/``switch``/..).
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000567
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000568 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000569
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000570 true:
571 if (foo())
572 {
573 } else
574 {}
575 for (int i = 0; i < 10; ++i)
576 {}
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000577
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000578 false:
579 if (foo()) {
580 } else {
581 }
582 for (int i = 0; i < 10; ++i) {
583 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000584
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000585 * ``bool AfterEnum`` Wrap enum definitions.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000586
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000587 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000588
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000589 true:
590 enum X : int
591 {
592 B
593 };
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000594
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000595 false:
596 enum X : int { B };
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000597
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000598 * ``bool AfterFunction`` Wrap function definitions.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000599
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000600 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000601
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000602 true:
603 void foo()
604 {
605 bar();
606 bar2();
607 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000608
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000609 false:
610 void foo() {
611 bar();
612 bar2();
613 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000614
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000615 * ``bool AfterNamespace`` Wrap namespace definitions.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000616
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000617 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000618
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000619 true:
620 namespace
621 {
622 int foo();
623 int bar();
624 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000625
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000626 false:
627 namespace {
628 int foo();
629 int bar();
630 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000631
Krasimir Georgievc5be6af2018-03-06 13:24:01 +0000632 * ``bool AfterObjCDeclaration`` Wrap ObjC definitions (interfaces, implementations...).
633 @autoreleasepool and @synchronized blocks are wrapped
634 according to `AfterControlStatement` flag.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000635
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000636 * ``bool AfterStruct`` Wrap struct definitions.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000637
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000638 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000639
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000640 true:
641 struct foo
642 {
643 int x;
644 };
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000645
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000646 false:
647 struct foo {
648 int x;
649 };
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000650
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000651 * ``bool AfterUnion`` Wrap union definitions.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000652
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000653 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000654
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000655 true:
656 union foo
657 {
658 int x;
659 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000660
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000661 false:
662 union foo {
663 int x;
664 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000665
Krasimir Georgievd6ce9372017-09-15 11:23:50 +0000666 * ``bool AfterExternBlock`` Wrap extern blocks.
667
668 .. code-block:: c++
669
670 true:
671 extern "C"
672 {
673 int foo();
674 }
675
676 false:
677 extern "C" {
678 int foo();
679 }
680
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000681 * ``bool BeforeCatch`` Wrap before ``catch``.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000682
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000683 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000684
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000685 true:
686 try {
687 foo();
688 }
689 catch () {
690 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000691
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000692 false:
693 try {
694 foo();
695 } catch () {
696 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000697
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000698 * ``bool BeforeElse`` Wrap before ``else``.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000699
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000700 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000701
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000702 true:
703 if (foo()) {
704 }
705 else {
706 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000707
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000708 false:
709 if (foo()) {
710 } else {
711 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000712
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000713 * ``bool IndentBraces`` Indent the wrapped braces themselves.
714
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +0000715 * ``bool SplitEmptyFunction`` If ``false``, empty function body can be put on a single line.
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000716 This option is used only if the opening brace of the function has
717 already been wrapped, i.e. the `AfterFunction` brace wrapping mode is
718 set, and the function could/should not be put on a single line (as per
719 `AllowShortFunctionsOnASingleLine` and constructor formatting options).
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000720
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000721 .. code-block:: c++
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000722
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000723 int f() vs. inf f()
724 {} {
725 }
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000726
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +0000727 * ``bool SplitEmptyRecord`` If ``false``, empty record (e.g. class, struct or union) body
728 can be put on a single line. This option is used only if the opening
729 brace of the record has already been wrapped, i.e. the `AfterClass`
730 (for classes) brace wrapping mode is set.
731
732 .. code-block:: c++
733
734 class Foo vs. class Foo
735 {} {
736 }
737
738 * ``bool SplitEmptyNamespace`` If ``false``, empty namespace body can be put on a single line.
739 This option is used only if the opening brace of the namespace has
740 already been wrapped, i.e. the `AfterNamespace` brace wrapping mode is
741 set.
742
743 .. code-block:: c++
744
745 namespace Foo vs. namespace Foo
746 {} {
747 }
748
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000749
Daniel Jasper6501f7e2015-10-27 12:38:37 +0000750**BreakAfterJavaFieldAnnotations** (``bool``)
751 Break after each annotation on a field in Java files.
752
Sylvestre Ledrude098242017-04-11 07:07:05 +0000753 .. code-block:: java
754
755 true: false:
756 @Partial vs. @Partial @Mock DataLoad loader;
757 @Mock
758 DataLoad loader;
759
Daniel Jasperac043c92014-09-15 11:11:00 +0000760**BreakBeforeBinaryOperators** (``BinaryOperatorStyle``)
761 The way to wrap binary operators.
762
763 Possible values:
764
765 * ``BOS_None`` (in configuration: ``None``)
766 Break after operators.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000767
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000768 .. code-block:: c++
769
770 LooooooooooongType loooooooooooooooooooooongVariable =
771 someLooooooooooooooooongFunction();
772
773 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
774 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ==
775 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
776 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa >
777 ccccccccccccccccccccccccccccccccccccccccc;
778
Daniel Jasperac043c92014-09-15 11:11:00 +0000779 * ``BOS_NonAssignment`` (in configuration: ``NonAssignment``)
780 Break before operators that aren't assignments.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000781
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000782 .. code-block:: c++
783
784 LooooooooooongType loooooooooooooooooooooongVariable =
785 someLooooooooooooooooongFunction();
786
787 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
788 + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
789 == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
790 && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
791 > ccccccccccccccccccccccccccccccccccccccccc;
792
Daniel Jasperac043c92014-09-15 11:11:00 +0000793 * ``BOS_All`` (in configuration: ``All``)
794 Break before operators.
795
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000796 .. code-block:: c++
797
798 LooooooooooongType loooooooooooooooooooooongVariable
799 = someLooooooooooooooooongFunction();
800
801 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
802 + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
803 == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
804 && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
805 > ccccccccccccccccccccccccccccccccccccccccc;
806
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000807
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000808
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000809**BreakBeforeBraces** (``BraceBreakingStyle``)
810 The brace breaking style to use.
811
812 Possible values:
813
814 * ``BS_Attach`` (in configuration: ``Attach``)
815 Always attach braces to surrounding context.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000816
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000817 .. code-block:: c++
818
819 try {
820 foo();
821 } catch () {
822 }
823 void foo() { bar(); }
824 class foo {};
825 if (foo()) {
826 } else {
827 }
828 enum X : int { A, B };
829
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000830 * ``BS_Linux`` (in configuration: ``Linux``)
831 Like ``Attach``, but break before braces on function, namespace and
832 class definitions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000833
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000834 .. code-block:: c++
835
836 try {
837 foo();
838 } catch () {
839 }
840 void foo() { bar(); }
841 class foo
842 {
843 };
844 if (foo()) {
845 } else {
846 }
847 enum X : int { A, B };
848
Birunthan Mohanathas305fa9c2015-07-12 03:13:54 +0000849 * ``BS_Mozilla`` (in configuration: ``Mozilla``)
850 Like ``Attach``, but break before braces on enum, function, and record
851 definitions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000852
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000853 .. code-block:: c++
854
855 try {
856 foo();
857 } catch () {
858 }
859 void foo() { bar(); }
860 class foo
861 {
862 };
863 if (foo()) {
864 } else {
865 }
866 enum X : int { A, B };
867
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000868 * ``BS_Stroustrup`` (in configuration: ``Stroustrup``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000869 Like ``Attach``, but break before function definitions, ``catch``, and
870 ``else``.
871
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000872 .. code-block:: c++
873
874 try {
875 foo();
876 } catch () {
877 }
878 void foo() { bar(); }
879 class foo
880 {
881 };
882 if (foo()) {
883 } else {
884 }
885 enum X : int
886 {
887 A,
888 B
889 };
890
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000891 * ``BS_Allman`` (in configuration: ``Allman``)
892 Always break before braces.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000893
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000894 .. code-block:: c++
895
896 try {
897 foo();
898 }
899 catch () {
900 }
901 void foo() { bar(); }
902 class foo {
903 };
904 if (foo()) {
905 }
906 else {
907 }
908 enum X : int { A, B };
909
Daniel Jasperee107ad2014-02-13 12:51:50 +0000910 * ``BS_GNU`` (in configuration: ``GNU``)
911 Always break before braces and add an extra level of indentation to
912 braces of control statements, not to those of class, function
913 or other definitions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000914
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000915 .. code-block:: c++
916
917 try
918 {
919 foo();
920 }
921 catch ()
922 {
923 }
924 void foo() { bar(); }
925 class foo
926 {
927 };
928 if (foo())
929 {
930 }
931 else
932 {
933 }
934 enum X : int
935 {
936 A,
937 B
938 };
939
Roman Kashitsyn291f64f2015-08-10 13:43:19 +0000940 * ``BS_WebKit`` (in configuration: ``WebKit``)
941 Like ``Attach``, but break before functions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000942
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000943 .. code-block:: c++
944
945 try {
946 foo();
947 } catch () {
948 }
949 void foo() { bar(); }
950 class foo {
951 };
952 if (foo()) {
953 } else {
954 }
955 enum X : int { A, B };
956
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000957 * ``BS_Custom`` (in configuration: ``Custom``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000958 Configure each individual brace in `BraceWrapping`.
959
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000960
961
Andi-Bogdan Postelnicu0ef8ee12017-03-10 15:10:37 +0000962**BreakBeforeInheritanceComma** (``bool``)
963 If ``true``, in the class inheritance expression clang-format will
964 break before ``:`` and ``,`` if there is multiple inheritance.
965
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000966 .. code-block:: c++
967
968 true: false:
969 class MyClass vs. class MyClass : public X, public Y {
970 : public X };
971 , public Y {
972 };
973
Alexander Kornienkofdca83d2013-12-10 10:18:34 +0000974**BreakBeforeTernaryOperators** (``bool``)
975 If ``true``, ternary operators will be placed after line breaks.
976
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000977 .. code-block:: c++
978
979 true:
980 veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription
981 ? firstValue
982 : SecondValueVeryVeryVeryVeryLong;
983
Sylvestre Ledru121224d2017-06-06 07:26:19 +0000984 false:
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000985 veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ?
986 firstValue :
987 SecondValueVeryVeryVeryVeryLong;
988
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000989**BreakConstructorInitializers** (``BreakConstructorInitializersStyle``)
990 The constructor initializers style to use.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000991
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000992 Possible values:
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000993
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000994 * ``BCIS_BeforeColon`` (in configuration: ``BeforeColon``)
995 Break constructor initializers before the colon and after the commas.
996
997 .. code-block:: c++
998
Krasimir Georgiev2537e222018-01-17 16:17:26 +0000999 Constructor()
1000 : initializer1(),
1001 initializer2()
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001002
1003 * ``BCIS_BeforeComma`` (in configuration: ``BeforeComma``)
1004 Break constructor initializers before the colon and commas, and align
1005 the commas with the colon.
1006
1007 .. code-block:: c++
1008
Krasimir Georgiev2537e222018-01-17 16:17:26 +00001009 Constructor()
1010 : initializer1()
1011 , initializer2()
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001012
1013 * ``BCIS_AfterColon`` (in configuration: ``AfterColon``)
1014 Break constructor initializers after the colon and commas.
1015
1016 .. code-block:: c++
1017
Krasimir Georgiev2537e222018-01-17 16:17:26 +00001018 Constructor() :
1019 initializer1(),
1020 initializer2()
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001021
1022
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001023
Alexander Kornienko1e048232016-02-23 16:11:51 +00001024**BreakStringLiterals** (``bool``)
1025 Allow breaking string literals when formatting.
1026
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001027**ColumnLimit** (``unsigned``)
1028 The column limit.
1029
1030 A column limit of ``0`` means that there is no column limit. In this case,
1031 clang-format will respect the input's line breaking decisions within
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001032 statements unless they contradict other rules.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001033
Daniel Jasperee107ad2014-02-13 12:51:50 +00001034**CommentPragmas** (``std::string``)
1035 A regular expression that describes comments with special meaning,
1036 which should not be split into lines or otherwise changed.
1037
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001038 .. code-block:: c++
1039
Jonathan Roelofs335777b2017-03-20 17:07:49 +00001040 // CommentPragmas: '^ FOOBAR pragma:'
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001041 // Will leave the following line unaffected
1042 #include <vector> // FOOBAR pragma: keep
1043
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001044**CompactNamespaces** (``bool``)
1045 If ``true``, consecutive namespace declarations will be on the same
1046 line. If ``false``, each namespace is declared on a new line.
1047
1048 .. code-block:: c++
1049
1050 true:
1051 namespace Foo { namespace Bar {
1052 }}
1053
1054 false:
1055 namespace Foo {
1056 namespace Bar {
1057 }
1058 }
1059
1060 If it does not fit on a single line, the overflowing namespaces get
1061 wrapped:
1062
1063 .. code-block:: c++
1064
1065 namespace Foo { namespace Bar {
1066 namespace Extra {
1067 }}}
1068
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001069**ConstructorInitializerAllOnOneLineOrOnePerLine** (``bool``)
1070 If the constructor initializers don't fit on a line, put each
1071 initializer on its own line.
1072
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001073 .. code-block:: c++
1074
1075 true:
1076 SomeClass::Constructor()
1077 : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) {
1078 return 0;
1079 }
1080
1081 false:
1082 SomeClass::Constructor()
1083 : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa),
1084 aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) {
1085 return 0;
1086 }
1087
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001088**ConstructorInitializerIndentWidth** (``unsigned``)
1089 The number of characters to use for indentation of constructor
1090 initializer lists.
1091
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001092**ContinuationIndentWidth** (``unsigned``)
1093 Indent width for line continuations.
1094
Sylvestre Ledrude098242017-04-11 07:07:05 +00001095 .. code-block:: c++
1096
1097 ContinuationIndentWidth: 2
1098
1099 int i = // VeryVeryVeryVeryVeryLongComment
1100 longFunction( // Again a long comment
1101 arg);
1102
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001103**Cpp11BracedListStyle** (``bool``)
1104 If ``true``, format braced lists as best suited for C++11 braced
1105 lists.
1106
1107 Important differences:
1108 - No spaces inside the braced list.
1109 - No line break before the closing brace.
1110 - Indentation with the continuation indent, not with the block indent.
1111
1112 Fundamentally, C++11 braced lists are formatted exactly like function
1113 calls would be formatted in their place. If the braced list follows a name
1114 (e.g. a type or variable name), clang-format formats as if the ``{}`` were
1115 the parentheses of a function call with that name. If there is no name,
1116 a zero-length name is assumed.
1117
Sylvestre Ledrude098242017-04-11 07:07:05 +00001118 .. code-block:: c++
1119
1120 true: false:
1121 vector<int> x{1, 2, 3, 4}; vs. vector<int> x{ 1, 2, 3, 4 };
1122 vector<T> x{{}, {}, {}, {}}; vector<T> x{ {}, {}, {}, {} };
1123 f(MyMap[{composite, key}]); f(MyMap[{ composite, key }]);
1124 new int[3]{1, 2, 3}; new int[3]{ 1, 2, 3 };
1125
Daniel Jasper553d4872014-06-17 12:40:34 +00001126**DerivePointerAlignment** (``bool``)
1127 If ``true``, analyze the formatted file for the most common
Sylvestre Ledrude098242017-04-11 07:07:05 +00001128 alignment of ``&`` and ``*``.
1129 Pointer and reference alignment styles are going to be updated according
1130 to the preferences found in the file.
1131 ``PointerAlignment`` is then used only as fallback.
Daniel Jasper553d4872014-06-17 12:40:34 +00001132
1133**DisableFormat** (``bool``)
Birunthan Mohanathasb744e722015-06-27 09:25:28 +00001134 Disables formatting completely.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001135
1136**ExperimentalAutoDetectBinPacking** (``bool``)
1137 If ``true``, clang-format detects whether function calls and
1138 definitions are formatted with one parameter per line.
1139
1140 Each call can be bin-packed, one-per-line or inconclusive. If it is
1141 inconclusive, e.g. completely on one line, but a decision needs to be
1142 made, clang-format analyzes whether there are other bin-packed cases in
1143 the input file and act accordingly.
1144
1145 NOTE: This is an experimental flag, that might go away or be renamed. Do
1146 not use this in config files, etc. Use at your own risk.
1147
Krasimir Georgiev32eaa862017-03-01 15:35:39 +00001148**FixNamespaceComments** (``bool``)
1149 If ``true``, clang-format adds missing namespace end comments and
1150 fixes invalid existing ones.
1151
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001152 .. code-block:: c++
1153
1154 true: false:
1155 namespace a { vs. namespace a {
1156 foo(); foo();
1157 } // namespace a; }
1158
Daniel Jaspere1e43192014-04-01 12:55:11 +00001159**ForEachMacros** (``std::vector<std::string>``)
Daniel Jasperb5524822014-04-09 14:05:49 +00001160 A vector of macros that should be interpreted as foreach loops
1161 instead of as function calls.
Daniel Jaspere1e43192014-04-01 12:55:11 +00001162
Daniel Jasperb5524822014-04-09 14:05:49 +00001163 These are expected to be macros of the form:
Daniel Jasperb5bda7c2015-10-06 12:11:51 +00001164
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001165 .. code-block:: c++
Daniel Jasper8e1ecca2015-10-07 13:02:45 +00001166
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001167 FOREACH(<variable-declaration>, ...)
1168 <loop-body>
1169
1170 In the .clang-format configuration file, this can be configured like:
Daniel Jasperb5bda7c2015-10-06 12:11:51 +00001171
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001172 .. code-block:: yaml
Daniel Jasper8e1ecca2015-10-07 13:02:45 +00001173
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001174 ForEachMacros: ['RANGES_FOR', 'FOREACH']
Daniel Jasperb5524822014-04-09 14:05:49 +00001175
1176 For example: BOOST_FOREACH.
Daniel Jaspere1e43192014-04-01 12:55:11 +00001177
Krasimir Georgiev4c2c9c32017-11-27 13:23:45 +00001178**IncludeBlocks** (``IncludeBlocksStyle``)
1179 Dependent on the value, multiple ``#include`` blocks can be sorted
1180 as one and divided based on category.
1181
1182 Possible values:
1183
1184 * ``IBS_Preserve`` (in configuration: ``Preserve``)
1185 Sort each ``#include`` block separately.
1186
1187 .. code-block:: c++
1188
1189 #include "b.h" into #include "b.h"
1190
1191 #include <lib/main.h> #include "a.h"
1192 #include "a.h" #include <lib/main.h>
1193
1194 * ``IBS_Merge`` (in configuration: ``Merge``)
1195 Merge multiple ``#include`` blocks together and sort as one.
1196
1197 .. code-block:: c++
1198
1199 #include "b.h" into #include "a.h"
1200 #include "b.h"
1201 #include <lib/main.h> #include <lib/main.h>
1202 #include "a.h"
1203
1204 * ``IBS_Regroup`` (in configuration: ``Regroup``)
1205 Merge multiple ``#include`` blocks together and sort as one.
Krasimir Georgiev2537e222018-01-17 16:17:26 +00001206 Then split into groups based on category priority. See
1207 ``IncludeCategories``.
Krasimir Georgiev4c2c9c32017-11-27 13:23:45 +00001208
1209 .. code-block:: c++
1210
1211 #include "b.h" into #include "a.h"
1212 #include "b.h"
1213 #include <lib/main.h>
1214 #include "a.h" #include <lib/main.h>
1215
1216
1217
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001218**IncludeCategories** (``std::vector<IncludeCategory>``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001219 Regular expressions denoting the different ``#include`` categories
1220 used for ordering ``#includes``.
Daniel Jasperc1bc38e2015-09-29 14:57:55 +00001221
1222 These regular expressions are matched against the filename of an include
1223 (including the <> or "") in order. The value belonging to the first
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001224 matching regular expression is assigned and ``#includes`` are sorted first
Daniel Jasperc1bc38e2015-09-29 14:57:55 +00001225 according to increasing category number and then alphabetically within
1226 each category.
1227
Alexander Kornienko1e048232016-02-23 16:11:51 +00001228 If none of the regular expressions match, INT_MAX is assigned as
1229 category. The main header for a source file automatically gets category 0.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001230 so that it is generally kept at the beginning of the ``#includes``
Alexander Kornienko1e048232016-02-23 16:11:51 +00001231 (http://llvm.org/docs/CodingStandards.html#include-style). However, you
1232 can also assign negative priorities if you have certain headers that
1233 always need to be first.
Daniel Jasperc1bc38e2015-09-29 14:57:55 +00001234
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001235 To configure this in the .clang-format file, use:
Daniel Jasperb5bda7c2015-10-06 12:11:51 +00001236
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001237 .. code-block:: yaml
Daniel Jasper8e1ecca2015-10-07 13:02:45 +00001238
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001239 IncludeCategories:
1240 - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
1241 Priority: 2
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +00001242 - Regex: '^(<|"(gtest|gmock|isl|json)/)'
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001243 Priority: 3
Sylvestre Ledruf3e295a2017-03-09 06:41:08 +00001244 - Regex: '.*'
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001245 Priority: 1
1246
Daniel Jasper9c8ff352016-03-21 14:11:27 +00001247**IncludeIsMainRegex** (``std::string``)
1248 Specify a regular expression of suffixes that are allowed in the
1249 file-to-main-include mapping.
1250
1251 When guessing whether a #include is the "main" include (to assign
1252 category 0, see above), use this regex of allowed suffixes to the header
1253 stem. A partial match is done, so that:
1254 - "" means "arbitrary suffix"
1255 - "$" means "no suffix"
1256
1257 For example, if configured to "(_test)?$", then a header a.h would be seen
1258 as the "main" include in both a.cc and a_test.cc.
1259
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001260**IndentCaseLabels** (``bool``)
1261 Indent case labels one level from the switch statement.
1262
1263 When ``false``, use the same indentation level as for the switch statement.
1264 Switch statement body is always indented one level more than case labels.
1265
Sylvestre Ledrude098242017-04-11 07:07:05 +00001266 .. code-block:: c++
1267
1268 false: true:
1269 switch (fool) { vs. switch (fool) {
1270 case 1: case 1:
1271 bar(); bar();
1272 break; break;
1273 default: default:
1274 plop(); plop();
1275 } }
1276
Krasimir Georgievad47c902017-08-30 14:34:57 +00001277**IndentPPDirectives** (``PPDirectiveIndentStyle``)
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +00001278 The preprocessor directive indenting style to use.
Krasimir Georgievad47c902017-08-30 14:34:57 +00001279
1280 Possible values:
1281
1282 * ``PPDIS_None`` (in configuration: ``None``)
1283 Does not indent any directives.
1284
1285 .. code-block:: c++
1286
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +00001287 #if FOO
1288 #if BAR
1289 #include <foo>
1290 #endif
1291 #endif
Krasimir Georgievad47c902017-08-30 14:34:57 +00001292
1293 * ``PPDIS_AfterHash`` (in configuration: ``AfterHash``)
1294 Indents directives after the hash.
1295
1296 .. code-block:: c++
1297
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +00001298 #if FOO
1299 # if BAR
1300 # include <foo>
1301 # endif
1302 #endif
1303
1304
Krasimir Georgievad47c902017-08-30 14:34:57 +00001305
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001306**IndentWidth** (``unsigned``)
Alexander Kornienko45ca09b2013-09-27 16:16:55 +00001307 The number of columns to use for indentation.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001308
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001309 .. code-block:: c++
1310
1311 IndentWidth: 3
Sylvestre Ledrude098242017-04-11 07:07:05 +00001312
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001313 void f() {
1314 someFunction();
1315 if (true, false) {
1316 f();
1317 }
1318 }
1319
Daniel Jasperc75e1ef2014-07-09 08:42:42 +00001320**IndentWrappedFunctionNames** (``bool``)
1321 Indent if a function definition or declaration is wrapped after the
1322 type.
1323
Sylvestre Ledrude098242017-04-11 07:07:05 +00001324 .. code-block:: c++
1325
1326 true:
1327 LoooooooooooooooooooooooooooooooooooooooongReturnType
1328 LoooooooooooooooooooooooooooooooongFunctionDeclaration();
1329
1330 false:
1331 LoooooooooooooooooooooooooooooooooooooooongReturnType
1332 LoooooooooooooooooooooooooooooooongFunctionDeclaration();
1333
Daniel Jasper9c8ff352016-03-21 14:11:27 +00001334**JavaScriptQuotes** (``JavaScriptQuoteStyle``)
1335 The JavaScriptQuoteStyle to use for JavaScript strings.
1336
1337 Possible values:
1338
1339 * ``JSQS_Leave`` (in configuration: ``Leave``)
1340 Leave string quotes as they are.
1341
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001342 .. code-block:: js
1343
1344 string1 = "foo";
1345 string2 = 'bar';
1346
Daniel Jasper9c8ff352016-03-21 14:11:27 +00001347 * ``JSQS_Single`` (in configuration: ``Single``)
1348 Always use single quotes.
1349
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001350 .. code-block:: js
1351
1352 string1 = 'foo';
1353 string2 = 'bar';
1354
Daniel Jasper9c8ff352016-03-21 14:11:27 +00001355 * ``JSQS_Double`` (in configuration: ``Double``)
1356 Always use double quotes.
1357
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001358 .. code-block:: js
1359
1360 string1 = "foo";
1361 string2 = "bar";
1362
Daniel Jasper9c8ff352016-03-21 14:11:27 +00001363
1364
Krasimir Georgiev32eaa862017-03-01 15:35:39 +00001365**JavaScriptWrapImports** (``bool``)
1366 Whether to wrap JavaScript import/export statements.
1367
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001368 .. code-block:: js
1369
1370 true:
1371 import {
1372 VeryLongImportsAreAnnoying,
1373 VeryLongImportsAreAnnoying,
1374 VeryLongImportsAreAnnoying,
1375 } from 'some/module.js'
1376
1377 false:
1378 import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js"
1379
Daniel Jasperb5524822014-04-09 14:05:49 +00001380**KeepEmptyLinesAtTheStartOfBlocks** (``bool``)
Sylvestre Ledrude098242017-04-11 07:07:05 +00001381 If true, the empty line at the start of blocks is kept.
1382
1383 .. code-block:: c++
1384
1385 true: false:
1386 if (foo) { vs. if (foo) {
1387 bar();
1388 bar(); }
1389 }
Daniel Jasperb5524822014-04-09 14:05:49 +00001390
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001391**Language** (``LanguageKind``)
1392 Language, this format style is targeted at.
1393
1394 Possible values:
1395
1396 * ``LK_None`` (in configuration: ``None``)
1397 Do not use.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001398
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001399 * ``LK_Cpp`` (in configuration: ``Cpp``)
Krasimir Georgiev32eaa862017-03-01 15:35:39 +00001400 Should be used for C, C++.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001401
Daniel Jasper18210d72014-10-09 09:52:05 +00001402 * ``LK_Java`` (in configuration: ``Java``)
1403 Should be used for Java.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001404
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001405 * ``LK_JavaScript`` (in configuration: ``JavaScript``)
1406 Should be used for JavaScript.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001407
Krasimir Georgiev32eaa862017-03-01 15:35:39 +00001408 * ``LK_ObjC`` (in configuration: ``ObjC``)
1409 Should be used for Objective-C, Objective-C++.
1410
Daniel Jasperee107ad2014-02-13 12:51:50 +00001411 * ``LK_Proto`` (in configuration: ``Proto``)
1412 Should be used for Protocol Buffers
1413 (https://developers.google.com/protocol-buffers/).
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001414
Alexander Kornienko1e048232016-02-23 16:11:51 +00001415 * ``LK_TableGen`` (in configuration: ``TableGen``)
1416 Should be used for TableGen code.
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001417
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +00001418 * ``LK_TextProto`` (in configuration: ``TextProto``)
1419 Should be used for Protocol Buffer messages in text format
1420 (https://developers.google.com/protocol-buffers/).
1421
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001422
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001423
Birunthan Mohanathasb001a0b2015-07-03 17:25:16 +00001424**MacroBlockBegin** (``std::string``)
1425 A regular expression matching macros that start a block.
1426
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001427 .. code-block:: c++
1428
1429 # With:
1430 MacroBlockBegin: "^NS_MAP_BEGIN|\
1431 NS_TABLE_HEAD$"
1432 MacroBlockEnd: "^\
1433 NS_MAP_END|\
1434 NS_TABLE_.*_END$"
1435
1436 NS_MAP_BEGIN
1437 foo();
1438 NS_MAP_END
1439
1440 NS_TABLE_HEAD
1441 bar();
1442 NS_TABLE_FOO_END
1443
1444 # Without:
1445 NS_MAP_BEGIN
1446 foo();
1447 NS_MAP_END
1448
1449 NS_TABLE_HEAD
1450 bar();
1451 NS_TABLE_FOO_END
1452
Birunthan Mohanathasb001a0b2015-07-03 17:25:16 +00001453**MacroBlockEnd** (``std::string``)
1454 A regular expression matching macros that end a block.
1455
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001456**MaxEmptyLinesToKeep** (``unsigned``)
1457 The maximum number of consecutive empty lines to keep.
1458
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001459 .. code-block:: c++
1460
1461 MaxEmptyLinesToKeep: 1 vs. MaxEmptyLinesToKeep: 0
1462 int f() { int f() {
1463 int = 1; int i = 1;
1464 i = foo();
1465 i = foo(); return i;
1466 }
1467 return i;
1468 }
1469
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001470**NamespaceIndentation** (``NamespaceIndentationKind``)
1471 The indentation used for namespaces.
1472
1473 Possible values:
1474
1475 * ``NI_None`` (in configuration: ``None``)
1476 Don't indent in namespaces.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001477
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001478 .. code-block:: c++
1479
1480 namespace out {
1481 int i;
1482 namespace in {
1483 int i;
1484 }
1485 }
1486
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001487 * ``NI_Inner`` (in configuration: ``Inner``)
1488 Indent only in inner namespaces (nested in other namespaces).
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001489
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001490 .. code-block:: c++
1491
1492 namespace out {
1493 int i;
1494 namespace in {
1495 int i;
1496 }
1497 }
1498
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001499 * ``NI_All`` (in configuration: ``All``)
1500 Indent in all namespaces.
1501
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001502 .. code-block:: c++
1503
1504 namespace out {
1505 int i;
1506 namespace in {
1507 int i;
1508 }
1509 }
1510
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001511
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001512
Krasimir Georgievc5be6af2018-03-06 13:24:01 +00001513**ObjCBinPackProtocolList** (``BinPackStyle``)
1514 Controls bin-packing Objective-C protocol conformance list
1515 items into as few lines as possible when they go over ``ColumnLimit``.
1516
1517 If ``Auto`` (the default), delegates to the value in
1518 ``BinPackParameters``. If that is ``true``, bin-packs Objective-C
1519 protocol conformance list items into as few lines as possible
1520 whenever they go over ``ColumnLimit``.
1521
1522 If ``Always``, always bin-packs Objective-C protocol conformance
1523 list items into as few lines as possible whenever they go over
1524 ``ColumnLimit``.
1525
1526 If ``Never``, lays out Objective-C protocol conformance list items
1527 onto individual lines whenever they go over ``ColumnLimit``.
1528
1529
1530 .. code-block:: c++
1531
1532 Always (or Auto, if BinPackParameters=true):
1533 @interface ccccccccccccc () <
1534 ccccccccccccc, ccccccccccccc,
1535 ccccccccccccc, ccccccccccccc> {
1536 }
1537
1538 Never (or Auto, if BinPackParameters=false):
1539 @interface ddddddddddddd () <
1540 ddddddddddddd,
1541 ddddddddddddd,
1542 ddddddddddddd,
1543 ddddddddddddd> {
1544 }
1545
1546 Possible values:
1547
1548 * ``BPS_Auto`` (in configuration: ``Auto``)
1549 Automatically determine parameter bin-packing behavior.
1550
1551 * ``BPS_Always`` (in configuration: ``Always``)
1552 Always bin-pack parameters.
1553
1554 * ``BPS_Never`` (in configuration: ``Never``)
1555 Never bin-pack parameters.
1556
1557
1558
Daniel Jaspereb2226e2014-10-28 16:56:37 +00001559**ObjCBlockIndentWidth** (``unsigned``)
1560 The number of characters to use for indentation of ObjC blocks.
1561
Sylvestre Ledrude098242017-04-11 07:07:05 +00001562 .. code-block:: objc
1563
1564 ObjCBlockIndentWidth: 4
1565
1566 [operation setCompletionBlock:^{
1567 [self onOperationDone];
1568 }];
1569
Daniel Jasperee107ad2014-02-13 12:51:50 +00001570**ObjCSpaceAfterProperty** (``bool``)
1571 Add a space after ``@property`` in Objective-C, i.e. use
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001572 ``@property (readonly)`` instead of ``@property(readonly)``.
Daniel Jasperee107ad2014-02-13 12:51:50 +00001573
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001574**ObjCSpaceBeforeProtocolList** (``bool``)
1575 Add a space in front of an Objective-C protocol list, i.e. use
1576 ``Foo <Protocol>`` instead of ``Foo<Protocol>``.
1577
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001578**PenaltyBreakAssignment** (``unsigned``)
1579 The penalty for breaking around an assignment operator.
1580
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001581**PenaltyBreakBeforeFirstCallParameter** (``unsigned``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001582 The penalty for breaking a function call after ``call(``.
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001583
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001584**PenaltyBreakComment** (``unsigned``)
1585 The penalty for each line break introduced inside a comment.
1586
1587**PenaltyBreakFirstLessLess** (``unsigned``)
1588 The penalty for breaking before the first ``<<``.
1589
1590**PenaltyBreakString** (``unsigned``)
1591 The penalty for each line break introduced inside a string literal.
1592
1593**PenaltyExcessCharacter** (``unsigned``)
1594 The penalty for each character outside of the column limit.
1595
1596**PenaltyReturnTypeOnItsOwnLine** (``unsigned``)
1597 Penalty for putting the return type of a function onto its own
1598 line.
1599
Daniel Jasper553d4872014-06-17 12:40:34 +00001600**PointerAlignment** (``PointerAlignmentStyle``)
1601 Pointer and reference alignment style.
1602
1603 Possible values:
1604
1605 * ``PAS_Left`` (in configuration: ``Left``)
1606 Align pointer to the left.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001607
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001608 .. code-block:: c++
1609
Sylvestre Ledruf3e295a2017-03-09 06:41:08 +00001610 int* a;
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001611
Daniel Jasper553d4872014-06-17 12:40:34 +00001612 * ``PAS_Right`` (in configuration: ``Right``)
1613 Align pointer to the right.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001614
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001615 .. code-block:: c++
1616
Sylvestre Ledruf3e295a2017-03-09 06:41:08 +00001617 int *a;
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001618
Daniel Jasper553d4872014-06-17 12:40:34 +00001619 * ``PAS_Middle`` (in configuration: ``Middle``)
1620 Align pointer in the middle.
1621
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001622 .. code-block:: c++
1623
Sylvestre Ledruf3e295a2017-03-09 06:41:08 +00001624 int * a;
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001625
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001626
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001627
Krasimir Georgiev818da9b2017-11-09 15:41:23 +00001628**RawStringFormats** (``std::vector<RawStringFormat>``)
Krasimir Georgiev2537e222018-01-17 16:17:26 +00001629 Defines hints for detecting supported languages code blocks in raw
1630 strings.
Krasimir Georgiev818da9b2017-11-09 15:41:23 +00001631
Krasimir Georgiev2537e222018-01-17 16:17:26 +00001632 A raw string with a matching delimiter or a matching enclosing function
1633 name will be reformatted assuming the specified language based on the
1634 style for that language defined in the .clang-format file. If no style has
1635 been defined in the .clang-format file for the specific language, a
1636 predefined style given by 'BasedOnStyle' is used. If 'BasedOnStyle' is not
1637 found, the formatting is based on llvm style. A matching delimiter takes
1638 precedence over a matching enclosing function name for determining the
1639 language of the raw string contents.
1640
Malcolm Parsons51d3fb02018-01-24 10:26:09 +00001641 If a canonical delimiter is specified, occurrences of other delimiters for
Krasimir Georgiev412ed092018-01-19 16:18:47 +00001642 the same language will be updated to the canonical if possible.
1643
Krasimir Georgiev2537e222018-01-17 16:17:26 +00001644 There should be at most one specification per language and each delimiter
1645 and enclosing function should not occur in multiple specifications.
Krasimir Georgiev818da9b2017-11-09 15:41:23 +00001646
1647 To configure this in the .clang-format file, use:
1648
1649 .. code-block:: yaml
1650
1651 RawStringFormats:
Krasimir Georgiev2537e222018-01-17 16:17:26 +00001652 - Language: TextProto
1653 Delimiters:
1654 - 'pb'
1655 - 'proto'
1656 EnclosingFunctions:
1657 - 'PARSE_TEXT_PROTO'
1658 BasedOnStyle: google
1659 - Language: Cpp
1660 Delimiters:
1661 - 'cc'
1662 - 'cpp'
1663 BasedOnStyle: llvm
Krasimir Georgiev412ed092018-01-19 16:18:47 +00001664 CanonicalDelimiter: 'cc'
Krasimir Georgiev818da9b2017-11-09 15:41:23 +00001665
Alexander Kornienko1e048232016-02-23 16:11:51 +00001666**ReflowComments** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001667 If ``true``, clang-format will attempt to re-flow comments.
Alexander Kornienko1e048232016-02-23 16:11:51 +00001668
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001669 .. code-block:: c++
1670
1671 false:
1672 // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
1673 /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */
1674
1675 true:
1676 // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
1677 // information
1678 /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
1679 * information */
1680
Alexander Kornienko1e048232016-02-23 16:11:51 +00001681**SortIncludes** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001682 If ``true``, clang-format will sort ``#includes``.
Alexander Kornienko1e048232016-02-23 16:11:51 +00001683
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001684 .. code-block:: c++
1685
1686 false: true:
1687 #include "b.h" vs. #include "a.h"
1688 #include "a.h" #include "b.h"
1689
Krasimir Georgievac16a202017-06-23 11:46:03 +00001690**SortUsingDeclarations** (``bool``)
1691 If ``true``, clang-format will sort using declarations.
1692
Krasimir Georgiev818da9b2017-11-09 15:41:23 +00001693 The order of using declarations is defined as follows:
1694 Split the strings by "::" and discard any initial empty strings. The last
1695 element of each list is a non-namespace name; all others are namespace
1696 names. Sort the lists of names lexicographically, where the sort order of
1697 individual names is that all non-namespace names come before all namespace
1698 names, and within those groups, names are in case-insensitive
1699 lexicographic order.
Krasimir Georgievac16a202017-06-23 11:46:03 +00001700
Krasimir Georgievd4102df2017-11-09 15:54:59 +00001701 .. code-block:: c++
1702
1703 false: true:
1704 using std::cout; vs. using std::cin;
1705 using std::cin; using std::cout;
1706
Daniel Jasperb87899b2014-09-10 13:11:45 +00001707**SpaceAfterCStyleCast** (``bool``)
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001708 If ``true``, a space is inserted after C style casts.
1709
1710 .. code-block:: c++
1711
1712 true: false:
Krasimir Georgievc5be6af2018-03-06 13:24:01 +00001713 (int) i; vs. (int)i;
Daniel Jasperb87899b2014-09-10 13:11:45 +00001714
Sylvestre Ledru83bbd572016-08-09 14:24:40 +00001715**SpaceAfterTemplateKeyword** (``bool``)
1716 If ``true``, a space will be inserted after the 'template' keyword.
1717
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001718 .. code-block:: c++
1719
1720 true: false:
1721 template <int> void foo(); vs. template<int> void foo();
1722
Daniel Jasperd94bff32013-09-25 15:15:02 +00001723**SpaceBeforeAssignmentOperators** (``bool``)
Alexander Kornienko45ca09b2013-09-27 16:16:55 +00001724 If ``false``, spaces will be removed before assignment operators.
Daniel Jasperd94bff32013-09-25 15:15:02 +00001725
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001726 .. code-block:: c++
1727
1728 true: false:
1729 int a = 5; vs. int a=5;
1730 a += 42 a+=42;
1731
Francois Ferrand2a9ea782018-03-01 10:09:13 +00001732**SpaceBeforeCtorInitializerColon** (``bool``)
1733 If ``false``, spaces will be removed before constructor initializer
1734 colon.
1735
1736 .. code-block:: c++
1737
1738 true: false:
1739 Foo::Foo() : a(a) {} Foo::Foo(): a(a) {}
1740
1741**SpaceBeforeInheritanceColon** (``bool``)
1742 If ``false``, spaces will be removed before inheritance colon.
1743
1744 .. code-block:: c++
1745
1746 true: false:
1747 class Foo : Bar {} vs. class Foo: Bar {}
1748
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001749**SpaceBeforeParens** (``SpaceBeforeParensOptions``)
1750 Defines in which cases to put a space before opening parentheses.
1751
1752 Possible values:
1753
1754 * ``SBPO_Never`` (in configuration: ``Never``)
1755 Never put a space before opening parentheses.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001756
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001757 .. code-block:: c++
1758
1759 void f() {
1760 if(true) {
1761 f();
1762 }
1763 }
1764
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001765 * ``SBPO_ControlStatements`` (in configuration: ``ControlStatements``)
1766 Put a space before opening parentheses only after control statement
1767 keywords (``for/if/while...``).
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001768
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001769 .. code-block:: c++
1770
1771 void f() {
1772 if (true) {
1773 f();
1774 }
1775 }
1776
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001777 * ``SBPO_Always`` (in configuration: ``Always``)
1778 Always put a space before opening parentheses, except when it's
1779 prohibited by the syntax rules (in function-like macro definitions) or
1780 when determined by other style rules (after unary operators, opening
1781 parentheses, etc.)
1782
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001783 .. code-block:: c++
1784
1785 void f () {
1786 if (true) {
1787 f ();
1788 }
1789 }
1790
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001791
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001792
Francois Ferrand2a9ea782018-03-01 10:09:13 +00001793**SpaceBeforeRangeBasedForLoopColon** (``bool``)
1794 If ``false``, spaces will be removed before range-based for loop
1795 colon.
1796
1797 .. code-block:: c++
1798
1799 true: false:
1800 for (auto v : values) {} vs. for(auto v: values) {}
1801
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001802**SpaceInEmptyParentheses** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001803 If ``true``, spaces may be inserted into ``()``.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001804
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001805 .. code-block:: c++
1806
1807 true: false:
1808 void f( ) { vs. void f() {
1809 int x[] = {foo( ), bar( )}; int x[] = {foo(), bar()};
1810 if (true) { if (true) {
1811 f( ); f();
1812 } }
1813 } }
1814
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001815**SpacesBeforeTrailingComments** (``unsigned``)
Daniel Jasperc0be7602014-05-15 13:55:19 +00001816 The number of spaces before trailing line comments
1817 (``//`` - comments).
Daniel Jasperb5524822014-04-09 14:05:49 +00001818
Alexander Kornienko70f97c92016-02-27 14:02:08 +00001819 This does not affect trailing block comments (``/*`` - comments) as
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001820 those commonly have different usage patterns and a number of special
1821 cases.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001822
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001823 .. code-block:: c++
1824
1825 SpacesBeforeTrailingComments: 3
1826 void f() {
1827 if (true) { // foo1
1828 f(); // bar
1829 } // foo
1830 }
1831
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001832**SpacesInAngles** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001833 If ``true``, spaces will be inserted after ``<`` and before ``>``
1834 in template argument lists.
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001835
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001836 .. code-block:: c++
1837
1838 true: false:
1839 static_cast< int >(arg); vs. static_cast<int>(arg);
1840 std::function< void(int) > fct; std::function<void(int)> fct;
1841
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001842**SpacesInCStyleCastParentheses** (``bool``)
Daniel Jasperee107ad2014-02-13 12:51:50 +00001843 If ``true``, spaces may be inserted into C style casts.
1844
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001845 .. code-block:: c++
1846
1847 true: false:
1848 x = ( int32 )y vs. x = (int32)y
1849
Daniel Jasperee107ad2014-02-13 12:51:50 +00001850**SpacesInContainerLiterals** (``bool``)
1851 If ``true``, spaces are inserted inside container literals (e.g.
1852 ObjC and Javascript array and dict literals).
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001853
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001854 .. code-block:: js
1855
1856 true: false:
1857 var arr = [ 1, 2, 3 ]; vs. var arr = [1, 2, 3];
1858 f({a : 1, b : 2, c : 3}); f({a: 1, b: 2, c: 3});
1859
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001860**SpacesInParentheses** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001861 If ``true``, spaces will be inserted after ``(`` and before ``)``.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001862
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001863 .. code-block:: c++
1864
1865 true: false:
1866 t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete;
1867
Daniel Jasperad981f82014-08-26 11:41:14 +00001868**SpacesInSquareBrackets** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001869 If ``true``, spaces will be inserted after ``[`` and before ``]``.
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001870 Lambdas or unspecified size array declarations will not be affected.
1871
1872 .. code-block:: c++
1873
1874 true: false:
1875 int a[ 5 ]; vs. int a[5];
1876 std::unique_ptr<int[]> foo() {} // Won't be affected
Daniel Jasperad981f82014-08-26 11:41:14 +00001877
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001878**Standard** (``LanguageStandard``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001879 Format compatible with this standard, e.g. use ``A<A<int> >``
1880 instead of ``A<A<int>>`` for ``LS_Cpp03``.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001881
1882 Possible values:
1883
1884 * ``LS_Cpp03`` (in configuration: ``Cpp03``)
1885 Use C++03-compatible syntax.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001886
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001887 * ``LS_Cpp11`` (in configuration: ``Cpp11``)
Daniel Jasper7fdbb3f2017-05-08 15:08:00 +00001888 Use features of C++11, C++14 and C++1z (e.g. ``A<A<int>>`` instead of
Nico Weberdc065182017-04-05 18:10:42 +00001889 ``A<A<int> >``).
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001890
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001891 * ``LS_Auto`` (in configuration: ``Auto``)
1892 Automatic detection based on the input.
1893
1894
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001895
Alexander Kornienko45ca09b2013-09-27 16:16:55 +00001896**TabWidth** (``unsigned``)
1897 The number of columns used for tab stops.
1898
1899**UseTab** (``UseTabStyle``)
1900 The way to use tab characters in the resulting file.
1901
1902 Possible values:
1903
1904 * ``UT_Never`` (in configuration: ``Never``)
1905 Never use tab.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001906
Alexander Kornienko45ca09b2013-09-27 16:16:55 +00001907 * ``UT_ForIndentation`` (in configuration: ``ForIndentation``)
1908 Use tabs only for indentation.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001909
Krasimir Georgiev32eaa862017-03-01 15:35:39 +00001910 * ``UT_ForContinuationAndIndentation`` (in configuration: ``ForContinuationAndIndentation``)
1911 Use tabs only for line continuation and indentation.
1912
Alexander Kornienko45ca09b2013-09-27 16:16:55 +00001913 * ``UT_Always`` (in configuration: ``Always``)
1914 Use tabs whenever we need to fill whitespace that spans at least from
1915 one tab stop to the next one.
1916
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001917
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001918
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001919.. END_FORMAT_STYLE_OPTIONS
1920
Daniel Jasper49d3d582015-10-05 07:24:55 +00001921Adding additional style options
1922===============================
1923
1924Each additional style option adds costs to the clang-format project. Some of
Sylvestre Ledrube8f3962016-02-14 20:20:58 +00001925these costs affect the clang-format development itself, as we need to make
Daniel Jasper49d3d582015-10-05 07:24:55 +00001926sure that any given combination of options work and that new features don't
1927break any of the existing options in any way. There are also costs for end users
1928as options become less discoverable and people have to think about and make a
1929decision on options they don't really care about.
1930
1931The goal of the clang-format project is more on the side of supporting a
1932limited set of styles really well as opposed to supporting every single style
1933used by a codebase somewhere in the wild. Of course, we do want to support all
1934major projects and thus have established the following bar for adding style
1935options. Each new style option must ..
1936
Daniel Jasperfcbea712015-10-05 13:30:42 +00001937 * be used in a project of significant size (have dozens of contributors)
1938 * have a publicly accessible style guide
1939 * have a person willing to contribute and maintain patches
Daniel Jasper49d3d582015-10-05 07:24:55 +00001940
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001941Examples
1942========
1943
1944A style similar to the `Linux Kernel style
1945<https://www.kernel.org/doc/Documentation/CodingStyle>`_:
1946
1947.. code-block:: yaml
1948
1949 BasedOnStyle: LLVM
1950 IndentWidth: 8
Alexander Kornienko8ba68f62013-09-27 16:19:25 +00001951 UseTab: Always
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001952 BreakBeforeBraces: Linux
1953 AllowShortIfStatementsOnASingleLine: false
1954 IndentCaseLabels: false
1955
1956The result is (imagine that tabs are used for indentation here):
1957
1958.. code-block:: c++
1959
1960 void test()
1961 {
1962 switch (x) {
1963 case 0:
1964 case 1:
1965 do_something();
1966 break;
1967 case 2:
1968 do_something_else();
1969 break;
1970 default:
1971 break;
1972 }
1973 if (condition)
1974 do_something_completely_different();
1975
1976 if (x == y) {
1977 q();
1978 } else if (x > y) {
1979 w();
1980 } else {
1981 r();
1982 }
1983 }
1984
1985A style similar to the default Visual Studio formatting style:
1986
1987.. code-block:: yaml
1988
Alexander Kornienko8ba68f62013-09-27 16:19:25 +00001989 UseTab: Never
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001990 IndentWidth: 4
1991 BreakBeforeBraces: Allman
1992 AllowShortIfStatementsOnASingleLine: false
1993 IndentCaseLabels: false
1994 ColumnLimit: 0
1995
1996The result is:
1997
1998.. code-block:: c++
1999
2000 void test()
2001 {
2002 switch (suffix)
2003 {
2004 case 0:
2005 case 1:
2006 do_something();
2007 break;
2008 case 2:
2009 do_something_else();
2010 break;
2011 default:
2012 break;
2013 }
2014 if (condition)
2015 do_somthing_completely_different();
2016
2017 if (x == y)
2018 {
2019 q();
2020 }
2021 else if (x > y)
2022 {
2023 w();
2024 }
2025 else
2026 {
2027 r();
2028 }
2029 }