Skip to content
Ignoring revisions in .git-blame-ignore-revs.

Latest commit

 

History

History
6942 lines (4867 loc) · 182 KB

ClangFormatStyleOptions.rst

File metadata and controls

6942 lines (4867 loc) · 182 KB
 
Jan 12, 2023
Jan 12, 2023
1
2
3
4
5
6
..
!!!!NOTE!!!!
This file is automatically generated, in part. Do not edit the style options
in this file directly. Instead, modify them in include/clang/Format/Format.h
and run the docs/tools/dump_format_style.py script to update this file.
Sep 28, 2021
Sep 28, 2021
7
8
9
.. raw:: html
<style type="text/css">
Apr 14, 2023
Apr 14, 2023
10
.versionbadge { background-color: #1c913d; height: 20px; display: inline-block; min-width: 120px; text-align: center; border-radius: 5px; color: #FFFFFF; font-family: "Verdana,Geneva,DejaVu Sans,sans-serif"; }
Sep 28, 2021
Sep 28, 2021
11
12
13
14
</style>
.. role:: versionbadge
15
16
17
18
19
20
21
22
23
==========================
Clang-Format Style Options
==========================
:doc:`ClangFormatStyleOptions` describes configurable formatting style options
supported by :doc:`LibFormat` and :doc:`ClangFormat`.
When using :program:`clang-format` command line utility or
``clang::format::reformat(...)`` functions from code, one can either use one of
Mar 21, 2019
Mar 21, 2019
24
25
the predefined styles (LLVM, Google, Chromium, Mozilla, WebKit, Microsoft) or
create a custom style by configuring specific style options.
26
27
28
29
30
31
32
Configuring Style with clang-format
===================================
:program:`clang-format` supports two ways to provide custom style options:
directly specify style configuration in the ``-style=`` command line option or
Sep 10, 2013
Sep 10, 2013
33
34
use ``-style=file`` and put style configuration in the ``.clang-format`` or
``_clang-format`` file in the project directory.
35
36
37
38
39
40
When using ``-style=file``, :program:`clang-format` for each input file will
try to find the ``.clang-format`` file located in the closest parent directory
of the input file. When the standard input is used, the search is started from
the current directory.
Jan 3, 2022
Jan 3, 2022
41
42
43
44
When using ``-style=file:<format_file_path>``, :program:`clang-format` for
each input file will use the format file located at `<format_file_path>`.
The path may be absolute or relative to the working directory.
45
46
47
48
49
50
51
52
53
The ``.clang-format`` file uses YAML format:
.. code-block:: yaml
key1: value1
key2: value2
# A comment.
...
Aug 12, 2014
Aug 12, 2014
54
55
56
57
The configuration file can consist of several sections each having different
``Language:`` parameter denoting the programming language this section of the
configuration is targeted at. See the description of the **Language** option
below for the list of supported languages. The first section may have no
Mar 6, 2021
Mar 6, 2021
58
language set, it will set the default style options for all languages.
Aug 12, 2014
Aug 12, 2014
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
Configuration sections for specific language will override options set in the
default section.
When :program:`clang-format` formats a file, it auto-detects the language using
the file name. When formatting standard input or a file that doesn't have the
extension corresponding to its language, ``-assume-filename=`` option can be
used to override the file name :program:`clang-format` uses to detect the
language.
An example of a configuration file for multiple languages:
.. code-block:: yaml
---
# We'll use defaults from the LLVM style, but with 4 columns indentation.
BasedOnStyle: LLVM
IndentWidth: 4
---
Language: Cpp
# Force pointers to the type for C++.
DerivePointerAlignment: false
PointerAlignment: Left
---
Language: JavaScript
# Use 100 columns for JS.
ColumnLimit: 100
---
Language: Proto
# Don't format .proto files.
DisableFormat: true
Mar 21, 2019
Mar 21, 2019
89
90
91
92
---
Language: CSharp
# Use 100 columns for C#.
ColumnLimit: 100
Aug 12, 2014
Aug 12, 2014
93
94
...
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
An easy way to get a valid ``.clang-format`` file containing all configuration
options of a certain predefined style is:
.. code-block:: console
clang-format -style=llvm -dump-config > .clang-format
When specifying configuration in the ``-style=`` option, the same configuration
is applied for all input files. The format of the configuration is:
.. code-block:: console
-style='{key1: value1, key2: value2, ...}'
Oct 7, 2014
Oct 7, 2014
110
111
112
113
114
115
Disabling Formatting on a Piece of Code
=======================================
Clang-format understands also special comments that switch formatting in a
delimited range. The code between a comment ``// clang-format off`` or
``/* clang-format off */`` up to a comment ``// clang-format on`` or
Feb 1, 2023
Feb 1, 2023
116
117
``/* clang-format on */`` will not be formatted. The comments themselves will be
formatted (aligned) normally. Also, a colon (``:``) and additional text may
Feb 3, 2023
Feb 3, 2023
118
follow ``// clang-format off`` or ``// clang-format on`` to explain why
Feb 1, 2023
Feb 1, 2023
119
clang-format is turned off or back on.
Oct 7, 2014
Oct 7, 2014
120
121
122
123
124
125
126
127
128
129
.. code-block:: c++
int formatted_code;
// clang-format off
void unformatted_code ;
// clang-format on
void formatted_code_again;
130
131
132
133
134
Configuring Style in Code
=========================
When using ``clang::format::reformat(...)`` functions, the format is specified
by supplying the `clang::format::FormatStyle
Nov 4, 2018
Nov 4, 2018
135
<https://clang.llvm.org/doxygen/structclang_1_1format_1_1FormatStyle.html>`_
136
137
138
139
140
141
142
143
structure.
Configurable Format Style Options
=================================
This section lists the supported style options. Value type is specified for
each option. For enumeration types possible values are specified both as a C++
Sep 4, 2013
Sep 4, 2013
144
145
enumeration member (with a prefix, e.g. ``LS_Auto``), and as a value usable in
the configuration (without a prefix: ``Auto``).
Jan 12, 2023
Jan 12, 2023
147
.. _BasedOnStyle:
Jan 12, 2023
Jan 12, 2023
149
**BasedOnStyle** (``String``) :ref:`<BasedOnStyle>`
150
151
152
153
154
155
156
157
158
The style used for all options not specifically set in the configuration.
This option is supported only in the :program:`clang-format` configuration
(both within ``-style='{...}'`` and the ``.clang-format`` file).
Possible values:
* ``LLVM``
A style complying with the `LLVM coding standards
Nov 4, 2018
Nov 4, 2018
159
<https://llvm.org/docs/CodingStandards.html>`_
160
161
* ``Google``
A style complying with `Google's C++ style guide
Jul 29, 2019
Jul 29, 2019
162
<https://google.github.io/styleguide/cppguide.html>`_
163
164
* ``Chromium``
A style complying with `Chromium's style guide
Nov 5, 2021
Nov 5, 2021
165
<https://chromium.googlesource.com/chromium/src/+/refs/heads/main/styleguide/styleguide.md>`_
166
167
* ``Mozilla``
A style complying with `Mozilla's style guide
Jan 3, 2022
Jan 3, 2022
168
<https://firefox-source-docs.mozilla.org/code-quality/coding-style/index.html>`_
169
170
* ``WebKit``
A style complying with `WebKit's style guide
Jan 23, 2019
Jan 23, 2019
171
<https://www.webkit.org/coding/coding-style.html>`_
Mar 21, 2019
Mar 21, 2019
172
173
* ``Microsoft``
A style complying with `Microsoft's style guide
Jan 29, 2022
Jan 29, 2022
174
<https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference>`_
May 21, 2020
May 21, 2020
175
176
177
* ``GNU``
A style complying with the `GNU coding standards
<https://www.gnu.org/prep/standards/standards.html>`_
Feb 14, 2021
Feb 14, 2021
178
179
180
181
182
183
184
185
186
* ``InheritParentConfig``
Not a real style, but allows to use the ``.clang-format`` file from the
parent directory (or its parent if there is none). If there is no parent
file found it falls back to the ``fallback`` style, and applies the changes
to that.
With this option you can overwrite some parts of your main style for your
subdirectories. This is also possible through the command line, e.g.:
``--style={BasedOnStyle: InheritParentConfig, ColumnLimit: 20}``
187
188
189
.. START_FORMAT_STYLE_OPTIONS
Jan 12, 2023
Jan 12, 2023
190
191
192
.. _AccessModifierOffset:
**AccessModifierOffset** (``Integer``) :versionbadge:`clang-format 3.3` :ref:`<AccessModifierOffset>`
Feb 23, 2016
Feb 23, 2016
193
The extra indent or outdent of access modifiers, e.g. ``public:``.
Jan 12, 2023
Jan 12, 2023
195
196
197
.. _AlignAfterOpenBracket:
**AlignAfterOpenBracket** (``BracketAlignmentStyle``) :versionbadge:`clang-format 3.8` :ref:`<AlignAfterOpenBracket>`
Dec 2, 2014
Dec 2, 2014
198
199
200
If ``true``, horizontally aligns arguments after an open bracket.
This applies to round brackets (parentheses), angle brackets and square
Feb 23, 2016
Feb 23, 2016
201
brackets.
Oct 6, 2015
Oct 6, 2015
202
Oct 27, 2015
Oct 27, 2015
203
204
205
206
207
208
209
210
211
Possible values:
* ``BAS_Align`` (in configuration: ``Align``)
Align parameters on the open bracket, e.g.:
.. code-block:: c++
someLongFunction(argument1,
argument2);
Feb 23, 2016
Feb 23, 2016
212
Oct 27, 2015
Oct 27, 2015
213
214
215
216
217
218
219
* ``BAS_DontAlign`` (in configuration: ``DontAlign``)
Don't align, instead use ``ContinuationIndentWidth``, e.g.:
.. code-block:: c++
someLongFunction(argument1,
argument2);
Feb 23, 2016
Feb 23, 2016
220
Oct 27, 2015
Oct 27, 2015
221
222
223
224
225
226
227
228
* ``BAS_AlwaysBreak`` (in configuration: ``AlwaysBreak``)
Always break after an open bracket, if the parameters don't fit
on a single line, e.g.:
.. code-block:: c++
someLongFunction(
argument1, argument2);
Oct 7, 2015
Oct 7, 2015
229
Jan 17, 2022
Jan 17, 2022
230
231
232
233
234
235
236
237
238
239
240
241
* ``BAS_BlockIndent`` (in configuration: ``BlockIndent``)
Always break after an open bracket, if the parameters don't fit
on a single line. Closing brackets will be placed on a new line.
E.g.:
.. code-block:: c++
someLongFunction(
argument1, argument2
)
Jul 9, 2023
Jul 9, 2023
242
.. note::
Jan 17, 2022
Jan 17, 2022
243
Jul 6, 2023
Jul 6, 2023
244
245
This currently only applies to braced initializer lists (when
``Cpp11BracedListStyle`` is ``true``) and parentheses.
Jan 17, 2022
Jan 17, 2022
246
Dec 2, 2014
Dec 2, 2014
247
Feb 23, 2016
Feb 23, 2016
248
Jan 12, 2023
Jan 12, 2023
249
250
251
.. _AlignArrayOfStructures:
**AlignArrayOfStructures** (``ArrayInitializerAlignmentStyle``) :versionbadge:`clang-format 13` :ref:`<AlignArrayOfStructures>`
Oct 8, 2024
Oct 8, 2024
252
If not ``None``, when using initialization for an array of structs
Jun 13, 2021
Jun 13, 2021
253
254
aligns the fields into columns.
Jul 9, 2023
Jul 9, 2023
255
256
257
258
259
.. note::
As of clang-format 15 this option only applied to arrays with equal
number of columns per row.
Mar 12, 2022
Mar 12, 2022
260
Jun 13, 2021
Jun 13, 2021
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
Possible values:
* ``AIAS_Left`` (in configuration: ``Left``)
Align array column and left justify the columns e.g.:
.. code-block:: c++
struct test demo[] =
{
{56, 23, "hello"},
{-1, 93463, "world"},
{7, 5, "!!" }
};
* ``AIAS_Right`` (in configuration: ``Right``)
Align array column and right justify the columns e.g.:
.. code-block:: c++
struct test demo[] =
{
{56, 23, "hello"},
{-1, 93463, "world"},
{ 7, 5, "!!"}
};
* ``AIAS_None`` (in configuration: ``None``)
Don't align array initializer columns.
Jan 12, 2023
Jan 12, 2023
292
293
294
.. _AlignConsecutiveAssignments:
**AlignConsecutiveAssignments** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 3.8` :ref:`<AlignConsecutiveAssignments>`
Jan 25, 2021
Jan 25, 2021
295
Style of aligning consecutive assignments.
Apr 29, 2015
Apr 29, 2015
296
Jan 25, 2021
Jan 25, 2021
297
``Consecutive`` will result in formattings like:
Oct 6, 2015
Oct 6, 2015
298
Oct 6, 2015
Oct 6, 2015
299
.. code-block:: c++
Oct 7, 2015
Oct 7, 2015
300
Jan 25, 2021
Jan 25, 2021
301
302
303
int a = 1;
int somelongname = 2;
double c = 3;
Oct 6, 2015
Oct 6, 2015
304
Mar 14, 2022
Mar 14, 2022
305
306
307
308
309
Nested configuration flags:
Alignment options.
They can also be read as a whole for compatibility. The choices are:
Oct 8, 2024
Oct 8, 2024
310
311
312
313
314
315
* ``None``
* ``Consecutive``
* ``AcrossEmptyLines``
* ``AcrossComments``
* ``AcrossEmptyLinesAndComments``
Mar 14, 2022
Mar 14, 2022
316
317
318
319
320
321
For example, to align across empty lines and not across comments, either
of these work.
.. code-block:: c++
Mar 4, 2024
Mar 4, 2024
322
AlignConsecutiveAssignments: AcrossEmptyLines
Mar 14, 2022
Mar 14, 2022
323
Mar 4, 2024
Mar 4, 2024
324
AlignConsecutiveAssignments:
Mar 14, 2022
Mar 14, 2022
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
Enabled: true
AcrossEmptyLines: true
AcrossComments: false
* ``bool Enabled`` Whether aligning is enabled.
.. code-block:: c++
#define SHORT_NAME 42
#define LONGER_NAME 0x007f
#define EVEN_LONGER_NAME (2)
#define foo(x) (x * x)
#define bar(y, z) (y + z)
int a = 1;
int somelongname = 2;
double c = 3;
Jan 25, 2021
Jan 25, 2021
342
Mar 14, 2022
Mar 14, 2022
343
344
345
int aaaa : 1;
int b : 12;
int ccc : 8;
Jan 25, 2021
Jan 25, 2021
346
Mar 14, 2022
Mar 14, 2022
347
348
349
int aaaa = 12;
float b = 23;
std::string ccc;
Jan 25, 2021
Jan 25, 2021
350
Mar 14, 2022
Mar 14, 2022
351
* ``bool AcrossEmptyLines`` Whether to align across empty lines.
Jan 25, 2021
Jan 25, 2021
352
Mar 14, 2022
Mar 14, 2022
353
.. code-block:: c++
Jan 25, 2021
Jan 25, 2021
354
Mar 14, 2022
Mar 14, 2022
355
356
357
358
true:
int a = 1;
int somelongname = 2;
double c = 3;
Jan 25, 2021
Jan 25, 2021
359
Mar 14, 2022
Mar 14, 2022
360
int d = 3;
Jan 25, 2021
Jan 25, 2021
361
Mar 14, 2022
Mar 14, 2022
362
363
364
365
false:
int a = 1;
int somelongname = 2;
double c = 3;
Jan 25, 2021
Jan 25, 2021
366
Mar 14, 2022
Mar 14, 2022
367
int d = 3;
Jan 25, 2021
Jan 25, 2021
368
Mar 14, 2022
Mar 14, 2022
369
* ``bool AcrossComments`` Whether to align across comments.
Jan 25, 2021
Jan 25, 2021
370
Mar 14, 2022
Mar 14, 2022
371
.. code-block:: c++
Jan 25, 2021
Jan 25, 2021
372
Mar 14, 2022
Mar 14, 2022
373
374
375
376
true:
int d = 3;
/* A comment. */
double e = 4;
Jan 25, 2021
Jan 25, 2021
377
Mar 14, 2022
Mar 14, 2022
378
379
380
381
false:
int d = 3;
/* A comment. */
double e = 4;
Jan 25, 2021
Jan 25, 2021
382
Mar 17, 2022
Mar 17, 2022
383
384
* ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound assignments
like ``+=`` are aligned along with ``=``.
Jan 25, 2021
Jan 25, 2021
385
Mar 14, 2022
Mar 14, 2022
386
387
388
389
390
391
392
393
394
395
.. code-block:: c++
true:
a &= 2;
bbb = 2;
false:
a &= 2;
bbb = 2;
Oct 7, 2024
Oct 7, 2024
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
* ``bool AlignFunctionDeclarations`` Only for ``AlignConsecutiveDeclarations``. Whether function declarations
are aligned.
.. code-block:: c++
true:
unsigned int f1(void);
void f2(void);
size_t f3(void);
false:
unsigned int f1(void);
void f2(void);
size_t f3(void);
Jan 11, 2024
Jan 11, 2024
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
* ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are
aligned.
.. code-block:: c++
true:
unsigned i;
int &r;
int *p;
int (*f)();
false:
unsigned i;
int &r;
int *p;
int (*f)();
Mar 17, 2022
Mar 17, 2022
428
429
430
* ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment
operators are left-padded to the same length as long ones in order to
put all assignment operators to the right of the left hand side.
Mar 14, 2022
Mar 14, 2022
431
432
433
434
435
436
.. code-block:: c++
true:
a >>= 2;
bbb = 2;
Jan 25, 2021
Jan 25, 2021
437
Mar 14, 2022
Mar 14, 2022
438
439
a = 2;
bbb >>= 2;
Jan 25, 2021
Jan 25, 2021
440
Mar 14, 2022
Mar 14, 2022
441
442
443
false:
a >>= 2;
bbb = 2;
Jan 25, 2021
Jan 25, 2021
444
Mar 14, 2022
Mar 14, 2022
445
446
a = 2;
bbb >>= 2;
Jan 25, 2021
Jan 25, 2021
447
448
Jan 12, 2023
Jan 12, 2023
449
450
451
.. _AlignConsecutiveBitFields:
**AlignConsecutiveBitFields** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 11` :ref:`<AlignConsecutiveBitFields>`
Mar 14, 2022
Mar 14, 2022
452
Style of aligning consecutive bit fields.
May 20, 2020
May 20, 2020
453
Jan 25, 2021
Jan 25, 2021
454
455
``Consecutive`` will align the bitfield separators of consecutive lines.
This will result in formattings like:
May 20, 2020
May 20, 2020
456
457
458
459
460
461
462
.. code-block:: c++
int aaaa : 1;
int b : 12;
int ccc : 8;
Mar 14, 2022
Mar 14, 2022
463
464
465
466
467
Nested configuration flags:
Alignment options.
They can also be read as a whole for compatibility. The choices are:
Oct 8, 2024
Oct 8, 2024
468
469
470
471
472
473
* ``None``
* ``Consecutive``
* ``AcrossEmptyLines``
* ``AcrossComments``
* ``AcrossEmptyLinesAndComments``
Mar 14, 2022
Mar 14, 2022
474
475
476
477
478
479
For example, to align across empty lines and not across comments, either
of these work.
.. code-block:: c++
Mar 4, 2024
Mar 4, 2024
480
AlignConsecutiveBitFields: AcrossEmptyLines
Mar 14, 2022
Mar 14, 2022
481
Mar 4, 2024
Mar 4, 2024
482
AlignConsecutiveBitFields:
Mar 14, 2022
Mar 14, 2022
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
Enabled: true
AcrossEmptyLines: true
AcrossComments: false
* ``bool Enabled`` Whether aligning is enabled.
.. code-block:: c++
#define SHORT_NAME 42
#define LONGER_NAME 0x007f
#define EVEN_LONGER_NAME (2)
#define foo(x) (x * x)
#define bar(y, z) (y + z)
int a = 1;
int somelongname = 2;
double c = 3;
Jan 25, 2021
Jan 25, 2021
500
Mar 14, 2022
Mar 14, 2022
501
502
503
int aaaa : 1;
int b : 12;
int ccc : 8;
Jan 25, 2021
Jan 25, 2021
504
Mar 14, 2022
Mar 14, 2022
505
506
507
int aaaa = 12;
float b = 23;
std::string ccc;
Jan 25, 2021
Jan 25, 2021
508
Mar 14, 2022
Mar 14, 2022
509
* ``bool AcrossEmptyLines`` Whether to align across empty lines.
Jan 25, 2021
Jan 25, 2021
510
Mar 14, 2022
Mar 14, 2022
511
.. code-block:: c++
Jan 25, 2021
Jan 25, 2021
512
Mar 14, 2022
Mar 14, 2022
513
514
515
516
true:
int a = 1;
int somelongname = 2;
double c = 3;
Jan 25, 2021
Jan 25, 2021
517
Mar 14, 2022
Mar 14, 2022
518
int d = 3;
Jan 25, 2021
Jan 25, 2021
519
Mar 14, 2022
Mar 14, 2022
520
521
522
523
false:
int a = 1;
int somelongname = 2;
double c = 3;
Jan 25, 2021
Jan 25, 2021
524
Mar 14, 2022
Mar 14, 2022
525
int d = 3;
Jan 25, 2021
Jan 25, 2021
526
Mar 14, 2022
Mar 14, 2022
527
* ``bool AcrossComments`` Whether to align across comments.
Jan 25, 2021
Jan 25, 2021
528
Mar 14, 2022
Mar 14, 2022
529
.. code-block:: c++
Jan 25, 2021
Jan 25, 2021
530
Mar 14, 2022
Mar 14, 2022
531
532
533
534
true:
int d = 3;
/* A comment. */
double e = 4;
Jan 25, 2021
Jan 25, 2021
535
Mar 14, 2022
Mar 14, 2022
536
537
538
539
false:
int d = 3;
/* A comment. */
double e = 4;
Jan 25, 2021
Jan 25, 2021
540
Mar 17, 2022
Mar 17, 2022
541
542
* ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound assignments
like ``+=`` are aligned along with ``=``.
Jan 25, 2021
Jan 25, 2021
543
Mar 14, 2022
Mar 14, 2022
544
545
546
547
548
549
550
551
552
553
.. code-block:: c++
true:
a &= 2;
bbb = 2;
false:
a &= 2;
bbb = 2;
Oct 7, 2024
Oct 7, 2024
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
* ``bool AlignFunctionDeclarations`` Only for ``AlignConsecutiveDeclarations``. Whether function declarations
are aligned.
.. code-block:: c++
true:
unsigned int f1(void);
void f2(void);
size_t f3(void);
false:
unsigned int f1(void);
void f2(void);
size_t f3(void);
Jan 11, 2024
Jan 11, 2024
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
* ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are
aligned.
.. code-block:: c++
true:
unsigned i;
int &r;
int *p;
int (*f)();
false:
unsigned i;
int &r;
int *p;
int (*f)();
Mar 17, 2022
Mar 17, 2022
586
587
588
* ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment
operators are left-padded to the same length as long ones in order to
put all assignment operators to the right of the left hand side.
Mar 14, 2022
Mar 14, 2022
589
590
591
592
593
594
.. code-block:: c++
true:
a >>= 2;
bbb = 2;
Jan 25, 2021
Jan 25, 2021
595
Mar 14, 2022
Mar 14, 2022
596
597
a = 2;
bbb >>= 2;
Jan 25, 2021
Jan 25, 2021
598
Mar 14, 2022
Mar 14, 2022
599
600
601
false:
a >>= 2;
bbb = 2;
Jan 25, 2021
Jan 25, 2021
602
Mar 14, 2022
Mar 14, 2022
603
604
a = 2;
bbb >>= 2;
Jan 25, 2021
Jan 25, 2021
605
606
Jan 12, 2023
Jan 12, 2023
607
608
609
.. _AlignConsecutiveDeclarations:
**AlignConsecutiveDeclarations** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 3.8` :ref:`<AlignConsecutiveDeclarations>`
Jan 25, 2021
Jan 25, 2021
610
Style of aligning consecutive declarations.
Oct 6, 2015
Oct 6, 2015
611
Jan 25, 2021
Jan 25, 2021
612
613
``Consecutive`` will align the declaration names of consecutive lines.
This will result in formattings like:
Oct 6, 2015
Oct 6, 2015
614
Oct 6, 2015
Oct 6, 2015
615
.. code-block:: c++
Oct 7, 2015
Oct 7, 2015
616
Oct 6, 2015
Oct 6, 2015
617
618
int aaaa = 12;
float b = 23;
Jan 25, 2021
Jan 25, 2021
619
std::string ccc;
Apr 29, 2015
Apr 29, 2015
620
Mar 14, 2022
Mar 14, 2022
621
622
623
624
625
Nested configuration flags:
Alignment options.
They can also be read as a whole for compatibility. The choices are:
Oct 8, 2024
Oct 8, 2024
626
627
628
629
630
631
* ``None``
* ``Consecutive``
* ``AcrossEmptyLines``
* ``AcrossComments``
* ``AcrossEmptyLinesAndComments``
Mar 14, 2022
Mar 14, 2022
632
633
634
635
636
637
For example, to align across empty lines and not across comments, either
of these work.
.. code-block:: c++
Mar 4, 2024
Mar 4, 2024
638
AlignConsecutiveDeclarations: AcrossEmptyLines
Mar 14, 2022
Mar 14, 2022
639
Mar 4, 2024
Mar 4, 2024
640
AlignConsecutiveDeclarations:
Mar 14, 2022
Mar 14, 2022
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
Enabled: true
AcrossEmptyLines: true
AcrossComments: false
* ``bool Enabled`` Whether aligning is enabled.
.. code-block:: c++
#define SHORT_NAME 42
#define LONGER_NAME 0x007f
#define EVEN_LONGER_NAME (2)
#define foo(x) (x * x)
#define bar(y, z) (y + z)
int a = 1;
int somelongname = 2;
double c = 3;
Jan 25, 2021
Jan 25, 2021
658
Mar 14, 2022
Mar 14, 2022
659
660
661
int aaaa : 1;
int b : 12;
int ccc : 8;
Jan 25, 2021
Jan 25, 2021
662
Mar 14, 2022
Mar 14, 2022
663
664
665
int aaaa = 12;
float b = 23;
std::string ccc;
Jan 25, 2021
Jan 25, 2021
666
Mar 14, 2022
Mar 14, 2022
667
* ``bool AcrossEmptyLines`` Whether to align across empty lines.
Jan 25, 2021
Jan 25, 2021
668
Mar 14, 2022
Mar 14, 2022
669
.. code-block:: c++
Jan 25, 2021
Jan 25, 2021
670
Mar 14, 2022
Mar 14, 2022
671
672
673
674
true:
int a = 1;
int somelongname = 2;
double c = 3;
Jan 25, 2021
Jan 25, 2021
675
Mar 14, 2022
Mar 14, 2022
676
int d = 3;
Jan 25, 2021
Jan 25, 2021
677
Mar 14, 2022
Mar 14, 2022
678
679
680
681
false:
int a = 1;
int somelongname = 2;
double c = 3;
Jan 25, 2021
Jan 25, 2021
682
Mar 14, 2022
Mar 14, 2022
683
int d = 3;
Jan 25, 2021
Jan 25, 2021
684
Mar 14, 2022
Mar 14, 2022
685
* ``bool AcrossComments`` Whether to align across comments.
Jan 25, 2021
Jan 25, 2021
686
Mar 14, 2022
Mar 14, 2022
687
.. code-block:: c++
Jan 25, 2021
Jan 25, 2021
688
Mar 14, 2022
Mar 14, 2022
689
690
691
692
true:
int d = 3;
/* A comment. */
double e = 4;
Jan 25, 2021
Jan 25, 2021
693
Mar 14, 2022
Mar 14, 2022
694
695
696
697
false:
int d = 3;
/* A comment. */
double e = 4;
Jan 25, 2021
Jan 25, 2021
698
Mar 17, 2022
Mar 17, 2022
699
700
* ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound assignments
like ``+=`` are aligned along with ``=``.
Jan 25, 2021
Jan 25, 2021
701
Mar 14, 2022
Mar 14, 2022
702
703
704
705
706
707
708
709
710
711
.. code-block:: c++
true:
a &= 2;
bbb = 2;
false:
a &= 2;
bbb = 2;
Oct 7, 2024
Oct 7, 2024
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
* ``bool AlignFunctionDeclarations`` Only for ``AlignConsecutiveDeclarations``. Whether function declarations
are aligned.
.. code-block:: c++
true:
unsigned int f1(void);
void f2(void);
size_t f3(void);
false:
unsigned int f1(void);
void f2(void);
size_t f3(void);
Jan 11, 2024
Jan 11, 2024
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
* ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are
aligned.
.. code-block:: c++
true:
unsigned i;
int &r;
int *p;
int (*f)();
false:
unsigned i;
int &r;
int *p;
int (*f)();
Mar 17, 2022
Mar 17, 2022
744
745
746
* ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment
operators are left-padded to the same length as long ones in order to
put all assignment operators to the right of the left hand side.
Mar 14, 2022
Mar 14, 2022
747
748
749
750
751
752
.. code-block:: c++
true:
a >>= 2;
bbb = 2;
Jan 25, 2021
Jan 25, 2021
753
Mar 14, 2022
Mar 14, 2022
754
755
a = 2;
bbb >>= 2;
Jan 25, 2021
Jan 25, 2021
756
Mar 14, 2022
Mar 14, 2022
757
758
759
false:
a >>= 2;
bbb = 2;
Jan 25, 2021
Jan 25, 2021
760
Mar 14, 2022
Mar 14, 2022
761
762
a = 2;
bbb >>= 2;
Jan 25, 2021
Jan 25, 2021
763
764
Jan 12, 2023
Jan 12, 2023
765
766
767
.. _AlignConsecutiveMacros:
**AlignConsecutiveMacros** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 9` :ref:`<AlignConsecutiveMacros>`
Jan 25, 2021
Jan 25, 2021
768
Style of aligning consecutive macro definitions.
Aug 10, 2019
Aug 10, 2019
769
Jan 25, 2021
Jan 25, 2021
770
``Consecutive`` will result in formattings like:
Aug 10, 2019
Aug 10, 2019
771
772
773
774
775
776
777
778
779
.. code-block:: c++
#define SHORT_NAME 42
#define LONGER_NAME 0x007f
#define EVEN_LONGER_NAME (2)
#define foo(x) (x * x)
#define bar(y, z) (y + z)
Mar 14, 2022
Mar 14, 2022
780
781
782
783
784
Nested configuration flags:
Alignment options.
They can also be read as a whole for compatibility. The choices are:
Oct 8, 2024
Oct 8, 2024
785
786
787
788
789
790
* ``None``
* ``Consecutive``
* ``AcrossEmptyLines``
* ``AcrossComments``
* ``AcrossEmptyLinesAndComments``
Mar 14, 2022
Mar 14, 2022
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
For example, to align across empty lines and not across comments, either
of these work.
.. code-block:: c++
AlignConsecutiveMacros: AcrossEmptyLines
AlignConsecutiveMacros:
Enabled: true
AcrossEmptyLines: true
AcrossComments: false
* ``bool Enabled`` Whether aligning is enabled.
.. code-block:: c++
#define SHORT_NAME 42
#define LONGER_NAME 0x007f
#define EVEN_LONGER_NAME (2)
#define foo(x) (x * x)
#define bar(y, z) (y + z)
int a = 1;
int somelongname = 2;
double c = 3;
Jan 25, 2021
Jan 25, 2021
817
Mar 14, 2022
Mar 14, 2022
818
819
820
int aaaa : 1;
int b : 12;
int ccc : 8;
Jan 25, 2021
Jan 25, 2021
821
Mar 14, 2022
Mar 14, 2022
822
823
824
int aaaa = 12;
float b = 23;
std::string ccc;
Jan 25, 2021
Jan 25, 2021
825
Mar 14, 2022
Mar 14, 2022
826
* ``bool AcrossEmptyLines`` Whether to align across empty lines.
Jan 25, 2021
Jan 25, 2021
827
Mar 14, 2022
Mar 14, 2022
828
.. code-block:: c++
Jan 25, 2021
Jan 25, 2021
829
Mar 14, 2022
Mar 14, 2022
830
831
832
833
true:
int a = 1;
int somelongname = 2;
double c = 3;
Jan 25, 2021
Jan 25, 2021
834
Mar 14, 2022
Mar 14, 2022
835
int d = 3;
Jan 25, 2021
Jan 25, 2021
836
Mar 14, 2022
Mar 14, 2022
837
838
839
840
false:
int a = 1;
int somelongname = 2;
double c = 3;
Jan 25, 2021
Jan 25, 2021
841
Mar 14, 2022
Mar 14, 2022
842
int d = 3;
Jan 25, 2021
Jan 25, 2021
843
Mar 14, 2022
Mar 14, 2022
844
* ``bool AcrossComments`` Whether to align across comments.
Jan 25, 2021
Jan 25, 2021
845
Mar 14, 2022
Mar 14, 2022
846
.. code-block:: c++
Jan 25, 2021
Jan 25, 2021
847
Mar 14, 2022
Mar 14, 2022
848
849
850
851
true:
int d = 3;
/* A comment. */
double e = 4;
Jan 25, 2021
Jan 25, 2021
852
Mar 14, 2022
Mar 14, 2022
853
854
855
856
false:
int d = 3;
/* A comment. */
double e = 4;
Jan 25, 2021
Jan 25, 2021
857
Mar 17, 2022
Mar 17, 2022
858
859
* ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound assignments
like ``+=`` are aligned along with ``=``.
Jan 25, 2021
Jan 25, 2021
860
Mar 14, 2022
Mar 14, 2022
861
862
863
864
865
866
867
868
869
870
.. code-block:: c++
true:
a &= 2;
bbb = 2;
false:
a &= 2;
bbb = 2;
Oct 7, 2024
Oct 7, 2024
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
* ``bool AlignFunctionDeclarations`` Only for ``AlignConsecutiveDeclarations``. Whether function declarations
are aligned.
.. code-block:: c++
true:
unsigned int f1(void);
void f2(void);
size_t f3(void);
false:
unsigned int f1(void);
void f2(void);
size_t f3(void);
Jan 11, 2024
Jan 11, 2024
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
* ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are
aligned.
.. code-block:: c++
true:
unsigned i;
int &r;
int *p;
int (*f)();
false:
unsigned i;
int &r;
int *p;
int (*f)();
Mar 17, 2022
Mar 17, 2022
903
904
905
* ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment
operators are left-padded to the same length as long ones in order to
put all assignment operators to the right of the left hand side.
Mar 14, 2022
Mar 14, 2022
906
907
908
909
910
911
.. code-block:: c++
true:
a >>= 2;
bbb = 2;
Jan 25, 2021
Jan 25, 2021
912
Mar 14, 2022
Mar 14, 2022
913
914
a = 2;
bbb >>= 2;
Jan 25, 2021
Jan 25, 2021
915
Mar 14, 2022
Mar 14, 2022
916
917
918
false:
a >>= 2;
bbb = 2;
Jan 25, 2021
Jan 25, 2021
919
Mar 14, 2022
Mar 14, 2022
920
921
a = 2;
bbb >>= 2;
Jan 25, 2021
Jan 25, 2021
922
923
Jul 25, 2023
Jul 25, 2023
924
925
926
927
.. _AlignConsecutiveShortCaseStatements:
**AlignConsecutiveShortCaseStatements** (``ShortCaseStatementsAlignmentStyle``) :versionbadge:`clang-format 17` :ref:`<AlignConsecutiveShortCaseStatements>`
Style of aligning consecutive short case labels.
May 7, 2024
May 7, 2024
928
929
Only applies if ``AllowShortCaseExpressionOnASingleLine`` or
``AllowShortCaseLabelsOnASingleLine`` is ``true``.
Jul 25, 2023
Jul 25, 2023
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
.. code-block:: yaml
# Example of usage:
AlignConsecutiveShortCaseStatements:
Enabled: true
AcrossEmptyLines: true
AcrossComments: true
AlignCaseColons: false
Nested configuration flags:
Alignment options.
* ``bool Enabled`` Whether aligning is enabled.
.. code-block:: c++
true:
switch (level) {
case log::info: return "info:";
case log::warning: return "warning:";
default: return "";
}
false:
switch (level) {
case log::info: return "info:";
case log::warning: return "warning:";
default: return "";
}
* ``bool AcrossEmptyLines`` Whether to align across empty lines.
.. code-block:: c++
true:
switch (level) {
case log::info: return "info:";
case log::warning: return "warning:";
default: return "";
}
false:
switch (level) {
case log::info: return "info:";
case log::warning: return "warning:";
default: return "";
}
* ``bool AcrossComments`` Whether to align across comments.
.. code-block:: c++
true:
switch (level) {
case log::info: return "info:";
case log::warning: return "warning:";
/* A comment. */
default: return "";
}
false:
switch (level) {
case log::info: return "info:";
case log::warning: return "warning:";
/* A comment. */
default: return "";