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