| 1 |
.. |
| 2 |
!!!!NOTE!!!! |
| 3 |
This file is automatically generated, in part. Do not edit the style options |
| 4 |
in this file directly. Instead, modify them in include/clang/Format/Format.h |
| 5 |
and run the docs/tools/dump_format_style.py script to update this file. |
| 6 |
|
| 7 |
.. raw:: html |
| 8 |
|
| 9 |
<style type="text/css"> |
| 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"; } |
| 11 |
</style> |
| 12 |
|
| 13 |
.. role:: versionbadge |
| 14 |
|
| 15 |
========================== |
| 16 |
Clang-Format Style Options |
| 17 |
========================== |
| 18 |
|
| 19 |
:doc:`ClangFormatStyleOptions` describes configurable formatting style options |
| 20 |
supported by :doc:`LibFormat` and :doc:`ClangFormat`. |
| 21 |
|
| 22 |
When using :program:`clang-format` command line utility or |
| 23 |
``clang::format::reformat(...)`` functions from code, one can either use one of |
| 24 |
the predefined styles (LLVM, Google, Chromium, Mozilla, WebKit, Microsoft) or |
| 25 |
create a custom style by configuring specific style options. |
| 26 |
|
| 27 |
|
| 28 |
Configuring Style with clang-format |
| 29 |
=================================== |
| 30 |
|
| 31 |
:program:`clang-format` supports two ways to provide custom style options: |
| 32 |
directly specify style configuration in the ``-style=`` command line option or |
| 33 |
use ``-style=file`` and put style configuration in the ``.clang-format`` or |
| 34 |
``_clang-format`` file in the project directory. |
| 35 |
|
| 36 |
When using ``-style=file``, :program:`clang-format` for each input file will |
| 37 |
try to find the ``.clang-format`` file located in the closest parent directory |
| 38 |
of the input file. When the standard input is used, the search is started from |
| 39 |
the current directory. |
| 40 |
|
| 41 |
When using ``-style=file:<format_file_path>``, :program:`clang-format` for |
| 42 |
each input file will use the format file located at `<format_file_path>`. |
| 43 |
The path may be absolute or relative to the working directory. |
| 44 |
|
| 45 |
The ``.clang-format`` file uses YAML format: |
| 46 |
|
| 47 |
.. code-block:: yaml |
| 48 |
|
| 49 |
key1: value1 |
| 50 |
key2: value2 |
| 51 |
# A comment. |
| 52 |
... |
| 53 |
|
| 54 |
The configuration file can consist of several sections each having different |
| 55 |
``Language:`` parameter denoting the programming language this section of the |
| 56 |
configuration is targeted at. See the description of the **Language** option |
| 57 |
below for the list of supported languages. The first section may have no |
| 58 |
language set, it will set the default style options for all languages. |
| 59 |
Configuration sections for specific language will override options set in the |
| 60 |
default section. |
| 61 |
|
| 62 |
When :program:`clang-format` formats a file, it auto-detects the language using |
| 63 |
the file name. When formatting standard input or a file that doesn't have the |
| 64 |
extension corresponding to its language, ``-assume-filename=`` option can be |
| 65 |
used to override the file name :program:`clang-format` uses to detect the |
| 66 |
language. |
| 67 |
|
| 68 |
An example of a configuration file for multiple languages: |
| 69 |
|
| 70 |
.. code-block:: yaml |
| 71 |
|
| 72 |
--- |
| 73 |
# We'll use defaults from the LLVM style, but with 4 columns indentation. |
| 74 |
BasedOnStyle: LLVM |
| 75 |
IndentWidth: 4 |
| 76 |
--- |
| 77 |
Language: Cpp |
| 78 |
# Force pointers to the type for C++. |
| 79 |
DerivePointerAlignment: false |
| 80 |
PointerAlignment: Left |
| 81 |
--- |
| 82 |
Language: JavaScript |
| 83 |
# Use 100 columns for JS. |
| 84 |
ColumnLimit: 100 |
| 85 |
--- |
| 86 |
Language: Proto |
| 87 |
# Don't format .proto files. |
| 88 |
DisableFormat: true |
| 89 |
--- |
| 90 |
Language: CSharp |
| 91 |
# Use 100 columns for C#. |
| 92 |
ColumnLimit: 100 |
| 93 |
... |
| 94 |
|
| 95 |
An easy way to get a valid ``.clang-format`` file containing all configuration |
| 96 |
options of a certain predefined style is: |
| 97 |
|
| 98 |
.. code-block:: console |
| 99 |
|
| 100 |
clang-format -style=llvm -dump-config > .clang-format |
| 101 |
|
| 102 |
When specifying configuration in the ``-style=`` option, the same configuration |
| 103 |
is applied for all input files. The format of the configuration is: |
| 104 |
|
| 105 |
.. code-block:: console |
| 106 |
|
| 107 |
-style='{key1: value1, key2: value2, ...}' |
| 108 |
|
| 109 |
|
| 110 |
Disabling Formatting on a Piece of Code |
| 111 |
======================================= |
| 112 |
|
| 113 |
Clang-format understands also special comments that switch formatting in a |
| 114 |
delimited range. The code between a comment ``// clang-format off`` or |
| 115 |
``/* clang-format off */`` up to a comment ``// clang-format on`` or |
| 116 |
``/* clang-format on */`` will not be formatted. The comments themselves will be |
| 117 |
formatted (aligned) normally. Also, a colon (``:``) and additional text may |
| 118 |
follow ``// clang-format off`` or ``// clang-format on`` to explain why |
| 119 |
clang-format is turned off or back on. |
| 120 |
|
| 121 |
.. code-block:: c++ |
| 122 |
|
| 123 |
int formatted_code; |
| 124 |
// clang-format off |
| 125 |
void unformatted_code ; |
| 126 |
// clang-format on |
| 127 |
void formatted_code_again; |
| 128 |
|
| 129 |
|
| 130 |
Configuring Style in Code |
| 131 |
========================= |
| 132 |
|
| 133 |
When using ``clang::format::reformat(...)`` functions, the format is specified |
| 134 |
by supplying the `clang::format::FormatStyle |
| 135 |
<https://clang.llvm.org/doxygen/structclang_1_1format_1_1FormatStyle.html>`_ |
| 136 |
structure. |
| 137 |
|
| 138 |
|
| 139 |
Configurable Format Style Options |
| 140 |
================================= |
| 141 |
|
| 142 |
This section lists the supported style options. Value type is specified for |
| 143 |
each option. For enumeration types possible values are specified both as a C++ |
| 144 |
enumeration member (with a prefix, e.g. ``LS_Auto``), and as a value usable in |
| 145 |
the configuration (without a prefix: ``Auto``). |
| 146 |
|
| 147 |
.. _BasedOnStyle: |
| 148 |
|
| 149 |
**BasedOnStyle** (``String``) :ref:`¶ <BasedOnStyle>` |
| 150 |
The style used for all options not specifically set in the configuration. |
| 151 |
|
| 152 |
This option is supported only in the :program:`clang-format` configuration |
| 153 |
(both within ``-style='{...}'`` and the ``.clang-format`` file). |
| 154 |
|
| 155 |
Possible values: |
| 156 |
|
| 157 |
* ``LLVM`` |
| 158 |
A style complying with the `LLVM coding standards |
| 159 |
<https://llvm.org/docs/CodingStandards.html>`_ |
| 160 |
* ``Google`` |
| 161 |
A style complying with `Google's C++ style guide |
| 162 |
<https://google.github.io/styleguide/cppguide.html>`_ |
| 163 |
* ``Chromium`` |
| 164 |
A style complying with `Chromium's style guide |
| 165 |
<https://chromium.googlesource.com/chromium/src/+/refs/heads/main/styleguide/styleguide.md>`_ |
| 166 |
* ``Mozilla`` |
| 167 |
A style complying with `Mozilla's style guide |
| 168 |
<https://firefox-source-docs.mozilla.org/code-quality/coding-style/index.html>`_ |
| 169 |
* ``WebKit`` |
| 170 |
A style complying with `WebKit's style guide |
| 171 |
<https://www.webkit.org/coding/coding-style.html>`_ |
| 172 |
* ``Microsoft`` |
| 173 |
A style complying with `Microsoft's style guide |
| 174 |
<https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference>`_ |
| 175 |
* ``GNU`` |
| 176 |
A style complying with the `GNU coding standards |
| 177 |
<https://www.gnu.org/prep/standards/standards.html>`_ |
| 178 |
* ``InheritParentConfig`` |
| 179 |
Not a real style, but allows to use the ``.clang-format`` file from the |
| 180 |
parent directory (or its parent if there is none). If there is no parent |
| 181 |
file found it falls back to the ``fallback`` style, and applies the changes |
| 182 |
to that. |
| 183 |
|
| 184 |
With this option you can overwrite some parts of your main style for your |
| 185 |
subdirectories. This is also possible through the command line, e.g.: |
| 186 |
``--style={BasedOnStyle: InheritParentConfig, ColumnLimit: 20}`` |
| 187 |
|
| 188 |
.. START_FORMAT_STYLE_OPTIONS |
| 189 |
|
| 190 |
.. _AccessModifierOffset: |
| 191 |
|
| 192 |
**AccessModifierOffset** (``Integer``) :versionbadge:`clang-format 3.3` :ref:`¶ <AccessModifierOffset>` |
| 193 |
The extra indent or outdent of access modifiers, e.g. ``public:``. |
| 194 |
|
| 195 |
.. _AlignAfterOpenBracket: |
| 196 |
|
| 197 |
**AlignAfterOpenBracket** (``BracketAlignmentStyle``) :versionbadge:`clang-format 3.8` :ref:`¶ <AlignAfterOpenBracket>` |
| 198 |
If ``true``, horizontally aligns arguments after an open bracket. |
| 199 |
|
| 200 |
This applies to round brackets (parentheses), angle brackets and square |
| 201 |
brackets. |
| 202 |
|
| 203 |
Possible values: |
| 204 |
|
| 205 |
* ``BAS_Align`` (in configuration: ``Align``) |
| 206 |
Align parameters on the open bracket, e.g.: |
| 207 |
|
| 208 |
.. code-block:: c++ |
| 209 |
|
| 210 |
someLongFunction(argument1, |
| 211 |
argument2); |
| 212 |
|
| 213 |
* ``BAS_DontAlign`` (in configuration: ``DontAlign``) |
| 214 |
Don't align, instead use ``ContinuationIndentWidth``, e.g.: |
| 215 |
|
| 216 |
.. code-block:: c++ |
| 217 |
|
| 218 |
someLongFunction(argument1, |
| 219 |
argument2); |
| 220 |
|
| 221 |
* ``BAS_AlwaysBreak`` (in configuration: ``AlwaysBreak``) |
| 222 |
Always break after an open bracket, if the parameters don't fit |
| 223 |
on a single line, e.g.: |
| 224 |
|
| 225 |
.. code-block:: c++ |
| 226 |
|
| 227 |
someLongFunction( |
| 228 |
argument1, argument2); |
| 229 |
|
| 230 |
* ``BAS_BlockIndent`` (in configuration: ``BlockIndent``) |
| 231 |
Always break after an open bracket, if the parameters don't fit |
| 232 |
on a single line. Closing brackets will be placed on a new line. |
| 233 |
E.g.: |
| 234 |
|
| 235 |
.. code-block:: c++ |
| 236 |
|
| 237 |
someLongFunction( |
| 238 |
argument1, argument2 |
| 239 |
) |
| 240 |
|
| 241 |
|
| 242 |
.. note:: |
| 243 |
|
| 244 |
This currently only applies to braced initializer lists (when |
| 245 |
``Cpp11BracedListStyle`` is ``true``) and parentheses. |
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
.. _AlignArrayOfStructures: |
| 250 |
|
| 251 |
**AlignArrayOfStructures** (``ArrayInitializerAlignmentStyle``) :versionbadge:`clang-format 13` :ref:`¶ <AlignArrayOfStructures>` |
| 252 |
if not ``None``, when using initialization for an array of structs |
| 253 |
aligns the fields into columns. |
| 254 |
|
| 255 |
|
| 256 |
.. note:: |
| 257 |
|
| 258 |
As of clang-format 15 this option only applied to arrays with equal |
| 259 |
number of columns per row. |
| 260 |
|
| 261 |
Possible values: |
| 262 |
|
| 263 |
* ``AIAS_Left`` (in configuration: ``Left``) |
| 264 |
Align array column and left justify the columns e.g.: |
| 265 |
|
| 266 |
.. code-block:: c++ |
| 267 |
|
| 268 |
struct test demo[] = |
| 269 |
{ |
| 270 |
{56, 23, "hello"}, |
| 271 |
{-1, 93463, "world"}, |
| 272 |
{7, 5, "!!" } |
| 273 |
}; |
| 274 |
|
| 275 |
* ``AIAS_Right`` (in configuration: ``Right``) |
| 276 |
Align array column and right justify the columns e.g.: |
| 277 |
|
| 278 |
.. code-block:: c++ |
| 279 |
|
| 280 |
struct test demo[] = |
| 281 |
{ |
| 282 |
{56, 23, "hello"}, |
| 283 |
{-1, 93463, "world"}, |
| 284 |
{ 7, 5, "!!"} |
| 285 |
}; |
| 286 |
|
| 287 |
* ``AIAS_None`` (in configuration: ``None``) |
| 288 |
Don't align array initializer columns. |
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
.. _AlignConsecutiveAssignments: |
| 293 |
|
| 294 |
**AlignConsecutiveAssignments** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 3.8` :ref:`¶ <AlignConsecutiveAssignments>` |
| 295 |
Style of aligning consecutive assignments. |
| 296 |
|
| 297 |
``Consecutive`` will result in formattings like: |
| 298 |
|
| 299 |
.. code-block:: c++ |
| 300 |
|
| 301 |
int a = 1; |
| 302 |
int somelongname = 2; |
| 303 |
double c = 3; |
| 304 |
|
| 305 |
Nested configuration flags: |
| 306 |
|
| 307 |
Alignment options. |
| 308 |
|
| 309 |
They can also be read as a whole for compatibility. The choices are: |
| 310 |
- None |
| 311 |
- Consecutive |
| 312 |
- AcrossEmptyLines |
| 313 |
- AcrossComments |
| 314 |
- AcrossEmptyLinesAndComments |
| 315 |
|
| 316 |
For example, to align across empty lines and not across comments, either |
| 317 |
of these work. |
| 318 |
|
| 319 |
.. code-block:: c++ |
| 320 |
|
| 321 |
AlignConsecutiveAssignments: AcrossEmptyLines |
| 322 |
|
| 323 |
AlignConsecutiveAssignments: |
| 324 |
Enabled: true |
| 325 |
AcrossEmptyLines: true |
| 326 |
AcrossComments: false |
| 327 |
|
| 328 |
* ``bool Enabled`` Whether aligning is enabled. |
| 329 |
|
| 330 |
.. code-block:: c++ |
| 331 |
|
| 332 |
#define SHORT_NAME 42 |
| 333 |
#define LONGER_NAME 0x007f |
| 334 |
#define EVEN_LONGER_NAME (2) |
| 335 |
#define foo(x) (x * x) |
| 336 |
#define bar(y, z) (y + z) |
| 337 |
|
| 338 |
int a = 1; |
| 339 |
int somelongname = 2; |
| 340 |
double c = 3; |
| 341 |
|
| 342 |
int aaaa : 1; |
| 343 |
int b : 12; |
| 344 |
int ccc : 8; |
| 345 |
|
| 346 |
int aaaa = 12; |
| 347 |
float b = 23; |
| 348 |
std::string ccc; |
| 349 |
|
| 350 |
* ``bool AcrossEmptyLines`` Whether to align across empty lines. |
| 351 |
|
| 352 |
.. code-block:: c++ |
| 353 |
|
| 354 |
true: |
| 355 |
int a = 1; |
| 356 |
int somelongname = 2; |
| 357 |
double c = 3; |
| 358 |
|
| 359 |
int d = 3; |
| 360 |
|
| 361 |
false: |
| 362 |
int a = 1; |
| 363 |
int somelongname = 2; |
| 364 |
double c = 3; |
| 365 |
|
| 366 |
int d = 3; |
| 367 |
|
| 368 |
* ``bool AcrossComments`` Whether to align across comments. |
| 369 |
|
| 370 |
.. code-block:: c++ |
| 371 |
|
| 372 |
true: |
| 373 |
int d = 3; |
| 374 |
/* A comment. */ |
| 375 |
double e = 4; |
| 376 |
|
| 377 |
false: |
| 378 |
int d = 3; |
| 379 |
/* A comment. */ |
| 380 |
double e = 4; |
| 381 |
|
| 382 |
* ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound assignments |
| 383 |
like ``+=`` are aligned along with ``=``. |
| 384 |
|
| 385 |
.. code-block:: c++ |
| 386 |
|
| 387 |
true: |
| 388 |
a &= 2; |
| 389 |
bbb = 2; |
| 390 |
|
| 391 |
false: |
| 392 |
a &= 2; |
| 393 |
bbb = 2; |
| 394 |
|
| 395 |
* ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are |
| 396 |
aligned. |
| 397 |
|
| 398 |
.. code-block:: c++ |
| 399 |
|
| 400 |
true: |
| 401 |
unsigned i; |
| 402 |
int &r; |
| 403 |
int *p; |
| 404 |
int (*f)(); |
| 405 |
|
| 406 |
false: |
| 407 |
unsigned i; |
| 408 |
int &r; |
| 409 |
int *p; |
| 410 |
int (*f)(); |
| 411 |
|
| 412 |
* ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment |
| 413 |
operators are left-padded to the same length as long ones in order to |
| 414 |
put all assignment operators to the right of the left hand side. |
| 415 |
|
| 416 |
.. code-block:: c++ |
| 417 |
|
| 418 |
true: |
| 419 |
a >>= 2; |
| 420 |
bbb = 2; |
| 421 |
|
| 422 |
a = 2; |
| 423 |
bbb >>= 2; |
| 424 |
|
| 425 |
false: |
| 426 |
a >>= 2; |
| 427 |
bbb = 2; |
| 428 |
|
| 429 |
a = 2; |
| 430 |
bbb >>= 2; |
| 431 |
|
| 432 |
|
| 433 |
.. _AlignConsecutiveBitFields: |
| 434 |
|
| 435 |
**AlignConsecutiveBitFields** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 11` :ref:`¶ <AlignConsecutiveBitFields>` |
| 436 |
Style of aligning consecutive bit fields. |
| 437 |
|
| 438 |
``Consecutive`` will align the bitfield separators of consecutive lines. |
| 439 |
This will result in formattings like: |
| 440 |
|
| 441 |
.. code-block:: c++ |
| 442 |
|
| 443 |
int aaaa : 1; |
| 444 |
int b : 12; |
| 445 |
int ccc : 8; |
| 446 |
|
| 447 |
Nested configuration flags: |
| 448 |
|
| 449 |
Alignment options. |
| 450 |
|
| 451 |
They can also be read as a whole for compatibility. The choices are: |
| 452 |
- None |
| 453 |
- Consecutive |
| 454 |
- AcrossEmptyLines |
| 455 |
- AcrossComments |
| 456 |
- AcrossEmptyLinesAndComments |
| 457 |
|
| 458 |
For example, to align across empty lines and not across comments, either |
| 459 |
of these work. |
| 460 |
|
| 461 |
.. code-block:: c++ |
| 462 |
|
| 463 |
AlignConsecutiveBitFields: AcrossEmptyLines |
| 464 |
|
| 465 |
AlignConsecutiveBitFields: |
| 466 |
Enabled: true |
| 467 |
AcrossEmptyLines: true |
| 468 |
AcrossComments: false |
| 469 |
|
| 470 |
* ``bool Enabled`` Whether aligning is enabled. |
| 471 |
|
| 472 |
.. code-block:: c++ |
| 473 |
|
| 474 |
#define SHORT_NAME 42 |
| 475 |
#define LONGER_NAME 0x007f |
| 476 |
#define EVEN_LONGER_NAME (2) |
| 477 |
#define foo(x) (x * x) |
| 478 |
#define bar(y, z) (y + z) |
| 479 |
|
| 480 |
int a = 1; |
| 481 |
int somelongname = 2; |
| 482 |
double c = 3; |
| 483 |
|
| 484 |
int aaaa : 1; |
| 485 |
int b : 12; |
| 486 |
int ccc : 8; |
| 487 |
|
| 488 |
int aaaa = 12; |
| 489 |
float b = 23; |
| 490 |
std::string ccc; |
| 491 |
|
| 492 |
* ``bool AcrossEmptyLines`` Whether to align across empty lines. |
| 493 |
|
| 494 |
.. code-block:: c++ |
| 495 |
|
| 496 |
true: |
| 497 |
int a = 1; |
| 498 |
int somelongname = 2; |
| 499 |
double c = 3; |
| 500 |
|
| 501 |
int d = 3; |
| 502 |
|
| 503 |
false: |
| 504 |
int a = 1; |
| 505 |
int somelongname = 2; |
| 506 |
double c = 3; |
| 507 |
|
| 508 |
int d = 3; |
| 509 |
|
| 510 |
* ``bool AcrossComments`` Whether to align across comments. |
| 511 |
|
| 512 |
.. code-block:: c++ |
| 513 |
|
| 514 |
true: |
| 515 |
int d = 3; |
| 516 |
/* A comment. */ |
| 517 |
double e = 4; |
| 518 |
|
| 519 |
false: |
| 520 |
int d = 3; |
| 521 |
/* A comment. */ |
| 522 |
double e = 4; |
| 523 |
|
| 524 |
* ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound assignments |
| 525 |
like ``+=`` are aligned along with ``=``. |
| 526 |
|
| 527 |
.. code-block:: c++ |
| 528 |
|
| 529 |
true: |
| 530 |
a &= 2; |
| 531 |
bbb = 2; |
| 532 |
|
| 533 |
false: |
| 534 |
a &= 2; |
| 535 |
bbb = 2; |
| 536 |
|
| 537 |
* ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are |
| 538 |
aligned. |
| 539 |
|
| 540 |
.. code-block:: c++ |
| 541 |
|
| 542 |
true: |
| 543 |
unsigned i; |
| 544 |
int &r; |
| 545 |
int *p; |
| 546 |
int (*f)(); |
| 547 |
|
| 548 |
false: |
| 549 |
unsigned i; |
| 550 |
int &r; |
| 551 |
int *p; |
| 552 |
int (*f)(); |
| 553 |
|
| 554 |
* ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment |
| 555 |
operators are left-padded to the same length as long ones in order to |
| 556 |
put all assignment operators to the right of the left hand side. |
| 557 |
|
| 558 |
.. code-block:: c++ |
| 559 |
|
| 560 |
true: |
| 561 |
a >>= 2; |
| 562 |
bbb = 2; |
| 563 |
|
| 564 |
a = 2; |
| 565 |
bbb >>= 2; |
| 566 |
|
| 567 |
false: |
| 568 |
a >>= 2; |
| 569 |
bbb = 2; |
| 570 |
|
| 571 |
a = 2; |
| 572 |
bbb >>= 2; |
| 573 |
|
| 574 |
|
| 575 |
.. _AlignConsecutiveDeclarations: |
| 576 |
|
| 577 |
**AlignConsecutiveDeclarations** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 3.8` :ref:`¶ <AlignConsecutiveDeclarations>` |
| 578 |
Style of aligning consecutive declarations. |
| 579 |
|
| 580 |
``Consecutive`` will align the declaration names of consecutive lines. |
| 581 |
This will result in formattings like: |
| 582 |
|
| 583 |
.. code-block:: c++ |
| 584 |
|
| 585 |
int aaaa = 12; |
| 586 |
float b = 23; |
| 587 |
std::string ccc; |
| 588 |
|
| 589 |
Nested configuration flags: |
| 590 |
|
| 591 |
Alignment options. |
| 592 |
|
| 593 |
They can also be read as a whole for compatibility. The choices are: |
| 594 |
- None |
| 595 |
- Consecutive |
| 596 |
- AcrossEmptyLines |
| 597 |
- AcrossComments |
| 598 |
- AcrossEmptyLinesAndComments |
| 599 |
|
| 600 |
For example, to align across empty lines and not across comments, either |
| 601 |
of these work. |
| 602 |
|
| 603 |
.. code-block:: c++ |
| 604 |
|
| 605 |
AlignConsecutiveDeclarations: AcrossEmptyLines |
| 606 |
|
| 607 |
AlignConsecutiveDeclarations: |
| 608 |
Enabled: true |
| 609 |
AcrossEmptyLines: true |
| 610 |
AcrossComments: false |
| 611 |
|
| 612 |
* ``bool Enabled`` Whether aligning is enabled. |
| 613 |
|
| 614 |
.. code-block:: c++ |
| 615 |
|
| 616 |
#define SHORT_NAME 42 |
| 617 |
#define LONGER_NAME 0x007f |
| 618 |
#define EVEN_LONGER_NAME (2) |
| 619 |
#define foo(x) (x * x) |
| 620 |
#define bar(y, z) (y + z) |
| 621 |
|
| 622 |
int a = 1; |
| 623 |
int somelongname = 2; |
| 624 |
double c = 3; |
| 625 |
|
| 626 |
int aaaa : 1; |
| 627 |
int b : 12; |
| 628 |
int ccc : 8; |
| 629 |
|
| 630 |
int aaaa = 12; |
| 631 |
float b = 23; |
| 632 |
std::string ccc; |
| 633 |
|
| 634 |
* ``bool AcrossEmptyLines`` Whether to align across empty lines. |
| 635 |
|
| 636 |
.. code-block:: c++ |
| 637 |
|
| 638 |
true: |
| 639 |
int a = 1; |
| 640 |
int somelongname = 2; |
| 641 |
double c = 3; |
| 642 |
|
| 643 |
int d = 3; |
| 644 |
|
| 645 |
false: |
| 646 |
int a = 1; |
| 647 |
int somelongname = 2; |
| 648 |
double c = 3; |
| 649 |
|
| 650 |
int d = 3; |
| 651 |
|
| 652 |
* ``bool AcrossComments`` Whether to align across comments. |
| 653 |
|
| 654 |
.. code-block:: c++ |
| 655 |
|
| 656 |
true: |
| 657 |
int d = 3; |
| 658 |
/* A comment. */ |
| 659 |
double e = 4; |
| 660 |
|
| 661 |
false: |
| 662 |
int d = 3; |
| 663 |
/* A comment. */ |
| 664 |
double e = 4; |
| 665 |
|
| 666 |
* ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound assignments |
| 667 |
like ``+=`` are aligned along with ``=``. |
| 668 |
|
| 669 |
.. code-block:: c++ |
| 670 |
|
| 671 |
true: |
| 672 |
a &= 2; |
| 673 |
bbb = 2; |
| 674 |
|
| 675 |
false: |
| 676 |
a &= 2; |
| 677 |
bbb = 2; |
| 678 |
|
| 679 |
* ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are |
| 680 |
aligned. |
| 681 |
|
| 682 |
.. code-block:: c++ |
| 683 |
|
| 684 |
true: |
| 685 |
unsigned i; |
| 686 |
int &r; |
| 687 |
int *p; |
| 688 |
int (*f)(); |
| 689 |
|
| 690 |
false: |
| 691 |
unsigned i; |
| 692 |
int &r; |
| 693 |
int *p; |
| 694 |
int (*f)(); |
| 695 |
|
| 696 |
* ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment |
| 697 |
operators are left-padded to the same length as long ones in order to |
| 698 |
put all assignment operators to the right of the left hand side. |
| 699 |
|
| 700 |
.. code-block:: c++ |
| 701 |
|
| 702 |
true: |
| 703 |
a >>= 2; |
| 704 |
bbb = 2; |
| 705 |
|
| 706 |
a = 2; |
| 707 |
bbb >>= 2; |
| 708 |
|
| 709 |
false: |
| 710 |
a >>= 2; |
| 711 |
bbb = 2; |
| 712 |
|
| 713 |
a = 2; |
| 714 |
bbb >>= 2; |
| 715 |
|
| 716 |
|
| 717 |
.. _AlignConsecutiveMacros: |
| 718 |
|
| 719 |
**AlignConsecutiveMacros** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 9` :ref:`¶ <AlignConsecutiveMacros>` |
| 720 |
Style of aligning consecutive macro definitions. |
| 721 |
|
| 722 |
``Consecutive`` will result in formattings like: |
| 723 |
|
| 724 |
.. code-block:: c++ |
| 725 |
|
| 726 |
#define SHORT_NAME 42 |
| 727 |
#define LONGER_NAME 0x007f |
| 728 |
#define EVEN_LONGER_NAME (2) |
| 729 |
#define foo(x) (x * x) |
| 730 |
#define bar(y, z) (y + z) |
| 731 |
|
| 732 |
Nested configuration flags: |
| 733 |
|
| 734 |
Alignment options. |
| 735 |
|
| 736 |
They can also be read as a whole for compatibility. The choices are: |
| 737 |
- None |
| 738 |
- Consecutive |
| 739 |
- AcrossEmptyLines |
| 740 |
- AcrossComments |
| 741 |
- AcrossEmptyLinesAndComments |
| 742 |
|
| 743 |
For example, to align across empty lines and not across comments, either |
| 744 |
of these work. |
| 745 |
|
| 746 |
.. code-block:: c++ |
| 747 |
|
| 748 |
AlignConsecutiveMacros: AcrossEmptyLines |
| 749 |
|
| 750 |
AlignConsecutiveMacros: |
| 751 |
Enabled: true |
| 752 |
AcrossEmptyLines: true |
| 753 |
AcrossComments: false |
| 754 |
|
| 755 |
* ``bool Enabled`` Whether aligning is enabled. |
| 756 |
|
| 757 |
.. code-block:: c++ |
| 758 |
|
| 759 |
#define SHORT_NAME 42 |
| 760 |
#define LONGER_NAME 0x007f |
| 761 |
#define EVEN_LONGER_NAME (2) |
| 762 |
#define foo(x) (x * x) |
| 763 |
#define bar(y, z) (y + z) |
| 764 |
|
| 765 |
int a = 1; |
| 766 |
int somelongname = 2; |
| 767 |
double c = 3; |
| 768 |
|
| 769 |
int aaaa : 1; |
| 770 |
int b : 12; |
| 771 |
int ccc : 8; |
| 772 |
|
| 773 |
int aaaa = 12; |
| 774 |
float b = 23; |
| 775 |
std::string ccc; |
| 776 |
|
| 777 |
* ``bool AcrossEmptyLines`` Whether to align across empty lines. |
| 778 |
|
| 779 |
.. code-block:: c++ |
| 780 |
|
| 781 |
true: |
| 782 |
int a = 1; |
| 783 |
int somelongname = 2; |
| 784 |
double c = 3; |
| 785 |
|
| 786 |
int d = 3; |
| 787 |
|
| 788 |
false: |
| 789 |
int a = 1; |
| 790 |
int somelongname = 2; |
| 791 |
double c = 3; |
| 792 |
|
| 793 |
int d = 3; |
| 794 |
|
| 795 |
* ``bool AcrossComments`` Whether to align across comments. |
| 796 |
|
| 797 |
.. code-block:: c++ |
| 798 |
|
| 799 |
true: |
| 800 |
int d = 3; |
| 801 |
/* A comment. */ |
| 802 |
double e = 4; |
| 803 |
|
| 804 |
false: |
| 805 |
int d = 3; |
| 806 |
/* A comment. */ |
| 807 |
double e = 4; |
| 808 |
|
| 809 |
* ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound assignments |
| 810 |
like ``+=`` are aligned along with ``=``. |
| 811 |
|
| 812 |
.. code-block:: c++ |
| 813 |
|
| 814 |
true: |
| 815 |
a &= 2; |
| 816 |
bbb = 2; |
| 817 |
|
| 818 |
false: |
| 819 |
a &= 2; |
| 820 |
bbb = 2; |
| 821 |
|
| 822 |
* ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are |
| 823 |
aligned. |
| 824 |
|
| 825 |
.. code-block:: c++ |
| 826 |
|
| 827 |
true: |
| 828 |
unsigned i; |
| 829 |
int &r; |
| 830 |
int *p; |
| 831 |
int (*f)(); |
| 832 |
|
| 833 |
false: |
| 834 |
unsigned i; |
| 835 |
int &r; |
| 836 |
int *p; |
| 837 |
int (*f)(); |
| 838 |
|
| 839 |
* ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment |
| 840 |
operators are left-padded to the same length as long ones in order to |
| 841 |
put all assignment operators to the right of the left hand side. |
| 842 |
|
| 843 |
.. code-block:: c++ |
| 844 |
|
| 845 |
true: |
| 846 |
a >>= 2; |
| 847 |
bbb = 2; |
| 848 |
|
| 849 |
a = 2; |
| 850 |
bbb >>= 2; |
| 851 |
|
| 852 |
false: |
| 853 |
a >>= 2; |
| 854 |
bbb = 2; |
| 855 |
|
| 856 |
a = 2; |
| 857 |
bbb >>= 2; |
| 858 |
|
| 859 |
|
| 860 |
.. _AlignConsecutiveShortCaseStatements: |
| 861 |
|
| 862 |
**AlignConsecutiveShortCaseStatements** (``ShortCaseStatementsAlignmentStyle``) :versionbadge:`clang-format 17` :ref:`¶ <AlignConsecutiveShortCaseStatements>` |
| 863 |
Style of aligning consecutive short case labels. |
| 864 |
Only applies if ``AllowShortCaseExpressionOnASingleLine`` or |
| 865 |
``AllowShortCaseLabelsOnASingleLine`` is ``true``. |
| 866 |
|
| 867 |
|
| 868 |
.. code-block:: yaml |
| 869 |
|
| 870 |
# Example of usage: |
| 871 |
AlignConsecutiveShortCaseStatements: |
| 872 |
Enabled: true |
| 873 |
AcrossEmptyLines: true |
| 874 |
AcrossComments: true |
| 875 |
AlignCaseColons: false |
| 876 |
|
| 877 |
Nested configuration flags: |
| 878 |
|
| 879 |
Alignment options. |
| 880 |
|
| 881 |
* ``bool Enabled`` Whether aligning is enabled. |
| 882 |
|
| 883 |
.. code-block:: c++ |
| 884 |
|
| 885 |
true: |
| 886 |
switch (level) { |
| 887 |
case log::info: return "info:"; |
| 888 |
case log::warning: return "warning:"; |
| 889 |
default: return ""; |
| 890 |
} |
| 891 |
|
| 892 |
false: |
| 893 |
switch (level) { |
| 894 |
case log::info: return "info:"; |
| 895 |
case log::warning: return "warning:"; |
| 896 |
default: return ""; |
| 897 |
} |
| 898 |
|
| 899 |
* ``bool AcrossEmptyLines`` Whether to align across empty lines. |
| 900 |
|
| 901 |
.. code-block:: c++ |
| 902 |
|
| 903 |
true: |
| 904 |
switch (level) { |
| 905 |
case log::info: return "info:"; |
| 906 |
case log::warning: return "warning:"; |
| 907 |
|
| 908 |
default: return ""; |
| 909 |
} |
| 910 |
|
| 911 |
false: |
| 912 |
switch (level) { |
| 913 |
case log::info: return "info:"; |
| 914 |
case log::warning: return "warning:"; |
| 915 |
|
| 916 |
default: return ""; |
| 917 |
} |
| 918 |
|
| 919 |
* ``bool AcrossComments`` Whether to align across comments. |
| 920 |
|
| 921 |
.. code-block:: c++ |
| 922 |
|
| 923 |
true: |
| 924 |
switch (level) { |
| 925 |
case log::info: return "info:"; |
| 926 |
case log::warning: return "warning:"; |
| 927 |
/* A comment. */ |
| 928 |
default: return ""; |
| 929 |
} |
| 930 |
|
| 931 |
false: |
| 932 |
switch (level) { |
| 933 |
case log::info: return "info:"; |
| 934 |
case log::warning: return "warning:"; |
| 935 |
/* A comment. */ |
| 936 |
default: return ""; |
| 937 |
} |
| 938 |
|
| 939 |
* ``bool AlignCaseArrows`` Whether to align the case arrows when aligning short case expressions. |
| 940 |
|
| 941 |
.. code-block:: java |
| 942 |
|
| 943 |
true: |
| 944 |
i = switch (day) { |
| 945 |
case THURSDAY, SATURDAY -> 8; |
| 946 |
case WEDNESDAY -> 9; |
| 947 |
default -> 0; |
| 948 |
}; |
| 949 |
|
| 950 |
false: |
| 951 |
i = switch (day) { |
| 952 |
case THURSDAY, SATURDAY -> 8; |
| 953 |
case WEDNESDAY -> 9; |
| 954 |
default -> 0; |
| 955 |
}; |
| 956 |
|
| 957 |
* ``bool AlignCaseColons`` Whether aligned case labels are aligned on the colon, or on the tokens |
| 958 |
after the colon. |
| 959 |
|
| 960 |
.. code-block:: c++ |
| 961 |
|
| 962 |
true: |
| 963 |
switch (level) { |
| 964 |
case log::info : return "info:"; |
| 965 |
case log::warning: return "warning:"; |
| 966 |
default : return ""; |
| 967 |
} |
| 968 |
|
| 969 |
false: |
| 970 |
switch (level) { |
| 971 |
case log::info: return "info:"; |
| 972 |
case log::warning: return "warning:"; |
| 973 |
default: return ""; |
| 974 |
} |
| 975 |
|
| 976 |
|
| 977 |
.. _AlignConsecutiveTableGenBreakingDAGArgColons: |
| 978 |
|
| 979 |
**AlignConsecutiveTableGenBreakingDAGArgColons** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 19` :ref:`¶ <AlignConsecutiveTableGenBreakingDAGArgColons>` |
| 980 |
Style of aligning consecutive TableGen DAGArg operator colons. |
| 981 |
If enabled, align the colon inside DAGArg which have line break inside. |
| 982 |
This works only when TableGenBreakInsideDAGArg is BreakElements or |
| 983 |
BreakAll and the DAGArg is not excepted by |
| 984 |
TableGenBreakingDAGArgOperators's effect. |
| 985 |
|
| 986 |
.. code-block:: c++ |
| 987 |
|
| 988 |
let dagarg = (ins |
| 989 |
a :$src1, |
| 990 |
aa :$src2, |
| 991 |
aaa:$src3 |
| 992 |
) |
| 993 |
|
| 994 |
Nested configuration flags: |
| 995 |
|
| 996 |
Alignment options. |
| 997 |
|
| 998 |
They can also be read as a whole for compatibility. The choices are: |
| 999 |
- None |
| 1000 |
- Consecutive |
| 1001 |
- AcrossEmptyLines |
| 1002 |
- AcrossComments |
| 1003 |
- AcrossEmptyLinesAndComments |
| 1004 |
|
| 1005 |
For example, to align across empty lines and not across comments, either |
| 1006 |
of these work. |
| 1007 |
|
| 1008 |
.. code-block:: c++ |
| 1009 |
|
| 1010 |
AlignConsecutiveTableGenBreakingDAGArgColons: AcrossEmptyLines |
| 1011 |
|
| 1012 |
AlignConsecutiveTableGenBreakingDAGArgColons: |
| 1013 |
Enabled: true |
| 1014 |
AcrossEmptyLines: true |
| 1015 |
AcrossComments: false |
| 1016 |
|
| 1017 |
* ``bool Enabled`` Whether aligning is enabled. |
| 1018 |
|
| 1019 |
.. code-block:: c++ |
| 1020 |
|
| 1021 |
#define SHORT_NAME 42 |
| 1022 |
#define LONGER_NAME 0x007f |
| 1023 |
#define EVEN_LONGER_NAME (2) |
| 1024 |
#define foo(x) (x * x) |
| 1025 |
#define bar(y, z) (y + z) |
| 1026 |
|
| 1027 |
int a = 1; |
| 1028 |
int somelongname = 2; |
| 1029 |
double c = 3; |
| 1030 |
|
| 1031 |
int aaaa : 1; |
| 1032 |
int b : 12; |
| 1033 |
int ccc : 8; |
| 1034 |
|
| 1035 |
int aaaa = 12; |
| 1036 |
float b = 23; |
| 1037 |
std::string ccc; |
| 1038 |
|
| 1039 |
* ``bool AcrossEmptyLines`` Whether to align across empty lines. |
| 1040 |
|
| 1041 |
.. code-block:: c++ |
| 1042 |
|
| 1043 |
true: |
| 1044 |
int a = 1; |
| 1045 |
int somelongname = 2; |
| 1046 |
double c = 3; |
| 1047 |
|
| 1048 |
int d = 3; |
| 1049 |
|
| 1050 |
false: |
| 1051 |
int a = 1; |
| 1052 |
int somelongname = 2; |
| 1053 |
double c = 3; |
| 1054 |
|
| 1055 |
int d = 3; |
| 1056 |
|
| 1057 |
* ``bool AcrossComments`` Whether to align across comments. |
| 1058 |
|
| 1059 |
.. code-block:: c++ |
| 1060 |
|
| 1061 |
true: |
| 1062 |
int d = 3; |
| 1063 |
/* A comment. */ |
| 1064 |
double e = 4; |
| 1065 |
|
| 1066 |
false: |
| 1067 |
int d = 3; |
| 1068 |
/* A comment. */ |
| 1069 |
double e = 4; |
| 1070 |
|
| 1071 |
* ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound assignments |
| 1072 |
like ``+=`` are aligned along with ``=``. |
| 1073 |
|
| 1074 |
.. code-block:: c++ |
| 1075 |
|
| 1076 |
true: |
| 1077 |
a &= 2; |
| 1078 |
bbb = 2; |
| 1079 |
|
| 1080 |
false: |
| 1081 |
a &= 2; |
| 1082 |
bbb = 2; |
| 1083 |
|
| 1084 |
* ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are |
| 1085 |
aligned. |
| 1086 |
|
| 1087 |
.. code-block:: c++ |
| 1088 |
|
| 1089 |
true: |
| 1090 |
unsigned i; |
| 1091 |
int &r; |
| 1092 |
int *p; |
| 1093 |
int (*f)(); |
| 1094 |
|
| 1095 |
false: |
| 1096 |
unsigned i; |
| 1097 |
int &r; |
| 1098 |
int *p; |
| 1099 |
int (*f)(); |
| 1100 |
|
| 1101 |
* ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment |
| 1102 |
operators are left-padded to the same length as long ones in order to |
| 1103 |
put all assignment operators to the right of the left hand side. |
| 1104 |
|
| 1105 |
.. code-block:: c++ |
| 1106 |
|
| 1107 |
true: |
| 1108 |
a >>= 2; |
| 1109 |
bbb = 2; |
| 1110 |
|
| 1111 |
a = 2; |
| 1112 |
bbb >>= 2; |
| 1113 |
|
| 1114 |
false: |
| 1115 |
a >>= 2; |
| 1116 |
bbb = 2; |
| 1117 |
|
| 1118 |
a = 2; |
| 1119 |
bbb >>= 2; |
| 1120 |
|
| 1121 |
|
| 1122 |
.. _AlignConsecutiveTableGenCondOperatorColons: |
| 1123 |
|
| 1124 |
**AlignConsecutiveTableGenCondOperatorColons** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 19` :ref:`¶ <AlignConsecutiveTableGenCondOperatorColons>` |
| 1125 |
Style of aligning consecutive TableGen cond operator colons. |
| 1126 |
Align the colons of cases inside !cond operators. |
| 1127 |
|
| 1128 |
.. code-block:: c++ |
| 1129 |
|
| 1130 |
!cond(!eq(size, 1) : 1, |
| 1131 |
!eq(size, 16): 1, |
| 1132 |
true : 0) |
| 1133 |
|
| 1134 |
Nested configuration flags: |
| 1135 |
|
| 1136 |
Alignment options. |
| 1137 |
|
| 1138 |
They can also be read as a whole for compatibility. The choices are: |
| 1139 |
- None |
| 1140 |
- Consecutive |
| 1141 |
- AcrossEmptyLines |
| 1142 |
- AcrossComments |
| 1143 |
- AcrossEmptyLinesAndComments |
| 1144 |
|
| 1145 |
For example, to align across empty lines and not across comments, either |
| 1146 |
of these work. |
| 1147 |
|
| 1148 |
.. code-block:: c++ |
| 1149 |
|
| 1150 |
AlignConsecutiveTableGenCondOperatorColons: AcrossEmptyLines |
| 1151 |
|
| 1152 |
AlignConsecutiveTableGenCondOperatorColons: |
| 1153 |
Enabled: true |
| 1154 |
AcrossEmptyLines: true |
| 1155 |
AcrossComments: false |
| 1156 |
|
| 1157 |
* ``bool Enabled`` Whether aligning is enabled. |
| 1158 |
|
| 1159 |
.. code-block:: c++ |
| 1160 |
|
| 1161 |
#define SHORT_NAME 42 |
| 1162 |
#define LONGER_NAME 0x007f |
| 1163 |
#define EVEN_LONGER_NAME (2) |
| 1164 |
#define foo(x) (x * x) |
| 1165 |
#define bar(y, z) (y + z) |
| 1166 |
|
| 1167 |
int a = 1; |
| 1168 |
int somelongname = 2; |
| 1169 |
double c = 3; |
| 1170 |
|
| 1171 |
int aaaa : 1; |
| 1172 |
int b : 12; |
| 1173 |
int ccc : 8; |
| 1174 |
|
| 1175 |
int aaaa = 12; |
| 1176 |
float b = 23; |
| 1177 |
std::string ccc; |
| 1178 |
|
| 1179 |
* ``bool AcrossEmptyLines`` Whether to align across empty lines. |
| 1180 |
|
| 1181 |
.. code-block:: c++ |
| 1182 |
|
| 1183 |
true: |
| 1184 |
int a = 1; |
| 1185 |
int somelongname = 2; |
| 1186 |
double c = 3; |
| 1187 |
|
| 1188 |
int d = 3; |
| 1189 |
|
| 1190 |
false: |
| 1191 |
int a = 1; |
| 1192 |
int somelongname = 2; |
| 1193 |
double c = 3; |
| 1194 |
|
| 1195 |
int d = 3; |
| 1196 |
|
| 1197 |
* ``bool AcrossComments`` Whether to align across comments. |
| 1198 |
|
| 1199 |
.. code-block:: c++ |
| 1200 |
|
| 1201 |
true: |
| 1202 |
int d = 3; |
| 1203 |
/* A comment. */ |
| 1204 |
double e = 4; |
| 1205 |
|
| 1206 |
false: |
| 1207 |
int d = 3; |
| 1208 |
/* A comment. */ |
| 1209 |
double e = 4; |
| 1210 |
|
| 1211 |
* ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound assignments |
| 1212 |
like ``+=`` are aligned along with ``=``. |
| 1213 |
|
| 1214 |
.. code-block:: c++ |
| 1215 |
|
| 1216 |
true: |
| 1217 |
a &= 2; |
| 1218 |
bbb = 2; |
| 1219 |
|
| 1220 |
false: |
| 1221 |
a &= 2; |
| 1222 |
bbb = 2; |
| 1223 |
|
| 1224 |
* ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are |
| 1225 |
aligned. |
| 1226 |
|
| 1227 |
.. code-block:: c++ |
| 1228 |
|
| 1229 |
true: |
| 1230 |
unsigned i; |
| 1231 |
int &r; |
| 1232 |
int *p; |
| 1233 |
int (*f)(); |
| 1234 |
|
| 1235 |
false: |
| 1236 |
unsigned i; |
| 1237 |
int &r; |
| 1238 |
int *p; |
| 1239 |
int (*f)(); |
| 1240 |
|
| 1241 |
* ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment |
| 1242 |
operators are left-padded to the same length as long ones in order to |
| 1243 |
put all assignment operators to the right of the left hand side. |
| 1244 |
|
| 1245 |
.. code-block:: c++ |
| 1246 |
|
| 1247 |
true: |
| 1248 |
a >>= 2; |
| 1249 |
bbb = 2; |
| 1250 |
|
| 1251 |
a = 2; |
| 1252 |
bbb >>= 2; |
| 1253 |
|
| 1254 |
false: |
| 1255 |
a >>= 2; |
| 1256 |
bbb = 2; |
| 1257 |
|
| 1258 |
a = 2; |
| 1259 |
bbb >>= 2; |
| 1260 |
|
| 1261 |
|
| 1262 |
.. _AlignConsecutiveTableGenDefinitionColons: |
| 1263 |
|
| 1264 |
**AlignConsecutiveTableGenDefinitionColons** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 19` :ref:`¶ <AlignConsecutiveTableGenDefinitionColons>` |
| 1265 |
Style of aligning consecutive TableGen definition colons. |
| 1266 |
This aligns the inheritance colons of consecutive definitions. |
| 1267 |
|
| 1268 |
.. code-block:: c++ |
| 1269 |
|
| 1270 |
def Def : Parent {} |
| 1271 |
def DefDef : Parent {} |
| 1272 |
def DefDefDef : Parent {} |
| 1273 |
|
| 1274 |
Nested configuration flags: |
| 1275 |
|
| 1276 |
Alignment options. |
| 1277 |
|
| 1278 |
They can also be read as a whole for compatibility. The choices are: |
| 1279 |
- None |
| 1280 |
- Consecutive |
| 1281 |
- AcrossEmptyLines |
| 1282 |
- AcrossComments |
| 1283 |
- AcrossEmptyLinesAndComments |
| 1284 |
|
| 1285 |
For example, to align across empty lines and not across comments, either |
| 1286 |
of these work. |
| 1287 |
|
| 1288 |
.. code-block:: c++ |
| 1289 |
|
| 1290 |
AlignConsecutiveTableGenDefinitionColons: AcrossEmptyLines |
| 1291 |
|
| 1292 |
AlignConsecutiveTableGenDefinitionColons: |
| 1293 |
Enabled: true |
| 1294 |
AcrossEmptyLines: true |
| 1295 |
AcrossComments: false |
| 1296 |
|
| 1297 |
* ``bool Enabled`` Whether aligning is enabled. |
| 1298 |
|
| 1299 |
.. code-block:: c++ |
| 1300 |
|
| 1301 |
#define SHORT_NAME 42 |
| 1302 |
#define LONGER_NAME 0x007f |
| 1303 |
#define EVEN_LONGER_NAME (2) |
| 1304 |
#define foo(x) (x * x) |
| 1305 |
#define bar(y, z) (y + z) |
| 1306 |
|
| 1307 |
int a = 1; |
| 1308 |
int somelongname = 2; |
| 1309 |
double c = 3; |
| 1310 |
|
| 1311 |
int aaaa : 1; |
| 1312 |
int b : 12; |
| 1313 |
int ccc : 8; |
| 1314 |
|
| 1315 |
int aaaa = 12; |
| 1316 |
float b = 23; |
| 1317 |
std::string ccc; |
| 1318 |
|
| 1319 |
* ``bool AcrossEmptyLines`` Whether to align across empty lines. |
| 1320 |
|
| 1321 |
.. code-block:: c++ |
| 1322 |
|
| 1323 |
true: |
| 1324 |
int a = 1; |
| 1325 |
int somelongname = 2; |
| 1326 |
double c = 3; |
| 1327 |
|
| 1328 |
int d = 3; |
| 1329 |
|
| 1330 |
false: |
| 1331 |
int a = 1; |
| 1332 |
int somelongname = 2; |
| 1333 |
double c = 3; |
| 1334 |
|
| 1335 |
int d = 3; |
| 1336 |
|
| 1337 |
* ``bool AcrossComments`` Whether to align across comments. |
| 1338 |
|
| 1339 |
.. code-block:: c++ |
| 1340 |
|
| 1341 |
true: |
| 1342 |
int d = 3; |
| 1343 |
/* A comment. */ |
| 1344 |
double e = 4; |
| 1345 |
|
| 1346 |
false: |
| 1347 |
int d = 3; |
| 1348 |
/* A comment. */ |
| 1349 |
double e = 4; |
| 1350 |
|
| 1351 |
* ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound assignments |
| 1352 |
like ``+=`` are aligned along with ``=``. |
| 1353 |
|
| 1354 |
.. code-block:: c++ |
| 1355 |
|
| 1356 |
true: |
| 1357 |
a &= 2; |
| 1358 |
bbb = 2; |
| 1359 |
|
| 1360 |
false: |
| 1361 |
a &= 2; |
| 1362 |
bbb = 2; |
| 1363 |
|
| 1364 |
* ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are |
| 1365 |
aligned. |
| 1366 |
|
| 1367 |
.. code-block:: c++ |
| 1368 |
|
| 1369 |
true: |
| 1370 |
unsigned i; |
| 1371 |
int &r; |
| 1372 |
int *p; |
| 1373 |
int (*f)(); |
| 1374 |
|
| 1375 |
false: |
| 1376 |
unsigned i; |
| 1377 |
int &r; |
| 1378 |
int *p; |
| 1379 |
int (*f)(); |
| 1380 |
|
| 1381 |
* ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment |
| 1382 |
operators are left-padded to the same length as long ones in order to |
| 1383 |
put all assignment operators to the right of the left hand side. |
| 1384 |
|
| 1385 |
.. code-block:: c++ |
| 1386 |
|
| 1387 |
true: |
| 1388 |
a >>= 2; |
| 1389 |
bbb = 2; |
| 1390 |
|
| 1391 |
a = 2; |
| 1392 |
bbb >>= 2; |
| 1393 |
|
| 1394 |
false: |
| 1395 |
a >>= 2; |
| 1396 |
bbb = 2; |
| 1397 |
|
| 1398 |
a = 2; |
| 1399 |
bbb >>= 2; |
| 1400 |
|
| 1401 |
|
| 1402 |
.. _AlignEscapedNewlines: |
| 1403 |
|
| 1404 |
**AlignEscapedNewlines** (``EscapedNewlineAlignmentStyle``) :versionbadge:`clang-format 5` :ref:`¶ <AlignEscapedNewlines>` |
| 1405 |
Options for aligning backslashes in escaped newlines. |
| 1406 |
|
| 1407 |
Possible values: |
| 1408 |
|
| 1409 |
* ``ENAS_DontAlign`` (in configuration: ``DontAlign``) |
| 1410 |
Don't align escaped newlines. |
| 1411 |
|
| 1412 |
.. code-block:: c++ |
| 1413 |
|
| 1414 |
#define A \ |
| 1415 |
int aaaa; \ |
| 1416 |
int b; \ |
| 1417 |
int dddddddddd; |
| 1418 |
|
| 1419 |
* ``ENAS_Left`` (in configuration: ``Left``) |
| 1420 |
Align escaped newlines as far left as possible. |
| 1421 |
|
| 1422 |
.. code-block:: c++ |
| 1423 |
|
| 1424 |
#define A \ |
| 1425 |
int aaaa; \ |
| 1426 |
int b; \ |
| 1427 |
int dddddddddd; |
| 1428 |
|
| 1429 |
* ``ENAS_LeftWithLastLine`` (in configuration: ``LeftWithLastLine``) |
| 1430 |
Align escaped newlines as far left as possible, using the last line of |
| 1431 |
the preprocessor directive as the reference if it's the longest. |
| 1432 |
|
| 1433 |
.. code-block:: c++ |
| 1434 |
|
| 1435 |
#define A \ |
| 1436 |
int aaaa; \ |
| 1437 |
int b; \ |
| 1438 |
int dddddddddd; |
| 1439 |
|
| 1440 |
* ``ENAS_Right`` (in configuration: ``Right``) |
| 1441 |
Align escaped newlines in the right-most column. |
| 1442 |
|
| 1443 |
.. code-block:: c++ |
| 1444 |
|
| 1445 |
#define A \ |
| 1446 |
int aaaa; \ |
| 1447 |
int b; \ |
| 1448 |
int dddddddddd; |
| 1449 |
|
| 1450 |
|
| 1451 |
|
| 1452 |
.. _AlignOperands: |
| 1453 |
|
| 1454 |
**AlignOperands** (``OperandAlignmentStyle``) :versionbadge:`clang-format 3.5` :ref:`¶ <AlignOperands>` |
| 1455 |
If ``true``, horizontally align operands of binary and ternary |
| 1456 |
expressions. |
| 1457 |
|
| 1458 |
Possible values: |
| 1459 |
|
| 1460 |
* ``OAS_DontAlign`` (in configuration: ``DontAlign``) |
| 1461 |
Do not align operands of binary and ternary expressions. |
| 1462 |
The wrapped lines are indented ``ContinuationIndentWidth`` spaces from |
| 1463 |
the start of the line. |
| 1464 |
|
| 1465 |
* ``OAS_Align`` (in configuration: ``Align``) |
| 1466 |
Horizontally align operands of binary and ternary expressions. |
| 1467 |
|
| 1468 |
Specifically, this aligns operands of a single expression that needs |
| 1469 |
to be split over multiple lines, e.g.: |
| 1470 |
|
| 1471 |
.. code-block:: c++ |
| 1472 |
|
| 1473 |
int aaa = bbbbbbbbbbbbbbb + |
| 1474 |
ccccccccccccccc; |
| 1475 |
|
| 1476 |
When ``BreakBeforeBinaryOperators`` is set, the wrapped operator is |
| 1477 |
aligned with the operand on the first line. |
| 1478 |
|
| 1479 |
.. code-block:: c++ |
| 1480 |
|
| 1481 |
int aaa = bbbbbbbbbbbbbbb |
| 1482 |
+ ccccccccccccccc; |
| 1483 |
|
| 1484 |
* ``OAS_AlignAfterOperator`` (in configuration: ``AlignAfterOperator``) |
| 1485 |
Horizontally align operands of binary and ternary expressions. |
| 1486 |
|
| 1487 |
This is similar to ``AO_Align``, except when |
| 1488 |
``BreakBeforeBinaryOperators`` is set, the operator is un-indented so |
| 1489 |
that the wrapped operand is aligned with the operand on the first line. |
| 1490 |
|
| 1491 |
.. code-block:: c++ |
| 1492 |
|
| 1493 |
int aaa = bbbbbbbbbbbbbbb |
| 1494 |
+ ccccccccccccccc; |
| 1495 |
|
| 1496 |
|
| 1497 |
|
| 1498 |
.. _AlignTrailingComments: |
| 1499 |
|
| 1500 |
**AlignTrailingComments** (``TrailingCommentsAlignmentStyle``) :versionbadge:`clang-format 3.7` :ref:`¶ <AlignTrailingComments>` |
| 1501 |
Control of trailing comments. |
| 1502 |
|
| 1503 |
The alignment stops at closing braces after a line break, and only |
| 1504 |
followed by other closing braces, a (``do-``) ``while``, a lambda call, or |
| 1505 |
a semicolon. |
| 1506 |
|
| 1507 |
|
| 1508 |
.. note:: |
| 1509 |
|
| 1510 |
As of clang-format 16 this option is not a bool but can be set |
| 1511 |
to the options. Conventional bool options still can be parsed as before. |
| 1512 |
|
| 1513 |
|
| 1514 |
.. code-block:: yaml |
| 1515 |
|
| 1516 |
# Example of usage: |
| 1517 |
AlignTrailingComments: |
| 1518 |
Kind: Always |
| 1519 |
OverEmptyLines: 2 |
| 1520 |
|
| 1521 |
Nested configuration flags: |
| 1522 |
|
| 1523 |
Alignment options |
| 1524 |
|
| 1525 |
* ``TrailingCommentsAlignmentKinds Kind`` |
| 1526 |
Specifies the way to align trailing comments. |
| 1527 |
|
| 1528 |
Possible values: |
| 1529 |
|
| 1530 |
* ``TCAS_Leave`` (in configuration: ``Leave``) |
| 1531 |
Leave trailing comments as they are. |
| 1532 |
|
| 1533 |
.. code-block:: c++ |
| 1534 |
|
| 1535 |
int a; // comment |
| 1536 |
int ab; // comment |
| 1537 |
|
| 1538 |
int abc; // comment |
| 1539 |
int abcd; // comment |
| 1540 |
|
| 1541 |
* ``TCAS_Always`` (in configuration: ``Always``) |
| 1542 |
Align trailing comments. |
| 1543 |
|
| 1544 |
.. code-block:: c++ |
| 1545 |
|
| 1546 |
int a; // comment |
| 1547 |
int ab; // comment |
| 1548 |
|
| 1549 |
int abc; // comment |
| 1550 |
int abcd; // comment |
| 1551 |
|
| 1552 |
* ``TCAS_Never`` (in configuration: ``Never``) |
| 1553 |
Don't align trailing comments but other formatter applies. |
| 1554 |
|
| 1555 |
.. code-block:: c++ |
| 1556 |
|
| 1557 |
int a; // comment |
| 1558 |
int ab; // comment |
| 1559 |
|
| 1560 |
int abc; // comment |
| 1561 |
int abcd; // comment |
| 1562 |
|
| 1563 |
|
| 1564 |
* ``unsigned OverEmptyLines`` How many empty lines to apply alignment. |
| 1565 |
When both ``MaxEmptyLinesToKeep`` and ``OverEmptyLines`` are set to 2, |
| 1566 |
it formats like below. |
| 1567 |
|
| 1568 |
.. code-block:: c++ |
| 1569 |
|
| 1570 |
int a; // all these |
| 1571 |
|
| 1572 |
int ab; // comments are |
| 1573 |
|
| 1574 |
|
| 1575 |
int abcdef; // aligned |
| 1576 |
|
| 1577 |
When ``MaxEmptyLinesToKeep`` is set to 2 and ``OverEmptyLines`` is set |
| 1578 |
to 1, it formats like below. |
| 1579 |
|
| 1580 |
.. code-block:: c++ |
| 1581 |
|
| 1582 |
int a; // these are |
| 1583 |
|
| 1584 |
int ab; // aligned |
| 1585 |
|
| 1586 |
|
| 1587 |
int abcdef; // but this isn't |
| 1588 |
|
| 1589 |
|
| 1590 |
.. _AllowAllArgumentsOnNextLine: |
| 1591 |
|
| 1592 |
**AllowAllArgumentsOnNextLine** (``Boolean``) :versionbadge:`clang-format 9` :ref:`¶ <AllowAllArgumentsOnNextLine>` |
| 1593 |
If a function call or braced initializer list doesn't fit on a |
| 1594 |
line, allow putting all arguments onto the next line, even if |
| 1595 |
``BinPackArguments`` is ``false``. |
| 1596 |
|
| 1597 |
.. code-block:: c++ |
| 1598 |
|
| 1599 |
true: |
| 1600 |
callFunction( |
| 1601 |
a, b, c, d); |
| 1602 |
|
| 1603 |
false: |
| 1604 |
callFunction(a, |
| 1605 |
b, |
| 1606 |
c, |
| 1607 |
d); |
| 1608 |
|
| 1609 |
.. _AllowAllConstructorInitializersOnNextLine: |
| 1610 |
|
| 1611 |
**AllowAllConstructorInitializersOnNextLine** (``Boolean``) :versionbadge:`clang-format 9` :ref:`¶ <AllowAllConstructorInitializersOnNextLine>` |
| 1612 |
This option is **deprecated**. See ``NextLine`` of |
| 1613 |
``PackConstructorInitializers``. |
| 1614 |
|
| 1615 |
.. _AllowAllParametersOfDeclarationOnNextLine: |
| 1616 |
|
| 1617 |
**AllowAllParametersOfDeclarationOnNextLine** (``Boolean``) :versionbadge:`clang-format 3.3` :ref:`¶ <AllowAllParametersOfDeclarationOnNextLine>` |
| 1618 |
If the function declaration doesn't fit on a line, |
| 1619 |
allow putting all parameters of a function declaration onto |
| 1620 |
the next line even if ``BinPackParameters`` is ``false``. |
| 1621 |
|
| 1622 |
.. code-block:: c++ |
| 1623 |
|
| 1624 |
true: |
| 1625 |
void myFunction( |
| 1626 |
int a, int b, int c, int d, int e); |
| 1627 |
|
| 1628 |
false: |
| 1629 |
void myFunction(int a, |
| 1630 |
int b, |
| 1631 |
int c, |
| 1632 |
int d, |
| 1633 |
int e); |
| 1634 |
|
| 1635 |
.. _AllowBreakBeforeNoexceptSpecifier: |
| 1636 |
|
| 1637 |
**AllowBreakBeforeNoexceptSpecifier** (``BreakBeforeNoexceptSpecifierStyle``) :versionbadge:`clang-format 18` :ref:`¶ <AllowBreakBeforeNoexceptSpecifier>` |
| 1638 |
Controls if there could be a line break before a ``noexcept`` specifier. |
| 1639 |
|
| 1640 |
Possible values: |
| 1641 |
|
| 1642 |
* ``BBNSS_Never`` (in configuration: ``Never``) |
| 1643 |
No line break allowed. |
| 1644 |
|
| 1645 |
.. code-block:: c++ |
| 1646 |
|
| 1647 |
void foo(int arg1, |
| 1648 |
double arg2) noexcept; |
| 1649 |
|
| 1650 |
void bar(int arg1, double arg2) noexcept( |
| 1651 |
noexcept(baz(arg1)) && |
| 1652 |
noexcept(baz(arg2))); |
| 1653 |
|
| 1654 |
* ``BBNSS_OnlyWithParen`` (in configuration: ``OnlyWithParen``) |
| 1655 |
For a simple ``noexcept`` there is no line break allowed, but when we |
| 1656 |
have a condition it is. |
| 1657 |
|
| 1658 |
.. code-block:: c++ |
| 1659 |
|
| 1660 |
void foo(int arg1, |
| 1661 |
double arg2) noexcept; |
| 1662 |
|
| 1663 |
void bar(int arg1, double arg2) |
| 1664 |
noexcept(noexcept(baz(arg1)) && |
| 1665 |
noexcept(baz(arg2))); |
| 1666 |
|
| 1667 |
* ``BBNSS_Always`` (in configuration: ``Always``) |
| 1668 |
Line breaks are allowed. But note that because of the associated |
| 1669 |
penalties ``clang-format`` often prefers not to break before the |
| 1670 |
``noexcept``. |
| 1671 |
|
| 1672 |
.. code-block:: c++ |
| 1673 |
|
| 1674 |
void foo(int arg1, |
| 1675 |
double arg2) noexcept; |
| 1676 |
|
| 1677 |
void bar(int arg1, double arg2) |
| 1678 |
noexcept(noexcept(baz(arg1)) && |
| 1679 |
noexcept(baz(arg2))); |
| 1680 |
|
| 1681 |
|
| 1682 |
|
| 1683 |
.. _AllowShortBlocksOnASingleLine: |
| 1684 |
|
| 1685 |
**AllowShortBlocksOnASingleLine** (``ShortBlockStyle``) :versionbadge:`clang-format 3.5` :ref:`¶ <AllowShortBlocksOnASingleLine>` |
| 1686 |
Dependent on the value, ``while (true) { continue; }`` can be put on a |
| 1687 |
single line. |
| 1688 |
|
| 1689 |
Possible values: |
| 1690 |
|
| 1691 |
* ``SBS_Never`` (in configuration: ``Never``) |
| 1692 |
Never merge blocks into a single line. |
| 1693 |
|
| 1694 |
.. code-block:: c++ |
| 1695 |
|
| 1696 |
while (true) { |
| 1697 |
} |
| 1698 |
while (true) { |
| 1699 |
continue; |
| 1700 |
} |
| 1701 |
|
| 1702 |
* ``SBS_Empty`` (in configuration: ``Empty``) |
| 1703 |
Only merge empty blocks. |
| 1704 |
|
| 1705 |
.. code-block:: c++ |
| 1706 |
|
| 1707 |
while (true) {} |
| 1708 |
while (true) { |
| 1709 |
continue; |
| 1710 |
} |
| 1711 |
|
| 1712 |
* ``SBS_Always`` (in configuration: ``Always``) |
| 1713 |
Always merge short blocks into a single line. |
| 1714 |
|
| 1715 |
.. code-block:: c++ |
| 1716 |
|
| 1717 |
while (true) {} |
| 1718 |
while (true) { continue; } |
| 1719 |
|
| 1720 |
|
| 1721 |
|
| 1722 |
.. _AllowShortCaseExpressionOnASingleLine: |
| 1723 |
|
| 1724 |
**AllowShortCaseExpressionOnASingleLine** (``Boolean``) :versionbadge:`clang-format 19` :ref:`¶ <AllowShortCaseExpressionOnASingleLine>` |
| 1725 |
Whether to merge a short switch labeled rule into a single line. |
| 1726 |
|
| 1727 |
.. code-block:: java |
| 1728 |
|
| 1729 |
true: false: |
| 1730 |
switch (a) { vs. switch (a) { |
| 1731 |
case 1 -> 1; case 1 -> |
| 1732 |
default -> 0; 1; |
| 1733 |
}; default -> |
| 1734 |
0; |
| 1735 |
}; |
| 1736 |
|
| 1737 |
.. _AllowShortCaseLabelsOnASingleLine: |
| 1738 |
|
| 1739 |
**AllowShortCaseLabelsOnASingleLine** (``Boolean``) :versionbadge:`clang-format 3.6` :ref:`¶ <AllowShortCaseLabelsOnASingleLine>` |
| 1740 |
If ``true``, short case labels will be contracted to a single line. |
| 1741 |
|
| 1742 |
.. code-block:: c++ |
| 1743 |
|
| 1744 |
true: false: |
| 1745 |
switch (a) { vs. switch (a) { |
| 1746 |
case 1: x = 1; break; case 1: |
| 1747 |
case 2: return; x = 1; |
| 1748 |
} break; |
| 1749 |
case 2: |
| 1750 |
return; |
| 1751 |
} |
| 1752 |
|
| 1753 |
.. _AllowShortCompoundRequirementOnASingleLine: |
| 1754 |
|
| 1755 |
**AllowShortCompoundRequirementOnASingleLine** (``Boolean``) :versionbadge:`clang-format 18` :ref:`¶ <AllowShortCompoundRequirementOnASingleLine>` |
| 1756 |
Allow short compound requirement on a single line. |
| 1757 |
|
| 1758 |
.. code-block:: c++ |
| 1759 |
|
| 1760 |
true: |
| 1761 |
template <typename T> |
| 1762 |
concept c = requires(T x) { |
| 1763 |
{ x + 1 } -> std::same_as<int>; |
| 1764 |
}; |
| 1765 |
|
| 1766 |
false: |
| 1767 |
template <typename T> |
| 1768 |
concept c = requires(T x) { |
| 1769 |
{ |
| 1770 |
x + 1 |
| 1771 |
} -> std::same_as<int>; |
| 1772 |
}; |
| 1773 |
|
| 1774 |
.. _AllowShortEnumsOnASingleLine: |
| 1775 |
|
| 1776 |
**AllowShortEnumsOnASingleLine** (``Boolean``) :versionbadge:`clang-format 11` :ref:`¶ <AllowShortEnumsOnASingleLine>` |
| 1777 |
Allow short enums on a single line. |
| 1778 |
|
| 1779 |
.. code-block:: c++ |
| 1780 |
|
| 1781 |
true: |
| 1782 |
enum { A, B } myEnum; |
| 1783 |
|
| 1784 |
false: |
| 1785 |
enum { |
| 1786 |
A, |
| 1787 |
B |
| 1788 |
} myEnum; |
| 1789 |
|
| 1790 |
.. _AllowShortFunctionsOnASingleLine: |
| 1791 |
|
| 1792 |
**AllowShortFunctionsOnASingleLine** (``ShortFunctionStyle``) :versionbadge:`clang-format 3.5` :ref:`¶ <AllowShortFunctionsOnASingleLine>` |
| 1793 |
Dependent on the value, ``int f() { return 0; }`` can be put on a |
| 1794 |
single line. |
| 1795 |
|
| 1796 |
Possible values: |
| 1797 |
|
| 1798 |
* ``SFS_None`` (in configuration: ``None``) |
| 1799 |
Never merge functions into a single line. |
| 1800 |
|
| 1801 |
* ``SFS_InlineOnly`` (in configuration: ``InlineOnly``) |
| 1802 |
Only merge functions defined inside a class. Same as ``inline``, |
| 1803 |
except it does not implies ``empty``: i.e. top level empty functions |
| 1804 |
are not merged either. |
| 1805 |
|
| 1806 |
.. code-block:: c++ |
| 1807 |
|
| 1808 |
class Foo { |
| 1809 |
void f() { foo(); } |
| 1810 |
}; |
| 1811 |
void f() { |
| 1812 |
foo(); |
| 1813 |
} |
| 1814 |
void f() { |
| 1815 |
} |
| 1816 |
|
| 1817 |
* ``SFS_Empty`` (in configuration: ``Empty``) |
| 1818 |
Only merge empty functions. |
| 1819 |
|
| 1820 |
.. code-block:: c++ |
| 1821 |
|
| 1822 |
void f() {} |
| 1823 |
void f2() { |
| 1824 |
bar2(); |
| 1825 |
} |
| 1826 |
|
| 1827 |
* ``SFS_Inline`` (in configuration: ``Inline``) |
| 1828 |
Only merge functions defined inside a class. Implies ``empty``. |
| 1829 |
|
| 1830 |
.. code-block:: c++ |
| 1831 |
|
| 1832 |
class Foo { |
| 1833 |
void f() { foo(); } |
| 1834 |
}; |
| 1835 |
void f() { |
| 1836 |
foo(); |
| 1837 |
} |
| 1838 |
void f() {} |
| 1839 |
|
| 1840 |
* ``SFS_All`` (in configuration: ``All``) |
| 1841 |
Merge all functions fitting on a single line. |
| 1842 |
|
| 1843 |
.. code-block:: c++ |
| 1844 |
|
| 1845 |
class Foo { |
| 1846 |
void f() { foo(); } |
| 1847 |
}; |
| 1848 |
void f() { bar(); } |
| 1849 |
|
| 1850 |
|
| 1851 |
|
| 1852 |
.. _AllowShortIfStatementsOnASingleLine: |
| 1853 |
|
| 1854 |
**AllowShortIfStatementsOnASingleLine** (``ShortIfStyle``) :versionbadge:`clang-format 3.3` :ref:`¶ <AllowShortIfStatementsOnASingleLine>` |
| 1855 |
Dependent on the value, ``if (a) return;`` can be put on a single line. |
| 1856 |
|
| 1857 |
Possible values: |
| 1858 |
|
| 1859 |
* ``SIS_Never`` (in configuration: ``Never``) |
| 1860 |
Never put short ifs on the same line. |
| 1861 |
|
| 1862 |
.. code-block:: c++ |
| 1863 |
|
| 1864 |
if (a) |
| 1865 |
return; |
| 1866 |
|
| 1867 |
if (b) |
| 1868 |
return; |
| 1869 |
else |
| 1870 |
return; |
| 1871 |
|
| 1872 |
if (c) |
| 1873 |
return; |
| 1874 |
else { |
| 1875 |
return; |
| 1876 |
} |
| 1877 |
|
| 1878 |
* ``SIS_WithoutElse`` (in configuration: ``WithoutElse``) |
| 1879 |
Put short ifs on the same line only if there is no else statement. |
| 1880 |
|
| 1881 |
.. code-block:: c++ |
| 1882 |
|
| 1883 |
if (a) return; |
| 1884 |
|
| 1885 |
if (b) |
| 1886 |
return; |
| 1887 |
else |
| 1888 |
return; |
| 1889 |
|
| 1890 |
if (c) |
| 1891 |
return; |
| 1892 |
else { |
| 1893 |
return; |
| 1894 |
} |
| 1895 |
|
| 1896 |
* ``SIS_OnlyFirstIf`` (in configuration: ``OnlyFirstIf``) |
| 1897 |
Put short ifs, but not else ifs nor else statements, on the same line. |
| 1898 |
|
| 1899 |
.. code-block:: c++ |
| 1900 |
|
| 1901 |
if (a) return; |
| 1902 |
|
| 1903 |
if (b) return; |
| 1904 |
else if (b) |
| 1905 |
return; |
| 1906 |
else |
| 1907 |
return; |
| 1908 |
|
| 1909 |
if (c) return; |
| 1910 |
else { |
| 1911 |
return; |
| 1912 |
} |
| 1913 |
|
| 1914 |
* ``SIS_AllIfsAndElse`` (in configuration: ``AllIfsAndElse``) |
| 1915 |
Always put short ifs, else ifs and else statements on the same |
| 1916 |
line. |
| 1917 |
|
| 1918 |
.. code-block:: c++ |
| 1919 |
|
| 1920 |
if (a) return; |
| 1921 |
|
| 1922 |
if (b) return; |
| 1923 |
else return; |
| 1924 |
|
| 1925 |
if (c) return; |
| 1926 |
else { |
| 1927 |
return; |
| 1928 |
} |
| 1929 |
|
| 1930 |
|
| 1931 |
|
| 1932 |
.. _AllowShortLambdasOnASingleLine: |
| 1933 |
|
| 1934 |
**AllowShortLambdasOnASingleLine** (``ShortLambdaStyle``) :versionbadge:`clang-format 9` :ref:`¶ <AllowShortLambdasOnASingleLine>` |
| 1935 |
Dependent on the value, ``auto lambda []() { return 0; }`` can be put on a |
| 1936 |
single line. |
| 1937 |
|
| 1938 |
Possible values: |
| 1939 |
|
| 1940 |
* ``SLS_None`` (in configuration: ``None``) |
| 1941 |
Never merge lambdas into a single line. |
| 1942 |
|
| 1943 |
* ``SLS_Empty`` (in configuration: ``Empty``) |
| 1944 |
Only merge empty lambdas. |
| 1945 |
|
| 1946 |
.. code-block:: c++ |
| 1947 |
|
| 1948 |
auto lambda = [](int a) {}; |
| 1949 |
auto lambda2 = [](int a) { |
| 1950 |
return a; |
| 1951 |
}; |
| 1952 |
|
| 1953 |
* ``SLS_Inline`` (in configuration: ``Inline``) |
| 1954 |
Merge lambda into a single line if the lambda is argument of a function. |
| 1955 |
|
| 1956 |
.. code-block:: c++ |
| 1957 |
|
| 1958 |
auto lambda = [](int x, int y) { |
| 1959 |
return x < y; |
| 1960 |
}; |
| 1961 |
sort(a.begin(), a.end(), [](int x, int y) { return x < y; }); |
| 1962 |
|
| 1963 |
* ``SLS_All`` (in configuration: ``All``) |
| 1964 |
Merge all lambdas fitting on a single line. |
| 1965 |
|
| 1966 |
.. code-block:: c++ |
| 1967 |
|
| 1968 |
auto lambda = [](int a) {}; |
| 1969 |
auto lambda2 = [](int a) { return a; }; |
| 1970 |
|
| 1971 |
|
| 1972 |
|
| 1973 |
.. _AllowShortLoopsOnASingleLine: |
| 1974 |
|
| 1975 |
**AllowShortLoopsOnASingleLine** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <AllowShortLoopsOnASingleLine>` |
| 1976 |
If ``true``, ``while (true) continue;`` can be put on a single |
| 1977 |
line. |
| 1978 |
|
| 1979 |
.. _AlwaysBreakAfterDefinitionReturnType: |
| 1980 |
|
| 1981 |
**AlwaysBreakAfterDefinitionReturnType** (``DefinitionReturnTypeBreakingStyle``) :versionbadge:`clang-format 3.7` :ref:`¶ <AlwaysBreakAfterDefinitionReturnType>` |
| 1982 |
The function definition return type breaking style to use. This |
| 1983 |
option is **deprecated** and is retained for backwards compatibility. |
| 1984 |
|
| 1985 |
Possible values: |
| 1986 |
|
| 1987 |
* ``DRTBS_None`` (in configuration: ``None``) |
| 1988 |
Break after return type automatically. |
| 1989 |
``PenaltyReturnTypeOnItsOwnLine`` is taken into account. |
| 1990 |
|
| 1991 |
* ``DRTBS_All`` (in configuration: ``All``) |
| 1992 |
Always break after the return type. |
| 1993 |
|
| 1994 |
* ``DRTBS_TopLevel`` (in configuration: ``TopLevel``) |
| 1995 |
Always break after the return types of top-level functions. |
| 1996 |
|
| 1997 |
|
| 1998 |
|
| 1999 |
.. _AlwaysBreakAfterReturnType: |
| 2000 |
|
| 2001 |
**AlwaysBreakAfterReturnType** (``deprecated``) :versionbadge:`clang-format 3.8` :ref:`¶ <AlwaysBreakAfterReturnType>` |
| 2002 |
This option is renamed to ``BreakAfterReturnType``. |
| 2003 |
|
| 2004 |
.. _AlwaysBreakBeforeMultilineStrings: |
| 2005 |
|
| 2006 |
**AlwaysBreakBeforeMultilineStrings** (``Boolean``) :versionbadge:`clang-format 3.4` :ref:`¶ <AlwaysBreakBeforeMultilineStrings>` |
| 2007 |
If ``true``, always break before multiline string literals. |
| 2008 |
|
| 2009 |
This flag is mean to make cases where there are multiple multiline strings |
| 2010 |
in a file look more consistent. Thus, it will only take effect if wrapping |
| 2011 |
the string at that point leads to it being indented |
| 2012 |
``ContinuationIndentWidth`` spaces from the start of the line. |
| 2013 |
|
| 2014 |
.. code-block:: c++ |
| 2015 |
|
| 2016 |
true: false: |
| 2017 |
aaaa = vs. aaaa = "bbbb" |
| 2018 |
"bbbb" "cccc"; |
| 2019 |
"cccc"; |
| 2020 |
|
| 2021 |
.. _AlwaysBreakTemplateDeclarations: |
| 2022 |
|
| 2023 |
**AlwaysBreakTemplateDeclarations** (``deprecated``) :versionbadge:`clang-format 3.4` :ref:`¶ <AlwaysBreakTemplateDeclarations>` |
| 2024 |
This option is renamed to ``BreakTemplateDeclarations``. |
| 2025 |
|
| 2026 |
.. _AttributeMacros: |
| 2027 |
|
| 2028 |
**AttributeMacros** (``List of Strings``) :versionbadge:`clang-format 12` :ref:`¶ <AttributeMacros>` |
| 2029 |
A vector of strings that should be interpreted as attributes/qualifiers |
| 2030 |
instead of identifiers. This can be useful for language extensions or |
| 2031 |
static analyzer annotations. |
| 2032 |
|
| 2033 |
For example: |
| 2034 |
|
| 2035 |
.. code-block:: c++ |
| 2036 |
|
| 2037 |
x = (char *__capability)&y; |
| 2038 |
int function(void) __unused; |
| 2039 |
void only_writes_to_buffer(char *__output buffer); |
| 2040 |
|
| 2041 |
In the .clang-format configuration file, this can be configured like: |
| 2042 |
|
| 2043 |
.. code-block:: yaml |
| 2044 |
|
| 2045 |
AttributeMacros: [__capability, __output, __unused] |
| 2046 |
|
| 2047 |
.. _BinPackArguments: |
| 2048 |
|
| 2049 |
**BinPackArguments** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <BinPackArguments>` |
| 2050 |
If ``false``, a function call's arguments will either be all on the |
| 2051 |
same line or will have one line each. |
| 2052 |
|
| 2053 |
.. code-block:: c++ |
| 2054 |
|
| 2055 |
true: |
| 2056 |
void f() { |
| 2057 |
f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa, |
| 2058 |
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); |
| 2059 |
} |
| 2060 |
|
| 2061 |
false: |
| 2062 |
void f() { |
| 2063 |
f(aaaaaaaaaaaaaaaaaaaa, |
| 2064 |
aaaaaaaaaaaaaaaaaaaa, |
| 2065 |
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); |
| 2066 |
} |
| 2067 |
|
| 2068 |
.. _BinPackParameters: |
| 2069 |
|
| 2070 |
**BinPackParameters** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <BinPackParameters>` |
| 2071 |
If ``false``, a function declaration's or function definition's |
| 2072 |
parameters will either all be on the same line or will have one line each. |
| 2073 |
|
| 2074 |
.. code-block:: c++ |
| 2075 |
|
| 2076 |
true: |
| 2077 |
void f(int aaaaaaaaaaaaaaaaaaaa, int aaaaaaaaaaaaaaaaaaaa, |
| 2078 |
int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {} |
| 2079 |
|
| 2080 |
false: |
| 2081 |
void f(int aaaaaaaaaaaaaaaaaaaa, |
| 2082 |
int aaaaaaaaaaaaaaaaaaaa, |
| 2083 |
int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {} |
| 2084 |
|
| 2085 |
.. _BitFieldColonSpacing: |
| 2086 |
|
| 2087 |
**BitFieldColonSpacing** (``BitFieldColonSpacingStyle``) :versionbadge:`clang-format 12` :ref:`¶ <BitFieldColonSpacing>` |
| 2088 |
The BitFieldColonSpacingStyle to use for bitfields. |
| 2089 |
|
| 2090 |
Possible values: |
| 2091 |
|
| 2092 |
* ``BFCS_Both`` (in configuration: ``Both``) |
| 2093 |
Add one space on each side of the ``:`` |
| 2094 |
|
| 2095 |
.. code-block:: c++ |
| 2096 |
|
| 2097 |
unsigned bf : 2; |
| 2098 |
|
| 2099 |
* ``BFCS_None`` (in configuration: ``None``) |
| 2100 |
Add no space around the ``:`` (except when needed for |
| 2101 |
``AlignConsecutiveBitFields``). |
| 2102 |
|
| 2103 |
.. code-block:: c++ |
| 2104 |
|
| 2105 |
unsigned bf:2; |
| 2106 |
|
| 2107 |
* ``BFCS_Before`` (in configuration: ``Before``) |
| 2108 |
Add space before the ``:`` only |
| 2109 |
|
| 2110 |
.. code-block:: c++ |
| 2111 |
|
| 2112 |
unsigned bf :2; |
| 2113 |
|
| 2114 |
* ``BFCS_After`` (in configuration: ``After``) |
| 2115 |
Add space after the ``:`` only (space may be added before if |
| 2116 |
needed for ``AlignConsecutiveBitFields``). |
| 2117 |
|
| 2118 |
.. code-block:: c++ |
| 2119 |
|
| 2120 |
unsigned bf: 2; |
| 2121 |
|
| 2122 |
|
| 2123 |
|
| 2124 |
.. _BraceWrapping: |
| 2125 |
|
| 2126 |
**BraceWrapping** (``BraceWrappingFlags``) :versionbadge:`clang-format 3.8` :ref:`¶ <BraceWrapping>` |
| 2127 |
Control of individual brace wrapping cases. |
| 2128 |
|
| 2129 |
If ``BreakBeforeBraces`` is set to ``BS_Custom``, use this to specify how |
| 2130 |
each individual brace case should be handled. Otherwise, this is ignored. |
| 2131 |
|
| 2132 |
.. code-block:: yaml |
| 2133 |
|
| 2134 |
# Example of usage: |
| 2135 |
BreakBeforeBraces: Custom |
| 2136 |
BraceWrapping: |
| 2137 |
AfterEnum: true |
| 2138 |
AfterStruct: false |
| 2139 |
SplitEmptyFunction: false |
| 2140 |
|
| 2141 |
Nested configuration flags: |
| 2142 |
|
| 2143 |
Precise control over the wrapping of braces. |
| 2144 |
|
| 2145 |
.. code-block:: c++ |
| 2146 |
|
| 2147 |
# Should be declared this way: |
| 2148 |
BreakBeforeBraces: Custom |
| 2149 |
BraceWrapping: |
| 2150 |
AfterClass: true |
| 2151 |
|
| 2152 |
* ``bool AfterCaseLabel`` Wrap case labels. |
| 2153 |
|
| 2154 |
.. code-block:: c++ |
| 2155 |
|
| 2156 |
false: true: |
| 2157 |
switch (foo) { vs. switch (foo) { |
| 2158 |
case 1: { case 1: |
| 2159 |
bar(); { |
| 2160 |
break; bar(); |
| 2161 |
} break; |
| 2162 |
default: { } |
| 2163 |
plop(); default: |
| 2164 |
} { |
| 2165 |
} plop(); |
| 2166 |
} |
| 2167 |
} |
| 2168 |
|
| 2169 |
* ``bool AfterClass`` Wrap class definitions. |
| 2170 |
|
| 2171 |
.. code-block:: c++ |
| 2172 |
|
| 2173 |
true: |
| 2174 |
class foo |
| 2175 |
{}; |
| 2176 |
|
| 2177 |
false: |
| 2178 |
class foo {}; |
| 2179 |
|
| 2180 |
* ``BraceWrappingAfterControlStatementStyle AfterControlStatement`` |
| 2181 |
Wrap control statements (``if``/``for``/``while``/``switch``/..). |
| 2182 |
|
| 2183 |
Possible values: |
| 2184 |
|
| 2185 |
* ``BWACS_Never`` (in configuration: ``Never``) |
| 2186 |
Never wrap braces after a control statement. |
| 2187 |
|
| 2188 |
.. code-block:: c++ |
| 2189 |
|
| 2190 |
if (foo()) { |
| 2191 |
} else { |
| 2192 |
} |
| 2193 |
for (int i = 0; i < 10; ++i) { |
| 2194 |
} |
| 2195 |
|
| 2196 |
* ``BWACS_MultiLine`` (in configuration: ``MultiLine``) |
| 2197 |
Only wrap braces after a multi-line control statement. |
| 2198 |
|
| 2199 |
.. code-block:: c++ |
| 2200 |
|
| 2201 |
if (foo && bar && |
| 2202 |
baz) |
| 2203 |
{ |
| 2204 |
quux(); |
| 2205 |
} |
| 2206 |
while (foo || bar) { |
| 2207 |
} |
| 2208 |
|
| 2209 |
* ``BWACS_Always`` (in configuration: ``Always``) |
| 2210 |
Always wrap braces after a control statement. |
| 2211 |
|
| 2212 |
.. code-block:: c++ |
| 2213 |
|
| 2214 |
if (foo()) |
| 2215 |
{ |
| 2216 |
} else |
| 2217 |
{} |
| 2218 |
for (int i = 0; i < 10; ++i) |
| 2219 |
{} |
| 2220 |
|
| 2221 |
|
| 2222 |
* ``bool AfterEnum`` Wrap enum definitions. |
| 2223 |
|
| 2224 |
.. code-block:: c++ |
| 2225 |
|
| 2226 |
true: |
| 2227 |
enum X : int |
| 2228 |
{ |
| 2229 |
B |
| 2230 |
}; |
| 2231 |
|
| 2232 |
false: |
| 2233 |
enum X : int { B }; |
| 2234 |
|
| 2235 |
* ``bool AfterFunction`` Wrap function definitions. |
| 2236 |
|
| 2237 |
.. code-block:: c++ |
| 2238 |
|
| 2239 |
true: |
| 2240 |
void foo() |
| 2241 |
{ |
| 2242 |
bar(); |
| 2243 |
bar2(); |
| 2244 |
} |
| 2245 |
|
| 2246 |
false: |
| 2247 |
void foo() { |
| 2248 |
bar(); |
| 2249 |
bar2(); |
| 2250 |
} |
| 2251 |
|
| 2252 |
* ``bool AfterNamespace`` Wrap namespace definitions. |
| 2253 |
|
| 2254 |
.. code-block:: c++ |
| 2255 |
|
| 2256 |
true: |
| 2257 |
namespace |
| 2258 |
{ |
| 2259 |
int foo(); |
| 2260 |
int bar(); |
| 2261 |
} |
| 2262 |
|
| 2263 |
false: |
| 2264 |
namespace { |
| 2265 |
int foo(); |
| 2266 |
int bar(); |
| 2267 |
} |
| 2268 |
|
| 2269 |
* ``bool AfterObjCDeclaration`` Wrap ObjC definitions (interfaces, implementations...). |
| 2270 |
|
| 2271 |
.. note:: |
| 2272 |
|
| 2273 |
@autoreleasepool and @synchronized blocks are wrapped |
| 2274 |
according to ``AfterControlStatement`` flag. |
| 2275 |
|
| 2276 |
* ``bool AfterStruct`` Wrap struct definitions. |
| 2277 |
|
| 2278 |
.. code-block:: c++ |
| 2279 |
|
| 2280 |
true: |
| 2281 |
struct foo |
| 2282 |
{ |
| 2283 |
int x; |
| 2284 |
}; |
| 2285 |
|
| 2286 |
false: |
| 2287 |
struct foo { |
| 2288 |
int x; |
| 2289 |
}; |
| 2290 |
|
| 2291 |
* ``bool AfterUnion`` Wrap union definitions. |
| 2292 |
|
| 2293 |
.. code-block:: c++ |
| 2294 |
|
| 2295 |
true: |
| 2296 |
union foo |
| 2297 |
{ |
| 2298 |
int x; |
| 2299 |
} |
| 2300 |
|
| 2301 |
false: |
| 2302 |
union foo { |
| 2303 |
int x; |
| 2304 |
} |
| 2305 |
|
| 2306 |
* ``bool AfterExternBlock`` Wrap extern blocks. |
| 2307 |
|
| 2308 |
.. code-block:: c++ |
| 2309 |
|
| 2310 |
true: |
| 2311 |
extern "C" |
| 2312 |
{ |
| 2313 |
int foo(); |
| 2314 |
} |
| 2315 |
|
| 2316 |
false: |
| 2317 |
extern "C" { |
| 2318 |
int foo(); |
| 2319 |
} |
| 2320 |
|
| 2321 |
* ``bool BeforeCatch`` Wrap before ``catch``. |
| 2322 |
|
| 2323 |
.. code-block:: c++ |
| 2324 |
|
| 2325 |
true: |
| 2326 |
try { |
| 2327 |
foo(); |
| 2328 |
} |
| 2329 |
catch () { |
| 2330 |
} |
| 2331 |
|
| 2332 |
false: |
| 2333 |
try { |
| 2334 |
foo(); |
| 2335 |
} catch () { |
| 2336 |
} |
| 2337 |
|
| 2338 |
* ``bool BeforeElse`` Wrap before ``else``. |
| 2339 |
|
| 2340 |
.. code-block:: c++ |
| 2341 |
|
| 2342 |
true: |
| 2343 |
if (foo()) { |
| 2344 |
} |
| 2345 |
else { |
| 2346 |
} |
| 2347 |
|
| 2348 |
false: |
| 2349 |
if (foo()) { |
| 2350 |
} else { |
| 2351 |
} |
| 2352 |
|
| 2353 |
* ``bool BeforeLambdaBody`` Wrap lambda block. |
| 2354 |
|
| 2355 |
.. code-block:: c++ |
| 2356 |
|
| 2357 |
true: |
| 2358 |
connect( |
| 2359 |
[]() |
| 2360 |
{ |
| 2361 |
foo(); |
| 2362 |
bar(); |
| 2363 |
}); |
| 2364 |
|
| 2365 |
false: |
| 2366 |
connect([]() { |
| 2367 |
foo(); |
| 2368 |
bar(); |
| 2369 |
}); |
| 2370 |
|
| 2371 |
* ``bool BeforeWhile`` Wrap before ``while``. |
| 2372 |
|
| 2373 |
.. code-block:: c++ |
| 2374 |
|
| 2375 |
true: |
| 2376 |
do { |
| 2377 |
foo(); |
| 2378 |
} |
| 2379 |
while (1); |
| 2380 |
|
| 2381 |
false: |
| 2382 |
do { |
| 2383 |
foo(); |
| 2384 |
} while (1); |
| 2385 |
|
| 2386 |
* ``bool IndentBraces`` Indent the wrapped braces themselves. |
| 2387 |
|
| 2388 |
* ``bool SplitEmptyFunction`` If ``false``, empty function body can be put on a single line. |
| 2389 |
This option is used only if the opening brace of the function has |
| 2390 |
already been wrapped, i.e. the ``AfterFunction`` brace wrapping mode is |
| 2391 |
set, and the function could/should not be put on a single line (as per |
| 2392 |
``AllowShortFunctionsOnASingleLine`` and constructor formatting |
| 2393 |
options). |
| 2394 |
|
| 2395 |
.. code-block:: c++ |
| 2396 |
|
| 2397 |
false: true: |
| 2398 |
int f() vs. int f() |
| 2399 |
{} { |
| 2400 |
} |
| 2401 |
|
| 2402 |
* ``bool SplitEmptyRecord`` If ``false``, empty record (e.g. class, struct or union) body |
| 2403 |
can be put on a single line. This option is used only if the opening |
| 2404 |
brace of the record has already been wrapped, i.e. the ``AfterClass`` |
| 2405 |
(for classes) brace wrapping mode is set. |
| 2406 |
|
| 2407 |
.. code-block:: c++ |
| 2408 |
|
| 2409 |
false: true: |
| 2410 |
class Foo vs. class Foo |
| 2411 |
{} { |
| 2412 |
} |
| 2413 |
|
| 2414 |
* ``bool SplitEmptyNamespace`` If ``false``, empty namespace body can be put on a single line. |
| 2415 |
This option is used only if the opening brace of the namespace has |
| 2416 |
already been wrapped, i.e. the ``AfterNamespace`` brace wrapping mode is |
| 2417 |
set. |
| 2418 |
|
| 2419 |
.. code-block:: c++ |
| 2420 |
|
| 2421 |
false: true: |
| 2422 |
namespace Foo vs. namespace Foo |
| 2423 |
{} { |
| 2424 |
} |
| 2425 |
|
| 2426 |
|
| 2427 |
.. _BracedInitializerIndentWidth: |
| 2428 |
|
| 2429 |
**BracedInitializerIndentWidth** (``Unsigned``) :versionbadge:`clang-format 17` :ref:`¶ <BracedInitializerIndentWidth>` |
| 2430 |
The number of columns to use to indent the contents of braced init lists. |
| 2431 |
If unset, ``ContinuationIndentWidth`` is used. |
| 2432 |
|
| 2433 |
.. code-block:: c++ |
| 2434 |
|
| 2435 |
AlignAfterOpenBracket: AlwaysBreak |
| 2436 |
BracedInitializerIndentWidth: 2 |
| 2437 |
|
| 2438 |
void f() { |
| 2439 |
SomeClass c{ |
| 2440 |
"foo", |
| 2441 |
"bar", |
| 2442 |
"baz", |
| 2443 |
}; |
| 2444 |
auto s = SomeStruct{ |
| 2445 |
.foo = "foo", |
| 2446 |
.bar = "bar", |
| 2447 |
.baz = "baz", |
| 2448 |
}; |
| 2449 |
SomeArrayT a[3] = { |
| 2450 |
{ |
| 2451 |
foo, |
| 2452 |
bar, |
| 2453 |
}, |
| 2454 |
{ |
| 2455 |
foo, |
| 2456 |
bar, |
| 2457 |
}, |
| 2458 |
SomeArrayT{}, |
| 2459 |
}; |
| 2460 |
} |
| 2461 |
|
| 2462 |
.. _BreakAdjacentStringLiterals: |
| 2463 |
|
| 2464 |
**BreakAdjacentStringLiterals** (``Boolean``) :versionbadge:`clang-format 18` :ref:`¶ <BreakAdjacentStringLiterals>` |
| 2465 |
Break between adjacent string literals. |
| 2466 |
|
| 2467 |
.. code-block:: c++ |
| 2468 |
|
| 2469 |
true: |
| 2470 |
return "Code" |
| 2471 |
"\0\52\26\55\55\0" |
| 2472 |
"x013" |
| 2473 |
"\02\xBA"; |
| 2474 |
false: |
| 2475 |
return "Code" "\0\52\26\55\55\0" "x013" "\02\xBA"; |
| 2476 |
|
| 2477 |
.. _BreakAfterAttributes: |
| 2478 |
|
| 2479 |
**BreakAfterAttributes** (``AttributeBreakingStyle``) :versionbadge:`clang-format 16` :ref:`¶ <BreakAfterAttributes>` |
| 2480 |
Break after a group of C++11 attributes before variable or function |
| 2481 |
(including constructor/destructor) declaration/definition names or before |
| 2482 |
control statements, i.e. ``if``, ``switch`` (including ``case`` and |
| 2483 |
``default`` labels), ``for``, and ``while`` statements. |
| 2484 |
|
| 2485 |
Possible values: |
| 2486 |
|
| 2487 |
* ``ABS_Always`` (in configuration: ``Always``) |
| 2488 |
Always break after attributes. |
| 2489 |
|
| 2490 |
.. code-block:: c++ |
| 2491 |
|
| 2492 |
[[maybe_unused]] |
| 2493 |
const int i; |
| 2494 |
[[gnu::const]] [[maybe_unused]] |
| 2495 |
int j; |
| 2496 |
|
| 2497 |
[[nodiscard]] |
| 2498 |
inline int f(); |
| 2499 |
[[gnu::const]] [[nodiscard]] |
| 2500 |
int g(); |
| 2501 |
|
| 2502 |
[[likely]] |
| 2503 |
if (a) |
| 2504 |
f(); |
| 2505 |
else |
| 2506 |
g(); |
| 2507 |
|
| 2508 |
switch (b) { |
| 2509 |
[[unlikely]] |
| 2510 |
case 1: |
| 2511 |
++b; |
| 2512 |
break; |
| 2513 |
[[likely]] |
| 2514 |
default: |
| 2515 |
return; |
| 2516 |
} |
| 2517 |
|
| 2518 |
* ``ABS_Leave`` (in configuration: ``Leave``) |
| 2519 |
Leave the line breaking after attributes as is. |
| 2520 |
|
| 2521 |
.. code-block:: c++ |
| 2522 |
|
| 2523 |
[[maybe_unused]] const int i; |
| 2524 |
[[gnu::const]] [[maybe_unused]] |
| 2525 |
int j; |
| 2526 |
|
| 2527 |
[[nodiscard]] inline int f(); |
| 2528 |
[[gnu::const]] [[nodiscard]] |
| 2529 |
int g(); |
| 2530 |
|
| 2531 |
[[likely]] if (a) |
| 2532 |
f(); |
| 2533 |
else |
| 2534 |
g(); |
| 2535 |
|
| 2536 |
switch (b) { |
| 2537 |
[[unlikely]] case 1: |
| 2538 |
++b; |
| 2539 |
break; |
| 2540 |
[[likely]] |
| 2541 |
default: |
| 2542 |
return; |
| 2543 |
} |
| 2544 |
|
| 2545 |
* ``ABS_Never`` (in configuration: ``Never``) |
| 2546 |
Never break after attributes. |
| 2547 |
|
| 2548 |
.. code-block:: c++ |
| 2549 |
|
| 2550 |
[[maybe_unused]] const int i; |
| 2551 |
[[gnu::const]] [[maybe_unused]] int j; |
| 2552 |
|
| 2553 |
[[nodiscard]] inline int f(); |
| 2554 |
[[gnu::const]] [[nodiscard]] int g(); |
| 2555 |
|
| 2556 |
[[likely]] if (a) |
| 2557 |
f(); |
| 2558 |
else |
| 2559 |
g(); |
| 2560 |
|
| 2561 |
switch (b) { |
| 2562 |
[[unlikely]] case 1: |
| 2563 |
++b; |
| 2564 |
break; |
| 2565 |
[[likely]] default: |
| 2566 |
return; |
| 2567 |
} |
| 2568 |
|
| 2569 |
|
| 2570 |
|
| 2571 |
.. _BreakAfterJavaFieldAnnotations: |
| 2572 |
|
| 2573 |
**BreakAfterJavaFieldAnnotations** (``Boolean``) :versionbadge:`clang-format 3.8` :ref:`¶ <BreakAfterJavaFieldAnnotations>` |
| 2574 |
Break after each annotation on a field in Java files. |
| 2575 |
|
| 2576 |
.. code-block:: java |
| 2577 |
|
| 2578 |
true: false: |
| 2579 |
@Partial vs. @Partial @Mock DataLoad loader; |
| 2580 |
@Mock |
| 2581 |
DataLoad loader; |
| 2582 |
|
| 2583 |
.. _BreakAfterReturnType: |
| 2584 |
|
| 2585 |
**BreakAfterReturnType** (``ReturnTypeBreakingStyle``) :versionbadge:`clang-format 19` :ref:`¶ <BreakAfterReturnType>` |
| 2586 |
The function declaration return type breaking style to use. |
| 2587 |
|
| 2588 |
Possible values: |
| 2589 |
|
| 2590 |
* ``RTBS_None`` (in configuration: ``None``) |
| 2591 |
This is **deprecated**. See ``Automatic`` below. |
| 2592 |
|
| 2593 |
* ``RTBS_Automatic`` (in configuration: ``Automatic``) |
| 2594 |
Break after return type based on ``PenaltyReturnTypeOnItsOwnLine``. |
| 2595 |
|
| 2596 |
.. code-block:: c++ |
| 2597 |
|
| 2598 |
class A { |
| 2599 |
int f() { return 0; }; |
| 2600 |
}; |
| 2601 |
int f(); |
| 2602 |
int f() { return 1; } |
| 2603 |
int |
| 2604 |
LongName::AnotherLongName(); |
| 2605 |
|
| 2606 |
* ``RTBS_ExceptShortType`` (in configuration: ``ExceptShortType``) |
| 2607 |
Same as ``Automatic`` above, except that there is no break after short |
| 2608 |
return types. |
| 2609 |
|
| 2610 |
.. code-block:: c++ |
| 2611 |
|
| 2612 |
class A { |
| 2613 |
int f() { return 0; }; |
| 2614 |
}; |
| 2615 |
int f(); |
| 2616 |
int f() { return 1; } |
| 2617 |
int LongName:: |
| 2618 |
AnotherLongName(); |
| 2619 |
|
| 2620 |
* ``RTBS_All`` (in configuration: ``All``) |
| 2621 |
Always break after the return type. |
| 2622 |
|
| 2623 |
.. code-block:: c++ |
| 2624 |
|
| 2625 |
class A { |
| 2626 |
int |
| 2627 |
f() { |
| 2628 |
return 0; |
| 2629 |
}; |
| 2630 |
}; |
| 2631 |
int |
| 2632 |
f(); |
| 2633 |
int |
| 2634 |
f() { |
| 2635 |
return 1; |
| 2636 |
} |
| 2637 |
int |
| 2638 |
LongName::AnotherLongName(); |
| 2639 |
|
| 2640 |
* ``RTBS_TopLevel`` (in configuration: ``TopLevel``) |
| 2641 |
Always break after the return types of top-level functions. |
| 2642 |
|
| 2643 |
.. code-block:: c++ |
| 2644 |
|
| 2645 |
class A { |
| 2646 |
int f() { return 0; }; |
| 2647 |
}; |
| 2648 |
int |
| 2649 |
f(); |
| 2650 |
int |
| 2651 |
f() { |
| 2652 |
return 1; |
| 2653 |
} |
| 2654 |
int |
| 2655 |
LongName::AnotherLongName(); |
| 2656 |
|
| 2657 |
* ``RTBS_AllDefinitions`` (in configuration: ``AllDefinitions``) |
| 2658 |
Always break after the return type of function definitions. |
| 2659 |
|
| 2660 |
.. code-block:: c++ |
| 2661 |
|
| 2662 |
class A { |
| 2663 |
int |
| 2664 |
f() { |
| 2665 |
return 0; |
| 2666 |
}; |
| 2667 |
}; |
| 2668 |
int f(); |
| 2669 |
int |
| 2670 |
f() { |
| 2671 |
return 1; |
| 2672 |
} |
| 2673 |
int |
| 2674 |
LongName::AnotherLongName(); |
| 2675 |
|
| 2676 |
* ``RTBS_TopLevelDefinitions`` (in configuration: ``TopLevelDefinitions``) |
| 2677 |
Always break after the return type of top-level definitions. |
| 2678 |
|
| 2679 |
.. code-block:: c++ |
| 2680 |
|
| 2681 |
class A { |
| 2682 |
int f() { return 0; }; |
| 2683 |
}; |
| 2684 |
int f(); |
| 2685 |
int |
| 2686 |
f() { |
| 2687 |
return 1; |
| 2688 |
} |
| 2689 |
int |
| 2690 |
LongName::AnotherLongName(); |
| 2691 |
|
| 2692 |
|
| 2693 |
|
| 2694 |
.. _BreakArrays: |
| 2695 |
|
| 2696 |
**BreakArrays** (``Boolean``) :versionbadge:`clang-format 16` :ref:`¶ <BreakArrays>` |
| 2697 |
If ``true``, clang-format will always break after a Json array ``[`` |
| 2698 |
otherwise it will scan until the closing ``]`` to determine if it should |
| 2699 |
add newlines between elements (prettier compatible). |
| 2700 |
|
| 2701 |
|
| 2702 |
.. note:: |
| 2703 |
|
| 2704 |
This is currently only for formatting JSON. |
| 2705 |
|
| 2706 |
.. code-block:: c++ |
| 2707 |
|
| 2708 |
true: false: |
| 2709 |
[ vs. [1, 2, 3, 4] |
| 2710 |
1, |
| 2711 |
2, |
| 2712 |
3, |
| 2713 |
4 |
| 2714 |
] |
| 2715 |
|
| 2716 |
.. _BreakBeforeBinaryOperators: |
| 2717 |
|
| 2718 |
**BreakBeforeBinaryOperators** (``BinaryOperatorStyle``) :versionbadge:`clang-format 3.6` :ref:`¶ <BreakBeforeBinaryOperators>` |
| 2719 |
The way to wrap binary operators. |
| 2720 |
|
| 2721 |
Possible values: |
| 2722 |
|
| 2723 |
* ``BOS_None`` (in configuration: ``None``) |
| 2724 |
Break after operators. |
| 2725 |
|
| 2726 |
.. code-block:: c++ |
| 2727 |
|
| 2728 |
LooooooooooongType loooooooooooooooooooooongVariable = |
| 2729 |
someLooooooooooooooooongFunction(); |
| 2730 |
|
| 2731 |
bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + |
| 2732 |
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa == |
| 2733 |
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa && |
| 2734 |
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa > |
| 2735 |
ccccccccccccccccccccccccccccccccccccccccc; |
| 2736 |
|
| 2737 |
* ``BOS_NonAssignment`` (in configuration: ``NonAssignment``) |
| 2738 |
Break before operators that aren't assignments. |
| 2739 |
|
| 2740 |
.. code-block:: c++ |
| 2741 |
|
| 2742 |
LooooooooooongType loooooooooooooooooooooongVariable = |
| 2743 |
someLooooooooooooooooongFunction(); |
| 2744 |
|
| 2745 |
bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
| 2746 |
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
| 2747 |
== aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
| 2748 |
&& aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
| 2749 |
> ccccccccccccccccccccccccccccccccccccccccc; |
| 2750 |
|
| 2751 |
* ``BOS_All`` (in configuration: ``All``) |
| 2752 |
Break before operators. |
| 2753 |
|
| 2754 |
.. code-block:: c++ |
| 2755 |
|
| 2756 |
LooooooooooongType loooooooooooooooooooooongVariable |
| 2757 |
= someLooooooooooooooooongFunction(); |
| 2758 |
|
| 2759 |
bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
| 2760 |
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
| 2761 |
== aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
| 2762 |
&& aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
| 2763 |
> ccccccccccccccccccccccccccccccccccccccccc; |
| 2764 |
|
| 2765 |
|
| 2766 |
|
| 2767 |
.. _BreakBeforeBraces: |
| 2768 |
|
| 2769 |
**BreakBeforeBraces** (``BraceBreakingStyle``) :versionbadge:`clang-format 3.7` :ref:`¶ <BreakBeforeBraces>` |
| 2770 |
The brace breaking style to use. |
| 2771 |
|
| 2772 |
Possible values: |
| 2773 |
|
| 2774 |
* ``BS_Attach`` (in configuration: ``Attach``) |
| 2775 |
Always attach braces to surrounding context. |
| 2776 |
|
| 2777 |
.. code-block:: c++ |
| 2778 |
|
| 2779 |
namespace N { |
| 2780 |
enum E { |
| 2781 |
E1, |
| 2782 |
E2, |
| 2783 |
}; |
| 2784 |
|
| 2785 |
class C { |
| 2786 |
public: |
| 2787 |
C(); |
| 2788 |
}; |
| 2789 |
|
| 2790 |
bool baz(int i) { |
| 2791 |
try { |
| 2792 |
do { |
| 2793 |
switch (i) { |
| 2794 |
case 1: { |
| 2795 |
foobar(); |
| 2796 |
break; |
| 2797 |
} |
| 2798 |
default: { |
| 2799 |
break; |
| 2800 |
} |
| 2801 |
} |
| 2802 |
} while (--i); |
| 2803 |
return true; |
| 2804 |
} catch (...) { |
| 2805 |
handleError(); |
| 2806 |
return false; |
| 2807 |
} |
| 2808 |
} |
| 2809 |
|
| 2810 |
void foo(bool b) { |
| 2811 |
if (b) { |
| 2812 |
baz(2); |
| 2813 |
} else { |
| 2814 |
baz(5); |
| 2815 |
} |
| 2816 |
} |
| 2817 |
|
| 2818 |
void bar() { foo(true); } |
| 2819 |
} // namespace N |
| 2820 |
|
| 2821 |
* ``BS_Linux`` (in configuration: ``Linux``) |
| 2822 |
Like ``Attach``, but break before braces on function, namespace and |
| 2823 |
class definitions. |
| 2824 |
|
| 2825 |
.. code-block:: c++ |
| 2826 |
|
| 2827 |
namespace N |
| 2828 |
{ |
| 2829 |
enum E { |
| 2830 |
E1, |
| 2831 |
E2, |
| 2832 |
}; |
| 2833 |
|
| 2834 |
class C |
| 2835 |
{ |
| 2836 |
public: |
| 2837 |
C(); |
| 2838 |
}; |
| 2839 |
|
| 2840 |
bool baz(int i) |
| 2841 |
{ |
| 2842 |
try { |
| 2843 |
do { |
| 2844 |
switch (i) { |
| 2845 |
case 1: { |
| 2846 |
foobar(); |
| 2847 |
break; |
| 2848 |
} |
| 2849 |
default: { |
| 2850 |
break; |
| 2851 |
} |
| 2852 |
} |
| 2853 |
} while (--i); |
| 2854 |
return true; |
| 2855 |
} catch (...) { |
| 2856 |
handleError(); |
| 2857 |
return false; |
| 2858 |
} |
| 2859 |
} |
| 2860 |
|
| 2861 |
void foo(bool b) |
| 2862 |
{ |
| 2863 |
if (b) { |
| 2864 |
baz(2); |
| 2865 |
} else { |
| 2866 |
baz(5); |
| 2867 |
} |
| 2868 |
} |
| 2869 |
|
| 2870 |
void bar() { foo(true); } |
| 2871 |
} // namespace N |
| 2872 |
|
| 2873 |
* ``BS_Mozilla`` (in configuration: ``Mozilla``) |
| 2874 |
Like ``Attach``, but break before braces on enum, function, and record |
| 2875 |
definitions. |
| 2876 |
|
| 2877 |
.. code-block:: c++ |
| 2878 |
|
| 2879 |
namespace N { |
| 2880 |
enum E |
| 2881 |
{ |
| 2882 |
E1, |
| 2883 |
E2, |
| 2884 |
}; |
| 2885 |
|
| 2886 |
class C |
| 2887 |
{ |
| 2888 |
public: |
| 2889 |
C(); |
| 2890 |
}; |
| 2891 |
|
| 2892 |
bool baz(int i) |
| 2893 |
{ |
| 2894 |
try { |
| 2895 |
do { |
| 2896 |
switch (i) { |
| 2897 |
case 1: { |
| 2898 |
foobar(); |
| 2899 |
break; |
| 2900 |
} |
| 2901 |
default: { |
| 2902 |
break; |
| 2903 |
} |
| 2904 |
} |
| 2905 |
} while (--i); |
| 2906 |
return true; |
| 2907 |
} catch (...) { |
| 2908 |
handleError(); |
| 2909 |
return false; |
| 2910 |
} |
| 2911 |
} |
| 2912 |
|
| 2913 |
void foo(bool b) |
| 2914 |
{ |
| 2915 |
if (b) { |
| 2916 |
baz(2); |
| 2917 |
} else { |
| 2918 |
baz(5); |
| 2919 |
} |
| 2920 |
} |
| 2921 |
|
| 2922 |
void bar() { foo(true); } |
| 2923 |
} // namespace N |
| 2924 |
|
| 2925 |
* ``BS_Stroustrup`` (in configuration: ``Stroustrup``) |
| 2926 |
Like ``Attach``, but break before function definitions, ``catch``, and |
| 2927 |
``else``. |
| 2928 |
|
| 2929 |
.. code-block:: c++ |
| 2930 |
|
| 2931 |
namespace N { |
| 2932 |
enum E { |
| 2933 |
E1, |
| 2934 |
E2, |
| 2935 |
}; |
| 2936 |
|
| 2937 |
class C { |
| 2938 |
public: |
| 2939 |
C(); |
| 2940 |
}; |
| 2941 |
|
| 2942 |
bool baz(int i) |
| 2943 |
{ |
| 2944 |
try { |
| 2945 |
do { |
| 2946 |
switch (i) { |
| 2947 |
case 1: { |
| 2948 |
foobar(); |
| 2949 |
break; |
| 2950 |
} |
| 2951 |
default: { |
| 2952 |
break; |
| 2953 |
} |
| 2954 |
} |
| 2955 |
} while (--i); |
| 2956 |
return true; |
| 2957 |
} |
| 2958 |
catch (...) { |
| 2959 |
handleError(); |
| 2960 |
return false; |
| 2961 |
} |
| 2962 |
} |
| 2963 |
|
| 2964 |
void foo(bool b) |
| 2965 |
{ |
| 2966 |
if (b) { |
| 2967 |
baz(2); |
| 2968 |
} |
| 2969 |
else { |
| 2970 |
baz(5); |
| 2971 |
} |
| 2972 |
} |
| 2973 |
|
| 2974 |
void bar() { foo(true); } |
| 2975 |
} // namespace N |
| 2976 |
|
| 2977 |
* ``BS_Allman`` (in configuration: ``Allman``) |
| 2978 |
Always break before braces. |
| 2979 |
|
| 2980 |
.. code-block:: c++ |
| 2981 |
|
| 2982 |
namespace N |
| 2983 |
{ |
| 2984 |
enum E |
| 2985 |
{ |
| 2986 |
E1, |
| 2987 |
E2, |
| 2988 |
}; |
| 2989 |
|
| 2990 |
class C |
| 2991 |
{ |
| 2992 |
public: |
| 2993 |
C(); |
| 2994 |
}; |
| 2995 |
|
| 2996 |
bool baz(int i) |
| 2997 |
{ |
| 2998 |
try |
| 2999 |
{ |
| 3000 |
do |
| 3001 |
{ |
| 3002 |
switch (i) |
| 3003 |
{ |
| 3004 |
case 1: |
| 3005 |
{ |
| 3006 |
foobar(); |
| 3007 |
break; |
| 3008 |
} |
| 3009 |
default: |
| 3010 |
{ |
| 3011 |
break; |
| 3012 |
} |
| 3013 |
} |
| 3014 |
} while (--i); |
| 3015 |
return true; |
| 3016 |
} |
| 3017 |
catch (...) |
| 3018 |
{ |
| 3019 |
handleError(); |
| 3020 |
return false; |
| 3021 |
} |
| 3022 |
} |
| 3023 |
|
| 3024 |
void foo(bool b) |
| 3025 |
{ |
| 3026 |
if (b) |
| 3027 |
{ |
| 3028 |
baz(2); |
| 3029 |
} |
| 3030 |
else |
| 3031 |
{ |
| 3032 |
baz(5); |
| 3033 |
} |
| 3034 |
} |
| 3035 |
|
| 3036 |
void bar() { foo(true); } |
| 3037 |
} // namespace N |
| 3038 |
|
| 3039 |
* ``BS_Whitesmiths`` (in configuration: ``Whitesmiths``) |
| 3040 |
Like ``Allman`` but always indent braces and line up code with braces. |
| 3041 |
|
| 3042 |
.. code-block:: c++ |
| 3043 |
|
| 3044 |
namespace N |
| 3045 |
{ |
| 3046 |
enum E |
| 3047 |
{ |
| 3048 |
E1, |
| 3049 |
E2, |
| 3050 |
}; |
| 3051 |
|
| 3052 |
class C |
| 3053 |
{ |
| 3054 |
public: |
| 3055 |
C(); |
| 3056 |
}; |
| 3057 |
|
| 3058 |
bool baz(int i) |
| 3059 |
{ |
| 3060 |
try |
| 3061 |
{ |
| 3062 |
do |
| 3063 |
{ |
| 3064 |
switch (i) |
| 3065 |
{ |
| 3066 |
case 1: |
| 3067 |
{ |
| 3068 |
foobar(); |
| 3069 |
break; |
| 3070 |
} |
| 3071 |
default: |
| 3072 |
{ |
| 3073 |
break; |
| 3074 |
} |
| 3075 |
} |
| 3076 |
} while (--i); |
| 3077 |
return true; |
| 3078 |
} |
| 3079 |
catch (...) |
| 3080 |
{ |
| 3081 |
handleError(); |
| 3082 |
return false; |
| 3083 |
} |
| 3084 |
} |
| 3085 |
|
| 3086 |
void foo(bool b) |
| 3087 |
{ |
| 3088 |
if (b) |
| 3089 |
{ |
| 3090 |
baz(2); |
| 3091 |
} |
| 3092 |
else |
| 3093 |
{ |
| 3094 |
baz(5); |
| 3095 |
} |
| 3096 |
} |
| 3097 |
|
| 3098 |
void bar() { foo(true); } |
| 3099 |
} // namespace N |
| 3100 |
|
| 3101 |
* ``BS_GNU`` (in configuration: ``GNU``) |
| 3102 |
Always break before braces and add an extra level of indentation to |
| 3103 |
braces of control statements, not to those of class, function |
| 3104 |
or other definitions. |
| 3105 |
|
| 3106 |
.. code-block:: c++ |
| 3107 |
|
| 3108 |
namespace N |
| 3109 |
{ |
| 3110 |
enum E |
| 3111 |
{ |
| 3112 |
E1, |
| 3113 |
E2, |
| 3114 |
}; |
| 3115 |
|
| 3116 |
class C |
| 3117 |
{ |
| 3118 |
public: |
| 3119 |
C(); |
| 3120 |
}; |
| 3121 |
|
| 3122 |
bool baz(int i) |
| 3123 |
{ |
| 3124 |
try |
| 3125 |
{ |
| 3126 |
do |
| 3127 |
{ |
| 3128 |
switch (i) |
| 3129 |
{ |
| 3130 |
case 1: |
| 3131 |
{ |
| 3132 |
foobar(); |
| 3133 |
break; |
| 3134 |
} |
| 3135 |
default: |
| 3136 |
{ |
| 3137 |
break; |
| 3138 |
} |
| 3139 |
} |
| 3140 |
} |
| 3141 |
while (--i); |
| 3142 |
return true; |
| 3143 |
} |
| 3144 |
catch (...) |
| 3145 |
{ |
| 3146 |
handleError(); |
| 3147 |
return false; |
| 3148 |
} |
| 3149 |
} |
| 3150 |
|
| 3151 |
void foo(bool b) |
| 3152 |
{ |
| 3153 |
if (b) |
| 3154 |
{ |
| 3155 |
baz(2); |
| 3156 |
} |
| 3157 |
else |
| 3158 |
{ |
| 3159 |
baz(5); |
| 3160 |
} |
| 3161 |
} |
| 3162 |
|
| 3163 |
void bar() { foo(true); } |
| 3164 |
} // namespace N |
| 3165 |
|
| 3166 |
* ``BS_WebKit`` (in configuration: ``WebKit``) |
| 3167 |
Like ``Attach``, but break before functions. |
| 3168 |
|
| 3169 |
.. code-block:: c++ |
| 3170 |
|
| 3171 |
namespace N { |
| 3172 |
enum E { |
| 3173 |
E1, |
| 3174 |
E2, |
| 3175 |
}; |
| 3176 |
|
| 3177 |
class C { |
| 3178 |
public: |
| 3179 |
C(); |
| 3180 |
}; |
| 3181 |
|
| 3182 |
bool baz(int i) |
| 3183 |
{ |
| 3184 |
try { |
| 3185 |
do { |
| 3186 |
switch (i) { |
| 3187 |
case 1: { |
| 3188 |
foobar(); |
| 3189 |
break; |
| 3190 |
} |
| 3191 |
default: { |
| 3192 |
break; |
| 3193 |
} |
| 3194 |
} |
| 3195 |
} while (--i); |
| 3196 |
return true; |
| 3197 |
} catch (...) { |
| 3198 |
handleError(); |
| 3199 |
return false; |
| 3200 |
} |
| 3201 |
} |
| 3202 |
|
| 3203 |
void foo(bool b) |
| 3204 |
{ |
| 3205 |
if (b) { |
| 3206 |
baz(2); |
| 3207 |
} else { |
| 3208 |
baz(5); |
| 3209 |
} |
| 3210 |
} |
| 3211 |
|
| 3212 |
void bar() { foo(true); } |
| 3213 |
} // namespace N |
| 3214 |
|
| 3215 |
* ``BS_Custom`` (in configuration: ``Custom``) |
| 3216 |
Configure each individual brace in ``BraceWrapping``. |
| 3217 |
|
| 3218 |
|
| 3219 |
|
| 3220 |
.. _BreakBeforeConceptDeclarations: |
| 3221 |
|
| 3222 |
**BreakBeforeConceptDeclarations** (``BreakBeforeConceptDeclarationsStyle``) :versionbadge:`clang-format 12` :ref:`¶ <BreakBeforeConceptDeclarations>` |
| 3223 |
The concept declaration style to use. |
| 3224 |
|
| 3225 |
Possible values: |
| 3226 |
|
| 3227 |
* ``BBCDS_Never`` (in configuration: ``Never``) |
| 3228 |
Keep the template declaration line together with ``concept``. |
| 3229 |
|
| 3230 |
.. code-block:: c++ |
| 3231 |
|
| 3232 |
template <typename T> concept C = ...; |
| 3233 |
|
| 3234 |
* ``BBCDS_Allowed`` (in configuration: ``Allowed``) |
| 3235 |
Breaking between template declaration and ``concept`` is allowed. The |
| 3236 |
actual behavior depends on the content and line breaking rules and |
| 3237 |
penalties. |
| 3238 |
|
| 3239 |
* ``BBCDS_Always`` (in configuration: ``Always``) |
| 3240 |
Always break before ``concept``, putting it in the line after the |
| 3241 |
template declaration. |
| 3242 |
|
| 3243 |
.. code-block:: c++ |
| 3244 |
|
| 3245 |
template <typename T> |
| 3246 |
concept C = ...; |
| 3247 |
|
| 3248 |
|
| 3249 |
|
| 3250 |
.. _BreakBeforeInlineASMColon: |
| 3251 |
|
| 3252 |
**BreakBeforeInlineASMColon** (``BreakBeforeInlineASMColonStyle``) :versionbadge:`clang-format 16` :ref:`¶ <BreakBeforeInlineASMColon>` |
| 3253 |
The inline ASM colon style to use. |
| 3254 |
|
| 3255 |
Possible values: |
| 3256 |
|
| 3257 |
* ``BBIAS_Never`` (in configuration: ``Never``) |
| 3258 |
No break before inline ASM colon. |
| 3259 |
|
| 3260 |
.. code-block:: c++ |
| 3261 |
|
| 3262 |
asm volatile("string", : : val); |
| 3263 |
|
| 3264 |
* ``BBIAS_OnlyMultiline`` (in configuration: ``OnlyMultiline``) |
| 3265 |
Break before inline ASM colon if the line length is longer than column |
| 3266 |
limit. |
| 3267 |
|
| 3268 |
.. code-block:: c++ |
| 3269 |
|
| 3270 |
asm volatile("string", : : val); |
| 3271 |
asm("cmoveq %1, %2, %[result]" |
| 3272 |
: [result] "=r"(result) |
| 3273 |
: "r"(test), "r"(new), "[result]"(old)); |
| 3274 |
|
| 3275 |
* ``BBIAS_Always`` (in configuration: ``Always``) |
| 3276 |
Always break before inline ASM colon. |
| 3277 |
|
| 3278 |
.. code-block:: c++ |
| 3279 |
|
| 3280 |
asm volatile("string", |
| 3281 |
: |
| 3282 |
: val); |
| 3283 |
|
| 3284 |
|
| 3285 |
|
| 3286 |
.. _BreakBeforeTernaryOperators: |
| 3287 |
|
| 3288 |
**BreakBeforeTernaryOperators** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <BreakBeforeTernaryOperators>` |
| 3289 |
If ``true``, ternary operators will be placed after line breaks. |
| 3290 |
|
| 3291 |
.. code-block:: c++ |
| 3292 |
|
| 3293 |
true: |
| 3294 |
veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription |
| 3295 |
? firstValue |
| 3296 |
: SecondValueVeryVeryVeryVeryLong; |
| 3297 |
|
| 3298 |
false: |
| 3299 |
veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ? |
| 3300 |
firstValue : |
| 3301 |
SecondValueVeryVeryVeryVeryLong; |
| 3302 |
|
| 3303 |
.. _BreakConstructorInitializers: |
| 3304 |
|
| 3305 |
**BreakConstructorInitializers** (``BreakConstructorInitializersStyle``) :versionbadge:`clang-format 5` :ref:`¶ <BreakConstructorInitializers>` |
| 3306 |
The break constructor initializers style to use. |
| 3307 |
|
| 3308 |
Possible values: |
| 3309 |
|
| 3310 |
* ``BCIS_BeforeColon`` (in configuration: ``BeforeColon``) |
| 3311 |
Break constructor initializers before the colon and after the commas. |
| 3312 |
|
| 3313 |
.. code-block:: c++ |
| 3314 |
|
| 3315 |
Constructor() |
| 3316 |
: initializer1(), |
| 3317 |
initializer2() |
| 3318 |
|
| 3319 |
* ``BCIS_BeforeComma`` (in configuration: ``BeforeComma``) |
| 3320 |
Break constructor initializers before the colon and commas, and align |
| 3321 |
the commas with the colon. |
| 3322 |
|
| 3323 |
.. code-block:: c++ |
| 3324 |
|
| 3325 |
Constructor() |
| 3326 |
: initializer1() |
| 3327 |
, initializer2() |
| 3328 |
|
| 3329 |
* ``BCIS_AfterColon`` (in configuration: ``AfterColon``) |
| 3330 |
Break constructor initializers after the colon and commas. |
| 3331 |
|
| 3332 |
.. code-block:: c++ |
| 3333 |
|
| 3334 |
Constructor() : |
| 3335 |
initializer1(), |
| 3336 |
initializer2() |
| 3337 |
|
| 3338 |
|
| 3339 |
|
| 3340 |
.. _BreakFunctionDefinitionParameters: |
| 3341 |
|
| 3342 |
**BreakFunctionDefinitionParameters** (``Boolean``) :versionbadge:`clang-format 19` :ref:`¶ <BreakFunctionDefinitionParameters>` |
| 3343 |
If ``true``, clang-format will always break before function definition |
| 3344 |
parameters. |
| 3345 |
|
| 3346 |
.. code-block:: c++ |
| 3347 |
|
| 3348 |
true: |
| 3349 |
void functionDefinition( |
| 3350 |
int A, int B) {} |
| 3351 |
|
| 3352 |
false: |
| 3353 |
void functionDefinition(int A, int B) {} |
| 3354 |
|
| 3355 |
.. _BreakInheritanceList: |
| 3356 |
|
| 3357 |
**BreakInheritanceList** (``BreakInheritanceListStyle``) :versionbadge:`clang-format 7` :ref:`¶ <BreakInheritanceList>` |
| 3358 |
The inheritance list style to use. |
| 3359 |
|
| 3360 |
Possible values: |
| 3361 |
|
| 3362 |
* ``BILS_BeforeColon`` (in configuration: ``BeforeColon``) |
| 3363 |
Break inheritance list before the colon and after the commas. |
| 3364 |
|
| 3365 |
.. code-block:: c++ |
| 3366 |
|
| 3367 |
class Foo |
| 3368 |
: Base1, |
| 3369 |
Base2 |
| 3370 |
{}; |
| 3371 |
|
| 3372 |
* ``BILS_BeforeComma`` (in configuration: ``BeforeComma``) |
| 3373 |
Break inheritance list before the colon and commas, and align |
| 3374 |
the commas with the colon. |
| 3375 |
|
| 3376 |
.. code-block:: c++ |
| 3377 |
|
| 3378 |
class Foo |
| 3379 |
: Base1 |
| 3380 |
, Base2 |
| 3381 |
{}; |
| 3382 |
|
| 3383 |
* ``BILS_AfterColon`` (in configuration: ``AfterColon``) |
| 3384 |
Break inheritance list after the colon and commas. |
| 3385 |
|
| 3386 |
.. code-block:: c++ |
| 3387 |
|
| 3388 |
class Foo : |
| 3389 |
Base1, |
| 3390 |
Base2 |
| 3391 |
{}; |
| 3392 |
|
| 3393 |
* ``BILS_AfterComma`` (in configuration: ``AfterComma``) |
| 3394 |
Break inheritance list only after the commas. |
| 3395 |
|
| 3396 |
.. code-block:: c++ |
| 3397 |
|
| 3398 |
class Foo : Base1, |
| 3399 |
Base2 |
| 3400 |
{}; |
| 3401 |
|
| 3402 |
|
| 3403 |
|
| 3404 |
.. _BreakStringLiterals: |
| 3405 |
|
| 3406 |
**BreakStringLiterals** (``Boolean``) :versionbadge:`clang-format 3.9` :ref:`¶ <BreakStringLiterals>` |
| 3407 |
Allow breaking string literals when formatting. |
| 3408 |
|
| 3409 |
In C, C++, and Objective-C: |
| 3410 |
|
| 3411 |
.. code-block:: c++ |
| 3412 |
|
| 3413 |
true: |
| 3414 |
const char* x = "veryVeryVeryVeryVeryVe" |
| 3415 |
"ryVeryVeryVeryVeryVery" |
| 3416 |
"VeryLongString"; |
| 3417 |
|
| 3418 |
false: |
| 3419 |
const char* x = |
| 3420 |
"veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString"; |
| 3421 |
|
| 3422 |
In C# and Java: |
| 3423 |
|
| 3424 |
.. code-block:: c++ |
| 3425 |
|
| 3426 |
true: |
| 3427 |
string x = "veryVeryVeryVeryVeryVe" + |
| 3428 |
"ryVeryVeryVeryVeryVery" + |
| 3429 |
"VeryLongString"; |
| 3430 |
|
| 3431 |
false: |
| 3432 |
string x = |
| 3433 |
"veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString"; |
| 3434 |
|
| 3435 |
C# interpolated strings are not broken. |
| 3436 |
|
| 3437 |
In Verilog: |
| 3438 |
|
| 3439 |
.. code-block:: c++ |
| 3440 |
|
| 3441 |
true: |
| 3442 |
string x = {"veryVeryVeryVeryVeryVe", |
| 3443 |
"ryVeryVeryVeryVeryVery", |
| 3444 |
"VeryLongString"}; |
| 3445 |
|
| 3446 |
false: |
| 3447 |
string x = |
| 3448 |
"veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString"; |
| 3449 |
|
| 3450 |
.. _BreakTemplateDeclarations: |
| 3451 |
|
| 3452 |
**BreakTemplateDeclarations** (``BreakTemplateDeclarationsStyle``) :versionbadge:`clang-format 19` :ref:`¶ <BreakTemplateDeclarations>` |
| 3453 |
The template declaration breaking style to use. |
| 3454 |
|
| 3455 |
Possible values: |
| 3456 |
|
| 3457 |
* ``BTDS_Leave`` (in configuration: ``Leave``) |
| 3458 |
Do not change the line breaking before the declaration. |
| 3459 |
|
| 3460 |
.. code-block:: c++ |
| 3461 |
|
| 3462 |
template <typename T> |
| 3463 |
T foo() { |
| 3464 |
} |
| 3465 |
template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa, |
| 3466 |
int bbbbbbbbbbbbbbbbbbbbb) { |
| 3467 |
} |
| 3468 |
|
| 3469 |
* ``BTDS_No`` (in configuration: ``No``) |
| 3470 |
Do not force break before declaration. |
| 3471 |
``PenaltyBreakTemplateDeclaration`` is taken into account. |
| 3472 |
|
| 3473 |
.. code-block:: c++ |
| 3474 |
|
| 3475 |
template <typename T> T foo() { |
| 3476 |
} |
| 3477 |
template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa, |
| 3478 |
int bbbbbbbbbbbbbbbbbbbbb) { |
| 3479 |
} |
| 3480 |
|
| 3481 |
* ``BTDS_MultiLine`` (in configuration: ``MultiLine``) |
| 3482 |
Force break after template declaration only when the following |
| 3483 |
declaration spans multiple lines. |
| 3484 |
|
| 3485 |
.. code-block:: c++ |
| 3486 |
|
| 3487 |
template <typename T> T foo() { |
| 3488 |
} |
| 3489 |
template <typename T> |
| 3490 |
T foo(int aaaaaaaaaaaaaaaaaaaaa, |
| 3491 |
int bbbbbbbbbbbbbbbbbbbbb) { |
| 3492 |
} |
| 3493 |
|
| 3494 |
* ``BTDS_Yes`` (in configuration: ``Yes``) |
| 3495 |
Always break after template declaration. |
| 3496 |
|
| 3497 |
.. code-block:: c++ |
| 3498 |
|
| 3499 |
template <typename T> |
| 3500 |
T foo() { |
| 3501 |
} |
| 3502 |
template <typename T> |
| 3503 |
T foo(int aaaaaaaaaaaaaaaaaaaaa, |
| 3504 |
int bbbbbbbbbbbbbbbbbbbbb) { |
| 3505 |
} |
| 3506 |
|
| 3507 |
|
| 3508 |
|
| 3509 |
.. _ColumnLimit: |
| 3510 |
|
| 3511 |
**ColumnLimit** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <ColumnLimit>` |
| 3512 |
The column limit. |
| 3513 |
|
| 3514 |
A column limit of ``0`` means that there is no column limit. In this case, |
| 3515 |
clang-format will respect the input's line breaking decisions within |
| 3516 |
statements unless they contradict other rules. |
| 3517 |
|
| 3518 |
.. _CommentPragmas: |
| 3519 |
|
| 3520 |
**CommentPragmas** (``String``) :versionbadge:`clang-format 3.7` :ref:`¶ <CommentPragmas>` |
| 3521 |
A regular expression that describes comments with special meaning, |
| 3522 |
which should not be split into lines or otherwise changed. |
| 3523 |
|
| 3524 |
.. code-block:: c++ |
| 3525 |
|
| 3526 |
// CommentPragmas: '^ FOOBAR pragma:' |
| 3527 |
// Will leave the following line unaffected |
| 3528 |
#include <vector> // FOOBAR pragma: keep |
| 3529 |
|
| 3530 |
.. _CompactNamespaces: |
| 3531 |
|
| 3532 |
**CompactNamespaces** (``Boolean``) :versionbadge:`clang-format 5` :ref:`¶ <CompactNamespaces>` |
| 3533 |
If ``true``, consecutive namespace declarations will be on the same |
| 3534 |
line. If ``false``, each namespace is declared on a new line. |
| 3535 |
|
| 3536 |
.. code-block:: c++ |
| 3537 |
|
| 3538 |
true: |
| 3539 |
namespace Foo { namespace Bar { |
| 3540 |
}} |
| 3541 |
|
| 3542 |
false: |
| 3543 |
namespace Foo { |
| 3544 |
namespace Bar { |
| 3545 |
} |
| 3546 |
} |
| 3547 |
|
| 3548 |
If it does not fit on a single line, the overflowing namespaces get |
| 3549 |
wrapped: |
| 3550 |
|
| 3551 |
.. code-block:: c++ |
| 3552 |
|
| 3553 |
namespace Foo { namespace Bar { |
| 3554 |
namespace Extra { |
| 3555 |
}}} |
| 3556 |
|
| 3557 |
.. _ConstructorInitializerAllOnOneLineOrOnePerLine: |
| 3558 |
|
| 3559 |
**ConstructorInitializerAllOnOneLineOrOnePerLine** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <ConstructorInitializerAllOnOneLineOrOnePerLine>` |
| 3560 |
This option is **deprecated**. See ``CurrentLine`` of |
| 3561 |
``PackConstructorInitializers``. |
| 3562 |
|
| 3563 |
.. _ConstructorInitializerIndentWidth: |
| 3564 |
|
| 3565 |
**ConstructorInitializerIndentWidth** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <ConstructorInitializerIndentWidth>` |
| 3566 |
The number of characters to use for indentation of constructor |
| 3567 |
initializer lists as well as inheritance lists. |
| 3568 |
|
| 3569 |
.. _ContinuationIndentWidth: |
| 3570 |
|
| 3571 |
**ContinuationIndentWidth** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <ContinuationIndentWidth>` |
| 3572 |
Indent width for line continuations. |
| 3573 |
|
| 3574 |
.. code-block:: c++ |
| 3575 |
|
| 3576 |
ContinuationIndentWidth: 2 |
| 3577 |
|
| 3578 |
int i = // VeryVeryVeryVeryVeryLongComment |
| 3579 |
longFunction( // Again a long comment |
| 3580 |
arg); |
| 3581 |
|
| 3582 |
.. _Cpp11BracedListStyle: |
| 3583 |
|
| 3584 |
**Cpp11BracedListStyle** (``Boolean``) :versionbadge:`clang-format 3.4` :ref:`¶ <Cpp11BracedListStyle>` |
| 3585 |
If ``true``, format braced lists as best suited for C++11 braced |
| 3586 |
lists. |
| 3587 |
|
| 3588 |
Important differences: |
| 3589 |
- No spaces inside the braced list. |
| 3590 |
- No line break before the closing brace. |
| 3591 |
- Indentation with the continuation indent, not with the block indent. |
| 3592 |
|
| 3593 |
Fundamentally, C++11 braced lists are formatted exactly like function |
| 3594 |
calls would be formatted in their place. If the braced list follows a name |
| 3595 |
(e.g. a type or variable name), clang-format formats as if the ``{}`` were |
| 3596 |
the parentheses of a function call with that name. If there is no name, |
| 3597 |
a zero-length name is assumed. |
| 3598 |
|
| 3599 |
.. code-block:: c++ |
| 3600 |
|
| 3601 |
true: false: |
| 3602 |
vector<int> x{1, 2, 3, 4}; vs. vector<int> x{ 1, 2, 3, 4 }; |
| 3603 |
vector<T> x{{}, {}, {}, {}}; vector<T> x{ {}, {}, {}, {} }; |
| 3604 |
f(MyMap[{composite, key}]); f(MyMap[{ composite, key }]); |
| 3605 |
new int[3]{1, 2, 3}; new int[3]{ 1, 2, 3 }; |
| 3606 |
|
| 3607 |
.. _DeriveLineEnding: |
| 3608 |
|
| 3609 |
**DeriveLineEnding** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ <DeriveLineEnding>` |
| 3610 |
This option is **deprecated**. See ``DeriveLF`` and ``DeriveCRLF`` of |
| 3611 |
``LineEnding``. |
| 3612 |
|
| 3613 |
.. _DerivePointerAlignment: |
| 3614 |
|
| 3615 |
**DerivePointerAlignment** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <DerivePointerAlignment>` |
| 3616 |
If ``true``, analyze the formatted file for the most common |
| 3617 |
alignment of ``&`` and ``*``. |
| 3618 |
Pointer and reference alignment styles are going to be updated according |
| 3619 |
to the preferences found in the file. |
| 3620 |
``PointerAlignment`` is then used only as fallback. |
| 3621 |
|
| 3622 |
.. _DisableFormat: |
| 3623 |
|
| 3624 |
**DisableFormat** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <DisableFormat>` |
| 3625 |
Disables formatting completely. |
| 3626 |
|
| 3627 |
.. _EmptyLineAfterAccessModifier: |
| 3628 |
|
| 3629 |
**EmptyLineAfterAccessModifier** (``EmptyLineAfterAccessModifierStyle``) :versionbadge:`clang-format 13` :ref:`¶ <EmptyLineAfterAccessModifier>` |
| 3630 |
Defines when to put an empty line after access modifiers. |
| 3631 |
``EmptyLineBeforeAccessModifier`` configuration handles the number of |
| 3632 |
empty lines between two access modifiers. |
| 3633 |
|
| 3634 |
Possible values: |
| 3635 |
|
| 3636 |
* ``ELAAMS_Never`` (in configuration: ``Never``) |
| 3637 |
Remove all empty lines after access modifiers. |
| 3638 |
|
| 3639 |
.. code-block:: c++ |
| 3640 |
|
| 3641 |
struct foo { |
| 3642 |
private: |
| 3643 |
int i; |
| 3644 |
protected: |
| 3645 |
int j; |
| 3646 |
/* comment */ |
| 3647 |
public: |
| 3648 |
foo() {} |
| 3649 |
private: |
| 3650 |
protected: |
| 3651 |
}; |
| 3652 |
|
| 3653 |
* ``ELAAMS_Leave`` (in configuration: ``Leave``) |
| 3654 |
Keep existing empty lines after access modifiers. |
| 3655 |
MaxEmptyLinesToKeep is applied instead. |
| 3656 |
|
| 3657 |
* ``ELAAMS_Always`` (in configuration: ``Always``) |
| 3658 |
Always add empty line after access modifiers if there are none. |
| 3659 |
MaxEmptyLinesToKeep is applied also. |
| 3660 |
|
| 3661 |
.. code-block:: c++ |
| 3662 |
|
| 3663 |
struct foo { |
| 3664 |
private: |
| 3665 |
|
| 3666 |
int i; |
| 3667 |
protected: |
| 3668 |
|
| 3669 |
int j; |
| 3670 |
/* comment */ |
| 3671 |
public: |
| 3672 |
|
| 3673 |
foo() {} |
| 3674 |
private: |
| 3675 |
|
| 3676 |
protected: |
| 3677 |
|
| 3678 |
}; |
| 3679 |
|
| 3680 |
|
| 3681 |
|
| 3682 |
.. _EmptyLineBeforeAccessModifier: |
| 3683 |
|
| 3684 |
**EmptyLineBeforeAccessModifier** (``EmptyLineBeforeAccessModifierStyle``) :versionbadge:`clang-format 12` :ref:`¶ <EmptyLineBeforeAccessModifier>` |
| 3685 |
Defines in which cases to put empty line before access modifiers. |
| 3686 |
|
| 3687 |
Possible values: |
| 3688 |
|
| 3689 |
* ``ELBAMS_Never`` (in configuration: ``Never``) |
| 3690 |
Remove all empty lines before access modifiers. |
| 3691 |
|
| 3692 |
.. code-block:: c++ |
| 3693 |
|
| 3694 |
struct foo { |
| 3695 |
private: |
| 3696 |
int i; |
| 3697 |
protected: |
| 3698 |
int j; |
| 3699 |
/* comment */ |
| 3700 |
public: |
| 3701 |
foo() {} |
| 3702 |
private: |
| 3703 |
protected: |
| 3704 |
}; |
| 3705 |
|
| 3706 |
* ``ELBAMS_Leave`` (in configuration: ``Leave``) |
| 3707 |
Keep existing empty lines before access modifiers. |
| 3708 |
|
| 3709 |
* ``ELBAMS_LogicalBlock`` (in configuration: ``LogicalBlock``) |
| 3710 |
Add empty line only when access modifier starts a new logical block. |
| 3711 |
Logical block is a group of one or more member fields or functions. |
| 3712 |
|
| 3713 |
.. code-block:: c++ |
| 3714 |
|
| 3715 |
struct foo { |
| 3716 |
private: |
| 3717 |
int i; |
| 3718 |
|
| 3719 |
protected: |
| 3720 |
int j; |
| 3721 |
/* comment */ |
| 3722 |
public: |
| 3723 |
foo() {} |
| 3724 |
|
| 3725 |
private: |
| 3726 |
protected: |
| 3727 |
}; |
| 3728 |
|
| 3729 |
* ``ELBAMS_Always`` (in configuration: ``Always``) |
| 3730 |
Always add empty line before access modifiers unless access modifier |
| 3731 |
is at the start of struct or class definition. |
| 3732 |
|
| 3733 |
.. code-block:: c++ |
| 3734 |
|
| 3735 |
struct foo { |
| 3736 |
private: |
| 3737 |
int i; |
| 3738 |
|
| 3739 |
protected: |
| 3740 |
int j; |
| 3741 |
/* comment */ |
| 3742 |
|
| 3743 |
public: |
| 3744 |
foo() {} |
| 3745 |
|
| 3746 |
private: |
| 3747 |
|
| 3748 |
protected: |
| 3749 |
}; |
| 3750 |
|
| 3751 |
|
| 3752 |
|
| 3753 |
.. _ExperimentalAutoDetectBinPacking: |
| 3754 |
|
| 3755 |
**ExperimentalAutoDetectBinPacking** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <ExperimentalAutoDetectBinPacking>` |
| 3756 |
If ``true``, clang-format detects whether function calls and |
| 3757 |
definitions are formatted with one parameter per line. |
| 3758 |
|
| 3759 |
Each call can be bin-packed, one-per-line or inconclusive. If it is |
| 3760 |
inconclusive, e.g. completely on one line, but a decision needs to be |
| 3761 |
made, clang-format analyzes whether there are other bin-packed cases in |
| 3762 |
the input file and act accordingly. |
| 3763 |
|
| 3764 |
|
| 3765 |
.. note:: |
| 3766 |
|
| 3767 |
This is an experimental flag, that might go away or be renamed. Do |
| 3768 |
not use this in config files, etc. Use at your own risk. |
| 3769 |
|
| 3770 |
.. _FixNamespaceComments: |
| 3771 |
|
| 3772 |
**FixNamespaceComments** (``Boolean``) :versionbadge:`clang-format 5` :ref:`¶ <FixNamespaceComments>` |
| 3773 |
If ``true``, clang-format adds missing namespace end comments for |
| 3774 |
namespaces and fixes invalid existing ones. This doesn't affect short |
| 3775 |
namespaces, which are controlled by ``ShortNamespaceLines``. |
| 3776 |
|
| 3777 |
.. code-block:: c++ |
| 3778 |
|
| 3779 |
true: false: |
| 3780 |
namespace longNamespace { vs. namespace longNamespace { |
| 3781 |
void foo(); void foo(); |
| 3782 |
void bar(); void bar(); |
| 3783 |
} // namespace a } |
| 3784 |
namespace shortNamespace { namespace shortNamespace { |
| 3785 |
void baz(); void baz(); |
| 3786 |
} } |
| 3787 |
|
| 3788 |
.. _ForEachMacros: |
| 3789 |
|
| 3790 |
**ForEachMacros** (``List of Strings``) :versionbadge:`clang-format 3.7` :ref:`¶ <ForEachMacros>` |
| 3791 |
A vector of macros that should be interpreted as foreach loops |
| 3792 |
instead of as function calls. |
| 3793 |
|
| 3794 |
These are expected to be macros of the form: |
| 3795 |
|
| 3796 |
.. code-block:: c++ |
| 3797 |
|
| 3798 |
FOREACH(<variable-declaration>, ...) |
| 3799 |
<loop-body> |
| 3800 |
|
| 3801 |
In the .clang-format configuration file, this can be configured like: |
| 3802 |
|
| 3803 |
.. code-block:: yaml |
| 3804 |
|
| 3805 |
ForEachMacros: [RANGES_FOR, FOREACH] |
| 3806 |
|
| 3807 |
For example: BOOST_FOREACH. |
| 3808 |
|
| 3809 |
.. _IfMacros: |
| 3810 |
|
| 3811 |
**IfMacros** (``List of Strings``) :versionbadge:`clang-format 13` :ref:`¶ <IfMacros>` |
| 3812 |
A vector of macros that should be interpreted as conditionals |
| 3813 |
instead of as function calls. |
| 3814 |
|
| 3815 |
These are expected to be macros of the form: |
| 3816 |
|
| 3817 |
.. code-block:: c++ |
| 3818 |
|
| 3819 |
IF(...) |
| 3820 |
<conditional-body> |
| 3821 |
else IF(...) |
| 3822 |
<conditional-body> |
| 3823 |
|
| 3824 |
In the .clang-format configuration file, this can be configured like: |
| 3825 |
|
| 3826 |
.. code-block:: yaml |
| 3827 |
|
| 3828 |
IfMacros: [IF] |
| 3829 |
|
| 3830 |
For example: `KJ_IF_MAYBE |
| 3831 |
<https://github.com/capnproto/capnproto/blob/master/kjdoc/tour.md#maybes>`_ |
| 3832 |
|
| 3833 |
.. _IncludeBlocks: |
| 3834 |
|
| 3835 |
**IncludeBlocks** (``IncludeBlocksStyle``) :versionbadge:`clang-format 6` :ref:`¶ <IncludeBlocks>` |
| 3836 |
Dependent on the value, multiple ``#include`` blocks can be sorted |
| 3837 |
as one and divided based on category. |
| 3838 |
|
| 3839 |
Possible values: |
| 3840 |
|
| 3841 |
* ``IBS_Preserve`` (in configuration: ``Preserve``) |
| 3842 |
Sort each ``#include`` block separately. |
| 3843 |
|
| 3844 |
.. code-block:: c++ |
| 3845 |
|
| 3846 |
#include "b.h" into #include "b.h" |
| 3847 |
|
| 3848 |
#include <lib/main.h> #include "a.h" |
| 3849 |
#include "a.h" #include <lib/main.h> |
| 3850 |
|
| 3851 |
* ``IBS_Merge`` (in configuration: ``Merge``) |
| 3852 |
Merge multiple ``#include`` blocks together and sort as one. |
| 3853 |
|
| 3854 |
.. code-block:: c++ |
| 3855 |
|
| 3856 |
#include "b.h" into #include "a.h" |
| 3857 |
#include "b.h" |
| 3858 |
#include <lib/main.h> #include <lib/main.h> |
| 3859 |
#include "a.h" |
| 3860 |
|
| 3861 |
* ``IBS_Regroup`` (in configuration: ``Regroup``) |
| 3862 |
Merge multiple ``#include`` blocks together and sort as one. |
| 3863 |
Then split into groups based on category priority. See |
| 3864 |
``IncludeCategories``. |
| 3865 |
|
| 3866 |
.. code-block:: c++ |
| 3867 |
|
| 3868 |
#include "b.h" into #include "a.h" |
| 3869 |
#include "b.h" |
| 3870 |
#include <lib/main.h> |
| 3871 |
#include "a.h" #include <lib/main.h> |
| 3872 |
|
| 3873 |
|
| 3874 |
|
| 3875 |
.. _IncludeCategories: |
| 3876 |
|
| 3877 |
**IncludeCategories** (``List of IncludeCategories``) :versionbadge:`clang-format 3.8` :ref:`¶ <IncludeCategories>` |
| 3878 |
Regular expressions denoting the different ``#include`` categories |
| 3879 |
used for ordering ``#includes``. |
| 3880 |
|
| 3881 |
`POSIX extended |
| 3882 |
<https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html>`_ |
| 3883 |
regular expressions are supported. |
| 3884 |
|
| 3885 |
These regular expressions are matched against the filename of an include |
| 3886 |
(including the <> or "") in order. The value belonging to the first |
| 3887 |
matching regular expression is assigned and ``#includes`` are sorted first |
| 3888 |
according to increasing category number and then alphabetically within |
| 3889 |
each category. |
| 3890 |
|
| 3891 |
If none of the regular expressions match, INT_MAX is assigned as |
| 3892 |
category. The main header for a source file automatically gets category 0. |
| 3893 |
so that it is generally kept at the beginning of the ``#includes`` |
| 3894 |
(https://llvm.org/docs/CodingStandards.html#include-style). However, you |
| 3895 |
can also assign negative priorities if you have certain headers that |
| 3896 |
always need to be first. |
| 3897 |
|
| 3898 |
There is a third and optional field ``SortPriority`` which can used while |
| 3899 |
``IncludeBlocks = IBS_Regroup`` to define the priority in which |
| 3900 |
``#includes`` should be ordered. The value of ``Priority`` defines the |
| 3901 |
order of ``#include blocks`` and also allows the grouping of ``#includes`` |
| 3902 |
of different priority. ``SortPriority`` is set to the value of |
| 3903 |
``Priority`` as default if it is not assigned. |
| 3904 |
|
| 3905 |
Each regular expression can be marked as case sensitive with the field |
| 3906 |
``CaseSensitive``, per default it is not. |
| 3907 |
|
| 3908 |
To configure this in the .clang-format file, use: |
| 3909 |
|
| 3910 |
.. code-block:: yaml |
| 3911 |
|
| 3912 |
IncludeCategories: |
| 3913 |
- Regex: '^"(llvm|llvm-c|clang|clang-c)/' |
| 3914 |
Priority: 2 |
| 3915 |
SortPriority: 2 |
| 3916 |
CaseSensitive: true |
| 3917 |
- Regex: '^((<|")(gtest|gmock|isl|json)/)' |
| 3918 |
Priority: 3 |
| 3919 |
- Regex: '<[[:alnum:].]+>' |
| 3920 |
Priority: 4 |
| 3921 |
- Regex: '.*' |
| 3922 |
Priority: 1 |
| 3923 |
SortPriority: 0 |
| 3924 |
|
| 3925 |
.. _IncludeIsMainRegex: |
| 3926 |
|
| 3927 |
**IncludeIsMainRegex** (``String``) :versionbadge:`clang-format 3.9` :ref:`¶ <IncludeIsMainRegex>` |
| 3928 |
Specify a regular expression of suffixes that are allowed in the |
| 3929 |
file-to-main-include mapping. |
| 3930 |
|
| 3931 |
When guessing whether a #include is the "main" include (to assign |
| 3932 |
category 0, see above), use this regex of allowed suffixes to the header |
| 3933 |
stem. A partial match is done, so that: |
| 3934 |
- "" means "arbitrary suffix" |
| 3935 |
- "$" means "no suffix" |
| 3936 |
|
| 3937 |
For example, if configured to "(_test)?$", then a header a.h would be seen |
| 3938 |
as the "main" include in both a.cc and a_test.cc. |
| 3939 |
|
| 3940 |
.. _IncludeIsMainSourceRegex: |
| 3941 |
|
| 3942 |
**IncludeIsMainSourceRegex** (``String``) :versionbadge:`clang-format 10` :ref:`¶ <IncludeIsMainSourceRegex>` |
| 3943 |
Specify a regular expression for files being formatted |
| 3944 |
that are allowed to be considered "main" in the |
| 3945 |
file-to-main-include mapping. |
| 3946 |
|
| 3947 |
By default, clang-format considers files as "main" only when they end |
| 3948 |
with: ``.c``, ``.cc``, ``.cpp``, ``.c++``, ``.cxx``, ``.m`` or ``.mm`` |
| 3949 |
extensions. |
| 3950 |
For these files a guessing of "main" include takes place |
| 3951 |
(to assign category 0, see above). This config option allows for |
| 3952 |
additional suffixes and extensions for files to be considered as "main". |
| 3953 |
|
| 3954 |
For example, if this option is configured to ``(Impl\.hpp)$``, |
| 3955 |
then a file ``ClassImpl.hpp`` is considered "main" (in addition to |
| 3956 |
``Class.c``, ``Class.cc``, ``Class.cpp`` and so on) and "main |
| 3957 |
include file" logic will be executed (with *IncludeIsMainRegex* setting |
| 3958 |
also being respected in later phase). Without this option set, |
| 3959 |
``ClassImpl.hpp`` would not have the main include file put on top |
| 3960 |
before any other include. |
| 3961 |
|
| 3962 |
.. _IndentAccessModifiers: |
| 3963 |
|
| 3964 |
**IndentAccessModifiers** (``Boolean``) :versionbadge:`clang-format 13` :ref:`¶ <IndentAccessModifiers>` |
| 3965 |
Specify whether access modifiers should have their own indentation level. |
| 3966 |
|
| 3967 |
When ``false``, access modifiers are indented (or outdented) relative to |
| 3968 |
the record members, respecting the ``AccessModifierOffset``. Record |
| 3969 |
members are indented one level below the record. |
| 3970 |
When ``true``, access modifiers get their own indentation level. As a |
| 3971 |
consequence, record members are always indented 2 levels below the record, |
| 3972 |
regardless of the access modifier presence. Value of the |
| 3973 |
``AccessModifierOffset`` is ignored. |
| 3974 |
|
| 3975 |
.. code-block:: c++ |
| 3976 |
|
| 3977 |
false: true: |
| 3978 |
class C { vs. class C { |
| 3979 |
class D { class D { |
| 3980 |
void bar(); void bar(); |
| 3981 |
protected: protected: |
| 3982 |
D(); D(); |
| 3983 |
}; }; |
| 3984 |
public: public: |
| 3985 |
C(); C(); |
| 3986 |
}; }; |
| 3987 |
void foo() { void foo() { |
| 3988 |
return 1; return 1; |
| 3989 |
} } |
| 3990 |
|
| 3991 |
.. _IndentCaseBlocks: |
| 3992 |
|
| 3993 |
**IndentCaseBlocks** (``Boolean``) :versionbadge:`clang-format 11` :ref:`¶ <IndentCaseBlocks>` |
| 3994 |
Indent case label blocks one level from the case label. |
| 3995 |
|
| 3996 |
When ``false``, the block following the case label uses the same |
| 3997 |
indentation level as for the case label, treating the case label the same |
| 3998 |
as an if-statement. |
| 3999 |
When ``true``, the block gets indented as a scope block. |
| 4000 |
|
| 4001 |
.. code-block:: c++ |
| 4002 |
|
| 4003 |
false: true: |
| 4004 |
switch (fool) { vs. switch (fool) { |
| 4005 |
case 1: { case 1: |
| 4006 |
bar(); { |
| 4007 |
} break; bar(); |
| 4008 |
default: { } |
| 4009 |
plop(); break; |
| 4010 |
} default: |
| 4011 |
} { |
| 4012 |
plop(); |
| 4013 |
} |
| 4014 |
} |
| 4015 |
|
| 4016 |
.. _IndentCaseLabels: |
| 4017 |
|
| 4018 |
**IndentCaseLabels** (``Boolean``) :versionbadge:`clang-format 3.3` :ref:`¶ <IndentCaseLabels>` |
| 4019 |
Indent case labels one level from the switch statement. |
| 4020 |
|
| 4021 |
When ``false``, use the same indentation level as for the switch |
| 4022 |
statement. Switch statement body is always indented one level more than |
| 4023 |
case labels (except the first block following the case label, which |
| 4024 |
itself indents the code - unless IndentCaseBlocks is enabled). |
| 4025 |
|
| 4026 |
.. code-block:: c++ |
| 4027 |
|
| 4028 |
false: true: |
| 4029 |
switch (fool) { vs. switch (fool) { |
| 4030 |
case 1: case 1: |
| 4031 |
bar(); bar(); |
| 4032 |
break; break; |
| 4033 |
default: default: |
| 4034 |
plop(); plop(); |
| 4035 |
} } |
| 4036 |
|
| 4037 |
.. _IndentExternBlock: |
| 4038 |
|
| 4039 |
**IndentExternBlock** (``IndentExternBlockStyle``) :versionbadge:`clang-format 11` :ref:`¶ <IndentExternBlock>` |
| 4040 |
IndentExternBlockStyle is the type of indenting of extern blocks. |
| 4041 |
|
| 4042 |
Possible values: |
| 4043 |
|
| 4044 |
* ``IEBS_AfterExternBlock`` (in configuration: ``AfterExternBlock``) |
| 4045 |
Backwards compatible with AfterExternBlock's indenting. |
| 4046 |
|
| 4047 |
.. code-block:: c++ |
| 4048 |
|
| 4049 |
IndentExternBlock: AfterExternBlock |
| 4050 |
BraceWrapping.AfterExternBlock: true |
| 4051 |
extern "C" |
| 4052 |
{ |
| 4053 |
void foo(); |
| 4054 |
} |
| 4055 |
|
| 4056 |
|
| 4057 |
.. code-block:: c++ |
| 4058 |
|
| 4059 |
IndentExternBlock: AfterExternBlock |
| 4060 |
BraceWrapping.AfterExternBlock: false |
| 4061 |
extern "C" { |
| 4062 |
void foo(); |
| 4063 |
} |
| 4064 |
|
| 4065 |
* ``IEBS_NoIndent`` (in configuration: ``NoIndent``) |
| 4066 |
Does not indent extern blocks. |
| 4067 |
|
| 4068 |
.. code-block:: c++ |
| 4069 |
|
| 4070 |
extern "C" { |
| 4071 |
void foo(); |
| 4072 |
} |
| 4073 |
|
| 4074 |
* ``IEBS_Indent`` (in configuration: ``Indent``) |
| 4075 |
Indents extern blocks. |
| 4076 |
|
| 4077 |
.. code-block:: c++ |
| 4078 |
|
| 4079 |
extern "C" { |
| 4080 |
void foo(); |
| 4081 |
} |
| 4082 |
|
| 4083 |
|
| 4084 |
|
| 4085 |
.. _IndentGotoLabels: |
| 4086 |
|
| 4087 |
**IndentGotoLabels** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ <IndentGotoLabels>` |
| 4088 |
Indent goto labels. |
| 4089 |
|
| 4090 |
When ``false``, goto labels are flushed left. |
| 4091 |
|
| 4092 |
.. code-block:: c++ |
| 4093 |
|
| 4094 |
true: false: |
| 4095 |
int f() { vs. int f() { |
| 4096 |
if (foo()) { if (foo()) { |
| 4097 |
label1: label1: |
| 4098 |
bar(); bar(); |
| 4099 |
} } |
| 4100 |
label2: label2: |
| 4101 |
return 1; return 1; |
| 4102 |
} } |
| 4103 |
|
| 4104 |
.. _IndentPPDirectives: |
| 4105 |
|
| 4106 |
**IndentPPDirectives** (``PPDirectiveIndentStyle``) :versionbadge:`clang-format 6` :ref:`¶ <IndentPPDirectives>` |
| 4107 |
The preprocessor directive indenting style to use. |
| 4108 |
|
| 4109 |
Possible values: |
| 4110 |
|
| 4111 |
* ``PPDIS_None`` (in configuration: ``None``) |
| 4112 |
Does not indent any directives. |
| 4113 |
|
| 4114 |
.. code-block:: c++ |
| 4115 |
|
| 4116 |
#if FOO |
| 4117 |
#if BAR |
| 4118 |
#include <foo> |
| 4119 |
#endif |
| 4120 |
#endif |
| 4121 |
|
| 4122 |
* ``PPDIS_AfterHash`` (in configuration: ``AfterHash``) |
| 4123 |
Indents directives after the hash. |
| 4124 |
|
| 4125 |
.. code-block:: c++ |
| 4126 |
|
| 4127 |
#if FOO |
| 4128 |
# if BAR |
| 4129 |
# include <foo> |
| 4130 |
# endif |
| 4131 |
#endif |
| 4132 |
|
| 4133 |
* ``PPDIS_BeforeHash`` (in configuration: ``BeforeHash``) |
| 4134 |
Indents directives before the hash. |
| 4135 |
|
| 4136 |
.. code-block:: c++ |
| 4137 |
|
| 4138 |
#if FOO |
| 4139 |
#if BAR |
| 4140 |
#include <foo> |
| 4141 |
#endif |
| 4142 |
#endif |
| 4143 |
|
| 4144 |
|
| 4145 |
|
| 4146 |
.. _IndentRequiresClause: |
| 4147 |
|
| 4148 |
**IndentRequiresClause** (``Boolean``) :versionbadge:`clang-format 15` :ref:`¶ <IndentRequiresClause>` |
| 4149 |
Indent the requires clause in a template. This only applies when |
| 4150 |
``RequiresClausePosition`` is ``OwnLine``, or ``WithFollowing``. |
| 4151 |
|
| 4152 |
In clang-format 12, 13 and 14 it was named ``IndentRequires``. |
| 4153 |
|
| 4154 |
.. code-block:: c++ |
| 4155 |
|
| 4156 |
true: |
| 4157 |
template <typename It> |
| 4158 |
requires Iterator<It> |
| 4159 |
void sort(It begin, It end) { |
| 4160 |
//.... |
| 4161 |
} |
| 4162 |
|
| 4163 |
false: |
| 4164 |
template <typename It> |
| 4165 |
requires Iterator<It> |
| 4166 |
void sort(It begin, It end) { |
| 4167 |
//.... |
| 4168 |
} |
| 4169 |
|
| 4170 |
.. _IndentWidth: |
| 4171 |
|
| 4172 |
**IndentWidth** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <IndentWidth>` |
| 4173 |
The number of columns to use for indentation. |
| 4174 |
|
| 4175 |
.. code-block:: c++ |
| 4176 |
|
| 4177 |
IndentWidth: 3 |
| 4178 |
|
| 4179 |
void f() { |
| 4180 |
someFunction(); |
| 4181 |
if (true, false) { |
| 4182 |
f(); |
| 4183 |
} |
| 4184 |
} |
| 4185 |
|
| 4186 |
.. _IndentWrappedFunctionNames: |
| 4187 |
|
| 4188 |
**IndentWrappedFunctionNames** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <IndentWrappedFunctionNames>` |
| 4189 |
Indent if a function definition or declaration is wrapped after the |
| 4190 |
type. |
| 4191 |
|
| 4192 |
.. code-block:: c++ |
| 4193 |
|
| 4194 |
true: |
| 4195 |
LoooooooooooooooooooooooooooooooooooooooongReturnType |
| 4196 |
LoooooooooooooooooooooooooooooooongFunctionDeclaration(); |
| 4197 |
|
| 4198 |
false: |
| 4199 |
LoooooooooooooooooooooooooooooooooooooooongReturnType |
| 4200 |
LoooooooooooooooooooooooooooooooongFunctionDeclaration(); |
| 4201 |
|
| 4202 |
.. _InsertBraces: |
| 4203 |
|
| 4204 |
**InsertBraces** (``Boolean``) :versionbadge:`clang-format 15` :ref:`¶ <InsertBraces>` |
| 4205 |
Insert braces after control statements (``if``, ``else``, ``for``, ``do``, |
| 4206 |
and ``while``) in C++ unless the control statements are inside macro |
| 4207 |
definitions or the braces would enclose preprocessor directives. |
| 4208 |
|
| 4209 |
.. warning:: |
| 4210 |
|
| 4211 |
Setting this option to ``true`` could lead to incorrect code formatting |
| 4212 |
due to clang-format's lack of complete semantic information. As such, |
| 4213 |
extra care should be taken to review code changes made by this option. |
| 4214 |
|
| 4215 |
.. code-block:: c++ |
| 4216 |
|
| 4217 |
false: true: |
| 4218 |
|
| 4219 |
if (isa<FunctionDecl>(D)) vs. if (isa<FunctionDecl>(D)) { |
| 4220 |
handleFunctionDecl(D); handleFunctionDecl(D); |
| 4221 |
else if (isa<VarDecl>(D)) } else if (isa<VarDecl>(D)) { |
| 4222 |
handleVarDecl(D); handleVarDecl(D); |
| 4223 |
else } else { |
| 4224 |
return; return; |
| 4225 |
} |
| 4226 |
|
| 4227 |
while (i--) vs. while (i--) { |
| 4228 |
for (auto *A : D.attrs()) for (auto *A : D.attrs()) { |
| 4229 |
handleAttr(A); handleAttr(A); |
| 4230 |
} |
| 4231 |
} |
| 4232 |
|
| 4233 |
do vs. do { |
| 4234 |
--i; --i; |
| 4235 |
while (i); } while (i); |
| 4236 |
|
| 4237 |
.. _InsertNewlineAtEOF: |
| 4238 |
|
| 4239 |
**InsertNewlineAtEOF** (``Boolean``) :versionbadge:`clang-format 16` :ref:`¶ <InsertNewlineAtEOF>` |
| 4240 |
Insert a newline at end of file if missing. |
| 4241 |
|
| 4242 |
.. _InsertTrailingCommas: |
| 4243 |
|
| 4244 |
**InsertTrailingCommas** (``TrailingCommaStyle``) :versionbadge:`clang-format 11` :ref:`¶ <InsertTrailingCommas>` |
| 4245 |
If set to ``TCS_Wrapped`` will insert trailing commas in container |
| 4246 |
literals (arrays and objects) that wrap across multiple lines. |
| 4247 |
It is currently only available for JavaScript |
| 4248 |
and disabled by default ``TCS_None``. |
| 4249 |
``InsertTrailingCommas`` cannot be used together with ``BinPackArguments`` |
| 4250 |
as inserting the comma disables bin-packing. |
| 4251 |
|
| 4252 |
.. code-block:: c++ |
| 4253 |
|
| 4254 |
TSC_Wrapped: |
| 4255 |
const someArray = [ |
| 4256 |
aaaaaaaaaaaaaaaaaaaaaaaaaa, |
| 4257 |
aaaaaaaaaaaaaaaaaaaaaaaaaa, |
| 4258 |
aaaaaaaaaaaaaaaaaaaaaaaaaa, |
| 4259 |
// ^ inserted |
| 4260 |
] |
| 4261 |
|
| 4262 |
Possible values: |
| 4263 |
|
| 4264 |
* ``TCS_None`` (in configuration: ``None``) |
| 4265 |
Do not insert trailing commas. |
| 4266 |
|
| 4267 |
* ``TCS_Wrapped`` (in configuration: ``Wrapped``) |
| 4268 |
Insert trailing commas in container literals that were wrapped over |
| 4269 |
multiple lines. Note that this is conceptually incompatible with |
| 4270 |
bin-packing, because the trailing comma is used as an indicator |
| 4271 |
that a container should be formatted one-per-line (i.e. not bin-packed). |
| 4272 |
So inserting a trailing comma counteracts bin-packing. |
| 4273 |
|
| 4274 |
|
| 4275 |
|
| 4276 |
.. _IntegerLiteralSeparator: |
| 4277 |
|
| 4278 |
**IntegerLiteralSeparator** (``IntegerLiteralSeparatorStyle``) :versionbadge:`clang-format 16` :ref:`¶ <IntegerLiteralSeparator>` |
| 4279 |
Format integer literal separators (``'`` for C++ and ``_`` for C#, Java, |
| 4280 |
and JavaScript). |
| 4281 |
|
| 4282 |
Nested configuration flags: |
| 4283 |
|
| 4284 |
Separator format of integer literals of different bases. |
| 4285 |
|
| 4286 |
If negative, remove separators. If ``0``, leave the literal as is. If |
| 4287 |
positive, insert separators between digits starting from the rightmost |
| 4288 |
digit. |
| 4289 |
|
| 4290 |
For example, the config below will leave separators in binary literals |
| 4291 |
alone, insert separators in decimal literals to separate the digits into |
| 4292 |
groups of 3, and remove separators in hexadecimal literals. |
| 4293 |
|
| 4294 |
.. code-block:: c++ |
| 4295 |
|
| 4296 |
IntegerLiteralSeparator: |
| 4297 |
Binary: 0 |
| 4298 |
Decimal: 3 |
| 4299 |
Hex: -1 |
| 4300 |
|
| 4301 |
You can also specify a minimum number of digits (``BinaryMinDigits``, |
| 4302 |
``DecimalMinDigits``, and ``HexMinDigits``) the integer literal must |
| 4303 |
have in order for the separators to be inserted. |
| 4304 |
|
| 4305 |
* ``int8_t Binary`` Format separators in binary literals. |
| 4306 |
|
| 4307 |
.. code-block:: text |
| 4308 |
|
| 4309 |
/* -1: */ b = 0b100111101101; |
| 4310 |
/* 0: */ b = 0b10011'11'0110'1; |
| 4311 |
/* 3: */ b = 0b100'111'101'101; |
| 4312 |
/* 4: */ b = 0b1001'1110'1101; |
| 4313 |
|
| 4314 |
* ``int8_t BinaryMinDigits`` Format separators in binary literals with a minimum number of digits. |
| 4315 |
|
| 4316 |
.. code-block:: text |
| 4317 |
|
| 4318 |
// Binary: 3 |
| 4319 |
// BinaryMinDigits: 7 |
| 4320 |
b1 = 0b101101; |
| 4321 |
b2 = 0b1'101'101; |
| 4322 |
|
| 4323 |
* ``int8_t Decimal`` Format separators in decimal literals. |
| 4324 |
|
| 4325 |
.. code-block:: text |
| 4326 |
|
| 4327 |
/* -1: */ d = 18446744073709550592ull; |
| 4328 |
/* 0: */ d = 184467'440737'0'95505'92ull; |
| 4329 |
/* 3: */ d = 18'446'744'073'709'550'592ull; |
| 4330 |
|
| 4331 |
* ``int8_t DecimalMinDigits`` Format separators in decimal literals with a minimum number of digits. |
| 4332 |
|
| 4333 |
.. code-block:: text |
| 4334 |
|
| 4335 |
// Decimal: 3 |
| 4336 |
// DecimalMinDigits: 5 |
| 4337 |
d1 = 2023; |
| 4338 |
d2 = 10'000; |
| 4339 |
|
| 4340 |
* ``int8_t Hex`` Format separators in hexadecimal literals. |
| 4341 |
|
| 4342 |
.. code-block:: text |
| 4343 |
|
| 4344 |
/* -1: */ h = 0xDEADBEEFDEADBEEFuz; |
| 4345 |
/* 0: */ h = 0xDEAD'BEEF'DE'AD'BEE'Fuz; |
| 4346 |
/* 2: */ h = 0xDE'AD'BE'EF'DE'AD'BE'EFuz; |
| 4347 |
|
| 4348 |
* ``int8_t HexMinDigits`` Format separators in hexadecimal literals with a minimum number of |
| 4349 |
digits. |
| 4350 |
|
| 4351 |
.. code-block:: text |
| 4352 |
|
| 4353 |
// Hex: 2 |
| 4354 |
// HexMinDigits: 6 |
| 4355 |
h1 = 0xABCDE; |
| 4356 |
h2 = 0xAB'CD'EF; |
| 4357 |
|
| 4358 |
|
| 4359 |
.. _JavaImportGroups: |
| 4360 |
|
| 4361 |
**JavaImportGroups** (``List of Strings``) :versionbadge:`clang-format 8` :ref:`¶ <JavaImportGroups>` |
| 4362 |
A vector of prefixes ordered by the desired groups for Java imports. |
| 4363 |
|
| 4364 |
One group's prefix can be a subset of another - the longest prefix is |
| 4365 |
always matched. Within a group, the imports are ordered lexicographically. |
| 4366 |
Static imports are grouped separately and follow the same group rules. |
| 4367 |
By default, static imports are placed before non-static imports, |
| 4368 |
but this behavior is changed by another option, |
| 4369 |
``SortJavaStaticImport``. |
| 4370 |
|
| 4371 |
In the .clang-format configuration file, this can be configured like |
| 4372 |
in the following yaml example. This will result in imports being |
| 4373 |
formatted as in the Java example below. |
| 4374 |
|
| 4375 |
.. code-block:: yaml |
| 4376 |
|
| 4377 |
JavaImportGroups: [com.example, com, org] |
| 4378 |
|
| 4379 |
|
| 4380 |
.. code-block:: java |
| 4381 |
|
| 4382 |
import static com.example.function1; |
| 4383 |
|
| 4384 |
import static com.test.function2; |
| 4385 |
|
| 4386 |
import static org.example.function3; |
| 4387 |
|
| 4388 |
import com.example.ClassA; |
| 4389 |
import com.example.Test; |
| 4390 |
import com.example.a.ClassB; |
| 4391 |
|
| 4392 |
import com.test.ClassC; |
| 4393 |
|
| 4394 |
import org.example.ClassD; |
| 4395 |
|
| 4396 |
.. _JavaScriptQuotes: |
| 4397 |
|
| 4398 |
**JavaScriptQuotes** (``JavaScriptQuoteStyle``) :versionbadge:`clang-format 3.9` :ref:`¶ <JavaScriptQuotes>` |
| 4399 |
The JavaScriptQuoteStyle to use for JavaScript strings. |
| 4400 |
|
| 4401 |
Possible values: |
| 4402 |
|
| 4403 |
* ``JSQS_Leave`` (in configuration: ``Leave``) |
| 4404 |
Leave string quotes as they are. |
| 4405 |
|
| 4406 |
.. code-block:: js |
| 4407 |
|
| 4408 |
string1 = "foo"; |
| 4409 |
string2 = 'bar'; |
| 4410 |
|
| 4411 |
* ``JSQS_Single`` (in configuration: ``Single``) |
| 4412 |
Always use single quotes. |
| 4413 |
|
| 4414 |
.. code-block:: js |
| 4415 |
|
| 4416 |
string1 = 'foo'; |
| 4417 |
string2 = 'bar'; |
| 4418 |
|
| 4419 |
* ``JSQS_Double`` (in configuration: ``Double``) |
| 4420 |
Always use double quotes. |
| 4421 |
|
| 4422 |
.. code-block:: js |
| 4423 |
|
| 4424 |
string1 = "foo"; |
| 4425 |
string2 = "bar"; |
| 4426 |
|
| 4427 |
|
| 4428 |
|
| 4429 |
.. _JavaScriptWrapImports: |
| 4430 |
|
| 4431 |
**JavaScriptWrapImports** (``Boolean``) :versionbadge:`clang-format 3.9` :ref:`¶ <JavaScriptWrapImports>` |
| 4432 |
Whether to wrap JavaScript import/export statements. |
| 4433 |
|
| 4434 |
.. code-block:: js |
| 4435 |
|
| 4436 |
true: |
| 4437 |
import { |
| 4438 |
VeryLongImportsAreAnnoying, |
| 4439 |
VeryLongImportsAreAnnoying, |
| 4440 |
VeryLongImportsAreAnnoying, |
| 4441 |
} from "some/module.js" |
| 4442 |
|
| 4443 |
false: |
| 4444 |
import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js" |
| 4445 |
|
| 4446 |
.. _KeepEmptyLines: |
| 4447 |
|
| 4448 |
**KeepEmptyLines** (``KeepEmptyLinesStyle``) :versionbadge:`clang-format 19` :ref:`¶ <KeepEmptyLines>` |
| 4449 |
Which empty lines are kept. See ``MaxEmptyLinesToKeep`` for how many |
| 4450 |
consecutive empty lines are kept. |
| 4451 |
|
| 4452 |
Nested configuration flags: |
| 4453 |
|
| 4454 |
Options regarding which empty lines are kept. |
| 4455 |
|
| 4456 |
For example, the config below will remove empty lines at start of the |
| 4457 |
file, end of the file, and start of blocks. |
| 4458 |
|
| 4459 |
|
| 4460 |
.. code-block:: c++ |
| 4461 |
|
| 4462 |
KeepEmptyLines: |
| 4463 |
AtEndOfFile: false |
| 4464 |
AtStartOfBlock: false |
| 4465 |
AtStartOfFile: false |
| 4466 |
|
| 4467 |
* ``bool AtEndOfFile`` Keep empty lines at end of file. |
| 4468 |
|
| 4469 |
* ``bool AtStartOfBlock`` Keep empty lines at start of a block. |
| 4470 |
|
| 4471 |
.. code-block:: c++ |
| 4472 |
|
| 4473 |
true: false: |
| 4474 |
if (foo) { vs. if (foo) { |
| 4475 |
bar(); |
| 4476 |
bar(); } |
| 4477 |
} |
| 4478 |
|
| 4479 |
* ``bool AtStartOfFile`` Keep empty lines at start of file. |
| 4480 |
|
| 4481 |
|
| 4482 |
.. _KeepEmptyLinesAtEOF: |
| 4483 |
|
| 4484 |
**KeepEmptyLinesAtEOF** (``Boolean``) :versionbadge:`clang-format 17` :ref:`¶ <KeepEmptyLinesAtEOF>` |
| 4485 |
This option is deprecated. See ``AtEndOfFile`` of ``KeepEmptyLines``. |
| 4486 |
|
| 4487 |
.. _KeepEmptyLinesAtTheStartOfBlocks: |
| 4488 |
|
| 4489 |
**KeepEmptyLinesAtTheStartOfBlocks** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <KeepEmptyLinesAtTheStartOfBlocks>` |
| 4490 |
This option is deprecated. See ``AtStartOfBlock`` of ``KeepEmptyLines``. |
| 4491 |
|
| 4492 |
.. _LambdaBodyIndentation: |
| 4493 |
|
| 4494 |
**LambdaBodyIndentation** (``LambdaBodyIndentationKind``) :versionbadge:`clang-format 13` :ref:`¶ <LambdaBodyIndentation>` |
| 4495 |
The indentation style of lambda bodies. ``Signature`` (the default) |
| 4496 |
causes the lambda body to be indented one additional level relative to |
| 4497 |
the indentation level of the signature. ``OuterScope`` forces the lambda |
| 4498 |
body to be indented one additional level relative to the parent scope |
| 4499 |
containing the lambda signature. |
| 4500 |
|
| 4501 |
Possible values: |
| 4502 |
|
| 4503 |
* ``LBI_Signature`` (in configuration: ``Signature``) |
| 4504 |
Align lambda body relative to the lambda signature. This is the default. |
| 4505 |
|
| 4506 |
.. code-block:: c++ |
| 4507 |
|
| 4508 |
someMethod( |
| 4509 |
[](SomeReallyLongLambdaSignatureArgument foo) { |
| 4510 |
return; |
| 4511 |
}); |
| 4512 |
|
| 4513 |
* ``LBI_OuterScope`` (in configuration: ``OuterScope``) |
| 4514 |
For statements within block scope, align lambda body relative to the |
| 4515 |
indentation level of the outer scope the lambda signature resides in. |
| 4516 |
|
| 4517 |
.. code-block:: c++ |
| 4518 |
|
| 4519 |
someMethod( |
| 4520 |
[](SomeReallyLongLambdaSignatureArgument foo) { |
| 4521 |
return; |
| 4522 |
}); |
| 4523 |
|
| 4524 |
someMethod(someOtherMethod( |
| 4525 |
[](SomeReallyLongLambdaSignatureArgument foo) { |
| 4526 |
return; |
| 4527 |
})); |
| 4528 |
|
| 4529 |
|
| 4530 |
|
| 4531 |
.. _Language: |
| 4532 |
|
| 4533 |
**Language** (``LanguageKind``) :versionbadge:`clang-format 3.5` :ref:`¶ <Language>` |
| 4534 |
Language, this format style is targeted at. |
| 4535 |
|
| 4536 |
Possible values: |
| 4537 |
|
| 4538 |
* ``LK_None`` (in configuration: ``None``) |
| 4539 |
Do not use. |
| 4540 |
|
| 4541 |
* ``LK_Cpp`` (in configuration: ``Cpp``) |
| 4542 |
Should be used for C, C++. |
| 4543 |
|
| 4544 |
* ``LK_CSharp`` (in configuration: ``CSharp``) |
| 4545 |
Should be used for C#. |
| 4546 |
|
| 4547 |
* ``LK_Java`` (in configuration: ``Java``) |
| 4548 |
Should be used for Java. |
| 4549 |
|
| 4550 |
* ``LK_JavaScript`` (in configuration: ``JavaScript``) |
| 4551 |
Should be used for JavaScript. |
| 4552 |
|
| 4553 |
* ``LK_Json`` (in configuration: ``Json``) |
| 4554 |
Should be used for JSON. |
| 4555 |
|
| 4556 |
* ``LK_ObjC`` (in configuration: ``ObjC``) |
| 4557 |
Should be used for Objective-C, Objective-C++. |
| 4558 |
|
| 4559 |
* ``LK_Proto`` (in configuration: ``Proto``) |
| 4560 |
Should be used for Protocol Buffers |
| 4561 |
(https://developers.google.com/protocol-buffers/). |
| 4562 |
|
| 4563 |
* ``LK_TableGen`` (in configuration: ``TableGen``) |
| 4564 |
Should be used for TableGen code. |
| 4565 |
|
| 4566 |
* ``LK_TextProto`` (in configuration: ``TextProto``) |
| 4567 |
Should be used for Protocol Buffer messages in text format |
| 4568 |
(https://developers.google.com/protocol-buffers/). |
| 4569 |
|
| 4570 |
* ``LK_Verilog`` (in configuration: ``Verilog``) |
| 4571 |
Should be used for Verilog and SystemVerilog. |
| 4572 |
https://standards.ieee.org/ieee/1800/6700/ |
| 4573 |
https://sci-hub.st/10.1109/IEEESTD.2018.8299595 |
| 4574 |
|
| 4575 |
|
| 4576 |
|
| 4577 |
.. _LineEnding: |
| 4578 |
|
| 4579 |
**LineEnding** (``LineEndingStyle``) :versionbadge:`clang-format 16` :ref:`¶ <LineEnding>` |
| 4580 |
Line ending style (``\n`` or ``\r\n``) to use. |
| 4581 |
|
| 4582 |
Possible values: |
| 4583 |
|
| 4584 |
* ``LE_LF`` (in configuration: ``LF``) |
| 4585 |
Use ``\n``. |
| 4586 |
|
| 4587 |
* ``LE_CRLF`` (in configuration: ``CRLF``) |
| 4588 |
Use ``\r\n``. |
| 4589 |
|
| 4590 |
* ``LE_DeriveLF`` (in configuration: ``DeriveLF``) |
| 4591 |
Use ``\n`` unless the input has more lines ending in ``\r\n``. |
| 4592 |
|
| 4593 |
* ``LE_DeriveCRLF`` (in configuration: ``DeriveCRLF``) |
| 4594 |
Use ``\r\n`` unless the input has more lines ending in ``\n``. |
| 4595 |
|
| 4596 |
|
| 4597 |
|
| 4598 |
.. _MacroBlockBegin: |
| 4599 |
|
| 4600 |
**MacroBlockBegin** (``String``) :versionbadge:`clang-format 3.7` :ref:`¶ <MacroBlockBegin>` |
| 4601 |
A regular expression matching macros that start a block. |
| 4602 |
|
| 4603 |
.. code-block:: c++ |
| 4604 |
|
| 4605 |
# With: |
| 4606 |
MacroBlockBegin: "^NS_MAP_BEGIN|\ |
| 4607 |
NS_TABLE_HEAD$" |
| 4608 |
MacroBlockEnd: "^\ |
| 4609 |
NS_MAP_END|\ |
| 4610 |
NS_TABLE_.*_END$" |
| 4611 |
|
| 4612 |
NS_MAP_BEGIN |
| 4613 |
foo(); |
| 4614 |
NS_MAP_END |
| 4615 |
|
| 4616 |
NS_TABLE_HEAD |
| 4617 |
bar(); |
| 4618 |
NS_TABLE_FOO_END |
| 4619 |
|
| 4620 |
# Without: |
| 4621 |
NS_MAP_BEGIN |
| 4622 |
foo(); |
| 4623 |
NS_MAP_END |
| 4624 |
|
| 4625 |
NS_TABLE_HEAD |
| 4626 |
bar(); |
| 4627 |
NS_TABLE_FOO_END |
| 4628 |
|
| 4629 |
.. _MacroBlockEnd: |
| 4630 |
|
| 4631 |
**MacroBlockEnd** (``String``) :versionbadge:`clang-format 3.7` :ref:`¶ <MacroBlockEnd>` |
| 4632 |
A regular expression matching macros that end a block. |
| 4633 |
|
| 4634 |
.. _Macros: |
| 4635 |
|
| 4636 |
**Macros** (``List of Strings``) :versionbadge:`clang-format 17` :ref:`¶ <Macros>` |
| 4637 |
A list of macros of the form ``<definition>=<expansion>`` . |
| 4638 |
|
| 4639 |
Code will be parsed with macros expanded, in order to determine how to |
| 4640 |
interpret and format the macro arguments. |
| 4641 |
|
| 4642 |
For example, the code: |
| 4643 |
|
| 4644 |
.. code-block:: c++ |
| 4645 |
|
| 4646 |
A(a*b); |
| 4647 |
|
| 4648 |
will usually be interpreted as a call to a function A, and the |
| 4649 |
multiplication expression will be formatted as ``a * b``. |
| 4650 |
|
| 4651 |
If we specify the macro definition: |
| 4652 |
|
| 4653 |
.. code-block:: yaml |
| 4654 |
|
| 4655 |
Macros: |
| 4656 |
- A(x)=x |
| 4657 |
|
| 4658 |
the code will now be parsed as a declaration of the variable b of type a*, |
| 4659 |
and formatted as ``a* b`` (depending on pointer-binding rules). |
| 4660 |
|
| 4661 |
Features and restrictions: |
| 4662 |
* Both function-like macros and object-like macros are supported. |
| 4663 |
* Macro arguments must be used exactly once in the expansion. |
| 4664 |
* No recursive expansion; macros referencing other macros will be |
| 4665 |
ignored. |
| 4666 |
* Overloading by arity is supported: for example, given the macro |
| 4667 |
definitions A=x, A()=y, A(a)=a |
| 4668 |
|
| 4669 |
|
| 4670 |
.. code-block:: c++ |
| 4671 |
|
| 4672 |
A; -> x; |
| 4673 |
A(); -> y; |
| 4674 |
A(z); -> z; |
| 4675 |
A(a, b); // will not be expanded. |
| 4676 |
|
| 4677 |
.. _MainIncludeChar: |
| 4678 |
|
| 4679 |
**MainIncludeChar** (``MainIncludeCharDiscriminator``) :versionbadge:`clang-format 19` :ref:`¶ <MainIncludeChar>` |
| 4680 |
When guessing whether a #include is the "main" include, only the include |
| 4681 |
directives that use the specified character are considered. |
| 4682 |
|
| 4683 |
Possible values: |
| 4684 |
|
| 4685 |
* ``MICD_Quote`` (in configuration: ``Quote``) |
| 4686 |
Main include uses quotes: ``#include "foo.hpp"`` (the default). |
| 4687 |
|
| 4688 |
* ``MICD_AngleBracket`` (in configuration: ``AngleBracket``) |
| 4689 |
Main include uses angle brackets: ``#include <foo.hpp>``. |
| 4690 |
|
| 4691 |
* ``MICD_Any`` (in configuration: ``Any``) |
| 4692 |
Main include uses either quotes or angle brackets. |
| 4693 |
|
| 4694 |
|
| 4695 |
|
| 4696 |
.. _MaxEmptyLinesToKeep: |
| 4697 |
|
| 4698 |
**MaxEmptyLinesToKeep** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <MaxEmptyLinesToKeep>` |
| 4699 |
The maximum number of consecutive empty lines to keep. |
| 4700 |
|
| 4701 |
.. code-block:: c++ |
| 4702 |
|
| 4703 |
MaxEmptyLinesToKeep: 1 vs. MaxEmptyLinesToKeep: 0 |
| 4704 |
int f() { int f() { |
| 4705 |
int = 1; int i = 1; |
| 4706 |
i = foo(); |
| 4707 |
i = foo(); return i; |
| 4708 |
} |
| 4709 |
return i; |
| 4710 |
} |
| 4711 |
|
| 4712 |
.. _NamespaceIndentation: |
| 4713 |
|
| 4714 |
**NamespaceIndentation** (``NamespaceIndentationKind``) :versionbadge:`clang-format 3.7` :ref:`¶ <NamespaceIndentation>` |
| 4715 |
The indentation used for namespaces. |
| 4716 |
|
| 4717 |
Possible values: |
| 4718 |
|
| 4719 |
* ``NI_None`` (in configuration: ``None``) |
| 4720 |
Don't indent in namespaces. |
| 4721 |
|
| 4722 |
.. code-block:: c++ |
| 4723 |
|
| 4724 |
namespace out { |
| 4725 |
int i; |
| 4726 |
namespace in { |
| 4727 |
int i; |
| 4728 |
} |
| 4729 |
} |
| 4730 |
|
| 4731 |
* ``NI_Inner`` (in configuration: ``Inner``) |
| 4732 |
Indent only in inner namespaces (nested in other namespaces). |
| 4733 |
|
| 4734 |
.. code-block:: c++ |
| 4735 |
|
| 4736 |
namespace out { |
| 4737 |
int i; |
| 4738 |
namespace in { |
| 4739 |
int i; |
| 4740 |
} |
| 4741 |
} |
| 4742 |
|
| 4743 |
* ``NI_All`` (in configuration: ``All``) |
| 4744 |
Indent in all namespaces. |
| 4745 |
|
| 4746 |
.. code-block:: c++ |
| 4747 |
|
| 4748 |
namespace out { |
| 4749 |
int i; |
| 4750 |
namespace in { |
| 4751 |
int i; |
| 4752 |
} |
| 4753 |
} |
| 4754 |
|
| 4755 |
|
| 4756 |
|
| 4757 |
.. _NamespaceMacros: |
| 4758 |
|
| 4759 |
**NamespaceMacros** (``List of Strings``) :versionbadge:`clang-format 9` :ref:`¶ <NamespaceMacros>` |
| 4760 |
A vector of macros which are used to open namespace blocks. |
| 4761 |
|
| 4762 |
These are expected to be macros of the form: |
| 4763 |
|
| 4764 |
.. code-block:: c++ |
| 4765 |
|
| 4766 |
NAMESPACE(<namespace-name>, ...) { |
| 4767 |
<namespace-content> |
| 4768 |
} |
| 4769 |
|
| 4770 |
For example: TESTSUITE |
| 4771 |
|
| 4772 |
.. _ObjCBinPackProtocolList: |
| 4773 |
|
| 4774 |
**ObjCBinPackProtocolList** (``BinPackStyle``) :versionbadge:`clang-format 7` :ref:`¶ <ObjCBinPackProtocolList>` |
| 4775 |
Controls bin-packing Objective-C protocol conformance list |
| 4776 |
items into as few lines as possible when they go over ``ColumnLimit``. |
| 4777 |
|
| 4778 |
If ``Auto`` (the default), delegates to the value in |
| 4779 |
``BinPackParameters``. If that is ``true``, bin-packs Objective-C |
| 4780 |
protocol conformance list items into as few lines as possible |
| 4781 |
whenever they go over ``ColumnLimit``. |
| 4782 |
|
| 4783 |
If ``Always``, always bin-packs Objective-C protocol conformance |
| 4784 |
list items into as few lines as possible whenever they go over |
| 4785 |
``ColumnLimit``. |
| 4786 |
|
| 4787 |
If ``Never``, lays out Objective-C protocol conformance list items |
| 4788 |
onto individual lines whenever they go over ``ColumnLimit``. |
| 4789 |
|
| 4790 |
|
| 4791 |
.. code-block:: objc |
| 4792 |
|
| 4793 |
Always (or Auto, if BinPackParameters=true): |
| 4794 |
@interface ccccccccccccc () < |
| 4795 |
ccccccccccccc, ccccccccccccc, |
| 4796 |
ccccccccccccc, ccccccccccccc> { |
| 4797 |
} |
| 4798 |
|
| 4799 |
Never (or Auto, if BinPackParameters=false): |
| 4800 |
@interface ddddddddddddd () < |
| 4801 |
ddddddddddddd, |
| 4802 |
ddddddddddddd, |
| 4803 |
ddddddddddddd, |
| 4804 |
ddddddddddddd> { |
| 4805 |
} |
| 4806 |
|
| 4807 |
Possible values: |
| 4808 |
|
| 4809 |
* ``BPS_Auto`` (in configuration: ``Auto``) |
| 4810 |
Automatically determine parameter bin-packing behavior. |
| 4811 |
|
| 4812 |
* ``BPS_Always`` (in configuration: ``Always``) |
| 4813 |
Always bin-pack parameters. |
| 4814 |
|
| 4815 |
* ``BPS_Never`` (in configuration: ``Never``) |
| 4816 |
Never bin-pack parameters. |
| 4817 |
|
| 4818 |
|
| 4819 |
|
| 4820 |
.. _ObjCBlockIndentWidth: |
| 4821 |
|
| 4822 |
**ObjCBlockIndentWidth** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <ObjCBlockIndentWidth>` |
| 4823 |
The number of characters to use for indentation of ObjC blocks. |
| 4824 |
|
| 4825 |
.. code-block:: objc |
| 4826 |
|
| 4827 |
ObjCBlockIndentWidth: 4 |
| 4828 |
|
| 4829 |
[operation setCompletionBlock:^{ |
| 4830 |
[self onOperationDone]; |
| 4831 |
}]; |
| 4832 |
|
| 4833 |
.. _ObjCBreakBeforeNestedBlockParam: |
| 4834 |
|
| 4835 |
**ObjCBreakBeforeNestedBlockParam** (``Boolean``) :versionbadge:`clang-format 11` :ref:`¶ <ObjCBreakBeforeNestedBlockParam>` |
| 4836 |
Break parameters list into lines when there is nested block |
| 4837 |
parameters in a function call. |
| 4838 |
|
| 4839 |
.. code-block:: c++ |
| 4840 |
|
| 4841 |
false: |
| 4842 |
- (void)_aMethod |
| 4843 |
{ |
| 4844 |
[self.test1 t:self w:self callback:^(typeof(self) self, NSNumber |
| 4845 |
*u, NSNumber *v) { |
| 4846 |
u = c; |
| 4847 |
}] |
| 4848 |
} |
| 4849 |
true: |
| 4850 |
- (void)_aMethod |
| 4851 |
{ |
| 4852 |
[self.test1 t:self |
| 4853 |
w:self |
| 4854 |
callback:^(typeof(self) self, NSNumber *u, NSNumber *v) { |
| 4855 |
u = c; |
| 4856 |
}] |
| 4857 |
} |
| 4858 |
|
| 4859 |
.. _ObjCPropertyAttributeOrder: |
| 4860 |
|
| 4861 |
**ObjCPropertyAttributeOrder** (``List of Strings``) :versionbadge:`clang-format 18` :ref:`¶ <ObjCPropertyAttributeOrder>` |
| 4862 |
The order in which ObjC property attributes should appear. |
| 4863 |
|
| 4864 |
Attributes in code will be sorted in the order specified. Any attributes |
| 4865 |
encountered that are not mentioned in this array will be sorted last, in |
| 4866 |
stable order. Comments between attributes will leave the attributes |
| 4867 |
untouched. |
| 4868 |
|
| 4869 |
.. warning:: |
| 4870 |
|
| 4871 |
Using this option could lead to incorrect code formatting due to |
| 4872 |
clang-format's lack of complete semantic information. As such, extra |
| 4873 |
care should be taken to review code changes made by this option. |
| 4874 |
|
| 4875 |
.. code-block:: yaml |
| 4876 |
|
| 4877 |
ObjCPropertyAttributeOrder: [ |
| 4878 |
class, direct, |
| 4879 |
atomic, nonatomic, |
| 4880 |
assign, retain, strong, copy, weak, unsafe_unretained, |
| 4881 |
readonly, readwrite, getter, setter, |
| 4882 |
nullable, nonnull, null_resettable, null_unspecified |
| 4883 |
] |
| 4884 |
|
| 4885 |
.. _ObjCSpaceAfterProperty: |
| 4886 |
|
| 4887 |
**ObjCSpaceAfterProperty** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <ObjCSpaceAfterProperty>` |
| 4888 |
Add a space after ``@property`` in Objective-C, i.e. use |
| 4889 |
``@property (readonly)`` instead of ``@property(readonly)``. |
| 4890 |
|
| 4891 |
.. _ObjCSpaceBeforeProtocolList: |
| 4892 |
|
| 4893 |
**ObjCSpaceBeforeProtocolList** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <ObjCSpaceBeforeProtocolList>` |
| 4894 |
Add a space in front of an Objective-C protocol list, i.e. use |
| 4895 |
``Foo <Protocol>`` instead of ``Foo<Protocol>``. |
| 4896 |
|
| 4897 |
.. _PPIndentWidth: |
| 4898 |
|
| 4899 |
**PPIndentWidth** (``Integer``) :versionbadge:`clang-format 13` :ref:`¶ <PPIndentWidth>` |
| 4900 |
The number of columns to use for indentation of preprocessor statements. |
| 4901 |
When set to -1 (default) ``IndentWidth`` is used also for preprocessor |
| 4902 |
statements. |
| 4903 |
|
| 4904 |
.. code-block:: c++ |
| 4905 |
|
| 4906 |
PPIndentWidth: 1 |
| 4907 |
|
| 4908 |
#ifdef __linux__ |
| 4909 |
# define FOO |
| 4910 |
#else |
| 4911 |
# define BAR |
| 4912 |
#endif |
| 4913 |
|
| 4914 |
.. _PackConstructorInitializers: |
| 4915 |
|
| 4916 |
**PackConstructorInitializers** (``PackConstructorInitializersStyle``) :versionbadge:`clang-format 14` :ref:`¶ <PackConstructorInitializers>` |
| 4917 |
The pack constructor initializers style to use. |
| 4918 |
|
| 4919 |
Possible values: |
| 4920 |
|
| 4921 |
* ``PCIS_Never`` (in configuration: ``Never``) |
| 4922 |
Always put each constructor initializer on its own line. |
| 4923 |
|
| 4924 |
.. code-block:: c++ |
| 4925 |
|
| 4926 |
Constructor() |
| 4927 |
: a(), |
| 4928 |
b() |
| 4929 |
|
| 4930 |
* ``PCIS_BinPack`` (in configuration: ``BinPack``) |
| 4931 |
Bin-pack constructor initializers. |
| 4932 |
|
| 4933 |
.. code-block:: c++ |
| 4934 |
|
| 4935 |
Constructor() |
| 4936 |
: aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), |
| 4937 |
cccccccccccccccccccc() |
| 4938 |
|
| 4939 |
* ``PCIS_CurrentLine`` (in configuration: ``CurrentLine``) |
| 4940 |
Put all constructor initializers on the current line if they fit. |
| 4941 |
Otherwise, put each one on its own line. |
| 4942 |
|
| 4943 |
.. code-block:: c++ |
| 4944 |
|
| 4945 |
Constructor() : a(), b() |
| 4946 |
|
| 4947 |
Constructor() |
| 4948 |
: aaaaaaaaaaaaaaaaaaaa(), |
| 4949 |
bbbbbbbbbbbbbbbbbbbb(), |
| 4950 |
ddddddddddddd() |
| 4951 |
|
| 4952 |
* ``PCIS_NextLine`` (in configuration: ``NextLine``) |
| 4953 |
Same as ``PCIS_CurrentLine`` except that if all constructor initializers |
| 4954 |
do not fit on the current line, try to fit them on the next line. |
| 4955 |
|
| 4956 |
.. code-block:: c++ |
| 4957 |
|
| 4958 |
Constructor() : a(), b() |
| 4959 |
|
| 4960 |
Constructor() |
| 4961 |
: aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), ddddddddddddd() |
| 4962 |
|
| 4963 |
Constructor() |
| 4964 |
: aaaaaaaaaaaaaaaaaaaa(), |
| 4965 |
bbbbbbbbbbbbbbbbbbbb(), |
| 4966 |
cccccccccccccccccccc() |
| 4967 |
|
| 4968 |
* ``PCIS_NextLineOnly`` (in configuration: ``NextLineOnly``) |
| 4969 |
Put all constructor initializers on the next line if they fit. |
| 4970 |
Otherwise, put each one on its own line. |
| 4971 |
|
| 4972 |
.. code-block:: c++ |
| 4973 |
|
| 4974 |
Constructor() |
| 4975 |
: a(), b() |
| 4976 |
|
| 4977 |
Constructor() |
| 4978 |
: aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), ddddddddddddd() |
| 4979 |
|
| 4980 |
Constructor() |
| 4981 |
: aaaaaaaaaaaaaaaaaaaa(), |
| 4982 |
bbbbbbbbbbbbbbbbbbbb(), |
| 4983 |
cccccccccccccccccccc() |
| 4984 |
|
| 4985 |
|
| 4986 |
|
| 4987 |
.. _PenaltyBreakAssignment: |
| 4988 |
|
| 4989 |
**PenaltyBreakAssignment** (``Unsigned``) :versionbadge:`clang-format 5` :ref:`¶ <PenaltyBreakAssignment>` |
| 4990 |
The penalty for breaking around an assignment operator. |
| 4991 |
|
| 4992 |
.. _PenaltyBreakBeforeFirstCallParameter: |
| 4993 |
|
| 4994 |
**PenaltyBreakBeforeFirstCallParameter** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <PenaltyBreakBeforeFirstCallParameter>` |
| 4995 |
The penalty for breaking a function call after ``call(``. |
| 4996 |
|
| 4997 |
.. _PenaltyBreakComment: |
| 4998 |
|
| 4999 |
**PenaltyBreakComment** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <PenaltyBreakComment>` |
| 5000 |
The penalty for each line break introduced inside a comment. |
| 5001 |
|
| 5002 |
.. _PenaltyBreakFirstLessLess: |
| 5003 |
|
| 5004 |
**PenaltyBreakFirstLessLess** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <PenaltyBreakFirstLessLess>` |
| 5005 |
The penalty for breaking before the first ``<<``. |
| 5006 |
|
| 5007 |
.. _PenaltyBreakOpenParenthesis: |
| 5008 |
|
| 5009 |
**PenaltyBreakOpenParenthesis** (``Unsigned``) :versionbadge:`clang-format 14` :ref:`¶ <PenaltyBreakOpenParenthesis>` |
| 5010 |
The penalty for breaking after ``(``. |
| 5011 |
|
| 5012 |
.. _PenaltyBreakScopeResolution: |
| 5013 |
|
| 5014 |
**PenaltyBreakScopeResolution** (``Unsigned``) :versionbadge:`clang-format 18` :ref:`¶ <PenaltyBreakScopeResolution>` |
| 5015 |
The penalty for breaking after ``::``. |
| 5016 |
|
| 5017 |
.. _PenaltyBreakString: |
| 5018 |
|
| 5019 |
**PenaltyBreakString** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <PenaltyBreakString>` |
| 5020 |
The penalty for each line break introduced inside a string literal. |
| 5021 |
|
| 5022 |
.. _PenaltyBreakTemplateDeclaration: |
| 5023 |
|
| 5024 |
**PenaltyBreakTemplateDeclaration** (``Unsigned``) :versionbadge:`clang-format 7` :ref:`¶ <PenaltyBreakTemplateDeclaration>` |
| 5025 |
The penalty for breaking after template declaration. |
| 5026 |
|
| 5027 |
.. _PenaltyExcessCharacter: |
| 5028 |
|
| 5029 |
**PenaltyExcessCharacter** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <PenaltyExcessCharacter>` |
| 5030 |
The penalty for each character outside of the column limit. |
| 5031 |
|
| 5032 |
.. _PenaltyIndentedWhitespace: |
| 5033 |
|
| 5034 |
**PenaltyIndentedWhitespace** (``Unsigned``) :versionbadge:`clang-format 12` :ref:`¶ <PenaltyIndentedWhitespace>` |
| 5035 |
Penalty for each character of whitespace indentation |
| 5036 |
(counted relative to leading non-whitespace column). |
| 5037 |
|
| 5038 |
.. _PenaltyReturnTypeOnItsOwnLine: |
| 5039 |
|
| 5040 |
**PenaltyReturnTypeOnItsOwnLine** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <PenaltyReturnTypeOnItsOwnLine>` |
| 5041 |
Penalty for putting the return type of a function onto its own line. |
| 5042 |
|
| 5043 |
.. _PointerAlignment: |
| 5044 |
|
| 5045 |
**PointerAlignment** (``PointerAlignmentStyle``) :versionbadge:`clang-format 3.7` :ref:`¶ <PointerAlignment>` |
| 5046 |
Pointer and reference alignment style. |
| 5047 |
|
| 5048 |
Possible values: |
| 5049 |
|
| 5050 |
* ``PAS_Left`` (in configuration: ``Left``) |
| 5051 |
Align pointer to the left. |
| 5052 |
|
| 5053 |
.. code-block:: c++ |
| 5054 |
|
| 5055 |
int* a; |
| 5056 |
|
| 5057 |
* ``PAS_Right`` (in configuration: ``Right``) |
| 5058 |
Align pointer to the right. |
| 5059 |
|
| 5060 |
.. code-block:: c++ |
| 5061 |
|
| 5062 |
int *a; |
| 5063 |
|
| 5064 |
* ``PAS_Middle`` (in configuration: ``Middle``) |
| 5065 |
Align pointer in the middle. |
| 5066 |
|
| 5067 |
.. code-block:: c++ |
| 5068 |
|
| 5069 |
int * a; |
| 5070 |
|
| 5071 |
|
| 5072 |
|
| 5073 |
.. _QualifierAlignment: |
| 5074 |
|
| 5075 |
**QualifierAlignment** (``QualifierAlignmentStyle``) :versionbadge:`clang-format 14` :ref:`¶ <QualifierAlignment>` |
| 5076 |
Different ways to arrange specifiers and qualifiers (e.g. const/volatile). |
| 5077 |
|
| 5078 |
.. warning:: |
| 5079 |
|
| 5080 |
Setting ``QualifierAlignment`` to something other than ``Leave``, COULD |
| 5081 |
lead to incorrect code formatting due to incorrect decisions made due to |
| 5082 |
clang-formats lack of complete semantic information. |
| 5083 |
As such extra care should be taken to review code changes made by the use |
| 5084 |
of this option. |
| 5085 |
|
| 5086 |
Possible values: |
| 5087 |
|
| 5088 |
* ``QAS_Leave`` (in configuration: ``Leave``) |
| 5089 |
Don't change specifiers/qualifiers to either Left or Right alignment |
| 5090 |
(default). |
| 5091 |
|
| 5092 |
.. code-block:: c++ |
| 5093 |
|
| 5094 |
int const a; |
| 5095 |
const int *a; |
| 5096 |
|
| 5097 |
* ``QAS_Left`` (in configuration: ``Left``) |
| 5098 |
Change specifiers/qualifiers to be left-aligned. |
| 5099 |
|
| 5100 |
.. code-block:: c++ |
| 5101 |
|
| 5102 |
const int a; |
| 5103 |
const int *a; |
| 5104 |
|
| 5105 |
* ``QAS_Right`` (in configuration: ``Right``) |
| 5106 |
Change specifiers/qualifiers to be right-aligned. |
| 5107 |
|
| 5108 |
.. code-block:: c++ |
| 5109 |
|
| 5110 |
int const a; |
| 5111 |
int const *a; |
| 5112 |
|
| 5113 |
* ``QAS_Custom`` (in configuration: ``Custom``) |
| 5114 |
Change specifiers/qualifiers to be aligned based on ``QualifierOrder``. |
| 5115 |
With: |
| 5116 |
|
| 5117 |
.. code-block:: yaml |
| 5118 |
|
| 5119 |
QualifierOrder: [inline, static, type, const] |
| 5120 |
|
| 5121 |
|
| 5122 |
.. code-block:: c++ |
| 5123 |
|
| 5124 |
|
| 5125 |
int const a; |
| 5126 |
int const *a; |
| 5127 |
|
| 5128 |
|
| 5129 |
|
| 5130 |
.. _QualifierOrder: |
| 5131 |
|
| 5132 |
**QualifierOrder** (``List of Strings``) :versionbadge:`clang-format 14` :ref:`¶ <QualifierOrder>` |
| 5133 |
The order in which the qualifiers appear. |
| 5134 |
Order is an array that can contain any of the following: |
| 5135 |
|
| 5136 |
* const |
| 5137 |
* inline |
| 5138 |
* static |
| 5139 |
* friend |
| 5140 |
* constexpr |
| 5141 |
* volatile |
| 5142 |
* restrict |
| 5143 |
* type |
| 5144 |
|
| 5145 |
|
| 5146 |
.. note:: |
| 5147 |
|
| 5148 |
It **must** contain ``type``. |
| 5149 |
|
| 5150 |
Items to the left of ``type`` will be placed to the left of the type and |
| 5151 |
aligned in the order supplied. Items to the right of ``type`` will be |
| 5152 |
placed to the right of the type and aligned in the order supplied. |
| 5153 |
|
| 5154 |
|
| 5155 |
.. code-block:: yaml |
| 5156 |
|
| 5157 |
QualifierOrder: [inline, static, type, const, volatile] |
| 5158 |
|
| 5159 |
.. _RawStringFormats: |
| 5160 |
|
| 5161 |
**RawStringFormats** (``List of RawStringFormats``) :versionbadge:`clang-format 6` :ref:`¶ <RawStringFormats>` |
| 5162 |
Defines hints for detecting supported languages code blocks in raw |
| 5163 |
strings. |
| 5164 |
|
| 5165 |
A raw string with a matching delimiter or a matching enclosing function |
| 5166 |
name will be reformatted assuming the specified language based on the |
| 5167 |
style for that language defined in the .clang-format file. If no style has |
| 5168 |
been defined in the .clang-format file for the specific language, a |
| 5169 |
predefined style given by ``BasedOnStyle`` is used. If ``BasedOnStyle`` is |
| 5170 |
not found, the formatting is based on ``LLVM`` style. A matching delimiter |
| 5171 |
takes precedence over a matching enclosing function name for determining |
| 5172 |
the language of the raw string contents. |
| 5173 |
|
| 5174 |
If a canonical delimiter is specified, occurrences of other delimiters for |
| 5175 |
the same language will be updated to the canonical if possible. |
| 5176 |
|
| 5177 |
There should be at most one specification per language and each delimiter |
| 5178 |
and enclosing function should not occur in multiple specifications. |
| 5179 |
|
| 5180 |
To configure this in the .clang-format file, use: |
| 5181 |
|
| 5182 |
.. code-block:: yaml |
| 5183 |
|
| 5184 |
RawStringFormats: |
| 5185 |
- Language: TextProto |
| 5186 |
Delimiters: |
| 5187 |
- pb |
| 5188 |
- proto |
| 5189 |
EnclosingFunctions: |
| 5190 |
- PARSE_TEXT_PROTO |
| 5191 |
BasedOnStyle: google |
| 5192 |
- Language: Cpp |
| 5193 |
Delimiters: |
| 5194 |
- cc |
| 5195 |
- cpp |
| 5196 |
BasedOnStyle: LLVM |
| 5197 |
CanonicalDelimiter: cc |
| 5198 |
|
| 5199 |
.. _ReferenceAlignment: |
| 5200 |
|
| 5201 |
**ReferenceAlignment** (``ReferenceAlignmentStyle``) :versionbadge:`clang-format 13` :ref:`¶ <ReferenceAlignment>` |
| 5202 |
Reference alignment style (overrides ``PointerAlignment`` for |
| 5203 |
references). |
| 5204 |
|
| 5205 |
Possible values: |
| 5206 |
|
| 5207 |
* ``RAS_Pointer`` (in configuration: ``Pointer``) |
| 5208 |
Align reference like ``PointerAlignment``. |
| 5209 |
|
| 5210 |
* ``RAS_Left`` (in configuration: ``Left``) |
| 5211 |
Align reference to the left. |
| 5212 |
|
| 5213 |
.. code-block:: c++ |
| 5214 |
|
| 5215 |
int& a; |
| 5216 |
|
| 5217 |
* ``RAS_Right`` (in configuration: ``Right``) |
| 5218 |
Align reference to the right. |
| 5219 |
|
| 5220 |
.. code-block:: c++ |
| 5221 |
|
| 5222 |
int &a; |
| 5223 |
|
| 5224 |
* ``RAS_Middle`` (in configuration: ``Middle``) |
| 5225 |
Align reference in the middle. |
| 5226 |
|
| 5227 |
.. code-block:: c++ |
| 5228 |
|
| 5229 |
int & a; |
| 5230 |
|
| 5231 |
|
| 5232 |
|
| 5233 |
.. _ReflowComments: |
| 5234 |
|
| 5235 |
**ReflowComments** (``Boolean``) :versionbadge:`clang-format 3.8` :ref:`¶ <ReflowComments>` |
| 5236 |
If ``true``, clang-format will attempt to re-flow comments. That is it |
| 5237 |
will touch a comment and *reflow* long comments into new lines, trying to |
| 5238 |
obey the ``ColumnLimit``. |
| 5239 |
|
| 5240 |
.. code-block:: c++ |
| 5241 |
|
| 5242 |
false: |
| 5243 |
// veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information |
| 5244 |
/* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */ |
| 5245 |
|
| 5246 |
true: |
| 5247 |
// veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of |
| 5248 |
// information |
| 5249 |
/* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of |
| 5250 |
* information */ |
| 5251 |
|
| 5252 |
.. _RemoveBracesLLVM: |
| 5253 |
|
| 5254 |
**RemoveBracesLLVM** (``Boolean``) :versionbadge:`clang-format 14` :ref:`¶ <RemoveBracesLLVM>` |
| 5255 |
Remove optional braces of control statements (``if``, ``else``, ``for``, |
| 5256 |
and ``while``) in C++ according to the LLVM coding style. |
| 5257 |
|
| 5258 |
.. warning:: |
| 5259 |
|
| 5260 |
This option will be renamed and expanded to support other styles. |
| 5261 |
|
| 5262 |
.. warning:: |
| 5263 |
|
| 5264 |
Setting this option to ``true`` could lead to incorrect code formatting |
| 5265 |
due to clang-format's lack of complete semantic information. As such, |
| 5266 |
extra care should be taken to review code changes made by this option. |
| 5267 |
|
| 5268 |
.. code-block:: c++ |
| 5269 |
|
| 5270 |
false: true: |
| 5271 |
|
| 5272 |
if (isa<FunctionDecl>(D)) { vs. if (isa<FunctionDecl>(D)) |
| 5273 |
handleFunctionDecl(D); handleFunctionDecl(D); |
| 5274 |
} else if (isa<VarDecl>(D)) { else if (isa<VarDecl>(D)) |
| 5275 |
handleVarDecl(D); handleVarDecl(D); |
| 5276 |
} |
| 5277 |
|
| 5278 |
if (isa<VarDecl>(D)) { vs. if (isa<VarDecl>(D)) { |
| 5279 |
for (auto *A : D.attrs()) { for (auto *A : D.attrs()) |
| 5280 |
if (shouldProcessAttr(A)) { if (shouldProcessAttr(A)) |
| 5281 |
handleAttr(A); handleAttr(A); |
| 5282 |
} } |
| 5283 |
} |
| 5284 |
} |
| 5285 |
|
| 5286 |
if (isa<FunctionDecl>(D)) { vs. if (isa<FunctionDecl>(D)) |
| 5287 |
for (auto *A : D.attrs()) { for (auto *A : D.attrs()) |
| 5288 |
handleAttr(A); handleAttr(A); |
| 5289 |
} |
| 5290 |
} |
| 5291 |
|
| 5292 |
if (auto *D = (T)(D)) { vs. if (auto *D = (T)(D)) { |
| 5293 |
if (shouldProcess(D)) { if (shouldProcess(D)) |
| 5294 |
handleVarDecl(D); handleVarDecl(D); |
| 5295 |
} else { else |
| 5296 |
markAsIgnored(D); markAsIgnored(D); |
| 5297 |
} } |
| 5298 |
} |
| 5299 |
|
| 5300 |
if (a) { vs. if (a) |
| 5301 |
b(); b(); |
| 5302 |
} else { else if (c) |
| 5303 |
if (c) { d(); |
| 5304 |
d(); else |
| 5305 |
} else { e(); |
| 5306 |
e(); |
| 5307 |
} |
| 5308 |
} |
| 5309 |
|
| 5310 |
.. _RemoveParentheses: |
| 5311 |
|
| 5312 |
**RemoveParentheses** (``RemoveParenthesesStyle``) :versionbadge:`clang-format 17` :ref:`¶ <RemoveParentheses>` |
| 5313 |
Remove redundant parentheses. |
| 5314 |
|
| 5315 |
.. warning:: |
| 5316 |
|
| 5317 |
Setting this option to any value other than ``Leave`` could lead to |
| 5318 |
incorrect code formatting due to clang-format's lack of complete semantic |
| 5319 |
information. As such, extra care should be taken to review code changes |
| 5320 |
made by this option. |
| 5321 |
|
| 5322 |
Possible values: |
| 5323 |
|
| 5324 |
* ``RPS_Leave`` (in configuration: ``Leave``) |
| 5325 |
Do not remove parentheses. |
| 5326 |
|
| 5327 |
.. code-block:: c++ |
| 5328 |
|
| 5329 |
class __declspec((dllimport)) X {}; |
| 5330 |
co_return (((0))); |
| 5331 |
return ((a + b) - ((c + d))); |
| 5332 |
|
| 5333 |
* ``RPS_MultipleParentheses`` (in configuration: ``MultipleParentheses``) |
| 5334 |
Replace multiple parentheses with single parentheses. |
| 5335 |
|
| 5336 |
.. code-block:: c++ |
| 5337 |
|
| 5338 |
class __declspec(dllimport) X {}; |
| 5339 |
co_return (0); |
| 5340 |
return ((a + b) - (c + d)); |
| 5341 |
|
| 5342 |
* ``RPS_ReturnStatement`` (in configuration: ``ReturnStatement``) |
| 5343 |
Also remove parentheses enclosing the expression in a |
| 5344 |
``return``/``co_return`` statement. |
| 5345 |
|
| 5346 |
.. code-block:: c++ |
| 5347 |
|
| 5348 |
class __declspec(dllimport) X {}; |
| 5349 |
co_return 0; |
| 5350 |
return (a + b) - (c + d); |
| 5351 |
|
| 5352 |
|
| 5353 |
|
| 5354 |
.. _RemoveSemicolon: |
| 5355 |
|
| 5356 |
**RemoveSemicolon** (``Boolean``) :versionbadge:`clang-format 16` :ref:`¶ <RemoveSemicolon>` |
| 5357 |
Remove semicolons after the closing braces of functions and |
| 5358 |
constructors/destructors. |
| 5359 |
|
| 5360 |
.. warning:: |
| 5361 |
|
| 5362 |
Setting this option to ``true`` could lead to incorrect code formatting |
| 5363 |
due to clang-format's lack of complete semantic information. As such, |
| 5364 |
extra care should be taken to review code changes made by this option. |
| 5365 |
|
| 5366 |
.. code-block:: c++ |
| 5367 |
|
| 5368 |
false: true: |
| 5369 |
|
| 5370 |
int max(int a, int b) { int max(int a, int b) { |
| 5371 |
return a > b ? a : b; return a > b ? a : b; |
| 5372 |
}; } |
| 5373 |
|
| 5374 |
.. _RequiresClausePosition: |
| 5375 |
|
| 5376 |
**RequiresClausePosition** (``RequiresClausePositionStyle``) :versionbadge:`clang-format 15` :ref:`¶ <RequiresClausePosition>` |
| 5377 |
The position of the ``requires`` clause. |
| 5378 |
|
| 5379 |
Possible values: |
| 5380 |
|
| 5381 |
* ``RCPS_OwnLine`` (in configuration: ``OwnLine``) |
| 5382 |
Always put the ``requires`` clause on its own line. |
| 5383 |
|
| 5384 |
.. code-block:: c++ |
| 5385 |
|
| 5386 |
template <typename T> |
| 5387 |
requires C<T> |
| 5388 |
struct Foo {... |
| 5389 |
|
| 5390 |
template <typename T> |
| 5391 |
requires C<T> |
| 5392 |
void bar(T t) {... |
| 5393 |
|
| 5394 |
template <typename T> |
| 5395 |
void baz(T t) |
| 5396 |
requires C<T> |
| 5397 |
{... |
| 5398 |
|
| 5399 |
* ``RCPS_WithPreceding`` (in configuration: ``WithPreceding``) |
| 5400 |
Try to put the clause together with the preceding part of a declaration. |
| 5401 |
For class templates: stick to the template declaration. |
| 5402 |
For function templates: stick to the template declaration. |
| 5403 |
For function declaration followed by a requires clause: stick to the |
| 5404 |
parameter list. |
| 5405 |
|
| 5406 |
.. code-block:: c++ |
| 5407 |
|
| 5408 |
template <typename T> requires C<T> |
| 5409 |
struct Foo {... |
| 5410 |
|
| 5411 |
template <typename T> requires C<T> |
| 5412 |
void bar(T t) {... |
| 5413 |
|
| 5414 |
template <typename T> |
| 5415 |
void baz(T t) requires C<T> |
| 5416 |
{... |
| 5417 |
|
| 5418 |
* ``RCPS_WithFollowing`` (in configuration: ``WithFollowing``) |
| 5419 |
Try to put the ``requires`` clause together with the class or function |
| 5420 |
declaration. |
| 5421 |
|
| 5422 |
.. code-block:: c++ |
| 5423 |
|
| 5424 |
template <typename T> |
| 5425 |
requires C<T> struct Foo {... |
| 5426 |
|
| 5427 |
template <typename T> |
| 5428 |
requires C<T> void bar(T t) {... |
| 5429 |
|
| 5430 |
template <typename T> |
| 5431 |
void baz(T t) |
| 5432 |
requires C<T> {... |
| 5433 |
|
| 5434 |
* ``RCPS_SingleLine`` (in configuration: ``SingleLine``) |
| 5435 |
Try to put everything in the same line if possible. Otherwise normal |
| 5436 |
line breaking rules take over. |
| 5437 |
|
| 5438 |
.. code-block:: c++ |
| 5439 |
|
| 5440 |
// Fitting: |
| 5441 |
template <typename T> requires C<T> struct Foo {... |
| 5442 |
|
| 5443 |
template <typename T> requires C<T> void bar(T t) {... |
| 5444 |
|
| 5445 |
template <typename T> void bar(T t) requires C<T> {... |
| 5446 |
|
| 5447 |
// Not fitting, one possible example: |
| 5448 |
template <typename LongName> |
| 5449 |
requires C<LongName> |
| 5450 |
struct Foo {... |
| 5451 |
|
| 5452 |
template <typename LongName> |
| 5453 |
requires C<LongName> |
| 5454 |
void bar(LongName ln) { |
| 5455 |
|
| 5456 |
template <typename LongName> |
| 5457 |
void bar(LongName ln) |
| 5458 |
requires C<LongName> { |
| 5459 |
|
| 5460 |
|
| 5461 |
|
| 5462 |
.. _RequiresExpressionIndentation: |
| 5463 |
|
| 5464 |
**RequiresExpressionIndentation** (``RequiresExpressionIndentationKind``) :versionbadge:`clang-format 16` :ref:`¶ <RequiresExpressionIndentation>` |
| 5465 |
The indentation used for requires expression bodies. |
| 5466 |
|
| 5467 |
Possible values: |
| 5468 |
|
| 5469 |
* ``REI_OuterScope`` (in configuration: ``OuterScope``) |
| 5470 |
Align requires expression body relative to the indentation level of the |
| 5471 |
outer scope the requires expression resides in. |
| 5472 |
This is the default. |
| 5473 |
|
| 5474 |
.. code-block:: c++ |
| 5475 |
|
| 5476 |
template <typename T> |
| 5477 |
concept C = requires(T t) { |
| 5478 |
... |
| 5479 |
} |
| 5480 |
|
| 5481 |
* ``REI_Keyword`` (in configuration: ``Keyword``) |
| 5482 |
Align requires expression body relative to the ``requires`` keyword. |
| 5483 |
|
| 5484 |
.. code-block:: c++ |
| 5485 |
|
| 5486 |
template <typename T> |
| 5487 |
concept C = requires(T t) { |
| 5488 |
... |
| 5489 |
} |
| 5490 |
|
| 5491 |
|
| 5492 |
|
| 5493 |
.. _SeparateDefinitionBlocks: |
| 5494 |
|
| 5495 |
**SeparateDefinitionBlocks** (``SeparateDefinitionStyle``) :versionbadge:`clang-format 14` :ref:`¶ <SeparateDefinitionBlocks>` |
| 5496 |
Specifies the use of empty lines to separate definition blocks, including |
| 5497 |
classes, structs, enums, and functions. |
| 5498 |
|
| 5499 |
.. code-block:: c++ |
| 5500 |
|
| 5501 |
Never v.s. Always |
| 5502 |
#include <cstring> #include <cstring> |
| 5503 |
struct Foo { |
| 5504 |
int a, b, c; struct Foo { |
| 5505 |
}; int a, b, c; |
| 5506 |
namespace Ns { }; |
| 5507 |
class Bar { |
| 5508 |
public: namespace Ns { |
| 5509 |
struct Foobar { class Bar { |
| 5510 |
int a; public: |
| 5511 |
int b; struct Foobar { |
| 5512 |
}; int a; |
| 5513 |
private: int b; |
| 5514 |
int t; }; |
| 5515 |
int method1() { |
| 5516 |
// ... private: |
| 5517 |
} int t; |
| 5518 |
enum List { |
| 5519 |
ITEM1, int method1() { |
| 5520 |
ITEM2 // ... |
| 5521 |
}; } |
| 5522 |
template<typename T> |
| 5523 |
int method2(T x) { enum List { |
| 5524 |
// ... ITEM1, |
| 5525 |
} ITEM2 |
| 5526 |
int i, j, k; }; |
| 5527 |
int method3(int par) { |
| 5528 |
// ... template<typename T> |
| 5529 |
} int method2(T x) { |
| 5530 |
}; // ... |
| 5531 |
class C {}; } |
| 5532 |
} |
| 5533 |
int i, j, k; |
| 5534 |
|
| 5535 |
int method3(int par) { |
| 5536 |
// ... |
| 5537 |
} |
| 5538 |
}; |
| 5539 |
|
| 5540 |
class C {}; |
| 5541 |
} |
| 5542 |
|
| 5543 |
Possible values: |
| 5544 |
|
| 5545 |
* ``SDS_Leave`` (in configuration: ``Leave``) |
| 5546 |
Leave definition blocks as they are. |
| 5547 |
|
| 5548 |
* ``SDS_Always`` (in configuration: ``Always``) |
| 5549 |
Insert an empty line between definition blocks. |
| 5550 |
|
| 5551 |
* ``SDS_Never`` (in configuration: ``Never``) |
| 5552 |
Remove any empty line between definition blocks. |
| 5553 |
|
| 5554 |
|
| 5555 |
|
| 5556 |
.. _ShortNamespaceLines: |
| 5557 |
|
| 5558 |
**ShortNamespaceLines** (``Unsigned``) :versionbadge:`clang-format 13` :ref:`¶ <ShortNamespaceLines>` |
| 5559 |
The maximal number of unwrapped lines that a short namespace spans. |
| 5560 |
Defaults to 1. |
| 5561 |
|
| 5562 |
This determines the maximum length of short namespaces by counting |
| 5563 |
unwrapped lines (i.e. containing neither opening nor closing |
| 5564 |
namespace brace) and makes ``FixNamespaceComments`` omit adding |
| 5565 |
end comments for those. |
| 5566 |
|
| 5567 |
.. code-block:: c++ |
| 5568 |
|
| 5569 |
ShortNamespaceLines: 1 vs. ShortNamespaceLines: 0 |
| 5570 |
namespace a { namespace a { |
| 5571 |
int foo; int foo; |
| 5572 |
} } // namespace a |
| 5573 |
|
| 5574 |
ShortNamespaceLines: 1 vs. ShortNamespaceLines: 0 |
| 5575 |
namespace b { namespace b { |
| 5576 |
int foo; int foo; |
| 5577 |
int bar; int bar; |
| 5578 |
} // namespace b } // namespace b |
| 5579 |
|
| 5580 |
.. _SkipMacroDefinitionBody: |
| 5581 |
|
| 5582 |
**SkipMacroDefinitionBody** (``Boolean``) :versionbadge:`clang-format 18` :ref:`¶ <SkipMacroDefinitionBody>` |
| 5583 |
Do not format macro definition body. |
| 5584 |
|
| 5585 |
.. _SortIncludes: |
| 5586 |
|
| 5587 |
**SortIncludes** (``SortIncludesOptions``) :versionbadge:`clang-format 3.8` :ref:`¶ <SortIncludes>` |
| 5588 |
Controls if and how clang-format will sort ``#includes``. |
| 5589 |
|
| 5590 |
Possible values: |
| 5591 |
|
| 5592 |
* ``SI_Never`` (in configuration: ``Never``) |
| 5593 |
Includes are never sorted. |
| 5594 |
|
| 5595 |
.. code-block:: c++ |
| 5596 |
|
| 5597 |
#include "B/A.h" |
| 5598 |
#include "A/B.h" |
| 5599 |
#include "a/b.h" |
| 5600 |
#include "A/b.h" |
| 5601 |
#include "B/a.h" |
| 5602 |
|
| 5603 |
* ``SI_CaseSensitive`` (in configuration: ``CaseSensitive``) |
| 5604 |
Includes are sorted in an ASCIIbetical or case sensitive fashion. |
| 5605 |
|
| 5606 |
.. code-block:: c++ |
| 5607 |
|
| 5608 |
#include "A/B.h" |
| 5609 |
#include "A/b.h" |
| 5610 |
#include "B/A.h" |
| 5611 |
#include "B/a.h" |
| 5612 |
#include "a/b.h" |
| 5613 |
|
| 5614 |
* ``SI_CaseInsensitive`` (in configuration: ``CaseInsensitive``) |
| 5615 |
Includes are sorted in an alphabetical or case insensitive fashion. |
| 5616 |
|
| 5617 |
.. code-block:: c++ |
| 5618 |
|
| 5619 |
#include "A/B.h" |
| 5620 |
#include "A/b.h" |
| 5621 |
#include "a/b.h" |
| 5622 |
#include "B/A.h" |
| 5623 |
#include "B/a.h" |
| 5624 |
|
| 5625 |
|
| 5626 |
|
| 5627 |
.. _SortJavaStaticImport: |
| 5628 |
|
| 5629 |
**SortJavaStaticImport** (``SortJavaStaticImportOptions``) :versionbadge:`clang-format 12` :ref:`¶ <SortJavaStaticImport>` |
| 5630 |
When sorting Java imports, by default static imports are placed before |
| 5631 |
non-static imports. If ``JavaStaticImportAfterImport`` is ``After``, |
| 5632 |
static imports are placed after non-static imports. |
| 5633 |
|
| 5634 |
Possible values: |
| 5635 |
|
| 5636 |
* ``SJSIO_Before`` (in configuration: ``Before``) |
| 5637 |
Static imports are placed before non-static imports. |
| 5638 |
|
| 5639 |
.. code-block:: java |
| 5640 |
|
| 5641 |
import static org.example.function1; |
| 5642 |
|
| 5643 |
import org.example.ClassA; |
| 5644 |
|
| 5645 |
* ``SJSIO_After`` (in configuration: ``After``) |
| 5646 |
Static imports are placed after non-static imports. |
| 5647 |
|
| 5648 |
.. code-block:: java |
| 5649 |
|
| 5650 |
import org.example.ClassA; |
| 5651 |
|
| 5652 |
import static org.example.function1; |
| 5653 |
|
| 5654 |
|
| 5655 |
|
| 5656 |
.. _SortUsingDeclarations: |
| 5657 |
|
| 5658 |
**SortUsingDeclarations** (``SortUsingDeclarationsOptions``) :versionbadge:`clang-format 5` :ref:`¶ <SortUsingDeclarations>` |
| 5659 |
Controls if and how clang-format will sort using declarations. |
| 5660 |
|
| 5661 |
Possible values: |
| 5662 |
|
| 5663 |
* ``SUD_Never`` (in configuration: ``Never``) |
| 5664 |
Using declarations are never sorted. |
| 5665 |
|
| 5666 |
.. code-block:: c++ |
| 5667 |
|
| 5668 |
using std::chrono::duration_cast; |
| 5669 |
using std::move; |
| 5670 |
using boost::regex; |
| 5671 |
using boost::regex_constants::icase; |
| 5672 |
using std::string; |
| 5673 |
|
| 5674 |
* ``SUD_Lexicographic`` (in configuration: ``Lexicographic``) |
| 5675 |
Using declarations are sorted in the order defined as follows: |
| 5676 |
Split the strings by ``::`` and discard any initial empty strings. Sort |
| 5677 |
the lists of names lexicographically, and within those groups, names are |
| 5678 |
in case-insensitive lexicographic order. |
| 5679 |
|
| 5680 |
.. code-block:: c++ |
| 5681 |
|
| 5682 |
using boost::regex; |
| 5683 |
using boost::regex_constants::icase; |
| 5684 |
using std::chrono::duration_cast; |
| 5685 |
using std::move; |
| 5686 |
using std::string; |
| 5687 |
|
| 5688 |
* ``SUD_LexicographicNumeric`` (in configuration: ``LexicographicNumeric``) |
| 5689 |
Using declarations are sorted in the order defined as follows: |
| 5690 |
Split the strings by ``::`` and discard any initial empty strings. The |
| 5691 |
last element of each list is a non-namespace name; all others are |
| 5692 |
namespace names. Sort the lists of names lexicographically, where the |
| 5693 |
sort order of individual names is that all non-namespace names come |
| 5694 |
before all namespace names, and within those groups, names are in |
| 5695 |
case-insensitive lexicographic order. |
| 5696 |
|
| 5697 |
.. code-block:: c++ |
| 5698 |
|
| 5699 |
using boost::regex; |
| 5700 |
using boost::regex_constants::icase; |
| 5701 |
using std::move; |
| 5702 |
using std::string; |
| 5703 |
using std::chrono::duration_cast; |
| 5704 |
|
| 5705 |
|
| 5706 |
|
| 5707 |
.. _SpaceAfterCStyleCast: |
| 5708 |
|
| 5709 |
**SpaceAfterCStyleCast** (``Boolean``) :versionbadge:`clang-format 3.5` :ref:`¶ <SpaceAfterCStyleCast>` |
| 5710 |
If ``true``, a space is inserted after C style casts. |
| 5711 |
|
| 5712 |
.. code-block:: c++ |
| 5713 |
|
| 5714 |
true: false: |
| 5715 |
(int) i; vs. (int)i; |
| 5716 |
|
| 5717 |
.. _SpaceAfterLogicalNot: |
| 5718 |
|
| 5719 |
**SpaceAfterLogicalNot** (``Boolean``) :versionbadge:`clang-format 9` :ref:`¶ <SpaceAfterLogicalNot>` |
| 5720 |
If ``true``, a space is inserted after the logical not operator (``!``). |
| 5721 |
|
| 5722 |
.. code-block:: c++ |
| 5723 |
|
| 5724 |
true: false: |
| 5725 |
! someExpression(); vs. !someExpression(); |
| 5726 |
|
| 5727 |
.. _SpaceAfterTemplateKeyword: |
| 5728 |
|
| 5729 |
**SpaceAfterTemplateKeyword** (``Boolean``) :versionbadge:`clang-format 4` :ref:`¶ <SpaceAfterTemplateKeyword>` |
| 5730 |
If ``true``, a space will be inserted after the ``template`` keyword. |
| 5731 |
|
| 5732 |
.. code-block:: c++ |
| 5733 |
|
| 5734 |
true: false: |
| 5735 |
template <int> void foo(); vs. template<int> void foo(); |
| 5736 |
|
| 5737 |
.. _SpaceAroundPointerQualifiers: |
| 5738 |
|
| 5739 |
**SpaceAroundPointerQualifiers** (``SpaceAroundPointerQualifiersStyle``) :versionbadge:`clang-format 12` :ref:`¶ <SpaceAroundPointerQualifiers>` |
| 5740 |
Defines in which cases to put a space before or after pointer qualifiers |
| 5741 |
|
| 5742 |
Possible values: |
| 5743 |
|
| 5744 |
* ``SAPQ_Default`` (in configuration: ``Default``) |
| 5745 |
Don't ensure spaces around pointer qualifiers and use PointerAlignment |
| 5746 |
instead. |
| 5747 |
|
| 5748 |
.. code-block:: c++ |
| 5749 |
|
| 5750 |
PointerAlignment: Left PointerAlignment: Right |
| 5751 |
void* const* x = NULL; vs. void *const *x = NULL; |
| 5752 |
|
| 5753 |
* ``SAPQ_Before`` (in configuration: ``Before``) |
| 5754 |
Ensure that there is a space before pointer qualifiers. |
| 5755 |
|
| 5756 |
.. code-block:: c++ |
| 5757 |
|
| 5758 |
PointerAlignment: Left PointerAlignment: Right |
| 5759 |
void* const* x = NULL; vs. void * const *x = NULL; |
| 5760 |
|
| 5761 |
* ``SAPQ_After`` (in configuration: ``After``) |
| 5762 |
Ensure that there is a space after pointer qualifiers. |
| 5763 |
|
| 5764 |
.. code-block:: c++ |
| 5765 |
|
| 5766 |
PointerAlignment: Left PointerAlignment: Right |
| 5767 |
void* const * x = NULL; vs. void *const *x = NULL; |
| 5768 |
|
| 5769 |
* ``SAPQ_Both`` (in configuration: ``Both``) |
| 5770 |
Ensure that there is a space both before and after pointer qualifiers. |
| 5771 |
|
| 5772 |
.. code-block:: c++ |
| 5773 |
|
| 5774 |
PointerAlignment: Left PointerAlignment: Right |
| 5775 |
void* const * x = NULL; vs. void * const *x = NULL; |
| 5776 |
|
| 5777 |
|
| 5778 |
|
| 5779 |
.. _SpaceBeforeAssignmentOperators: |
| 5780 |
|
| 5781 |
**SpaceBeforeAssignmentOperators** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <SpaceBeforeAssignmentOperators>` |
| 5782 |
If ``false``, spaces will be removed before assignment operators. |
| 5783 |
|
| 5784 |
.. code-block:: c++ |
| 5785 |
|
| 5786 |
true: false: |
| 5787 |
int a = 5; vs. int a= 5; |
| 5788 |
a += 42; a+= 42; |
| 5789 |
|
| 5790 |
.. _SpaceBeforeCaseColon: |
| 5791 |
|
| 5792 |
**SpaceBeforeCaseColon** (``Boolean``) :versionbadge:`clang-format 12` :ref:`¶ <SpaceBeforeCaseColon>` |
| 5793 |
If ``false``, spaces will be removed before case colon. |
| 5794 |
|
| 5795 |
.. code-block:: c++ |
| 5796 |
|
| 5797 |
true: false |
| 5798 |
switch (x) { vs. switch (x) { |
| 5799 |
case 1 : break; case 1: break; |
| 5800 |
} } |
| 5801 |
|
| 5802 |
.. _SpaceBeforeCpp11BracedList: |
| 5803 |
|
| 5804 |
**SpaceBeforeCpp11BracedList** (``Boolean``) :versionbadge:`clang-format 7` :ref:`¶ <SpaceBeforeCpp11BracedList>` |
| 5805 |
If ``true``, a space will be inserted before a C++11 braced list |
| 5806 |
used to initialize an object (after the preceding identifier or type). |
| 5807 |
|
| 5808 |
.. code-block:: c++ |
| 5809 |
|
| 5810 |
true: false: |
| 5811 |
Foo foo { bar }; vs. Foo foo{ bar }; |
| 5812 |
Foo {}; Foo{}; |
| 5813 |
vector<int> { 1, 2, 3 }; vector<int>{ 1, 2, 3 }; |
| 5814 |
new int[3] { 1, 2, 3 }; new int[3]{ 1, 2, 3 }; |
| 5815 |
|
| 5816 |
.. _SpaceBeforeCtorInitializerColon: |
| 5817 |
|
| 5818 |
**SpaceBeforeCtorInitializerColon** (``Boolean``) :versionbadge:`clang-format 7` :ref:`¶ <SpaceBeforeCtorInitializerColon>` |
| 5819 |
If ``false``, spaces will be removed before constructor initializer |
| 5820 |
colon. |
| 5821 |
|
| 5822 |
.. code-block:: c++ |
| 5823 |
|
| 5824 |
true: false: |
| 5825 |
Foo::Foo() : a(a) {} Foo::Foo(): a(a) {} |
| 5826 |
|
| 5827 |
.. _SpaceBeforeInheritanceColon: |
| 5828 |
|
| 5829 |
**SpaceBeforeInheritanceColon** (``Boolean``) :versionbadge:`clang-format 7` :ref:`¶ <SpaceBeforeInheritanceColon>` |
| 5830 |
If ``false``, spaces will be removed before inheritance colon. |
| 5831 |
|
| 5832 |
.. code-block:: c++ |
| 5833 |
|
| 5834 |
true: false: |
| 5835 |
class Foo : Bar {} vs. class Foo: Bar {} |
| 5836 |
|
| 5837 |
.. _SpaceBeforeJsonColon: |
| 5838 |
|
| 5839 |
**SpaceBeforeJsonColon** (``Boolean``) :versionbadge:`clang-format 17` :ref:`¶ <SpaceBeforeJsonColon>` |
| 5840 |
If ``true``, a space will be added before a JSON colon. For other |
| 5841 |
languages, e.g. JavaScript, use ``SpacesInContainerLiterals`` instead. |
| 5842 |
|
| 5843 |
.. code-block:: c++ |
| 5844 |
|
| 5845 |
true: false: |
| 5846 |
{ { |
| 5847 |
"key" : "value" vs. "key": "value" |
| 5848 |
} } |
| 5849 |
|
| 5850 |
.. _SpaceBeforeParens: |
| 5851 |
|
| 5852 |
**SpaceBeforeParens** (``SpaceBeforeParensStyle``) :versionbadge:`clang-format 3.5` :ref:`¶ <SpaceBeforeParens>` |
| 5853 |
Defines in which cases to put a space before opening parentheses. |
| 5854 |
|
| 5855 |
Possible values: |
| 5856 |
|
| 5857 |
* ``SBPO_Never`` (in configuration: ``Never``) |
| 5858 |
This is **deprecated** and replaced by ``Custom`` below, with all |
| 5859 |
``SpaceBeforeParensOptions`` but ``AfterPlacementOperator`` set to |
| 5860 |
``false``. |
| 5861 |
|
| 5862 |
* ``SBPO_ControlStatements`` (in configuration: ``ControlStatements``) |
| 5863 |
Put a space before opening parentheses only after control statement |
| 5864 |
keywords (``for/if/while...``). |
| 5865 |
|
| 5866 |
.. code-block:: c++ |
| 5867 |
|
| 5868 |
void f() { |
| 5869 |
if (true) { |
| 5870 |
f(); |
| 5871 |
} |
| 5872 |
} |
| 5873 |
|
| 5874 |
* ``SBPO_ControlStatementsExceptControlMacros`` (in configuration: ``ControlStatementsExceptControlMacros``) |
| 5875 |
Same as ``SBPO_ControlStatements`` except this option doesn't apply to |
| 5876 |
ForEach and If macros. This is useful in projects where ForEach/If |
| 5877 |
macros are treated as function calls instead of control statements. |
| 5878 |
``SBPO_ControlStatementsExceptForEachMacros`` remains an alias for |
| 5879 |
backward compatibility. |
| 5880 |
|
| 5881 |
.. code-block:: c++ |
| 5882 |
|
| 5883 |
void f() { |
| 5884 |
Q_FOREACH(...) { |
| 5885 |
f(); |
| 5886 |
} |
| 5887 |
} |
| 5888 |
|
| 5889 |
* ``SBPO_NonEmptyParentheses`` (in configuration: ``NonEmptyParentheses``) |
| 5890 |
Put a space before opening parentheses only if the parentheses are not |
| 5891 |
empty. |
| 5892 |
|
| 5893 |
.. code-block:: c++ |
| 5894 |
|
| 5895 |
void() { |
| 5896 |
if (true) { |
| 5897 |
f(); |
| 5898 |
g (x, y, z); |
| 5899 |
} |
| 5900 |
} |
| 5901 |
|
| 5902 |
* ``SBPO_Always`` (in configuration: ``Always``) |
| 5903 |
Always put a space before opening parentheses, except when it's |
| 5904 |
prohibited by the syntax rules (in function-like macro definitions) or |
| 5905 |
when determined by other style rules (after unary operators, opening |
| 5906 |
parentheses, etc.) |
| 5907 |
|
| 5908 |
.. code-block:: c++ |
| 5909 |
|
| 5910 |
void f () { |
| 5911 |
if (true) { |
| 5912 |
f (); |
| 5913 |
} |
| 5914 |
} |
| 5915 |
|
| 5916 |
* ``SBPO_Custom`` (in configuration: ``Custom``) |
| 5917 |
Configure each individual space before parentheses in |
| 5918 |
``SpaceBeforeParensOptions``. |
| 5919 |
|
| 5920 |
|
| 5921 |
|
| 5922 |
.. _SpaceBeforeParensOptions: |
| 5923 |
|
| 5924 |
**SpaceBeforeParensOptions** (``SpaceBeforeParensCustom``) :versionbadge:`clang-format 14` :ref:`¶ <SpaceBeforeParensOptions>` |
| 5925 |
Control of individual space before parentheses. |
| 5926 |
|
| 5927 |
If ``SpaceBeforeParens`` is set to ``Custom``, use this to specify |
| 5928 |
how each individual space before parentheses case should be handled. |
| 5929 |
Otherwise, this is ignored. |
| 5930 |
|
| 5931 |
.. code-block:: yaml |
| 5932 |
|
| 5933 |
# Example of usage: |
| 5934 |
SpaceBeforeParens: Custom |
| 5935 |
SpaceBeforeParensOptions: |
| 5936 |
AfterControlStatements: true |
| 5937 |
AfterFunctionDefinitionName: true |
| 5938 |
|
| 5939 |
Nested configuration flags: |
| 5940 |
|
| 5941 |
Precise control over the spacing before parentheses. |
| 5942 |
|
| 5943 |
.. code-block:: c++ |
| 5944 |
|
| 5945 |
# Should be declared this way: |
| 5946 |
SpaceBeforeParens: Custom |
| 5947 |
SpaceBeforeParensOptions: |
| 5948 |
AfterControlStatements: true |
| 5949 |
AfterFunctionDefinitionName: true |
| 5950 |
|
| 5951 |
* ``bool AfterControlStatements`` If ``true``, put space between control statement keywords |
| 5952 |
(for/if/while...) and opening parentheses. |
| 5953 |
|
| 5954 |
.. code-block:: c++ |
| 5955 |
|
| 5956 |
true: false: |
| 5957 |
if (...) {} vs. if(...) {} |
| 5958 |
|
| 5959 |
* ``bool AfterForeachMacros`` If ``true``, put space between foreach macros and opening parentheses. |
| 5960 |
|
| 5961 |
.. code-block:: c++ |
| 5962 |
|
| 5963 |
true: false: |
| 5964 |
FOREACH (...) vs. FOREACH(...) |
| 5965 |
<loop-body> <loop-body> |
| 5966 |
|
| 5967 |
* ``bool AfterFunctionDeclarationName`` If ``true``, put a space between function declaration name and opening |
| 5968 |
parentheses. |
| 5969 |
|
| 5970 |
.. code-block:: c++ |
| 5971 |
|
| 5972 |
true: false: |
| 5973 |
void f (); vs. void f(); |
| 5974 |
|
| 5975 |
* ``bool AfterFunctionDefinitionName`` If ``true``, put a space between function definition name and opening |
| 5976 |
parentheses. |
| 5977 |
|
| 5978 |
.. code-block:: c++ |
| 5979 |
|
| 5980 |
true: false: |
| 5981 |
void f () {} vs. void f() {} |
| 5982 |
|
| 5983 |
* ``bool AfterIfMacros`` If ``true``, put space between if macros and opening parentheses. |
| 5984 |
|
| 5985 |
.. code-block:: c++ |
| 5986 |
|
| 5987 |
true: false: |
| 5988 |
IF (...) vs. IF(...) |
| 5989 |
<conditional-body> <conditional-body> |
| 5990 |
|
| 5991 |
* ``bool AfterOverloadedOperator`` If ``true``, put a space between operator overloading and opening |
| 5992 |
parentheses. |
| 5993 |
|
| 5994 |
.. code-block:: c++ |
| 5995 |
|
| 5996 |
true: false: |
| 5997 |
void operator++ (int a); vs. void operator++(int a); |
| 5998 |
object.operator++ (10); object.operator++(10); |
| 5999 |
|
| 6000 |
* ``bool AfterPlacementOperator`` If ``true``, put a space between operator ``new``/``delete`` and opening |
| 6001 |
parenthesis. |
| 6002 |
|
| 6003 |
.. code-block:: c++ |
| 6004 |
|
| 6005 |
true: false: |
| 6006 |
new (buf) T; vs. new(buf) T; |
| 6007 |
delete (buf) T; delete(buf) T; |
| 6008 |
|
| 6009 |
* ``bool AfterRequiresInClause`` If ``true``, put space between requires keyword in a requires clause and |
| 6010 |
opening parentheses, if there is one. |
| 6011 |
|
| 6012 |
.. code-block:: c++ |
| 6013 |
|
| 6014 |
true: false: |
| 6015 |
template<typename T> vs. template<typename T> |
| 6016 |
requires (A<T> && B<T>) requires(A<T> && B<T>) |
| 6017 |
... ... |
| 6018 |
|
| 6019 |
* ``bool AfterRequiresInExpression`` If ``true``, put space between requires keyword in a requires expression |
| 6020 |
and opening parentheses. |
| 6021 |
|
| 6022 |
.. code-block:: c++ |
| 6023 |
|
| 6024 |
true: false: |
| 6025 |
template<typename T> vs. template<typename T> |
| 6026 |
concept C = requires (T t) { concept C = requires(T t) { |
| 6027 |
... ... |
| 6028 |
} } |
| 6029 |
|
| 6030 |
* ``bool BeforeNonEmptyParentheses`` If ``true``, put a space before opening parentheses only if the |
| 6031 |
parentheses are not empty. |
| 6032 |
|
| 6033 |
.. code-block:: c++ |
| 6034 |
|
| 6035 |
true: false: |
| 6036 |
void f (int a); vs. void f(); |
| 6037 |
f (a); f(); |
| 6038 |
|
| 6039 |
|
| 6040 |
.. _SpaceBeforeRangeBasedForLoopColon: |
| 6041 |
|
| 6042 |
**SpaceBeforeRangeBasedForLoopColon** (``Boolean``) :versionbadge:`clang-format 7` :ref:`¶ <SpaceBeforeRangeBasedForLoopColon>` |
| 6043 |
If ``false``, spaces will be removed before range-based for loop |
| 6044 |
colon. |
| 6045 |
|
| 6046 |
.. code-block:: c++ |
| 6047 |
|
| 6048 |
true: false: |
| 6049 |
for (auto v : values) {} vs. for(auto v: values) {} |
| 6050 |
|
| 6051 |
.. _SpaceBeforeSquareBrackets: |
| 6052 |
|
| 6053 |
**SpaceBeforeSquareBrackets** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ <SpaceBeforeSquareBrackets>` |
| 6054 |
If ``true``, spaces will be before ``[``. |
| 6055 |
Lambdas will not be affected. Only the first ``[`` will get a space added. |
| 6056 |
|
| 6057 |
.. code-block:: c++ |
| 6058 |
|
| 6059 |
true: false: |
| 6060 |
int a [5]; vs. int a[5]; |
| 6061 |
int a [5][5]; vs. int a[5][5]; |
| 6062 |
|
| 6063 |
.. _SpaceInEmptyBlock: |
| 6064 |
|
| 6065 |
**SpaceInEmptyBlock** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ <SpaceInEmptyBlock>` |
| 6066 |
If ``true``, spaces will be inserted into ``{}``. |
| 6067 |
|
| 6068 |
.. code-block:: c++ |
| 6069 |
|
| 6070 |
true: false: |
| 6071 |
void f() { } vs. void f() {} |
| 6072 |
while (true) { } while (true) {} |
| 6073 |
|
| 6074 |
.. _SpaceInEmptyParentheses: |
| 6075 |
|
| 6076 |
**SpaceInEmptyParentheses** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <SpaceInEmptyParentheses>` |
| 6077 |
If ``true``, spaces may be inserted into ``()``. |
| 6078 |
This option is **deprecated**. See ``InEmptyParentheses`` of |
| 6079 |
``SpacesInParensOptions``. |
| 6080 |
|
| 6081 |
.. _SpacesBeforeTrailingComments: |
| 6082 |
|
| 6083 |
**SpacesBeforeTrailingComments** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <SpacesBeforeTrailingComments>` |
| 6084 |
The number of spaces before trailing line comments |
| 6085 |
(``//`` - comments). |
| 6086 |
|
| 6087 |
This does not affect trailing block comments (``/*`` - comments) as those |
| 6088 |
commonly have different usage patterns and a number of special cases. In |
| 6089 |
the case of Verilog, it doesn't affect a comment right after the opening |
| 6090 |
parenthesis in the port or parameter list in a module header, because it |
| 6091 |
is probably for the port on the following line instead of the parenthesis |
| 6092 |
it follows. |
| 6093 |
|
| 6094 |
.. code-block:: c++ |
| 6095 |
|
| 6096 |
SpacesBeforeTrailingComments: 3 |
| 6097 |
void f() { |
| 6098 |
if (true) { // foo1 |
| 6099 |
f(); // bar |
| 6100 |
} // foo |
| 6101 |
} |
| 6102 |
|
| 6103 |
.. _SpacesInAngles: |
| 6104 |
|
| 6105 |
**SpacesInAngles** (``SpacesInAnglesStyle``) :versionbadge:`clang-format 3.4` :ref:`¶ <SpacesInAngles>` |
| 6106 |
The SpacesInAnglesStyle to use for template argument lists. |
| 6107 |
|
| 6108 |
Possible values: |
| 6109 |
|
| 6110 |
* ``SIAS_Never`` (in configuration: ``Never``) |
| 6111 |
Remove spaces after ``<`` and before ``>``. |
| 6112 |
|
| 6113 |
.. code-block:: c++ |
| 6114 |
|
| 6115 |
static_cast<int>(arg); |
| 6116 |
std::function<void(int)> fct; |
| 6117 |
|
| 6118 |
* ``SIAS_Always`` (in configuration: ``Always``) |
| 6119 |
Add spaces after ``<`` and before ``>``. |
| 6120 |
|
| 6121 |
.. code-block:: c++ |
| 6122 |
|
| 6123 |
static_cast< int >(arg); |
| 6124 |
std::function< void(int) > fct; |
| 6125 |
|
| 6126 |
* ``SIAS_Leave`` (in configuration: ``Leave``) |
| 6127 |
Keep a single space after ``<`` and before ``>`` if any spaces were |
| 6128 |
present. Option ``Standard: Cpp03`` takes precedence. |
| 6129 |
|
| 6130 |
|
| 6131 |
|
| 6132 |
.. _SpacesInCStyleCastParentheses: |
| 6133 |
|
| 6134 |
**SpacesInCStyleCastParentheses** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <SpacesInCStyleCastParentheses>` |
| 6135 |
If ``true``, spaces may be inserted into C style casts. |
| 6136 |
This option is **deprecated**. See ``InCStyleCasts`` of |
| 6137 |
``SpacesInParensOptions``. |
| 6138 |
|
| 6139 |
.. _SpacesInConditionalStatement: |
| 6140 |
|
| 6141 |
**SpacesInConditionalStatement** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ <SpacesInConditionalStatement>` |
| 6142 |
If ``true``, spaces will be inserted around if/for/switch/while |
| 6143 |
conditions. |
| 6144 |
This option is **deprecated**. See ``InConditionalStatements`` of |
| 6145 |
``SpacesInParensOptions``. |
| 6146 |
|
| 6147 |
.. _SpacesInContainerLiterals: |
| 6148 |
|
| 6149 |
**SpacesInContainerLiterals** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <SpacesInContainerLiterals>` |
| 6150 |
If ``true``, spaces are inserted inside container literals (e.g. ObjC and |
| 6151 |
Javascript array and dict literals). For JSON, use |
| 6152 |
``SpaceBeforeJsonColon`` instead. |
| 6153 |
|
| 6154 |
.. code-block:: js |
| 6155 |
|
| 6156 |
true: false: |
| 6157 |
var arr = [ 1, 2, 3 ]; vs. var arr = [1, 2, 3]; |
| 6158 |
f({a : 1, b : 2, c : 3}); f({a: 1, b: 2, c: 3}); |
| 6159 |
|
| 6160 |
.. _SpacesInLineCommentPrefix: |
| 6161 |
|
| 6162 |
**SpacesInLineCommentPrefix** (``SpacesInLineComment``) :versionbadge:`clang-format 13` :ref:`¶ <SpacesInLineCommentPrefix>` |
| 6163 |
How many spaces are allowed at the start of a line comment. To disable the |
| 6164 |
maximum set it to ``-1``, apart from that the maximum takes precedence |
| 6165 |
over the minimum. |
| 6166 |
|
| 6167 |
.. code-block:: c++ |
| 6168 |
|
| 6169 |
Minimum = 1 |
| 6170 |
Maximum = -1 |
| 6171 |
// One space is forced |
| 6172 |
|
| 6173 |
// but more spaces are possible |
| 6174 |
|
| 6175 |
Minimum = 0 |
| 6176 |
Maximum = 0 |
| 6177 |
//Forces to start every comment directly after the slashes |
| 6178 |
|
| 6179 |
Note that in line comment sections the relative indent of the subsequent |
| 6180 |
lines is kept, that means the following: |
| 6181 |
|
| 6182 |
.. code-block:: c++ |
| 6183 |
|
| 6184 |
before: after: |
| 6185 |
Minimum: 1 |
| 6186 |
//if (b) { // if (b) { |
| 6187 |
// return true; // return true; |
| 6188 |
//} // } |
| 6189 |
|
| 6190 |
Maximum: 0 |
| 6191 |
/// List: ///List: |
| 6192 |
/// - Foo /// - Foo |
| 6193 |
/// - Bar /// - Bar |
| 6194 |
|
| 6195 |
This option has only effect if ``ReflowComments`` is set to ``true``. |
| 6196 |
|
| 6197 |
Nested configuration flags: |
| 6198 |
|
| 6199 |
Control of spaces within a single line comment. |
| 6200 |
|
| 6201 |
* ``unsigned Minimum`` The minimum number of spaces at the start of the comment. |
| 6202 |
|
| 6203 |
* ``unsigned Maximum`` The maximum number of spaces at the start of the comment. |
| 6204 |
|
| 6205 |
|
| 6206 |
.. _SpacesInParens: |
| 6207 |
|
| 6208 |
**SpacesInParens** (``SpacesInParensStyle``) :versionbadge:`clang-format 17` :ref:`¶ <SpacesInParens>` |
| 6209 |
Defines in which cases spaces will be inserted after ``(`` and before |
| 6210 |
``)``. |
| 6211 |
|
| 6212 |
Possible values: |
| 6213 |
|
| 6214 |
* ``SIPO_Never`` (in configuration: ``Never``) |
| 6215 |
Never put a space in parentheses. |
| 6216 |
|
| 6217 |
.. code-block:: c++ |
| 6218 |
|
| 6219 |
void f() { |
| 6220 |
if(true) { |
| 6221 |
f(); |
| 6222 |
} |
| 6223 |
} |
| 6224 |
|
| 6225 |
* ``SIPO_Custom`` (in configuration: ``Custom``) |
| 6226 |
Configure each individual space in parentheses in |
| 6227 |
`SpacesInParensOptions`. |
| 6228 |
|
| 6229 |
|
| 6230 |
|
| 6231 |
.. _SpacesInParensOptions: |
| 6232 |
|
| 6233 |
**SpacesInParensOptions** (``SpacesInParensCustom``) :versionbadge:`clang-format 17` :ref:`¶ <SpacesInParensOptions>` |
| 6234 |
Control of individual spaces in parentheses. |
| 6235 |
|
| 6236 |
If ``SpacesInParens`` is set to ``Custom``, use this to specify |
| 6237 |
how each individual space in parentheses case should be handled. |
| 6238 |
Otherwise, this is ignored. |
| 6239 |
|
| 6240 |
.. code-block:: yaml |
| 6241 |
|
| 6242 |
# Example of usage: |
| 6243 |
SpacesInParens: Custom |
| 6244 |
SpacesInParensOptions: |
| 6245 |
ExceptDoubleParentheses: false |
| 6246 |
InConditionalStatements: true |
| 6247 |
InEmptyParentheses: true |
| 6248 |
|
| 6249 |
Nested configuration flags: |
| 6250 |
|
| 6251 |
Precise control over the spacing in parentheses. |
| 6252 |
|
| 6253 |
.. code-block:: c++ |
| 6254 |
|
| 6255 |
# Should be declared this way: |
| 6256 |
SpacesInParens: Custom |
| 6257 |
SpacesInParensOptions: |
| 6258 |
ExceptDoubleParentheses: false |
| 6259 |
InConditionalStatements: true |
| 6260 |
Other: true |
| 6261 |
|
| 6262 |
* ``bool ExceptDoubleParentheses`` Override any of the following options to prevent addition of space |
| 6263 |
when both opening and closing parentheses use multiple parentheses. |
| 6264 |
|
| 6265 |
.. code-block:: c++ |
| 6266 |
|
| 6267 |
true: |
| 6268 |
__attribute__(( noreturn )) |
| 6269 |
__decltype__(( x )) |
| 6270 |
if (( a = b )) |
| 6271 |
false: |
| 6272 |
Uses the applicable option. |
| 6273 |
|
| 6274 |
* ``bool InConditionalStatements`` Put a space in parentheses only inside conditional statements |
| 6275 |
(``for/if/while/switch...``). |
| 6276 |
|
| 6277 |
.. code-block:: c++ |
| 6278 |
|
| 6279 |
true: false: |
| 6280 |
if ( a ) { ... } vs. if (a) { ... } |
| 6281 |
while ( i < 5 ) { ... } while (i < 5) { ... } |
| 6282 |
|
| 6283 |
* ``bool InCStyleCasts`` Put a space in C style casts. |
| 6284 |
|
| 6285 |
.. code-block:: c++ |
| 6286 |
|
| 6287 |
true: false: |
| 6288 |
x = ( int32 )y vs. x = (int32)y |
| 6289 |
y = (( int (*)(int) )foo)(x); y = ((int (*)(int))foo)(x); |
| 6290 |
|
| 6291 |
* ``bool InEmptyParentheses`` Insert a space in empty parentheses, i.e. ``()``. |
| 6292 |
|
| 6293 |
.. code-block:: c++ |
| 6294 |
|
| 6295 |
true: false: |
| 6296 |
void f( ) { vs. void f() { |
| 6297 |
int x[] = {foo( ), bar( )}; int x[] = {foo(), bar()}; |
| 6298 |
if (true) { if (true) { |
| 6299 |
f( ); f(); |
| 6300 |
} } |
| 6301 |
} } |
| 6302 |
|
| 6303 |
* ``bool Other`` Put a space in parentheses not covered by preceding options. |
| 6304 |
|
| 6305 |
.. code-block:: c++ |
| 6306 |
|
| 6307 |
true: false: |
| 6308 |
t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete; |
| 6309 |
|
| 6310 |
|
| 6311 |
.. _SpacesInParentheses: |
| 6312 |
|
| 6313 |
**SpacesInParentheses** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <SpacesInParentheses>` |
| 6314 |
If ``true``, spaces will be inserted after ``(`` and before ``)``. |
| 6315 |
This option is **deprecated**. The previous behavior is preserved by using |
| 6316 |
``SpacesInParens`` with ``Custom`` and by setting all |
| 6317 |
``SpacesInParensOptions`` to ``true`` except for ``InCStyleCasts`` and |
| 6318 |
``InEmptyParentheses``. |
| 6319 |
|
| 6320 |
.. _SpacesInSquareBrackets: |
| 6321 |
|
| 6322 |
**SpacesInSquareBrackets** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <SpacesInSquareBrackets>` |
| 6323 |
If ``true``, spaces will be inserted after ``[`` and before ``]``. |
| 6324 |
Lambdas without arguments or unspecified size array declarations will not |
| 6325 |
be affected. |
| 6326 |
|
| 6327 |
.. code-block:: c++ |
| 6328 |
|
| 6329 |
true: false: |
| 6330 |
int a[ 5 ]; vs. int a[5]; |
| 6331 |
std::unique_ptr<int[]> foo() {} // Won't be affected |
| 6332 |
|
| 6333 |
.. _Standard: |
| 6334 |
|
| 6335 |
**Standard** (``LanguageStandard``) :versionbadge:`clang-format 3.7` :ref:`¶ <Standard>` |
| 6336 |
Parse and format C++ constructs compatible with this standard. |
| 6337 |
|
| 6338 |
.. code-block:: c++ |
| 6339 |
|
| 6340 |
c++03: latest: |
| 6341 |
vector<set<int> > x; vs. vector<set<int>> x; |
| 6342 |
|
| 6343 |
Possible values: |
| 6344 |
|
| 6345 |
* ``LS_Cpp03`` (in configuration: ``c++03``) |
| 6346 |
Parse and format as C++03. |
| 6347 |
``Cpp03`` is a deprecated alias for ``c++03`` |
| 6348 |
|
| 6349 |
* ``LS_Cpp11`` (in configuration: ``c++11``) |
| 6350 |
Parse and format as C++11. |
| 6351 |
|
| 6352 |
* ``LS_Cpp14`` (in configuration: ``c++14``) |
| 6353 |
Parse and format as C++14. |
| 6354 |
|
| 6355 |
* ``LS_Cpp17`` (in configuration: ``c++17``) |
| 6356 |
Parse and format as C++17. |
| 6357 |
|
| 6358 |
* ``LS_Cpp20`` (in configuration: ``c++20``) |
| 6359 |
Parse and format as C++20. |
| 6360 |
|
| 6361 |
* ``LS_Latest`` (in configuration: ``Latest``) |
| 6362 |
Parse and format using the latest supported language version. |
| 6363 |
``Cpp11`` is a deprecated alias for ``Latest`` |
| 6364 |
|
| 6365 |
* ``LS_Auto`` (in configuration: ``Auto``) |
| 6366 |
Automatic detection based on the input. |
| 6367 |
|
| 6368 |
|
| 6369 |
|
| 6370 |
.. _StatementAttributeLikeMacros: |
| 6371 |
|
| 6372 |
**StatementAttributeLikeMacros** (``List of Strings``) :versionbadge:`clang-format 12` :ref:`¶ <StatementAttributeLikeMacros>` |
| 6373 |
Macros which are ignored in front of a statement, as if they were an |
| 6374 |
attribute. So that they are not parsed as identifier, for example for Qts |
| 6375 |
emit. |
| 6376 |
|
| 6377 |
.. code-block:: c++ |
| 6378 |
|
| 6379 |
AlignConsecutiveDeclarations: true |
| 6380 |
StatementAttributeLikeMacros: [] |
| 6381 |
unsigned char data = 'x'; |
| 6382 |
emit signal(data); // This is parsed as variable declaration. |
| 6383 |
|
| 6384 |
AlignConsecutiveDeclarations: true |
| 6385 |
StatementAttributeLikeMacros: [emit] |
| 6386 |
unsigned char data = 'x'; |
| 6387 |
emit signal(data); // Now it's fine again. |
| 6388 |
|
| 6389 |
.. _StatementMacros: |
| 6390 |
|
| 6391 |
**StatementMacros** (``List of Strings``) :versionbadge:`clang-format 8` :ref:`¶ <StatementMacros>` |
| 6392 |
A vector of macros that should be interpreted as complete |
| 6393 |
statements. |
| 6394 |
|
| 6395 |
Typical macros are expressions, and require a semi-colon to be |
| 6396 |
added; sometimes this is not the case, and this allows to make |
| 6397 |
clang-format aware of such cases. |
| 6398 |
|
| 6399 |
For example: Q_UNUSED |
| 6400 |
|
| 6401 |
.. _TabWidth: |
| 6402 |
|
| 6403 |
**TabWidth** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <TabWidth>` |
| 6404 |
The number of columns used for tab stops. |
| 6405 |
|
| 6406 |
.. _TableGenBreakInsideDAGArg: |
| 6407 |
|
| 6408 |
**TableGenBreakInsideDAGArg** (``DAGArgStyle``) :versionbadge:`clang-format 19` :ref:`¶ <TableGenBreakInsideDAGArg>` |
| 6409 |
The styles of the line break inside the DAGArg in TableGen. |
| 6410 |
|
| 6411 |
Possible values: |
| 6412 |
|
| 6413 |
* ``DAS_DontBreak`` (in configuration: ``DontBreak``) |
| 6414 |
Never break inside DAGArg. |
| 6415 |
|
| 6416 |
.. code-block:: c++ |
| 6417 |
|
| 6418 |
let DAGArgIns = (ins i32:$src1, i32:$src2); |
| 6419 |
|
| 6420 |
* ``DAS_BreakElements`` (in configuration: ``BreakElements``) |
| 6421 |
Break inside DAGArg after each list element but for the last. |
| 6422 |
This aligns to the first element. |
| 6423 |
|
| 6424 |
.. code-block:: c++ |
| 6425 |
|
| 6426 |
let DAGArgIns = (ins i32:$src1, |
| 6427 |
i32:$src2); |
| 6428 |
|
| 6429 |
* ``DAS_BreakAll`` (in configuration: ``BreakAll``) |
| 6430 |
Break inside DAGArg after the operator and the all elements. |
| 6431 |
|
| 6432 |
.. code-block:: c++ |
| 6433 |
|
| 6434 |
let DAGArgIns = (ins |
| 6435 |
i32:$src1, |
| 6436 |
i32:$src2 |
| 6437 |
); |
| 6438 |
|
| 6439 |
|
| 6440 |
|
| 6441 |
.. _TableGenBreakingDAGArgOperators: |
| 6442 |
|
| 6443 |
**TableGenBreakingDAGArgOperators** (``List of Strings``) :versionbadge:`clang-format 19` :ref:`¶ <TableGenBreakingDAGArgOperators>` |
| 6444 |
Works only when TableGenBreakInsideDAGArg is not DontBreak. |
| 6445 |
The string list needs to consist of identifiers in TableGen. |
| 6446 |
If any identifier is specified, this limits the line breaks by |
| 6447 |
TableGenBreakInsideDAGArg option only on DAGArg values beginning with |
| 6448 |
the specified identifiers. |
| 6449 |
|
| 6450 |
For example the configuration, |
| 6451 |
|
| 6452 |
.. code-block:: yaml |
| 6453 |
|
| 6454 |
TableGenBreakInsideDAGArg: BreakAll |
| 6455 |
TableGenBreakingDAGArgOperators: [ins, outs] |
| 6456 |
|
| 6457 |
makes the line break only occurs inside DAGArgs beginning with the |
| 6458 |
specified identifiers ``ins`` and ``outs``. |
| 6459 |
|
| 6460 |
|
| 6461 |
.. code-block:: c++ |
| 6462 |
|
| 6463 |
let DAGArgIns = (ins |
| 6464 |
i32:$src1, |
| 6465 |
i32:$src2 |
| 6466 |
); |
| 6467 |
let DAGArgOtherID = (other i32:$other1, i32:$other2); |
| 6468 |
let DAGArgBang = (!cast<SomeType>("Some") i32:$src1, i32:$src2) |
| 6469 |
|
| 6470 |
.. _TypeNames: |
| 6471 |
|
| 6472 |
**TypeNames** (``List of Strings``) :versionbadge:`clang-format 17` :ref:`¶ <TypeNames>` |
| 6473 |
A vector of non-keyword identifiers that should be interpreted as type |
| 6474 |
names. |
| 6475 |
|
| 6476 |
A ``*``, ``&``, or ``&&`` between a type name and another non-keyword |
| 6477 |
identifier is annotated as a pointer or reference token instead of a |
| 6478 |
binary operator. |
| 6479 |
|
| 6480 |
.. _TypenameMacros: |
| 6481 |
|
| 6482 |
**TypenameMacros** (``List of Strings``) :versionbadge:`clang-format 9` :ref:`¶ <TypenameMacros>` |
| 6483 |
A vector of macros that should be interpreted as type declarations |
| 6484 |
instead of as function calls. |
| 6485 |
|
| 6486 |
These are expected to be macros of the form: |
| 6487 |
|
| 6488 |
.. code-block:: c++ |
| 6489 |
|
| 6490 |
STACK_OF(...) |
| 6491 |
|
| 6492 |
In the .clang-format configuration file, this can be configured like: |
| 6493 |
|
| 6494 |
.. code-block:: yaml |
| 6495 |
|
| 6496 |
TypenameMacros: [STACK_OF, LIST] |
| 6497 |
|
| 6498 |
For example: OpenSSL STACK_OF, BSD LIST_ENTRY. |
| 6499 |
|
| 6500 |
.. _UseCRLF: |
| 6501 |
|
| 6502 |
**UseCRLF** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ <UseCRLF>` |
| 6503 |
This option is **deprecated**. See ``LF`` and ``CRLF`` of ``LineEnding``. |
| 6504 |
|
| 6505 |
.. _UseTab: |
| 6506 |
|
| 6507 |
**UseTab** (``UseTabStyle``) :versionbadge:`clang-format 3.7` :ref:`¶ <UseTab>` |
| 6508 |
The way to use tab characters in the resulting file. |
| 6509 |
|
| 6510 |
Possible values: |
| 6511 |
|
| 6512 |
* ``UT_Never`` (in configuration: ``Never``) |
| 6513 |
Never use tab. |
| 6514 |
|
| 6515 |
* ``UT_ForIndentation`` (in configuration: ``ForIndentation``) |
| 6516 |
Use tabs only for indentation. |
| 6517 |
|
| 6518 |
* ``UT_ForContinuationAndIndentation`` (in configuration: ``ForContinuationAndIndentation``) |
| 6519 |
Fill all leading whitespace with tabs, and use spaces for alignment that |
| 6520 |
appears within a line (e.g. consecutive assignments and declarations). |
| 6521 |
|
| 6522 |
* ``UT_AlignWithSpaces`` (in configuration: ``AlignWithSpaces``) |
| 6523 |
Use tabs for line continuation and indentation, and spaces for |
| 6524 |
alignment. |
| 6525 |
|
| 6526 |
* ``UT_Always`` (in configuration: ``Always``) |
| 6527 |
Use tabs whenever we need to fill whitespace that spans at least from |
| 6528 |
one tab stop to the next one. |
| 6529 |
|
| 6530 |
|
| 6531 |
|
| 6532 |
.. _VerilogBreakBetweenInstancePorts: |
| 6533 |
|
| 6534 |
**VerilogBreakBetweenInstancePorts** (``Boolean``) :versionbadge:`clang-format 17` :ref:`¶ <VerilogBreakBetweenInstancePorts>` |
| 6535 |
For Verilog, put each port on its own line in module instantiations. |
| 6536 |
|
| 6537 |
.. code-block:: c++ |
| 6538 |
|
| 6539 |
true: |
| 6540 |
ffnand ff1(.q(), |
| 6541 |
.qbar(out1), |
| 6542 |
.clear(in1), |
| 6543 |
.preset(in2)); |
| 6544 |
|
| 6545 |
false: |
| 6546 |
ffnand ff1(.q(), .qbar(out1), .clear(in1), .preset(in2)); |
| 6547 |
|
| 6548 |
.. _WhitespaceSensitiveMacros: |
| 6549 |
|
| 6550 |
**WhitespaceSensitiveMacros** (``List of Strings``) :versionbadge:`clang-format 11` :ref:`¶ <WhitespaceSensitiveMacros>` |
| 6551 |
A vector of macros which are whitespace-sensitive and should not |
| 6552 |
be touched. |
| 6553 |
|
| 6554 |
These are expected to be macros of the form: |
| 6555 |
|
| 6556 |
.. code-block:: c++ |
| 6557 |
|
| 6558 |
STRINGIZE(...) |
| 6559 |
|
| 6560 |
In the .clang-format configuration file, this can be configured like: |
| 6561 |
|
| 6562 |
.. code-block:: yaml |
| 6563 |
|
| 6564 |
WhitespaceSensitiveMacros: [STRINGIZE, PP_STRINGIZE] |
| 6565 |
|
| 6566 |
For example: BOOST_PP_STRINGIZE |
| 6567 |
|
| 6568 |
.. END_FORMAT_STYLE_OPTIONS |
| 6569 |
|
| 6570 |
Adding additional style options |
| 6571 |
=============================== |
| 6572 |
|
| 6573 |
Each additional style option adds costs to the clang-format project. Some of |
| 6574 |
these costs affect the clang-format development itself, as we need to make |
| 6575 |
sure that any given combination of options work and that new features don't |
| 6576 |
break any of the existing options in any way. There are also costs for end users |
| 6577 |
as options become less discoverable and people have to think about and make a |
| 6578 |
decision on options they don't really care about. |
| 6579 |
|
| 6580 |
The goal of the clang-format project is more on the side of supporting a |
| 6581 |
limited set of styles really well as opposed to supporting every single style |
| 6582 |
used by a codebase somewhere in the wild. Of course, we do want to support all |
| 6583 |
major projects and thus have established the following bar for adding style |
| 6584 |
options. Each new style option must: |
| 6585 |
|
| 6586 |
* be used in a project of significant size (have dozens of contributors) |
| 6587 |
* have a publicly accessible style guide |
| 6588 |
* have a person willing to contribute and maintain patches |
| 6589 |
|
| 6590 |
Examples |
| 6591 |
======== |
| 6592 |
|
| 6593 |
A style similar to the `Linux Kernel style |
| 6594 |
<https://www.kernel.org/doc/html/latest/process/coding-style.html>`_: |
| 6595 |
|
| 6596 |
.. code-block:: yaml |
| 6597 |
|
| 6598 |
BasedOnStyle: LLVM |
| 6599 |
IndentWidth: 8 |
| 6600 |
UseTab: Always |
| 6601 |
BreakBeforeBraces: Linux |
| 6602 |
AllowShortIfStatementsOnASingleLine: false |
| 6603 |
IndentCaseLabels: false |
| 6604 |
|
| 6605 |
The result is (imagine that tabs are used for indentation here): |
| 6606 |
|
| 6607 |
.. code-block:: c++ |
| 6608 |
|
| 6609 |
void test() |
| 6610 |
{ |
| 6611 |
switch (x) { |
| 6612 |
case 0: |
| 6613 |
case 1: |
| 6614 |
do_something(); |
| 6615 |
break; |
| 6616 |
case 2: |
| 6617 |
do_something_else(); |
| 6618 |
break; |
| 6619 |
default: |
| 6620 |
break; |
| 6621 |
} |
| 6622 |
if (condition) |
| 6623 |
do_something_completely_different(); |
| 6624 |
|
| 6625 |
if (x == y) { |
| 6626 |
q(); |
| 6627 |
} else if (x > y) { |
| 6628 |
w(); |
| 6629 |
} else { |
| 6630 |
r(); |
| 6631 |
} |
| 6632 |
} |
| 6633 |
|
| 6634 |
A style similar to the default Visual Studio formatting style: |
| 6635 |
|
| 6636 |
.. code-block:: yaml |
| 6637 |
|
| 6638 |
UseTab: Never |
| 6639 |
IndentWidth: 4 |
| 6640 |
BreakBeforeBraces: Allman |
| 6641 |
AllowShortIfStatementsOnASingleLine: false |
| 6642 |
IndentCaseLabels: false |
| 6643 |
ColumnLimit: 0 |
| 6644 |
|
| 6645 |
The result is: |
| 6646 |
|
| 6647 |
.. code-block:: c++ |
| 6648 |
|
| 6649 |
void test() |
| 6650 |
{ |
| 6651 |
switch (suffix) |
| 6652 |
{ |
| 6653 |
case 0: |
| 6654 |
case 1: |
| 6655 |
do_something(); |
| 6656 |
break; |
| 6657 |
case 2: |
| 6658 |
do_something_else(); |
| 6659 |
break; |
| 6660 |
default: |
| 6661 |
break; |
| 6662 |
} |
| 6663 |
if (condition) |
| 6664 |
do_something_completely_different(); |
| 6665 |
|
| 6666 |
if (x == y) |
| 6667 |
{ |
| 6668 |
q(); |
| 6669 |
} |
| 6670 |
else if (x > y) |
| 6671 |
{ |
| 6672 |
w(); |
| 6673 |
} |
| 6674 |
else |
| 6675 |
{ |
| 6676 |
r(); |
| 6677 |
} |
| 6678 |
} |