blob: 3a99ac1cb244fa23eeb9b06cc00e7158d79f9833 [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
269 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
272
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000273**AllowAllParametersOfDeclarationOnNextLine** (``bool``)
274 Allow putting all parameters of a function declaration onto
275 the next line even if ``BinPackParameters`` is ``false``.
276
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000277 .. code-block:: c++
278
279 true: false:
280 myFunction(foo, vs. myFunction(foo, bar, plop);
281 bar,
282 plop);
283
Daniel Jasper17605d32014-05-14 09:33:35 +0000284**AllowShortBlocksOnASingleLine** (``bool``)
285 Allows contracting simple braced statements to a single line.
286
287 E.g., this allows ``if (a) { return; }`` to be put on a single line.
288
Daniel Jasperb87899b2014-09-10 13:11:45 +0000289**AllowShortCaseLabelsOnASingleLine** (``bool``)
290 If ``true``, short case labels will be contracted to a single line.
291
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000292 .. code-block:: c++
293
294 true: false:
295 switch (a) { vs. switch (a) {
296 case 1: x = 1; break; case 1:
297 case 2: return; x = 1;
298 } break;
299 case 2:
300 return;
301 }
302
Daniel Jasperb5524822014-04-09 14:05:49 +0000303**AllowShortFunctionsOnASingleLine** (``ShortFunctionStyle``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000304 Dependent on the value, ``int f() { return 0; }`` can be put on a
305 single line.
Daniel Jasperb5524822014-04-09 14:05:49 +0000306
307 Possible values:
308
309 * ``SFS_None`` (in configuration: ``None``)
310 Never merge functions into a single line.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000311
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000312 * ``SFS_InlineOnly`` (in configuration: ``InlineOnly``)
313 Only merge functions defined inside a class. Same as "inline",
314 except it does not implies "empty": i.e. top level empty functions
315 are not merged either.
316
317 .. code-block:: c++
318
319 class Foo {
320 void f() { foo(); }
321 };
322 void f() {
323 foo();
324 }
325 void f() {
326 }
327
Daniel Jasper3219e432014-12-02 13:24:51 +0000328 * ``SFS_Empty`` (in configuration: ``Empty``)
329 Only merge empty functions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000330
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000331 .. code-block:: c++
332
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000333 void f() {}
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000334 void f2() {
335 bar2();
336 }
337
Daniel Jasper20580fd2015-06-11 13:31:45 +0000338 * ``SFS_Inline`` (in configuration: ``Inline``)
339 Only merge functions defined inside a class. Implies "empty".
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000340
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000341 .. code-block:: c++
342
Jonathan Roelofs335777b2017-03-20 17:07:49 +0000343 class Foo {
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000344 void f() { foo(); }
345 };
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000346 void f() {
347 foo();
348 }
349 void f() {}
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000350
Daniel Jasperb5524822014-04-09 14:05:49 +0000351 * ``SFS_All`` (in configuration: ``All``)
352 Merge all functions fitting on a single line.
353
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000354 .. code-block:: c++
355
Jonathan Roelofs335777b2017-03-20 17:07:49 +0000356 class Foo {
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000357 void f() { foo(); }
358 };
359 void f() { bar(); }
360
Alexander Kornienkofdca83d2013-12-10 10:18:34 +0000361
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000362
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000363**AllowShortIfStatementsOnASingleLine** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000364 If ``true``, ``if (a) return;`` can be put on a single line.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000365
366**AllowShortLoopsOnASingleLine** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000367 If ``true``, ``while (true) continue;`` can be put on a single
368 line.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000369
Birunthan Mohanathasa0388a82015-06-29 15:30:42 +0000370**AlwaysBreakAfterDefinitionReturnType** (``DefinitionReturnTypeBreakingStyle``)
Zachary Turner448592e2015-12-18 22:20:15 +0000371 The function definition return type breaking style to use. This
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000372 option is **deprecated** and is retained for backwards compatibility.
Daniel Jasperca4ea1c2014-08-05 12:16:31 +0000373
Birunthan Mohanathasa0388a82015-06-29 15:30:42 +0000374 Possible values:
375
376 * ``DRTBS_None`` (in configuration: ``None``)
377 Break after return type automatically.
378 ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000379
Birunthan Mohanathasa0388a82015-06-29 15:30:42 +0000380 * ``DRTBS_All`` (in configuration: ``All``)
381 Always break after the return type.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000382
Birunthan Mohanathasa0388a82015-06-29 15:30:42 +0000383 * ``DRTBS_TopLevel`` (in configuration: ``TopLevel``)
Zachary Turner448592e2015-12-18 22:20:15 +0000384 Always break after the return types of top-level functions.
385
386
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000387
Zachary Turner448592e2015-12-18 22:20:15 +0000388**AlwaysBreakAfterReturnType** (``ReturnTypeBreakingStyle``)
389 The function declaration return type breaking style to use.
390
391 Possible values:
392
393 * ``RTBS_None`` (in configuration: ``None``)
394 Break after return type automatically.
395 ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000396
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000397 .. code-block:: c++
398
399 class A {
400 int f() { return 0; };
401 };
402 int f();
403 int f() { return 1; }
404
Zachary Turner448592e2015-12-18 22:20:15 +0000405 * ``RTBS_All`` (in configuration: ``All``)
406 Always break after the return type.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000407
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000408 .. code-block:: c++
409
410 class A {
411 int
412 f() {
413 return 0;
414 };
415 };
416 int
417 f();
418 int
419 f() {
420 return 1;
421 }
422
Zachary Turner448592e2015-12-18 22:20:15 +0000423 * ``RTBS_TopLevel`` (in configuration: ``TopLevel``)
424 Always break after the return types of top-level functions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000425
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000426 .. code-block:: c++
427
428 class A {
429 int f() { return 0; };
430 };
431 int
432 f();
433 int
434 f() {
435 return 1;
436 }
437
Zachary Turner448592e2015-12-18 22:20:15 +0000438 * ``RTBS_AllDefinitions`` (in configuration: ``AllDefinitions``)
439 Always break after the return type of function definitions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000440
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000441 .. code-block:: c++
442
443 class A {
444 int
445 f() {
446 return 0;
447 };
448 };
449 int f();
450 int
451 f() {
452 return 1;
453 }
454
Zachary Turner448592e2015-12-18 22:20:15 +0000455 * ``RTBS_TopLevelDefinitions`` (in configuration: ``TopLevelDefinitions``)
456 Always break after the return type of top-level definitions.
Birunthan Mohanathasa0388a82015-06-29 15:30:42 +0000457
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +0000458 .. code-block:: c++
459
460 class A {
461 int f() { return 0; };
462 };
463 int f();
464 int
465 f() {
466 return 1;
467 }
468
Daniel Jasperca4ea1c2014-08-05 12:16:31 +0000469
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000470
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000471**AlwaysBreakBeforeMultilineStrings** (``bool``)
472 If ``true``, always break before multiline string literals.
473
Daniel Jasper2aaedd32015-06-18 09:12:47 +0000474 This flag is mean to make cases where there are multiple multiline strings
475 in a file look more consistent. Thus, it will only take effect if wrapping
476 the string at that point leads to it being indented
477 ``ContinuationIndentWidth`` spaces from the start of the line.
478
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000479 .. code-block:: c++
480
481 true: false:
482 aaaa = vs. aaaa = "bbbb"
483 "bbbb" "cccc";
484 "cccc";
485
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000486**AlwaysBreakTemplateDeclarations** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000487 If ``true``, always break after the ``template<...>`` of a template
488 declaration.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000489
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000490 .. code-block:: c++
491
492 true: false:
493 template <typename T> vs. template <typename T> class C {};
494 class C {};
495
Daniel Jasper18210d72014-10-09 09:52:05 +0000496**BinPackArguments** (``bool``)
497 If ``false``, a function call's arguments will either be all on the
498 same line or will have one line each.
499
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000500 .. code-block:: c++
501
502 true:
503 void f() {
504 f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa,
505 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
506 }
507
508 false:
509 void f() {
510 f(aaaaaaaaaaaaaaaaaaaa,
511 aaaaaaaaaaaaaaaaaaaa,
512 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
513 }
514
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000515**BinPackParameters** (``bool``)
Daniel Jasper18210d72014-10-09 09:52:05 +0000516 If ``false``, a function declaration's or function definition's
517 parameters will either all be on the same line or will have one line each.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000518
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000519 .. code-block:: c++
520
521 true:
522 void f(int aaaaaaaaaaaaaaaaaaaa, int aaaaaaaaaaaaaaaaaaaa,
523 int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
524
525 false:
526 void f(int aaaaaaaaaaaaaaaaaaaa,
527 int aaaaaaaaaaaaaaaaaaaa,
528 int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
529
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000530**BraceWrapping** (``BraceWrappingFlags``)
531 Control of individual brace wrapping cases.
532
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000533 If ``BreakBeforeBraces`` is set to ``BS_Custom``, use this to specify how
534 each individual brace case should be handled. Otherwise, this is ignored.
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000535
536 Nested configuration flags:
537
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000538
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000539 * ``bool AfterClass`` Wrap class definitions.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000540
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000541 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000542
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000543 true:
544 class foo {};
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000545
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000546 false:
547 class foo
548 {};
Eric Fiselier1571fae2017-06-15 03:38:08 +0000549
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000550 * ``bool AfterControlStatement`` Wrap control statements (``if``/``for``/``while``/``switch``/..).
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000551
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000552 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000553
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000554 true:
555 if (foo())
556 {
557 } else
558 {}
559 for (int i = 0; i < 10; ++i)
560 {}
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000561
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000562 false:
563 if (foo()) {
564 } else {
565 }
566 for (int i = 0; i < 10; ++i) {
567 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000568
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000569 * ``bool AfterEnum`` Wrap enum definitions.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000570
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000571 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000572
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000573 true:
574 enum X : int
575 {
576 B
577 };
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000578
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000579 false:
580 enum X : int { B };
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000581
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000582 * ``bool AfterFunction`` Wrap function definitions.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000583
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000584 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000585
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000586 true:
587 void foo()
588 {
589 bar();
590 bar2();
591 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000592
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000593 false:
594 void foo() {
595 bar();
596 bar2();
597 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000598
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000599 * ``bool AfterNamespace`` Wrap namespace definitions.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000600
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000601 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000602
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000603 true:
604 namespace
605 {
606 int foo();
607 int bar();
608 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000609
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000610 false:
611 namespace {
612 int foo();
613 int bar();
614 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000615
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000616 * ``bool AfterObjCDeclaration`` Wrap ObjC definitions (``@autoreleasepool``, interfaces, ..).
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000617
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000618 * ``bool AfterStruct`` Wrap struct definitions.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000619
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000620 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000621
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000622 true:
623 struct foo
624 {
625 int x;
626 };
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000627
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000628 false:
629 struct foo {
630 int x;
631 };
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000632
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000633 * ``bool AfterUnion`` Wrap union definitions.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000634
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000635 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000636
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000637 true:
638 union foo
639 {
640 int x;
641 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000642
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000643 false:
644 union foo {
645 int x;
646 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000647
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000648 * ``bool BeforeCatch`` Wrap before ``catch``.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000649
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000650 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000651
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000652 true:
653 try {
654 foo();
655 }
656 catch () {
657 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000658
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000659 false:
660 try {
661 foo();
662 } catch () {
663 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000664
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000665 * ``bool BeforeElse`` Wrap before ``else``.
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000666
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000667 .. code-block:: c++
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000668
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000669 true:
670 if (foo()) {
671 }
672 else {
673 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000674
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000675 false:
676 if (foo()) {
677 } else {
678 }
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000679
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000680 * ``bool IndentBraces`` Indent the wrapped braces themselves.
681
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +0000682 * ``bool SplitEmptyFunction`` If ``false``, empty function body can be put on a single line.
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000683 This option is used only if the opening brace of the function has
684 already been wrapped, i.e. the `AfterFunction` brace wrapping mode is
685 set, and the function could/should not be put on a single line (as per
686 `AllowShortFunctionsOnASingleLine` and constructor formatting options).
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000687
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000688 .. code-block:: c++
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000689
Krasimir Georgiev90b4ce32017-06-23 11:29:40 +0000690 int f() vs. inf f()
691 {} {
692 }
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000693
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +0000694 * ``bool SplitEmptyRecord`` If ``false``, empty record (e.g. class, struct or union) body
695 can be put on a single line. This option is used only if the opening
696 brace of the record has already been wrapped, i.e. the `AfterClass`
697 (for classes) brace wrapping mode is set.
698
699 .. code-block:: c++
700
701 class Foo vs. class Foo
702 {} {
703 }
704
705 * ``bool SplitEmptyNamespace`` If ``false``, empty namespace body can be put on a single line.
706 This option is used only if the opening brace of the namespace has
707 already been wrapped, i.e. the `AfterNamespace` brace wrapping mode is
708 set.
709
710 .. code-block:: c++
711
712 namespace Foo vs. namespace Foo
713 {} {
714 }
715
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000716
Daniel Jasper6501f7e2015-10-27 12:38:37 +0000717**BreakAfterJavaFieldAnnotations** (``bool``)
718 Break after each annotation on a field in Java files.
719
Sylvestre Ledrude098242017-04-11 07:07:05 +0000720 .. code-block:: java
721
722 true: false:
723 @Partial vs. @Partial @Mock DataLoad loader;
724 @Mock
725 DataLoad loader;
726
Daniel Jasperac043c92014-09-15 11:11:00 +0000727**BreakBeforeBinaryOperators** (``BinaryOperatorStyle``)
728 The way to wrap binary operators.
729
730 Possible values:
731
732 * ``BOS_None`` (in configuration: ``None``)
733 Break after operators.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000734
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000735 .. code-block:: c++
736
737 LooooooooooongType loooooooooooooooooooooongVariable =
738 someLooooooooooooooooongFunction();
739
740 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
741 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ==
742 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
743 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa >
744 ccccccccccccccccccccccccccccccccccccccccc;
745
Daniel Jasperac043c92014-09-15 11:11:00 +0000746 * ``BOS_NonAssignment`` (in configuration: ``NonAssignment``)
747 Break before operators that aren't assignments.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000748
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000749 .. code-block:: c++
750
751 LooooooooooongType loooooooooooooooooooooongVariable =
752 someLooooooooooooooooongFunction();
753
754 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
755 + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
756 == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
757 && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
758 > ccccccccccccccccccccccccccccccccccccccccc;
759
Daniel Jasperac043c92014-09-15 11:11:00 +0000760 * ``BOS_All`` (in configuration: ``All``)
761 Break before operators.
762
Sylvestre Ledru35b392d2017-03-20 12:56:40 +0000763 .. code-block:: c++
764
765 LooooooooooongType loooooooooooooooooooooongVariable
766 = someLooooooooooooooooongFunction();
767
768 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
769 + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
770 == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
771 && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
772 > ccccccccccccccccccccccccccccccccccccccccc;
773
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000774
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000775
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000776**BreakBeforeBraces** (``BraceBreakingStyle``)
777 The brace breaking style to use.
778
779 Possible values:
780
781 * ``BS_Attach`` (in configuration: ``Attach``)
782 Always attach braces to surrounding context.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000783
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000784 .. code-block:: c++
785
786 try {
787 foo();
788 } catch () {
789 }
790 void foo() { bar(); }
791 class foo {};
792 if (foo()) {
793 } else {
794 }
795 enum X : int { A, B };
796
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000797 * ``BS_Linux`` (in configuration: ``Linux``)
798 Like ``Attach``, but break before braces on function, namespace and
799 class definitions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000800
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000801 .. code-block:: c++
802
803 try {
804 foo();
805 } catch () {
806 }
807 void foo() { bar(); }
808 class foo
809 {
810 };
811 if (foo()) {
812 } else {
813 }
814 enum X : int { A, B };
815
Birunthan Mohanathas305fa9c2015-07-12 03:13:54 +0000816 * ``BS_Mozilla`` (in configuration: ``Mozilla``)
817 Like ``Attach``, but break before braces on enum, function, and record
818 definitions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000819
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000820 .. code-block:: c++
821
822 try {
823 foo();
824 } catch () {
825 }
826 void foo() { bar(); }
827 class foo
828 {
829 };
830 if (foo()) {
831 } else {
832 }
833 enum X : int { A, B };
834
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000835 * ``BS_Stroustrup`` (in configuration: ``Stroustrup``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000836 Like ``Attach``, but break before function definitions, ``catch``, and
837 ``else``.
838
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000839 .. code-block:: c++
840
841 try {
842 foo();
843 } catch () {
844 }
845 void foo() { bar(); }
846 class foo
847 {
848 };
849 if (foo()) {
850 } else {
851 }
852 enum X : int
853 {
854 A,
855 B
856 };
857
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000858 * ``BS_Allman`` (in configuration: ``Allman``)
859 Always break before braces.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000860
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000861 .. code-block:: c++
862
863 try {
864 foo();
865 }
866 catch () {
867 }
868 void foo() { bar(); }
869 class foo {
870 };
871 if (foo()) {
872 }
873 else {
874 }
875 enum X : int { A, B };
876
Daniel Jasperee107ad2014-02-13 12:51:50 +0000877 * ``BS_GNU`` (in configuration: ``GNU``)
878 Always break before braces and add an extra level of indentation to
879 braces of control statements, not to those of class, function
880 or other definitions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000881
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000882 .. code-block:: c++
883
884 try
885 {
886 foo();
887 }
888 catch ()
889 {
890 }
891 void foo() { bar(); }
892 class foo
893 {
894 };
895 if (foo())
896 {
897 }
898 else
899 {
900 }
901 enum X : int
902 {
903 A,
904 B
905 };
906
Roman Kashitsyn291f64f2015-08-10 13:43:19 +0000907 * ``BS_WebKit`` (in configuration: ``WebKit``)
908 Like ``Attach``, but break before functions.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000909
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000910 .. code-block:: c++
911
912 try {
913 foo();
914 } catch () {
915 }
916 void foo() { bar(); }
917 class foo {
918 };
919 if (foo()) {
920 } else {
921 }
922 enum X : int { A, B };
923
Daniel Jasperc1bc38e2015-09-29 14:57:55 +0000924 * ``BS_Custom`` (in configuration: ``Custom``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +0000925 Configure each individual brace in `BraceWrapping`.
926
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000927
928
Andi-Bogdan Postelnicu0ef8ee12017-03-10 15:10:37 +0000929**BreakBeforeInheritanceComma** (``bool``)
930 If ``true``, in the class inheritance expression clang-format will
931 break before ``:`` and ``,`` if there is multiple inheritance.
932
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000933 .. code-block:: c++
934
935 true: false:
936 class MyClass vs. class MyClass : public X, public Y {
937 : public X };
938 , public Y {
939 };
940
Alexander Kornienkofdca83d2013-12-10 10:18:34 +0000941**BreakBeforeTernaryOperators** (``bool``)
942 If ``true``, ternary operators will be placed after line breaks.
943
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000944 .. code-block:: c++
945
946 true:
947 veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription
948 ? firstValue
949 : SecondValueVeryVeryVeryVeryLong;
950
Sylvestre Ledru121224d2017-06-06 07:26:19 +0000951 false:
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +0000952 veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ?
953 firstValue :
954 SecondValueVeryVeryVeryVeryLong;
955
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000956**BreakConstructorInitializers** (``BreakConstructorInitializersStyle``)
957 The constructor initializers style to use.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000958
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000959 Possible values:
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000960
Krasimir Georgiev575b25f2017-06-23 08:48:00 +0000961 * ``BCIS_BeforeColon`` (in configuration: ``BeforeColon``)
962 Break constructor initializers before the colon and after the commas.
963
964 .. code-block:: c++
965
966 Constructor()
967 : initializer1(),
968 initializer2()
969
970 * ``BCIS_BeforeComma`` (in configuration: ``BeforeComma``)
971 Break constructor initializers before the colon and commas, and align
972 the commas with the colon.
973
974 .. code-block:: c++
975
976 Constructor()
977 : initializer1()
978 , initializer2()
979
980 * ``BCIS_AfterColon`` (in configuration: ``AfterColon``)
981 Break constructor initializers after the colon and commas.
982
983 .. code-block:: c++
984
985 Constructor() :
986 initializer1(),
987 initializer2()
988
989
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +0000990
Alexander Kornienko1e048232016-02-23 16:11:51 +0000991**BreakStringLiterals** (``bool``)
992 Allow breaking string literals when formatting.
993
Alexander Kornienkod278e0e2013-09-04 15:09:13 +0000994**ColumnLimit** (``unsigned``)
995 The column limit.
996
997 A column limit of ``0`` means that there is no column limit. In this case,
998 clang-format will respect the input's line breaking decisions within
Alexander Kornienkofdca83d2013-12-10 10:18:34 +0000999 statements unless they contradict other rules.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001000
Daniel Jasperee107ad2014-02-13 12:51:50 +00001001**CommentPragmas** (``std::string``)
1002 A regular expression that describes comments with special meaning,
1003 which should not be split into lines or otherwise changed.
1004
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001005 .. code-block:: c++
1006
Jonathan Roelofs335777b2017-03-20 17:07:49 +00001007 // CommentPragmas: '^ FOOBAR pragma:'
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001008 // Will leave the following line unaffected
1009 #include <vector> // FOOBAR pragma: keep
1010
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001011**CompactNamespaces** (``bool``)
1012 If ``true``, consecutive namespace declarations will be on the same
1013 line. If ``false``, each namespace is declared on a new line.
1014
1015 .. code-block:: c++
1016
1017 true:
1018 namespace Foo { namespace Bar {
1019 }}
1020
1021 false:
1022 namespace Foo {
1023 namespace Bar {
1024 }
1025 }
1026
1027 If it does not fit on a single line, the overflowing namespaces get
1028 wrapped:
1029
1030 .. code-block:: c++
1031
1032 namespace Foo { namespace Bar {
1033 namespace Extra {
1034 }}}
1035
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001036**ConstructorInitializerAllOnOneLineOrOnePerLine** (``bool``)
1037 If the constructor initializers don't fit on a line, put each
1038 initializer on its own line.
1039
Sylvestre Ledru7d21a3d2017-03-13 14:42:47 +00001040 .. code-block:: c++
1041
1042 true:
1043 SomeClass::Constructor()
1044 : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) {
1045 return 0;
1046 }
1047
1048 false:
1049 SomeClass::Constructor()
1050 : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa),
1051 aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) {
1052 return 0;
1053 }
1054
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001055**ConstructorInitializerIndentWidth** (``unsigned``)
1056 The number of characters to use for indentation of constructor
1057 initializer lists.
1058
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001059**ContinuationIndentWidth** (``unsigned``)
1060 Indent width for line continuations.
1061
Sylvestre Ledrude098242017-04-11 07:07:05 +00001062 .. code-block:: c++
1063
1064 ContinuationIndentWidth: 2
1065
1066 int i = // VeryVeryVeryVeryVeryLongComment
1067 longFunction( // Again a long comment
1068 arg);
1069
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001070**Cpp11BracedListStyle** (``bool``)
1071 If ``true``, format braced lists as best suited for C++11 braced
1072 lists.
1073
1074 Important differences:
1075 - No spaces inside the braced list.
1076 - No line break before the closing brace.
1077 - Indentation with the continuation indent, not with the block indent.
1078
1079 Fundamentally, C++11 braced lists are formatted exactly like function
1080 calls would be formatted in their place. If the braced list follows a name
1081 (e.g. a type or variable name), clang-format formats as if the ``{}`` were
1082 the parentheses of a function call with that name. If there is no name,
1083 a zero-length name is assumed.
1084
Sylvestre Ledrude098242017-04-11 07:07:05 +00001085 .. code-block:: c++
1086
1087 true: false:
1088 vector<int> x{1, 2, 3, 4}; vs. vector<int> x{ 1, 2, 3, 4 };
1089 vector<T> x{{}, {}, {}, {}}; vector<T> x{ {}, {}, {}, {} };
1090 f(MyMap[{composite, key}]); f(MyMap[{ composite, key }]);
1091 new int[3]{1, 2, 3}; new int[3]{ 1, 2, 3 };
1092
Daniel Jasper553d4872014-06-17 12:40:34 +00001093**DerivePointerAlignment** (``bool``)
1094 If ``true``, analyze the formatted file for the most common
Sylvestre Ledrude098242017-04-11 07:07:05 +00001095 alignment of ``&`` and ``*``.
1096 Pointer and reference alignment styles are going to be updated according
1097 to the preferences found in the file.
1098 ``PointerAlignment`` is then used only as fallback.
Daniel Jasper553d4872014-06-17 12:40:34 +00001099
1100**DisableFormat** (``bool``)
Birunthan Mohanathasb744e722015-06-27 09:25:28 +00001101 Disables formatting completely.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001102
1103**ExperimentalAutoDetectBinPacking** (``bool``)
1104 If ``true``, clang-format detects whether function calls and
1105 definitions are formatted with one parameter per line.
1106
1107 Each call can be bin-packed, one-per-line or inconclusive. If it is
1108 inconclusive, e.g. completely on one line, but a decision needs to be
1109 made, clang-format analyzes whether there are other bin-packed cases in
1110 the input file and act accordingly.
1111
1112 NOTE: This is an experimental flag, that might go away or be renamed. Do
1113 not use this in config files, etc. Use at your own risk.
1114
Krasimir Georgiev32eaa862017-03-01 15:35:39 +00001115**FixNamespaceComments** (``bool``)
1116 If ``true``, clang-format adds missing namespace end comments and
1117 fixes invalid existing ones.
1118
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001119 .. code-block:: c++
1120
1121 true: false:
1122 namespace a { vs. namespace a {
1123 foo(); foo();
1124 } // namespace a; }
1125
Daniel Jaspere1e43192014-04-01 12:55:11 +00001126**ForEachMacros** (``std::vector<std::string>``)
Daniel Jasperb5524822014-04-09 14:05:49 +00001127 A vector of macros that should be interpreted as foreach loops
1128 instead of as function calls.
Daniel Jaspere1e43192014-04-01 12:55:11 +00001129
Daniel Jasperb5524822014-04-09 14:05:49 +00001130 These are expected to be macros of the form:
Daniel Jasperb5bda7c2015-10-06 12:11:51 +00001131
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001132 .. code-block:: c++
Daniel Jasper8e1ecca2015-10-07 13:02:45 +00001133
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001134 FOREACH(<variable-declaration>, ...)
1135 <loop-body>
1136
1137 In the .clang-format configuration file, this can be configured like:
Daniel Jasperb5bda7c2015-10-06 12:11:51 +00001138
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001139 .. code-block:: yaml
Daniel Jasper8e1ecca2015-10-07 13:02:45 +00001140
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001141 ForEachMacros: ['RANGES_FOR', 'FOREACH']
Daniel Jasperb5524822014-04-09 14:05:49 +00001142
1143 For example: BOOST_FOREACH.
Daniel Jaspere1e43192014-04-01 12:55:11 +00001144
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001145**IncludeCategories** (``std::vector<IncludeCategory>``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001146 Regular expressions denoting the different ``#include`` categories
1147 used for ordering ``#includes``.
Daniel Jasperc1bc38e2015-09-29 14:57:55 +00001148
1149 These regular expressions are matched against the filename of an include
1150 (including the <> or "") in order. The value belonging to the first
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001151 matching regular expression is assigned and ``#includes`` are sorted first
Daniel Jasperc1bc38e2015-09-29 14:57:55 +00001152 according to increasing category number and then alphabetically within
1153 each category.
1154
Alexander Kornienko1e048232016-02-23 16:11:51 +00001155 If none of the regular expressions match, INT_MAX is assigned as
1156 category. The main header for a source file automatically gets category 0.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001157 so that it is generally kept at the beginning of the ``#includes``
Alexander Kornienko1e048232016-02-23 16:11:51 +00001158 (http://llvm.org/docs/CodingStandards.html#include-style). However, you
1159 can also assign negative priorities if you have certain headers that
1160 always need to be first.
Daniel Jasperc1bc38e2015-09-29 14:57:55 +00001161
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001162 To configure this in the .clang-format file, use:
Daniel Jasperb5bda7c2015-10-06 12:11:51 +00001163
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001164 .. code-block:: yaml
Daniel Jasper8e1ecca2015-10-07 13:02:45 +00001165
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001166 IncludeCategories:
1167 - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
1168 Priority: 2
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +00001169 - Regex: '^(<|"(gtest|gmock|isl|json)/)'
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001170 Priority: 3
Sylvestre Ledruf3e295a2017-03-09 06:41:08 +00001171 - Regex: '.*'
Daniel Jasper8ce1b8d2015-10-06 11:54:18 +00001172 Priority: 1
1173
Daniel Jasper9c8ff352016-03-21 14:11:27 +00001174**IncludeIsMainRegex** (``std::string``)
1175 Specify a regular expression of suffixes that are allowed in the
1176 file-to-main-include mapping.
1177
1178 When guessing whether a #include is the "main" include (to assign
1179 category 0, see above), use this regex of allowed suffixes to the header
1180 stem. A partial match is done, so that:
1181 - "" means "arbitrary suffix"
1182 - "$" means "no suffix"
1183
1184 For example, if configured to "(_test)?$", then a header a.h would be seen
1185 as the "main" include in both a.cc and a_test.cc.
1186
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001187**IndentCaseLabels** (``bool``)
1188 Indent case labels one level from the switch statement.
1189
1190 When ``false``, use the same indentation level as for the switch statement.
1191 Switch statement body is always indented one level more than case labels.
1192
Sylvestre Ledrude098242017-04-11 07:07:05 +00001193 .. code-block:: c++
1194
1195 false: true:
1196 switch (fool) { vs. switch (fool) {
1197 case 1: case 1:
1198 bar(); bar();
1199 break; break;
1200 default: default:
1201 plop(); plop();
1202 } }
1203
Krasimir Georgievad47c902017-08-30 14:34:57 +00001204**IndentPPDirectives** (``PPDirectiveIndentStyle``)
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +00001205 The preprocessor directive indenting style to use.
Krasimir Georgievad47c902017-08-30 14:34:57 +00001206
1207 Possible values:
1208
1209 * ``PPDIS_None`` (in configuration: ``None``)
1210 Does not indent any directives.
1211
1212 .. code-block:: c++
1213
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +00001214 #if FOO
1215 #if BAR
1216 #include <foo>
1217 #endif
1218 #endif
Krasimir Georgievad47c902017-08-30 14:34:57 +00001219
1220 * ``PPDIS_AfterHash`` (in configuration: ``AfterHash``)
1221 Indents directives after the hash.
1222
1223 .. code-block:: c++
1224
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +00001225 #if FOO
1226 # if BAR
1227 # include <foo>
1228 # endif
1229 #endif
1230
1231
Krasimir Georgievad47c902017-08-30 14:34:57 +00001232
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001233**IndentWidth** (``unsigned``)
Alexander Kornienko45ca09b2013-09-27 16:16:55 +00001234 The number of columns to use for indentation.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001235
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001236 .. code-block:: c++
1237
1238 IndentWidth: 3
Sylvestre Ledrude098242017-04-11 07:07:05 +00001239
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001240 void f() {
1241 someFunction();
1242 if (true, false) {
1243 f();
1244 }
1245 }
1246
Daniel Jasperc75e1ef2014-07-09 08:42:42 +00001247**IndentWrappedFunctionNames** (``bool``)
1248 Indent if a function definition or declaration is wrapped after the
1249 type.
1250
Sylvestre Ledrude098242017-04-11 07:07:05 +00001251 .. code-block:: c++
1252
1253 true:
1254 LoooooooooooooooooooooooooooooooooooooooongReturnType
1255 LoooooooooooooooooooooooooooooooongFunctionDeclaration();
1256
1257 false:
1258 LoooooooooooooooooooooooooooooooooooooooongReturnType
1259 LoooooooooooooooooooooooooooooooongFunctionDeclaration();
1260
Daniel Jasper9c8ff352016-03-21 14:11:27 +00001261**JavaScriptQuotes** (``JavaScriptQuoteStyle``)
1262 The JavaScriptQuoteStyle to use for JavaScript strings.
1263
1264 Possible values:
1265
1266 * ``JSQS_Leave`` (in configuration: ``Leave``)
1267 Leave string quotes as they are.
1268
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001269 .. code-block:: js
1270
1271 string1 = "foo";
1272 string2 = 'bar';
1273
Daniel Jasper9c8ff352016-03-21 14:11:27 +00001274 * ``JSQS_Single`` (in configuration: ``Single``)
1275 Always use single quotes.
1276
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001277 .. code-block:: js
1278
1279 string1 = 'foo';
1280 string2 = 'bar';
1281
Daniel Jasper9c8ff352016-03-21 14:11:27 +00001282 * ``JSQS_Double`` (in configuration: ``Double``)
1283 Always use double quotes.
1284
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001285 .. code-block:: js
1286
1287 string1 = "foo";
1288 string2 = "bar";
1289
Daniel Jasper9c8ff352016-03-21 14:11:27 +00001290
1291
Krasimir Georgiev32eaa862017-03-01 15:35:39 +00001292**JavaScriptWrapImports** (``bool``)
1293 Whether to wrap JavaScript import/export statements.
1294
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001295 .. code-block:: js
1296
1297 true:
1298 import {
1299 VeryLongImportsAreAnnoying,
1300 VeryLongImportsAreAnnoying,
1301 VeryLongImportsAreAnnoying,
1302 } from 'some/module.js'
1303
1304 false:
1305 import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js"
1306
Daniel Jasperb5524822014-04-09 14:05:49 +00001307**KeepEmptyLinesAtTheStartOfBlocks** (``bool``)
Sylvestre Ledrude098242017-04-11 07:07:05 +00001308 If true, the empty line at the start of blocks is kept.
1309
1310 .. code-block:: c++
1311
1312 true: false:
1313 if (foo) { vs. if (foo) {
1314 bar();
1315 bar(); }
1316 }
Daniel Jasperb5524822014-04-09 14:05:49 +00001317
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001318**Language** (``LanguageKind``)
1319 Language, this format style is targeted at.
1320
1321 Possible values:
1322
1323 * ``LK_None`` (in configuration: ``None``)
1324 Do not use.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001325
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001326 * ``LK_Cpp`` (in configuration: ``Cpp``)
Krasimir Georgiev32eaa862017-03-01 15:35:39 +00001327 Should be used for C, C++.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001328
Daniel Jasper18210d72014-10-09 09:52:05 +00001329 * ``LK_Java`` (in configuration: ``Java``)
1330 Should be used for Java.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001331
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001332 * ``LK_JavaScript`` (in configuration: ``JavaScript``)
1333 Should be used for JavaScript.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001334
Krasimir Georgiev32eaa862017-03-01 15:35:39 +00001335 * ``LK_ObjC`` (in configuration: ``ObjC``)
1336 Should be used for Objective-C, Objective-C++.
1337
Daniel Jasperee107ad2014-02-13 12:51:50 +00001338 * ``LK_Proto`` (in configuration: ``Proto``)
1339 Should be used for Protocol Buffers
1340 (https://developers.google.com/protocol-buffers/).
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001341
Alexander Kornienko1e048232016-02-23 16:11:51 +00001342 * ``LK_TableGen`` (in configuration: ``TableGen``)
1343 Should be used for TableGen code.
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001344
Sylvestre Ledru44d1ef12017-09-07 12:08:49 +00001345 * ``LK_TextProto`` (in configuration: ``TextProto``)
1346 Should be used for Protocol Buffer messages in text format
1347 (https://developers.google.com/protocol-buffers/).
1348
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001349
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001350
Birunthan Mohanathasb001a0b2015-07-03 17:25:16 +00001351**MacroBlockBegin** (``std::string``)
1352 A regular expression matching macros that start a block.
1353
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001354 .. code-block:: c++
1355
1356 # With:
1357 MacroBlockBegin: "^NS_MAP_BEGIN|\
1358 NS_TABLE_HEAD$"
1359 MacroBlockEnd: "^\
1360 NS_MAP_END|\
1361 NS_TABLE_.*_END$"
1362
1363 NS_MAP_BEGIN
1364 foo();
1365 NS_MAP_END
1366
1367 NS_TABLE_HEAD
1368 bar();
1369 NS_TABLE_FOO_END
1370
1371 # Without:
1372 NS_MAP_BEGIN
1373 foo();
1374 NS_MAP_END
1375
1376 NS_TABLE_HEAD
1377 bar();
1378 NS_TABLE_FOO_END
1379
Birunthan Mohanathasb001a0b2015-07-03 17:25:16 +00001380**MacroBlockEnd** (``std::string``)
1381 A regular expression matching macros that end a block.
1382
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001383**MaxEmptyLinesToKeep** (``unsigned``)
1384 The maximum number of consecutive empty lines to keep.
1385
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001386 .. code-block:: c++
1387
1388 MaxEmptyLinesToKeep: 1 vs. MaxEmptyLinesToKeep: 0
1389 int f() { int f() {
1390 int = 1; int i = 1;
1391 i = foo();
1392 i = foo(); return i;
1393 }
1394 return i;
1395 }
1396
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001397**NamespaceIndentation** (``NamespaceIndentationKind``)
1398 The indentation used for namespaces.
1399
1400 Possible values:
1401
1402 * ``NI_None`` (in configuration: ``None``)
1403 Don't indent in namespaces.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001404
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001405 .. code-block:: c++
1406
1407 namespace out {
1408 int i;
1409 namespace in {
1410 int i;
1411 }
1412 }
1413
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001414 * ``NI_Inner`` (in configuration: ``Inner``)
1415 Indent only in inner namespaces (nested in other namespaces).
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001416
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001417 .. code-block:: c++
1418
1419 namespace out {
1420 int i;
1421 namespace in {
1422 int i;
1423 }
1424 }
1425
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001426 * ``NI_All`` (in configuration: ``All``)
1427 Indent in all namespaces.
1428
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001429 .. code-block:: c++
1430
1431 namespace out {
1432 int i;
1433 namespace in {
1434 int i;
1435 }
1436 }
1437
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001438
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001439
Daniel Jaspereb2226e2014-10-28 16:56:37 +00001440**ObjCBlockIndentWidth** (``unsigned``)
1441 The number of characters to use for indentation of ObjC blocks.
1442
Sylvestre Ledrude098242017-04-11 07:07:05 +00001443 .. code-block:: objc
1444
1445 ObjCBlockIndentWidth: 4
1446
1447 [operation setCompletionBlock:^{
1448 [self onOperationDone];
1449 }];
1450
Daniel Jasperee107ad2014-02-13 12:51:50 +00001451**ObjCSpaceAfterProperty** (``bool``)
1452 Add a space after ``@property`` in Objective-C, i.e. use
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001453 ``@property (readonly)`` instead of ``@property(readonly)``.
Daniel Jasperee107ad2014-02-13 12:51:50 +00001454
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001455**ObjCSpaceBeforeProtocolList** (``bool``)
1456 Add a space in front of an Objective-C protocol list, i.e. use
1457 ``Foo <Protocol>`` instead of ``Foo<Protocol>``.
1458
Krasimir Georgiev575b25f2017-06-23 08:48:00 +00001459**PenaltyBreakAssignment** (``unsigned``)
1460 The penalty for breaking around an assignment operator.
1461
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001462**PenaltyBreakBeforeFirstCallParameter** (``unsigned``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001463 The penalty for breaking a function call after ``call(``.
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001464
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001465**PenaltyBreakComment** (``unsigned``)
1466 The penalty for each line break introduced inside a comment.
1467
1468**PenaltyBreakFirstLessLess** (``unsigned``)
1469 The penalty for breaking before the first ``<<``.
1470
1471**PenaltyBreakString** (``unsigned``)
1472 The penalty for each line break introduced inside a string literal.
1473
1474**PenaltyExcessCharacter** (``unsigned``)
1475 The penalty for each character outside of the column limit.
1476
1477**PenaltyReturnTypeOnItsOwnLine** (``unsigned``)
1478 Penalty for putting the return type of a function onto its own
1479 line.
1480
Daniel Jasper553d4872014-06-17 12:40:34 +00001481**PointerAlignment** (``PointerAlignmentStyle``)
1482 Pointer and reference alignment style.
1483
1484 Possible values:
1485
1486 * ``PAS_Left`` (in configuration: ``Left``)
1487 Align pointer to the left.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001488
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001489 .. code-block:: c++
1490
Sylvestre Ledruf3e295a2017-03-09 06:41:08 +00001491 int* a;
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001492
Daniel Jasper553d4872014-06-17 12:40:34 +00001493 * ``PAS_Right`` (in configuration: ``Right``)
1494 Align pointer to the right.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001495
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001496 .. code-block:: c++
1497
Sylvestre Ledruf3e295a2017-03-09 06:41:08 +00001498 int *a;
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001499
Daniel Jasper553d4872014-06-17 12:40:34 +00001500 * ``PAS_Middle`` (in configuration: ``Middle``)
1501 Align pointer in the middle.
1502
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001503 .. code-block:: c++
1504
Sylvestre Ledruf3e295a2017-03-09 06:41:08 +00001505 int * a;
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001506
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001507
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001508
Alexander Kornienko1e048232016-02-23 16:11:51 +00001509**ReflowComments** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001510 If ``true``, clang-format will attempt to re-flow comments.
Alexander Kornienko1e048232016-02-23 16:11:51 +00001511
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001512 .. code-block:: c++
1513
1514 false:
1515 // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
1516 /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */
1517
1518 true:
1519 // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
1520 // information
1521 /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
1522 * information */
1523
Alexander Kornienko1e048232016-02-23 16:11:51 +00001524**SortIncludes** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001525 If ``true``, clang-format will sort ``#includes``.
Alexander Kornienko1e048232016-02-23 16:11:51 +00001526
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001527 .. code-block:: c++
1528
1529 false: true:
1530 #include "b.h" vs. #include "a.h"
1531 #include "a.h" #include "b.h"
1532
Krasimir Georgievac16a202017-06-23 11:46:03 +00001533**SortUsingDeclarations** (``bool``)
1534 If ``true``, clang-format will sort using declarations.
1535
1536 .. code-block:: c++
1537
1538 false: true:
1539 using std::cout; vs. using std::cin;
1540 using std::cin; using std::cout;
1541
Daniel Jasperb87899b2014-09-10 13:11:45 +00001542**SpaceAfterCStyleCast** (``bool``)
Sylvestre Ledru0385ccb2017-03-08 13:24:46 +00001543 If ``true``, a space is inserted after C style casts.
1544
1545 .. code-block:: c++
1546
1547 true: false:
1548 (int)i; vs. (int) i;
Daniel Jasperb87899b2014-09-10 13:11:45 +00001549
Sylvestre Ledru83bbd572016-08-09 14:24:40 +00001550**SpaceAfterTemplateKeyword** (``bool``)
1551 If ``true``, a space will be inserted after the 'template' keyword.
1552
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001553 .. code-block:: c++
1554
1555 true: false:
1556 template <int> void foo(); vs. template<int> void foo();
1557
Daniel Jasperd94bff32013-09-25 15:15:02 +00001558**SpaceBeforeAssignmentOperators** (``bool``)
Alexander Kornienko45ca09b2013-09-27 16:16:55 +00001559 If ``false``, spaces will be removed before assignment operators.
Daniel Jasperd94bff32013-09-25 15:15:02 +00001560
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001561 .. code-block:: c++
1562
1563 true: false:
1564 int a = 5; vs. int a=5;
1565 a += 42 a+=42;
1566
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001567**SpaceBeforeParens** (``SpaceBeforeParensOptions``)
1568 Defines in which cases to put a space before opening parentheses.
1569
1570 Possible values:
1571
1572 * ``SBPO_Never`` (in configuration: ``Never``)
1573 Never put a space before opening parentheses.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001574
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001575 .. code-block:: c++
1576
1577 void f() {
1578 if(true) {
1579 f();
1580 }
1581 }
1582
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001583 * ``SBPO_ControlStatements`` (in configuration: ``ControlStatements``)
1584 Put a space before opening parentheses only after control statement
1585 keywords (``for/if/while...``).
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001586
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001587 .. code-block:: c++
1588
1589 void f() {
1590 if (true) {
1591 f();
1592 }
1593 }
1594
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001595 * ``SBPO_Always`` (in configuration: ``Always``)
1596 Always put a space before opening parentheses, except when it's
1597 prohibited by the syntax rules (in function-like macro definitions) or
1598 when determined by other style rules (after unary operators, opening
1599 parentheses, etc.)
1600
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001601 .. code-block:: c++
1602
1603 void f () {
1604 if (true) {
1605 f ();
1606 }
1607 }
1608
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001609
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001610
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001611**SpaceInEmptyParentheses** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001612 If ``true``, spaces may be inserted into ``()``.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001613
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001614 .. code-block:: c++
1615
1616 true: false:
1617 void f( ) { vs. void f() {
1618 int x[] = {foo( ), bar( )}; int x[] = {foo(), bar()};
1619 if (true) { if (true) {
1620 f( ); f();
1621 } }
1622 } }
1623
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001624**SpacesBeforeTrailingComments** (``unsigned``)
Daniel Jasperc0be7602014-05-15 13:55:19 +00001625 The number of spaces before trailing line comments
1626 (``//`` - comments).
Daniel Jasperb5524822014-04-09 14:05:49 +00001627
Alexander Kornienko70f97c92016-02-27 14:02:08 +00001628 This does not affect trailing block comments (``/*`` - comments) as
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001629 those commonly have different usage patterns and a number of special
1630 cases.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001631
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001632 .. code-block:: c++
1633
1634 SpacesBeforeTrailingComments: 3
1635 void f() {
1636 if (true) { // foo1
1637 f(); // bar
1638 } // foo
1639 }
1640
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001641**SpacesInAngles** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001642 If ``true``, spaces will be inserted after ``<`` and before ``>``
1643 in template argument lists.
Alexander Kornienkofdca83d2013-12-10 10:18:34 +00001644
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001645 .. code-block:: c++
1646
1647 true: false:
1648 static_cast< int >(arg); vs. static_cast<int>(arg);
1649 std::function< void(int) > fct; std::function<void(int)> fct;
1650
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001651**SpacesInCStyleCastParentheses** (``bool``)
Daniel Jasperee107ad2014-02-13 12:51:50 +00001652 If ``true``, spaces may be inserted into C style casts.
1653
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001654 .. code-block:: c++
1655
1656 true: false:
1657 x = ( int32 )y vs. x = (int32)y
1658
Daniel Jasperee107ad2014-02-13 12:51:50 +00001659**SpacesInContainerLiterals** (``bool``)
1660 If ``true``, spaces are inserted inside container literals (e.g.
1661 ObjC and Javascript array and dict literals).
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001662
Sylvestre Ledru35b392d2017-03-20 12:56:40 +00001663 .. code-block:: js
1664
1665 true: false:
1666 var arr = [ 1, 2, 3 ]; vs. var arr = [1, 2, 3];
1667 f({a : 1, b : 2, c : 3}); f({a: 1, b: 2, c: 3});
1668
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001669**SpacesInParentheses** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001670 If ``true``, spaces will be inserted after ``(`` and before ``)``.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001671
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001672 .. code-block:: c++
1673
1674 true: false:
1675 t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete;
1676
Daniel Jasperad981f82014-08-26 11:41:14 +00001677**SpacesInSquareBrackets** (``bool``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001678 If ``true``, spaces will be inserted after ``[`` and before ``]``.
Sylvestre Ledrud1eff2f2017-03-06 16:35:28 +00001679 Lambdas or unspecified size array declarations will not be affected.
1680
1681 .. code-block:: c++
1682
1683 true: false:
1684 int a[ 5 ]; vs. int a[5];
1685 std::unique_ptr<int[]> foo() {} // Won't be affected
Daniel Jasperad981f82014-08-26 11:41:14 +00001686
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001687**Standard** (``LanguageStandard``)
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001688 Format compatible with this standard, e.g. use ``A<A<int> >``
1689 instead of ``A<A<int>>`` for ``LS_Cpp03``.
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001690
1691 Possible values:
1692
1693 * ``LS_Cpp03`` (in configuration: ``Cpp03``)
1694 Use C++03-compatible syntax.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001695
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001696 * ``LS_Cpp11`` (in configuration: ``Cpp11``)
Daniel Jasper7fdbb3f2017-05-08 15:08:00 +00001697 Use features of C++11, C++14 and C++1z (e.g. ``A<A<int>>`` instead of
Nico Weberdc065182017-04-05 18:10:42 +00001698 ``A<A<int> >``).
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001699
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001700 * ``LS_Auto`` (in configuration: ``Auto``)
1701 Automatic detection based on the input.
1702
1703
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001704
Alexander Kornienko45ca09b2013-09-27 16:16:55 +00001705**TabWidth** (``unsigned``)
1706 The number of columns used for tab stops.
1707
1708**UseTab** (``UseTabStyle``)
1709 The way to use tab characters in the resulting file.
1710
1711 Possible values:
1712
1713 * ``UT_Never`` (in configuration: ``Never``)
1714 Never use tab.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001715
Alexander Kornienko45ca09b2013-09-27 16:16:55 +00001716 * ``UT_ForIndentation`` (in configuration: ``ForIndentation``)
1717 Use tabs only for indentation.
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001718
Krasimir Georgiev32eaa862017-03-01 15:35:39 +00001719 * ``UT_ForContinuationAndIndentation`` (in configuration: ``ForContinuationAndIndentation``)
1720 Use tabs only for line continuation and indentation.
1721
Alexander Kornienko45ca09b2013-09-27 16:16:55 +00001722 * ``UT_Always`` (in configuration: ``Always``)
1723 Use tabs whenever we need to fill whitespace that spans at least from
1724 one tab stop to the next one.
1725
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001726
Alexander Kornienkob00a7d22016-02-23 16:12:00 +00001727
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001728.. END_FORMAT_STYLE_OPTIONS
1729
Daniel Jasper49d3d582015-10-05 07:24:55 +00001730Adding additional style options
1731===============================
1732
1733Each additional style option adds costs to the clang-format project. Some of
Sylvestre Ledrube8f3962016-02-14 20:20:58 +00001734these costs affect the clang-format development itself, as we need to make
Daniel Jasper49d3d582015-10-05 07:24:55 +00001735sure that any given combination of options work and that new features don't
1736break any of the existing options in any way. There are also costs for end users
1737as options become less discoverable and people have to think about and make a
1738decision on options they don't really care about.
1739
1740The goal of the clang-format project is more on the side of supporting a
1741limited set of styles really well as opposed to supporting every single style
1742used by a codebase somewhere in the wild. Of course, we do want to support all
1743major projects and thus have established the following bar for adding style
1744options. Each new style option must ..
1745
Daniel Jasperfcbea712015-10-05 13:30:42 +00001746 * be used in a project of significant size (have dozens of contributors)
1747 * have a publicly accessible style guide
1748 * have a person willing to contribute and maintain patches
Daniel Jasper49d3d582015-10-05 07:24:55 +00001749
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001750Examples
1751========
1752
1753A style similar to the `Linux Kernel style
1754<https://www.kernel.org/doc/Documentation/CodingStyle>`_:
1755
1756.. code-block:: yaml
1757
1758 BasedOnStyle: LLVM
1759 IndentWidth: 8
Alexander Kornienko8ba68f62013-09-27 16:19:25 +00001760 UseTab: Always
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001761 BreakBeforeBraces: Linux
1762 AllowShortIfStatementsOnASingleLine: false
1763 IndentCaseLabels: false
1764
1765The result is (imagine that tabs are used for indentation here):
1766
1767.. code-block:: c++
1768
1769 void test()
1770 {
1771 switch (x) {
1772 case 0:
1773 case 1:
1774 do_something();
1775 break;
1776 case 2:
1777 do_something_else();
1778 break;
1779 default:
1780 break;
1781 }
1782 if (condition)
1783 do_something_completely_different();
1784
1785 if (x == y) {
1786 q();
1787 } else if (x > y) {
1788 w();
1789 } else {
1790 r();
1791 }
1792 }
1793
1794A style similar to the default Visual Studio formatting style:
1795
1796.. code-block:: yaml
1797
Alexander Kornienko8ba68f62013-09-27 16:19:25 +00001798 UseTab: Never
Alexander Kornienkod278e0e2013-09-04 15:09:13 +00001799 IndentWidth: 4
1800 BreakBeforeBraces: Allman
1801 AllowShortIfStatementsOnASingleLine: false
1802 IndentCaseLabels: false
1803 ColumnLimit: 0
1804
1805The result is:
1806
1807.. code-block:: c++
1808
1809 void test()
1810 {
1811 switch (suffix)
1812 {
1813 case 0:
1814 case 1:
1815 do_something();
1816 break;
1817 case 2:
1818 do_something_else();
1819 break;
1820 default:
1821 break;
1822 }
1823 if (condition)
1824 do_somthing_completely_different();
1825
1826 if (x == y)
1827 {
1828 q();
1829 }
1830 else if (x > y)
1831 {
1832 w();
1833 }
1834 else
1835 {
1836 r();
1837 }
1838 }