1.. raw:: html 2 3 <style type="text/css"> 4 .versionbadge { background-color: #1c913d; height: 20px; display: inline-block; width: 120px; text-align: center; border-radius: 5px; color: #FFFFFF; font-family="Verdana,Geneva,DejaVu Sans,sans-serif" } 5 </style> 6 7.. role:: versionbadge 8 9========================== 10Clang-Format Style Options 11========================== 12 13:doc:`ClangFormatStyleOptions` describes configurable formatting style options 14supported by :doc:`LibFormat` and :doc:`ClangFormat`. 15 16When using :program:`clang-format` command line utility or 17``clang::format::reformat(...)`` functions from code, one can either use one of 18the predefined styles (LLVM, Google, Chromium, Mozilla, WebKit, Microsoft) or 19create a custom style by configuring specific style options. 20 21 22Configuring Style with clang-format 23=================================== 24 25:program:`clang-format` supports two ways to provide custom style options: 26directly specify style configuration in the ``-style=`` command line option or 27use ``-style=file`` and put style configuration in the ``.clang-format`` or 28``_clang-format`` file in the project directory. 29 30When using ``-style=file``, :program:`clang-format` for each input file will 31try to find the ``.clang-format`` file located in the closest parent directory 32of the input file. When the standard input is used, the search is started from 33the current directory. 34 35When using ``-style=file:<format_file_path>``, :program:`clang-format` for 36each input file will use the format file located at `<format_file_path>`. 37The path may be absolute or relative to the working directory. 38 39The ``.clang-format`` file uses YAML format: 40 41.. code-block:: yaml 42 43 key1: value1 44 key2: value2 45 # A comment. 46 ... 47 48The configuration file can consist of several sections each having different 49``Language:`` parameter denoting the programming language this section of the 50configuration is targeted at. See the description of the **Language** option 51below for the list of supported languages. The first section may have no 52language set, it will set the default style options for all languages. 53Configuration sections for specific language will override options set in the 54default section. 55 56When :program:`clang-format` formats a file, it auto-detects the language using 57the file name. When formatting standard input or a file that doesn't have the 58extension corresponding to its language, ``-assume-filename=`` option can be 59used to override the file name :program:`clang-format` uses to detect the 60language. 61 62An example of a configuration file for multiple languages: 63 64.. code-block:: yaml 65 66 --- 67 # We'll use defaults from the LLVM style, but with 4 columns indentation. 68 BasedOnStyle: LLVM 69 IndentWidth: 4 70 --- 71 Language: Cpp 72 # Force pointers to the type for C++. 73 DerivePointerAlignment: false 74 PointerAlignment: Left 75 --- 76 Language: JavaScript 77 # Use 100 columns for JS. 78 ColumnLimit: 100 79 --- 80 Language: Proto 81 # Don't format .proto files. 82 DisableFormat: true 83 --- 84 Language: CSharp 85 # Use 100 columns for C#. 86 ColumnLimit: 100 87 ... 88 89An easy way to get a valid ``.clang-format`` file containing all configuration 90options of a certain predefined style is: 91 92.. code-block:: console 93 94 clang-format -style=llvm -dump-config > .clang-format 95 96When specifying configuration in the ``-style=`` option, the same configuration 97is applied for all input files. The format of the configuration is: 98 99.. code-block:: console 100 101 -style='{key1: value1, key2: value2, ...}' 102 103 104Disabling Formatting on a Piece of Code 105======================================= 106 107Clang-format understands also special comments that switch formatting in a 108delimited range. The code between a comment ``// clang-format off`` or 109``/* clang-format off */`` up to a comment ``// clang-format on`` or 110``/* clang-format on */`` will not be formatted. The comments themselves 111will be formatted (aligned) normally. 112 113.. code-block:: c++ 114 115 int formatted_code; 116 // clang-format off 117 void unformatted_code ; 118 // clang-format on 119 void formatted_code_again; 120 121 122Configuring Style in Code 123========================= 124 125When using ``clang::format::reformat(...)`` functions, the format is specified 126by supplying the `clang::format::FormatStyle 127<https://clang.llvm.org/doxygen/structclang_1_1format_1_1FormatStyle.html>`_ 128structure. 129 130 131Configurable Format Style Options 132================================= 133 134This section lists the supported style options. Value type is specified for 135each option. For enumeration types possible values are specified both as a C++ 136enumeration member (with a prefix, e.g. ``LS_Auto``), and as a value usable in 137the configuration (without a prefix: ``Auto``). 138 139 140**BasedOnStyle** (``String``) 141 The style used for all options not specifically set in the configuration. 142 143 This option is supported only in the :program:`clang-format` configuration 144 (both within ``-style='{...}'`` and the ``.clang-format`` file). 145 146 Possible values: 147 148 * ``LLVM`` 149 A style complying with the `LLVM coding standards 150 <https://llvm.org/docs/CodingStandards.html>`_ 151 * ``Google`` 152 A style complying with `Google's C++ style guide 153 <https://google.github.io/styleguide/cppguide.html>`_ 154 * ``Chromium`` 155 A style complying with `Chromium's style guide 156 <https://chromium.googlesource.com/chromium/src/+/refs/heads/main/styleguide/styleguide.md>`_ 157 * ``Mozilla`` 158 A style complying with `Mozilla's style guide 159 <https://firefox-source-docs.mozilla.org/code-quality/coding-style/index.html>`_ 160 * ``WebKit`` 161 A style complying with `WebKit's style guide 162 <https://www.webkit.org/coding/coding-style.html>`_ 163 * ``Microsoft`` 164 A style complying with `Microsoft's style guide 165 <https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference>`_ 166 * ``GNU`` 167 A style complying with the `GNU coding standards 168 <https://www.gnu.org/prep/standards/standards.html>`_ 169 * ``InheritParentConfig`` 170 Not a real style, but allows to use the ``.clang-format`` file from the 171 parent directory (or its parent if there is none). If there is no parent 172 file found it falls back to the ``fallback`` style, and applies the changes 173 to that. 174 175 With this option you can overwrite some parts of your main style for your 176 subdirectories. This is also possible through the command line, e.g.: 177 ``--style={BasedOnStyle: InheritParentConfig, ColumnLimit: 20}`` 178 179.. START_FORMAT_STYLE_OPTIONS 180 181**AccessModifierOffset** (``Integer``) :versionbadge:`clang-format 3.3` 182 The extra indent or outdent of access modifiers, e.g. ``public:``. 183 184**AlignAfterOpenBracket** (``BracketAlignmentStyle``) :versionbadge:`clang-format 3.8` 185 If ``true``, horizontally aligns arguments after an open bracket. 186 187 This applies to round brackets (parentheses), angle brackets and square 188 brackets. 189 190 Possible values: 191 192 * ``BAS_Align`` (in configuration: ``Align``) 193 Align parameters on the open bracket, e.g.: 194 195 .. code-block:: c++ 196 197 someLongFunction(argument1, 198 argument2); 199 200 * ``BAS_DontAlign`` (in configuration: ``DontAlign``) 201 Don't align, instead use ``ContinuationIndentWidth``, e.g.: 202 203 .. code-block:: c++ 204 205 someLongFunction(argument1, 206 argument2); 207 208 * ``BAS_AlwaysBreak`` (in configuration: ``AlwaysBreak``) 209 Always break after an open bracket, if the parameters don't fit 210 on a single line, e.g.: 211 212 .. code-block:: c++ 213 214 someLongFunction( 215 argument1, argument2); 216 217 * ``BAS_BlockIndent`` (in configuration: ``BlockIndent``) 218 Always break after an open bracket, if the parameters don't fit 219 on a single line. Closing brackets will be placed on a new line. 220 E.g.: 221 222 .. code-block:: c++ 223 224 someLongFunction( 225 argument1, argument2 226 ) 227 228 229 .. warning:: 230 231 Note: This currently only applies to parentheses. 232 233 234 235**AlignArrayOfStructures** (``ArrayInitializerAlignmentStyle``) :versionbadge:`clang-format 13` 236 if not ``None``, when using initialization for an array of structs 237 aligns the fields into columns. 238 239 Possible values: 240 241 * ``AIAS_Left`` (in configuration: ``Left``) 242 Align array column and left justify the columns e.g.: 243 244 .. code-block:: c++ 245 246 struct test demo[] = 247 { 248 {56, 23, "hello"}, 249 {-1, 93463, "world"}, 250 {7, 5, "!!" } 251 }; 252 253 * ``AIAS_Right`` (in configuration: ``Right``) 254 Align array column and right justify the columns e.g.: 255 256 .. code-block:: c++ 257 258 struct test demo[] = 259 { 260 {56, 23, "hello"}, 261 {-1, 93463, "world"}, 262 { 7, 5, "!!"} 263 }; 264 265 * ``AIAS_None`` (in configuration: ``None``) 266 Don't align array initializer columns. 267 268 269 270**AlignConsecutiveAssignments** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 3.8` 271 Style of aligning consecutive assignments. 272 273 ``Consecutive`` will result in formattings like: 274 275 .. code-block:: c++ 276 277 int a = 1; 278 int somelongname = 2; 279 double c = 3; 280 281 Possible values: 282 283 * ``ACS_None`` (in configuration: ``None``) 284 Do not align assignments on consecutive lines. 285 286 * ``ACS_Consecutive`` (in configuration: ``Consecutive``) 287 Align assignments on consecutive lines. This will result in 288 formattings like: 289 290 .. code-block:: c++ 291 292 int a = 1; 293 int somelongname = 2; 294 double c = 3; 295 296 int d = 3; 297 /* A comment. */ 298 double e = 4; 299 300 * ``ACS_AcrossEmptyLines`` (in configuration: ``AcrossEmptyLines``) 301 Same as ACS_Consecutive, but also spans over empty lines, e.g. 302 303 .. code-block:: c++ 304 305 int a = 1; 306 int somelongname = 2; 307 double c = 3; 308 309 int d = 3; 310 /* A comment. */ 311 double e = 4; 312 313 * ``ACS_AcrossComments`` (in configuration: ``AcrossComments``) 314 Same as ACS_Consecutive, but also spans over lines only containing 315 comments, e.g. 316 317 .. code-block:: c++ 318 319 int a = 1; 320 int somelongname = 2; 321 double c = 3; 322 323 int d = 3; 324 /* A comment. */ 325 double e = 4; 326 327 * ``ACS_AcrossEmptyLinesAndComments`` 328 (in configuration: ``AcrossEmptyLinesAndComments``) 329 330 Same as ACS_Consecutive, but also spans over lines only containing 331 comments and empty lines, e.g. 332 333 .. code-block:: c++ 334 335 int a = 1; 336 int somelongname = 2; 337 double c = 3; 338 339 int d = 3; 340 /* A comment. */ 341 double e = 4; 342 343**AlignConsecutiveBitFields** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 11` 344 Style of aligning consecutive bit field. 345 346 ``Consecutive`` will align the bitfield separators of consecutive lines. 347 This will result in formattings like: 348 349 .. code-block:: c++ 350 351 int aaaa : 1; 352 int b : 12; 353 int ccc : 8; 354 355 Possible values: 356 357 * ``ACS_None`` (in configuration: ``None``) 358 Do not align bit fields on consecutive lines. 359 360 * ``ACS_Consecutive`` (in configuration: ``Consecutive``) 361 Align bit fields on consecutive lines. This will result in 362 formattings like: 363 364 .. code-block:: c++ 365 366 int aaaa : 1; 367 int b : 12; 368 int ccc : 8; 369 370 int d : 2; 371 /* A comment. */ 372 int ee : 3; 373 374 * ``ACS_AcrossEmptyLines`` (in configuration: ``AcrossEmptyLines``) 375 Same as ACS_Consecutive, but also spans over empty lines, e.g. 376 377 .. code-block:: c++ 378 379 int aaaa : 1; 380 int b : 12; 381 int ccc : 8; 382 383 int d : 2; 384 /* A comment. */ 385 int ee : 3; 386 387 * ``ACS_AcrossComments`` (in configuration: ``AcrossComments``) 388 Same as ACS_Consecutive, but also spans over lines only containing 389 comments, e.g. 390 391 .. code-block:: c++ 392 393 int aaaa : 1; 394 int b : 12; 395 int ccc : 8; 396 397 int d : 2; 398 /* A comment. */ 399 int ee : 3; 400 401 * ``ACS_AcrossEmptyLinesAndComments`` 402 (in configuration: ``AcrossEmptyLinesAndComments``) 403 404 Same as ACS_Consecutive, but also spans over lines only containing 405 comments and empty lines, e.g. 406 407 .. code-block:: c++ 408 409 int aaaa : 1; 410 int b : 12; 411 int ccc : 8; 412 413 int d : 2; 414 /* A comment. */ 415 int ee : 3; 416 417**AlignConsecutiveDeclarations** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 3.8` 418 Style of aligning consecutive declarations. 419 420 ``Consecutive`` will align the declaration names of consecutive lines. 421 This will result in formattings like: 422 423 .. code-block:: c++ 424 425 int aaaa = 12; 426 float b = 23; 427 std::string ccc; 428 429 Possible values: 430 431 * ``ACS_None`` (in configuration: ``None``) 432 Do not align bit declarations on consecutive lines. 433 434 * ``ACS_Consecutive`` (in configuration: ``Consecutive``) 435 Align declarations on consecutive lines. This will result in 436 formattings like: 437 438 .. code-block:: c++ 439 440 int aaaa = 12; 441 float b = 23; 442 std::string ccc; 443 444 int a = 42; 445 /* A comment. */ 446 bool c = false; 447 448 * ``ACS_AcrossEmptyLines`` (in configuration: ``AcrossEmptyLines``) 449 Same as ACS_Consecutive, but also spans over empty lines, e.g. 450 451 .. code-block:: c++ 452 453 int aaaa = 12; 454 float b = 23; 455 std::string ccc; 456 457 int a = 42; 458 /* A comment. */ 459 bool c = false; 460 461 * ``ACS_AcrossComments`` (in configuration: ``AcrossComments``) 462 Same as ACS_Consecutive, but also spans over lines only containing 463 comments, e.g. 464 465 .. code-block:: c++ 466 467 int aaaa = 12; 468 float b = 23; 469 std::string ccc; 470 471 int a = 42; 472 /* A comment. */ 473 bool c = false; 474 475 * ``ACS_AcrossEmptyLinesAndComments`` 476 (in configuration: ``AcrossEmptyLinesAndComments``) 477 478 Same as ACS_Consecutive, but also spans over lines only containing 479 comments and empty lines, e.g. 480 481 .. code-block:: c++ 482 483 int aaaa = 12; 484 float b = 23; 485 std::string ccc; 486 487 int a = 42; 488 /* A comment. */ 489 bool c = false; 490 491**AlignConsecutiveMacros** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 9` 492 Style of aligning consecutive macro definitions. 493 494 ``Consecutive`` will result in formattings like: 495 496 .. code-block:: c++ 497 498 #define SHORT_NAME 42 499 #define LONGER_NAME 0x007f 500 #define EVEN_LONGER_NAME (2) 501 #define foo(x) (x * x) 502 #define bar(y, z) (y + z) 503 504 Possible values: 505 506 * ``ACS_None`` (in configuration: ``None``) 507 Do not align macro definitions on consecutive lines. 508 509 * ``ACS_Consecutive`` (in configuration: ``Consecutive``) 510 Align macro definitions on consecutive lines. This will result in 511 formattings like: 512 513 .. code-block:: c++ 514 515 #define SHORT_NAME 42 516 #define LONGER_NAME 0x007f 517 #define EVEN_LONGER_NAME (2) 518 519 #define foo(x) (x * x) 520 /* some comment */ 521 #define bar(y, z) (y + z) 522 523 * ``ACS_AcrossEmptyLines`` (in configuration: ``AcrossEmptyLines``) 524 Same as ACS_Consecutive, but also spans over empty lines, e.g. 525 526 .. code-block:: c++ 527 528 #define SHORT_NAME 42 529 #define LONGER_NAME 0x007f 530 #define EVEN_LONGER_NAME (2) 531 532 #define foo(x) (x * x) 533 /* some comment */ 534 #define bar(y, z) (y + z) 535 536 * ``ACS_AcrossComments`` (in configuration: ``AcrossComments``) 537 Same as ACS_Consecutive, but also spans over lines only containing 538 comments, e.g. 539 540 .. code-block:: c++ 541 542 #define SHORT_NAME 42 543 #define LONGER_NAME 0x007f 544 #define EVEN_LONGER_NAME (2) 545 546 #define foo(x) (x * x) 547 /* some comment */ 548 #define bar(y, z) (y + z) 549 550 * ``ACS_AcrossEmptyLinesAndComments`` 551 (in configuration: ``AcrossEmptyLinesAndComments``) 552 553 Same as ACS_Consecutive, but also spans over lines only containing 554 comments and empty lines, e.g. 555 556 .. code-block:: c++ 557 558 #define SHORT_NAME 42 559 #define LONGER_NAME 0x007f 560 #define EVEN_LONGER_NAME (2) 561 562 #define foo(x) (x * x) 563 /* some comment */ 564 #define bar(y, z) (y + z) 565 566**AlignEscapedNewlines** (``EscapedNewlineAlignmentStyle``) :versionbadge:`clang-format 5` 567 Options for aligning backslashes in escaped newlines. 568 569 Possible values: 570 571 * ``ENAS_DontAlign`` (in configuration: ``DontAlign``) 572 Don't align escaped newlines. 573 574 .. code-block:: c++ 575 576 #define A \ 577 int aaaa; \ 578 int b; \ 579 int dddddddddd; 580 581 * ``ENAS_Left`` (in configuration: ``Left``) 582 Align escaped newlines as far left as possible. 583 584 .. code-block:: c++ 585 586 true: 587 #define A \ 588 int aaaa; \ 589 int b; \ 590 int dddddddddd; 591 592 false: 593 594 * ``ENAS_Right`` (in configuration: ``Right``) 595 Align escaped newlines in the right-most column. 596 597 .. code-block:: c++ 598 599 #define A \ 600 int aaaa; \ 601 int b; \ 602 int dddddddddd; 603 604 605 606**AlignOperands** (``OperandAlignmentStyle``) :versionbadge:`clang-format 12` 607 If ``true``, horizontally align operands of binary and ternary 608 expressions. 609 610 Possible values: 611 612 * ``OAS_DontAlign`` (in configuration: ``DontAlign``) 613 Do not align operands of binary and ternary expressions. 614 The wrapped lines are indented ``ContinuationIndentWidth`` spaces from 615 the start of the line. 616 617 * ``OAS_Align`` (in configuration: ``Align``) 618 Horizontally align operands of binary and ternary expressions. 619 620 Specifically, this aligns operands of a single expression that needs 621 to be split over multiple lines, e.g.: 622 623 .. code-block:: c++ 624 625 int aaa = bbbbbbbbbbbbbbb + 626 ccccccccccccccc; 627 628 When ``BreakBeforeBinaryOperators`` is set, the wrapped operator is 629 aligned with the operand on the first line. 630 631 .. code-block:: c++ 632 633 int aaa = bbbbbbbbbbbbbbb 634 + ccccccccccccccc; 635 636 * ``OAS_AlignAfterOperator`` (in configuration: ``AlignAfterOperator``) 637 Horizontally align operands of binary and ternary expressions. 638 639 This is similar to ``AO_Align``, except when 640 ``BreakBeforeBinaryOperators`` is set, the operator is un-indented so 641 that the wrapped operand is aligned with the operand on the first line. 642 643 .. code-block:: c++ 644 645 int aaa = bbbbbbbbbbbbbbb 646 + ccccccccccccccc; 647 648 649 650**AlignTrailingComments** (``Boolean``) :versionbadge:`clang-format 3.7` 651 If ``true``, aligns trailing comments. 652 653 .. code-block:: c++ 654 655 true: false: 656 int a; // My comment a vs. int a; // My comment a 657 int b = 2; // comment b int b = 2; // comment about b 658 659**AllowAllArgumentsOnNextLine** (``Boolean``) :versionbadge:`clang-format 9` 660 If a function call or braced initializer list doesn't fit on a 661 line, allow putting all arguments onto the next line, even if 662 ``BinPackArguments`` is ``false``. 663 664 .. code-block:: c++ 665 666 true: 667 callFunction( 668 a, b, c, d); 669 670 false: 671 callFunction(a, 672 b, 673 c, 674 d); 675 676**AllowAllConstructorInitializersOnNextLine** (``Boolean``) :versionbadge:`clang-format 9` 677 This option is **deprecated**. See ``NextLine`` of 678 ``PackConstructorInitializers``. 679 680**AllowAllParametersOfDeclarationOnNextLine** (``Boolean``) :versionbadge:`clang-format 3.3` 681 If the function declaration doesn't fit on a line, 682 allow putting all parameters of a function declaration onto 683 the next line even if ``BinPackParameters`` is ``false``. 684 685 .. code-block:: c++ 686 687 true: 688 void myFunction( 689 int a, int b, int c, int d, int e); 690 691 false: 692 void myFunction(int a, 693 int b, 694 int c, 695 int d, 696 int e); 697 698**AllowShortBlocksOnASingleLine** (``ShortBlockStyle``) :versionbadge:`clang-format 11` 699 Dependent on the value, ``while (true) { continue; }`` can be put on a 700 single line. 701 702 Possible values: 703 704 * ``SBS_Never`` (in configuration: ``Never``) 705 Never merge blocks into a single line. 706 707 .. code-block:: c++ 708 709 while (true) { 710 } 711 while (true) { 712 continue; 713 } 714 715 * ``SBS_Empty`` (in configuration: ``Empty``) 716 Only merge empty blocks. 717 718 .. code-block:: c++ 719 720 while (true) {} 721 while (true) { 722 continue; 723 } 724 725 * ``SBS_Always`` (in configuration: ``Always``) 726 Always merge short blocks into a single line. 727 728 .. code-block:: c++ 729 730 while (true) {} 731 while (true) { continue; } 732 733 734 735**AllowShortCaseLabelsOnASingleLine** (``Boolean``) :versionbadge:`clang-format 3.6` 736 If ``true``, short case labels will be contracted to a single line. 737 738 .. code-block:: c++ 739 740 true: false: 741 switch (a) { vs. switch (a) { 742 case 1: x = 1; break; case 1: 743 case 2: return; x = 1; 744 } break; 745 case 2: 746 return; 747 } 748 749**AllowShortEnumsOnASingleLine** (``Boolean``) :versionbadge:`clang-format 12` 750 Allow short enums on a single line. 751 752 .. code-block:: c++ 753 754 true: 755 enum { A, B } myEnum; 756 757 false: 758 enum { 759 A, 760 B 761 } myEnum; 762 763**AllowShortFunctionsOnASingleLine** (``ShortFunctionStyle``) :versionbadge:`clang-format 3.5` 764 Dependent on the value, ``int f() { return 0; }`` can be put on a 765 single line. 766 767 Possible values: 768 769 * ``SFS_None`` (in configuration: ``None``) 770 Never merge functions into a single line. 771 772 * ``SFS_InlineOnly`` (in configuration: ``InlineOnly``) 773 Only merge functions defined inside a class. Same as "inline", 774 except it does not implies "empty": i.e. top level empty functions 775 are not merged either. 776 777 .. code-block:: c++ 778 779 class Foo { 780 void f() { foo(); } 781 }; 782 void f() { 783 foo(); 784 } 785 void f() { 786 } 787 788 * ``SFS_Empty`` (in configuration: ``Empty``) 789 Only merge empty functions. 790 791 .. code-block:: c++ 792 793 void f() {} 794 void f2() { 795 bar2(); 796 } 797 798 * ``SFS_Inline`` (in configuration: ``Inline``) 799 Only merge functions defined inside a class. Implies "empty". 800 801 .. code-block:: c++ 802 803 class Foo { 804 void f() { foo(); } 805 }; 806 void f() { 807 foo(); 808 } 809 void f() {} 810 811 * ``SFS_All`` (in configuration: ``All``) 812 Merge all functions fitting on a single line. 813 814 .. code-block:: c++ 815 816 class Foo { 817 void f() { foo(); } 818 }; 819 void f() { bar(); } 820 821 822 823**AllowShortIfStatementsOnASingleLine** (``ShortIfStyle``) :versionbadge:`clang-format 9` 824 Dependent on the value, ``if (a) return;`` can be put on a single line. 825 826 Possible values: 827 828 * ``SIS_Never`` (in configuration: ``Never``) 829 Never put short ifs on the same line. 830 831 .. code-block:: c++ 832 833 if (a) 834 return; 835 836 if (b) 837 return; 838 else 839 return; 840 841 if (c) 842 return; 843 else { 844 return; 845 } 846 847 * ``SIS_WithoutElse`` (in configuration: ``WithoutElse``) 848 Put short ifs on the same line only if there is no else statement. 849 850 .. code-block:: c++ 851 852 if (a) return; 853 854 if (b) 855 return; 856 else 857 return; 858 859 if (c) 860 return; 861 else { 862 return; 863 } 864 865 * ``SIS_OnlyFirstIf`` (in configuration: ``OnlyFirstIf``) 866 Put short ifs, but not else ifs nor else statements, on the same line. 867 868 .. code-block:: c++ 869 870 if (a) return; 871 872 if (b) return; 873 else if (b) 874 return; 875 else 876 return; 877 878 if (c) return; 879 else { 880 return; 881 } 882 883 * ``SIS_AllIfsAndElse`` (in configuration: ``AllIfsAndElse``) 884 Always put short ifs, else ifs and else statements on the same 885 line. 886 887 .. code-block:: c++ 888 889 if (a) return; 890 891 if (b) return; 892 else return; 893 894 if (c) return; 895 else { 896 return; 897 } 898 899 900 901**AllowShortLambdasOnASingleLine** (``ShortLambdaStyle``) :versionbadge:`clang-format 9` 902 Dependent on the value, ``auto lambda []() { return 0; }`` can be put on a 903 single line. 904 905 Possible values: 906 907 * ``SLS_None`` (in configuration: ``None``) 908 Never merge lambdas into a single line. 909 910 * ``SLS_Empty`` (in configuration: ``Empty``) 911 Only merge empty lambdas. 912 913 .. code-block:: c++ 914 915 auto lambda = [](int a) {} 916 auto lambda2 = [](int a) { 917 return a; 918 }; 919 920 * ``SLS_Inline`` (in configuration: ``Inline``) 921 Merge lambda into a single line if argument of a function. 922 923 .. code-block:: c++ 924 925 auto lambda = [](int a) { 926 return a; 927 }; 928 sort(a.begin(), a.end(), ()[] { return x < y; }) 929 930 * ``SLS_All`` (in configuration: ``All``) 931 Merge all lambdas fitting on a single line. 932 933 .. code-block:: c++ 934 935 auto lambda = [](int a) {} 936 auto lambda2 = [](int a) { return a; }; 937 938 939 940**AllowShortLoopsOnASingleLine** (``Boolean``) :versionbadge:`clang-format 3.7` 941 If ``true``, ``while (true) continue;`` can be put on a single 942 line. 943 944**AlwaysBreakAfterDefinitionReturnType** (``DefinitionReturnTypeBreakingStyle``) :versionbadge:`clang-format 3.7` 945 The function definition return type breaking style to use. This 946 option is **deprecated** and is retained for backwards compatibility. 947 948 Possible values: 949 950 * ``DRTBS_None`` (in configuration: ``None``) 951 Break after return type automatically. 952 ``PenaltyReturnTypeOnItsOwnLine`` is taken into account. 953 954 * ``DRTBS_All`` (in configuration: ``All``) 955 Always break after the return type. 956 957 * ``DRTBS_TopLevel`` (in configuration: ``TopLevel``) 958 Always break after the return types of top-level functions. 959 960 961 962**AlwaysBreakAfterReturnType** (``ReturnTypeBreakingStyle``) :versionbadge:`clang-format 3.8` 963 The function declaration return type breaking style to use. 964 965 Possible values: 966 967 * ``RTBS_None`` (in configuration: ``None``) 968 Break after return type automatically. 969 ``PenaltyReturnTypeOnItsOwnLine`` is taken into account. 970 971 .. code-block:: c++ 972 973 class A { 974 int f() { return 0; }; 975 }; 976 int f(); 977 int f() { return 1; } 978 979 * ``RTBS_All`` (in configuration: ``All``) 980 Always break after the return type. 981 982 .. code-block:: c++ 983 984 class A { 985 int 986 f() { 987 return 0; 988 }; 989 }; 990 int 991 f(); 992 int 993 f() { 994 return 1; 995 } 996 997 * ``RTBS_TopLevel`` (in configuration: ``TopLevel``) 998 Always break after the return types of top-level functions. 999 1000 .. code-block:: c++ 1001 1002 class A { 1003 int f() { return 0; }; 1004 }; 1005 int 1006 f(); 1007 int 1008 f() { 1009 return 1; 1010 } 1011 1012 * ``RTBS_AllDefinitions`` (in configuration: ``AllDefinitions``) 1013 Always break after the return type of function definitions. 1014 1015 .. code-block:: c++ 1016 1017 class A { 1018 int 1019 f() { 1020 return 0; 1021 }; 1022 }; 1023 int f(); 1024 int 1025 f() { 1026 return 1; 1027 } 1028 1029 * ``RTBS_TopLevelDefinitions`` (in configuration: ``TopLevelDefinitions``) 1030 Always break after the return type of top-level definitions. 1031 1032 .. code-block:: c++ 1033 1034 class A { 1035 int f() { return 0; }; 1036 }; 1037 int f(); 1038 int 1039 f() { 1040 return 1; 1041 } 1042 1043 1044 1045**AlwaysBreakBeforeMultilineStrings** (``Boolean``) :versionbadge:`clang-format 3.4` 1046 If ``true``, always break before multiline string literals. 1047 1048 This flag is mean to make cases where there are multiple multiline strings 1049 in a file look more consistent. Thus, it will only take effect if wrapping 1050 the string at that point leads to it being indented 1051 ``ContinuationIndentWidth`` spaces from the start of the line. 1052 1053 .. code-block:: c++ 1054 1055 true: false: 1056 aaaa = vs. aaaa = "bbbb" 1057 "bbbb" "cccc"; 1058 "cccc"; 1059 1060**AlwaysBreakTemplateDeclarations** (``BreakTemplateDeclarationsStyle``) :versionbadge:`clang-format 7` 1061 The template declaration breaking style to use. 1062 1063 Possible values: 1064 1065 * ``BTDS_No`` (in configuration: ``No``) 1066 Do not force break before declaration. 1067 ``PenaltyBreakTemplateDeclaration`` is taken into account. 1068 1069 .. code-block:: c++ 1070 1071 template <typename T> T foo() { 1072 } 1073 template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa, 1074 int bbbbbbbbbbbbbbbbbbbbb) { 1075 } 1076 1077 * ``BTDS_MultiLine`` (in configuration: ``MultiLine``) 1078 Force break after template declaration only when the following 1079 declaration spans multiple lines. 1080 1081 .. code-block:: c++ 1082 1083 template <typename T> T foo() { 1084 } 1085 template <typename T> 1086 T foo(int aaaaaaaaaaaaaaaaaaaaa, 1087 int bbbbbbbbbbbbbbbbbbbbb) { 1088 } 1089 1090 * ``BTDS_Yes`` (in configuration: ``Yes``) 1091 Always break after template declaration. 1092 1093 .. code-block:: c++ 1094 1095 template <typename T> 1096 T foo() { 1097 } 1098 template <typename T> 1099 T foo(int aaaaaaaaaaaaaaaaaaaaa, 1100 int bbbbbbbbbbbbbbbbbbbbb) { 1101 } 1102 1103 1104 1105**AttributeMacros** (``List of Strings``) :versionbadge:`clang-format 12` 1106 A vector of strings that should be interpreted as attributes/qualifiers 1107 instead of identifiers. This can be useful for language extensions or 1108 static analyzer annotations. 1109 1110 For example: 1111 1112 .. code-block:: c++ 1113 1114 x = (char *__capability)&y; 1115 int function(void) __ununsed; 1116 void only_writes_to_buffer(char *__output buffer); 1117 1118 In the .clang-format configuration file, this can be configured like: 1119 1120 .. code-block:: yaml 1121 1122 AttributeMacros: ['__capability', '__output', '__ununsed'] 1123 1124**BinPackArguments** (``Boolean``) :versionbadge:`clang-format 3.7` 1125 If ``false``, a function call's arguments will either be all on the 1126 same line or will have one line each. 1127 1128 .. code-block:: c++ 1129 1130 true: 1131 void f() { 1132 f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa, 1133 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); 1134 } 1135 1136 false: 1137 void f() { 1138 f(aaaaaaaaaaaaaaaaaaaa, 1139 aaaaaaaaaaaaaaaaaaaa, 1140 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); 1141 } 1142 1143**BinPackParameters** (``Boolean``) :versionbadge:`clang-format 3.7` 1144 If ``false``, a function declaration's or function definition's 1145 parameters will either all be on the same line or will have one line each. 1146 1147 .. code-block:: c++ 1148 1149 true: 1150 void f(int aaaaaaaaaaaaaaaaaaaa, int aaaaaaaaaaaaaaaaaaaa, 1151 int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {} 1152 1153 false: 1154 void f(int aaaaaaaaaaaaaaaaaaaa, 1155 int aaaaaaaaaaaaaaaaaaaa, 1156 int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {} 1157 1158**BitFieldColonSpacing** (``BitFieldColonSpacingStyle``) :versionbadge:`clang-format 12` 1159 The BitFieldColonSpacingStyle to use for bitfields. 1160 1161 Possible values: 1162 1163 * ``BFCS_Both`` (in configuration: ``Both``) 1164 Add one space on each side of the ``:`` 1165 1166 .. code-block:: c++ 1167 1168 unsigned bf : 2; 1169 1170 * ``BFCS_None`` (in configuration: ``None``) 1171 Add no space around the ``:`` (except when needed for 1172 ``AlignConsecutiveBitFields``). 1173 1174 .. code-block:: c++ 1175 1176 unsigned bf:2; 1177 1178 * ``BFCS_Before`` (in configuration: ``Before``) 1179 Add space before the ``:`` only 1180 1181 .. code-block:: c++ 1182 1183 unsigned bf :2; 1184 1185 * ``BFCS_After`` (in configuration: ``After``) 1186 Add space after the ``:`` only (space may be added before if 1187 needed for ``AlignConsecutiveBitFields``). 1188 1189 .. code-block:: c++ 1190 1191 unsigned bf: 2; 1192 1193 1194 1195**BraceWrapping** (``BraceWrappingFlags``) :versionbadge:`clang-format 3.8` 1196 Control of individual brace wrapping cases. 1197 1198 If ``BreakBeforeBraces`` is set to ``BS_Custom``, use this to specify how 1199 each individual brace case should be handled. Otherwise, this is ignored. 1200 1201 .. code-block:: yaml 1202 1203 # Example of usage: 1204 BreakBeforeBraces: Custom 1205 BraceWrapping: 1206 AfterEnum: true 1207 AfterStruct: false 1208 SplitEmptyFunction: false 1209 1210 Nested configuration flags: 1211 1212 1213 * ``bool AfterCaseLabel`` Wrap case labels. 1214 1215 .. code-block:: c++ 1216 1217 false: true: 1218 switch (foo) { vs. switch (foo) { 1219 case 1: { case 1: 1220 bar(); { 1221 break; bar(); 1222 } break; 1223 default: { } 1224 plop(); default: 1225 } { 1226 } plop(); 1227 } 1228 } 1229 1230 * ``bool AfterClass`` Wrap class definitions. 1231 1232 .. code-block:: c++ 1233 1234 true: 1235 class foo {}; 1236 1237 false: 1238 class foo 1239 {}; 1240 1241 * ``BraceWrappingAfterControlStatementStyle AfterControlStatement`` 1242 Wrap control statements (``if``/``for``/``while``/``switch``/..). 1243 1244 Possible values: 1245 1246 * ``BWACS_Never`` (in configuration: ``Never``) 1247 Never wrap braces after a control statement. 1248 1249 .. code-block:: c++ 1250 1251 if (foo()) { 1252 } else { 1253 } 1254 for (int i = 0; i < 10; ++i) { 1255 } 1256 1257 * ``BWACS_MultiLine`` (in configuration: ``MultiLine``) 1258 Only wrap braces after a multi-line control statement. 1259 1260 .. code-block:: c++ 1261 1262 if (foo && bar && 1263 baz) 1264 { 1265 quux(); 1266 } 1267 while (foo || bar) { 1268 } 1269 1270 * ``BWACS_Always`` (in configuration: ``Always``) 1271 Always wrap braces after a control statement. 1272 1273 .. code-block:: c++ 1274 1275 if (foo()) 1276 { 1277 } else 1278 {} 1279 for (int i = 0; i < 10; ++i) 1280 {} 1281 1282 1283 * ``bool AfterEnum`` Wrap enum definitions. 1284 1285 .. code-block:: c++ 1286 1287 true: 1288 enum X : int 1289 { 1290 B 1291 }; 1292 1293 false: 1294 enum X : int { B }; 1295 1296 * ``bool AfterFunction`` Wrap function definitions. 1297 1298 .. code-block:: c++ 1299 1300 true: 1301 void foo() 1302 { 1303 bar(); 1304 bar2(); 1305 } 1306 1307 false: 1308 void foo() { 1309 bar(); 1310 bar2(); 1311 } 1312 1313 * ``bool AfterNamespace`` Wrap namespace definitions. 1314 1315 .. code-block:: c++ 1316 1317 true: 1318 namespace 1319 { 1320 int foo(); 1321 int bar(); 1322 } 1323 1324 false: 1325 namespace { 1326 int foo(); 1327 int bar(); 1328 } 1329 1330 * ``bool AfterObjCDeclaration`` Wrap ObjC definitions (interfaces, implementations...). 1331 @autoreleasepool and @synchronized blocks are wrapped 1332 according to `AfterControlStatement` flag. 1333 1334 * ``bool AfterStruct`` Wrap struct definitions. 1335 1336 .. code-block:: c++ 1337 1338 true: 1339 struct foo 1340 { 1341 int x; 1342 }; 1343 1344 false: 1345 struct foo { 1346 int x; 1347 }; 1348 1349 * ``bool AfterUnion`` Wrap union definitions. 1350 1351 .. code-block:: c++ 1352 1353 true: 1354 union foo 1355 { 1356 int x; 1357 } 1358 1359 false: 1360 union foo { 1361 int x; 1362 } 1363 1364 * ``bool AfterExternBlock`` Wrap extern blocks. 1365 1366 .. code-block:: c++ 1367 1368 true: 1369 extern "C" 1370 { 1371 int foo(); 1372 } 1373 1374 false: 1375 extern "C" { 1376 int foo(); 1377 } 1378 1379 * ``bool BeforeCatch`` Wrap before ``catch``. 1380 1381 .. code-block:: c++ 1382 1383 true: 1384 try { 1385 foo(); 1386 } 1387 catch () { 1388 } 1389 1390 false: 1391 try { 1392 foo(); 1393 } catch () { 1394 } 1395 1396 * ``bool BeforeElse`` Wrap before ``else``. 1397 1398 .. code-block:: c++ 1399 1400 true: 1401 if (foo()) { 1402 } 1403 else { 1404 } 1405 1406 false: 1407 if (foo()) { 1408 } else { 1409 } 1410 1411 * ``bool BeforeLambdaBody`` Wrap lambda block. 1412 1413 .. code-block:: c++ 1414 1415 true: 1416 connect( 1417 []() 1418 { 1419 foo(); 1420 bar(); 1421 }); 1422 1423 false: 1424 connect([]() { 1425 foo(); 1426 bar(); 1427 }); 1428 1429 * ``bool BeforeWhile`` Wrap before ``while``. 1430 1431 .. code-block:: c++ 1432 1433 true: 1434 do { 1435 foo(); 1436 } 1437 while (1); 1438 1439 false: 1440 do { 1441 foo(); 1442 } while (1); 1443 1444 * ``bool IndentBraces`` Indent the wrapped braces themselves. 1445 1446 * ``bool SplitEmptyFunction`` If ``false``, empty function body can be put on a single line. 1447 This option is used only if the opening brace of the function has 1448 already been wrapped, i.e. the `AfterFunction` brace wrapping mode is 1449 set, and the function could/should not be put on a single line (as per 1450 `AllowShortFunctionsOnASingleLine` and constructor formatting options). 1451 1452 .. code-block:: c++ 1453 1454 int f() vs. int f() 1455 {} { 1456 } 1457 1458 * ``bool SplitEmptyRecord`` If ``false``, empty record (e.g. class, struct or union) body 1459 can be put on a single line. This option is used only if the opening 1460 brace of the record has already been wrapped, i.e. the `AfterClass` 1461 (for classes) brace wrapping mode is set. 1462 1463 .. code-block:: c++ 1464 1465 class Foo vs. class Foo 1466 {} { 1467 } 1468 1469 * ``bool SplitEmptyNamespace`` If ``false``, empty namespace body can be put on a single line. 1470 This option is used only if the opening brace of the namespace has 1471 already been wrapped, i.e. the `AfterNamespace` brace wrapping mode is 1472 set. 1473 1474 .. code-block:: c++ 1475 1476 namespace Foo vs. namespace Foo 1477 {} { 1478 } 1479 1480 1481**BreakAfterJavaFieldAnnotations** (``Boolean``) :versionbadge:`clang-format 3.8` 1482 Break after each annotation on a field in Java files. 1483 1484 .. code-block:: java 1485 1486 true: false: 1487 @Partial vs. @Partial @Mock DataLoad loader; 1488 @Mock 1489 DataLoad loader; 1490 1491**BreakBeforeBinaryOperators** (``BinaryOperatorStyle``) :versionbadge:`clang-format 3.6` 1492 The way to wrap binary operators. 1493 1494 Possible values: 1495 1496 * ``BOS_None`` (in configuration: ``None``) 1497 Break after operators. 1498 1499 .. code-block:: c++ 1500 1501 LooooooooooongType loooooooooooooooooooooongVariable = 1502 someLooooooooooooooooongFunction(); 1503 1504 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + 1505 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa == 1506 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa && 1507 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa > 1508 ccccccccccccccccccccccccccccccccccccccccc; 1509 1510 * ``BOS_NonAssignment`` (in configuration: ``NonAssignment``) 1511 Break before operators that aren't assignments. 1512 1513 .. code-block:: c++ 1514 1515 LooooooooooongType loooooooooooooooooooooongVariable = 1516 someLooooooooooooooooongFunction(); 1517 1518 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 1519 + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 1520 == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 1521 && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 1522 > ccccccccccccccccccccccccccccccccccccccccc; 1523 1524 * ``BOS_All`` (in configuration: ``All``) 1525 Break before operators. 1526 1527 .. code-block:: c++ 1528 1529 LooooooooooongType loooooooooooooooooooooongVariable 1530 = someLooooooooooooooooongFunction(); 1531 1532 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 1533 + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 1534 == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 1535 && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 1536 > ccccccccccccccccccccccccccccccccccccccccc; 1537 1538 1539 1540**BreakBeforeBraces** (``BraceBreakingStyle``) :versionbadge:`clang-format 3.7` 1541 The brace breaking style to use. 1542 1543 Possible values: 1544 1545 * ``BS_Attach`` (in configuration: ``Attach``) 1546 Always attach braces to surrounding context. 1547 1548 .. code-block:: c++ 1549 1550 namespace N { 1551 enum E { 1552 E1, 1553 E2, 1554 }; 1555 1556 class C { 1557 public: 1558 C(); 1559 }; 1560 1561 bool baz(int i) { 1562 try { 1563 do { 1564 switch (i) { 1565 case 1: { 1566 foobar(); 1567 break; 1568 } 1569 default: { 1570 break; 1571 } 1572 } 1573 } while (--i); 1574 return true; 1575 } catch (...) { 1576 handleError(); 1577 return false; 1578 } 1579 } 1580 1581 void foo(bool b) { 1582 if (b) { 1583 baz(2); 1584 } else { 1585 baz(5); 1586 } 1587 } 1588 1589 void bar() { foo(true); } 1590 } // namespace N 1591 1592 * ``BS_Linux`` (in configuration: ``Linux``) 1593 Like ``Attach``, but break before braces on function, namespace and 1594 class definitions. 1595 1596 .. code-block:: c++ 1597 1598 namespace N 1599 { 1600 enum E { 1601 E1, 1602 E2, 1603 }; 1604 1605 class C 1606 { 1607 public: 1608 C(); 1609 }; 1610 1611 bool baz(int i) 1612 { 1613 try { 1614 do { 1615 switch (i) { 1616 case 1: { 1617 foobar(); 1618 break; 1619 } 1620 default: { 1621 break; 1622 } 1623 } 1624 } while (--i); 1625 return true; 1626 } catch (...) { 1627 handleError(); 1628 return false; 1629 } 1630 } 1631 1632 void foo(bool b) 1633 { 1634 if (b) { 1635 baz(2); 1636 } else { 1637 baz(5); 1638 } 1639 } 1640 1641 void bar() { foo(true); } 1642 } // namespace N 1643 1644 * ``BS_Mozilla`` (in configuration: ``Mozilla``) 1645 Like ``Attach``, but break before braces on enum, function, and record 1646 definitions. 1647 1648 .. code-block:: c++ 1649 1650 namespace N { 1651 enum E 1652 { 1653 E1, 1654 E2, 1655 }; 1656 1657 class C 1658 { 1659 public: 1660 C(); 1661 }; 1662 1663 bool baz(int i) 1664 { 1665 try { 1666 do { 1667 switch (i) { 1668 case 1: { 1669 foobar(); 1670 break; 1671 } 1672 default: { 1673 break; 1674 } 1675 } 1676 } while (--i); 1677 return true; 1678 } catch (...) { 1679 handleError(); 1680 return false; 1681 } 1682 } 1683 1684 void foo(bool b) 1685 { 1686 if (b) { 1687 baz(2); 1688 } else { 1689 baz(5); 1690 } 1691 } 1692 1693 void bar() { foo(true); } 1694 } // namespace N 1695 1696 * ``BS_Stroustrup`` (in configuration: ``Stroustrup``) 1697 Like ``Attach``, but break before function definitions, ``catch``, and 1698 ``else``. 1699 1700 .. code-block:: c++ 1701 1702 namespace N { 1703 enum E { 1704 E1, 1705 E2, 1706 }; 1707 1708 class C { 1709 public: 1710 C(); 1711 }; 1712 1713 bool baz(int i) 1714 { 1715 try { 1716 do { 1717 switch (i) { 1718 case 1: { 1719 foobar(); 1720 break; 1721 } 1722 default: { 1723 break; 1724 } 1725 } 1726 } while (--i); 1727 return true; 1728 } 1729 catch (...) { 1730 handleError(); 1731 return false; 1732 } 1733 } 1734 1735 void foo(bool b) 1736 { 1737 if (b) { 1738 baz(2); 1739 } 1740 else { 1741 baz(5); 1742 } 1743 } 1744 1745 void bar() { foo(true); } 1746 } // namespace N 1747 1748 * ``BS_Allman`` (in configuration: ``Allman``) 1749 Always break before braces. 1750 1751 .. code-block:: c++ 1752 1753 namespace N 1754 { 1755 enum E 1756 { 1757 E1, 1758 E2, 1759 }; 1760 1761 class C 1762 { 1763 public: 1764 C(); 1765 }; 1766 1767 bool baz(int i) 1768 { 1769 try 1770 { 1771 do 1772 { 1773 switch (i) 1774 { 1775 case 1: 1776 { 1777 foobar(); 1778 break; 1779 } 1780 default: 1781 { 1782 break; 1783 } 1784 } 1785 } while (--i); 1786 return true; 1787 } 1788 catch (...) 1789 { 1790 handleError(); 1791 return false; 1792 } 1793 } 1794 1795 void foo(bool b) 1796 { 1797 if (b) 1798 { 1799 baz(2); 1800 } 1801 else 1802 { 1803 baz(5); 1804 } 1805 } 1806 1807 void bar() { foo(true); } 1808 } // namespace N 1809 1810 * ``BS_Whitesmiths`` (in configuration: ``Whitesmiths``) 1811 Like ``Allman`` but always indent braces and line up code with braces. 1812 1813 .. code-block:: c++ 1814 1815 namespace N 1816 { 1817 enum E 1818 { 1819 E1, 1820 E2, 1821 }; 1822 1823 class C 1824 { 1825 public: 1826 C(); 1827 }; 1828 1829 bool baz(int i) 1830 { 1831 try 1832 { 1833 do 1834 { 1835 switch (i) 1836 { 1837 case 1: 1838 { 1839 foobar(); 1840 break; 1841 } 1842 default: 1843 { 1844 break; 1845 } 1846 } 1847 } while (--i); 1848 return true; 1849 } 1850 catch (...) 1851 { 1852 handleError(); 1853 return false; 1854 } 1855 } 1856 1857 void foo(bool b) 1858 { 1859 if (b) 1860 { 1861 baz(2); 1862 } 1863 else 1864 { 1865 baz(5); 1866 } 1867 } 1868 1869 void bar() { foo(true); } 1870 } // namespace N 1871 1872 * ``BS_GNU`` (in configuration: ``GNU``) 1873 Always break before braces and add an extra level of indentation to 1874 braces of control statements, not to those of class, function 1875 or other definitions. 1876 1877 .. code-block:: c++ 1878 1879 namespace N 1880 { 1881 enum E 1882 { 1883 E1, 1884 E2, 1885 }; 1886 1887 class C 1888 { 1889 public: 1890 C(); 1891 }; 1892 1893 bool baz(int i) 1894 { 1895 try 1896 { 1897 do 1898 { 1899 switch (i) 1900 { 1901 case 1: 1902 { 1903 foobar(); 1904 break; 1905 } 1906 default: 1907 { 1908 break; 1909 } 1910 } 1911 } 1912 while (--i); 1913 return true; 1914 } 1915 catch (...) 1916 { 1917 handleError(); 1918 return false; 1919 } 1920 } 1921 1922 void foo(bool b) 1923 { 1924 if (b) 1925 { 1926 baz(2); 1927 } 1928 else 1929 { 1930 baz(5); 1931 } 1932 } 1933 1934 void bar() { foo(true); } 1935 } // namespace N 1936 1937 * ``BS_WebKit`` (in configuration: ``WebKit``) 1938 Like ``Attach``, but break before functions. 1939 1940 .. code-block:: c++ 1941 1942 namespace N { 1943 enum E { 1944 E1, 1945 E2, 1946 }; 1947 1948 class C { 1949 public: 1950 C(); 1951 }; 1952 1953 bool baz(int i) 1954 { 1955 try { 1956 do { 1957 switch (i) { 1958 case 1: { 1959 foobar(); 1960 break; 1961 } 1962 default: { 1963 break; 1964 } 1965 } 1966 } while (--i); 1967 return true; 1968 } catch (...) { 1969 handleError(); 1970 return false; 1971 } 1972 } 1973 1974 void foo(bool b) 1975 { 1976 if (b) { 1977 baz(2); 1978 } else { 1979 baz(5); 1980 } 1981 } 1982 1983 void bar() { foo(true); } 1984 } // namespace N 1985 1986 * ``BS_Custom`` (in configuration: ``Custom``) 1987 Configure each individual brace in `BraceWrapping`. 1988 1989 1990 1991**BreakBeforeConceptDeclarations** (``Boolean``) :versionbadge:`clang-format 13` 1992 If ``true``, concept will be placed on a new line. 1993 1994 .. code-block:: c++ 1995 1996 true: 1997 template<typename T> 1998 concept ... 1999 2000 false: 2001 template<typename T> concept ... 2002 2003**BreakBeforeTernaryOperators** (``Boolean``) :versionbadge:`clang-format 3.7` 2004 If ``true``, ternary operators will be placed after line breaks. 2005 2006 .. code-block:: c++ 2007 2008 true: 2009 veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription 2010 ? firstValue 2011 : SecondValueVeryVeryVeryVeryLong; 2012 2013 false: 2014 veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ? 2015 firstValue : 2016 SecondValueVeryVeryVeryVeryLong; 2017 2018**BreakConstructorInitializers** (``BreakConstructorInitializersStyle``) :versionbadge:`clang-format 5` 2019 The break constructor initializers style to use. 2020 2021 Possible values: 2022 2023 * ``BCIS_BeforeColon`` (in configuration: ``BeforeColon``) 2024 Break constructor initializers before the colon and after the commas. 2025 2026 .. code-block:: c++ 2027 2028 Constructor() 2029 : initializer1(), 2030 initializer2() 2031 2032 * ``BCIS_BeforeComma`` (in configuration: ``BeforeComma``) 2033 Break constructor initializers before the colon and commas, and align 2034 the commas with the colon. 2035 2036 .. code-block:: c++ 2037 2038 Constructor() 2039 : initializer1() 2040 , initializer2() 2041 2042 * ``BCIS_AfterColon`` (in configuration: ``AfterColon``) 2043 Break constructor initializers after the colon and commas. 2044 2045 .. code-block:: c++ 2046 2047 Constructor() : 2048 initializer1(), 2049 initializer2() 2050 2051 2052 2053**BreakInheritanceList** (``BreakInheritanceListStyle``) :versionbadge:`clang-format 7` 2054 The inheritance list style to use. 2055 2056 Possible values: 2057 2058 * ``BILS_BeforeColon`` (in configuration: ``BeforeColon``) 2059 Break inheritance list before the colon and after the commas. 2060 2061 .. code-block:: c++ 2062 2063 class Foo 2064 : Base1, 2065 Base2 2066 {}; 2067 2068 * ``BILS_BeforeComma`` (in configuration: ``BeforeComma``) 2069 Break inheritance list before the colon and commas, and align 2070 the commas with the colon. 2071 2072 .. code-block:: c++ 2073 2074 class Foo 2075 : Base1 2076 , Base2 2077 {}; 2078 2079 * ``BILS_AfterColon`` (in configuration: ``AfterColon``) 2080 Break inheritance list after the colon and commas. 2081 2082 .. code-block:: c++ 2083 2084 class Foo : 2085 Base1, 2086 Base2 2087 {}; 2088 2089 * ``BILS_AfterComma`` (in configuration: ``AfterComma``) 2090 Break inheritance list only after the commas. 2091 2092 .. code-block:: c++ 2093 2094 class Foo : Base1, 2095 Base2 2096 {}; 2097 2098 2099 2100**BreakStringLiterals** (``Boolean``) :versionbadge:`clang-format 3.9` 2101 Allow breaking string literals when formatting. 2102 2103 .. code-block:: c++ 2104 2105 true: 2106 const char* x = "veryVeryVeryVeryVeryVe" 2107 "ryVeryVeryVeryVeryVery" 2108 "VeryLongString"; 2109 2110 false: 2111 const char* x = 2112 "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString"; 2113 2114**ColumnLimit** (``Unsigned``) :versionbadge:`clang-format 3.7` 2115 The column limit. 2116 2117 A column limit of ``0`` means that there is no column limit. In this case, 2118 clang-format will respect the input's line breaking decisions within 2119 statements unless they contradict other rules. 2120 2121**CommentPragmas** (``String``) :versionbadge:`clang-format 3.7` 2122 A regular expression that describes comments with special meaning, 2123 which should not be split into lines or otherwise changed. 2124 2125 .. code-block:: c++ 2126 2127 // CommentPragmas: '^ FOOBAR pragma:' 2128 // Will leave the following line unaffected 2129 #include <vector> // FOOBAR pragma: keep 2130 2131**CompactNamespaces** (``Boolean``) :versionbadge:`clang-format 5` 2132 If ``true``, consecutive namespace declarations will be on the same 2133 line. If ``false``, each namespace is declared on a new line. 2134 2135 .. code-block:: c++ 2136 2137 true: 2138 namespace Foo { namespace Bar { 2139 }} 2140 2141 false: 2142 namespace Foo { 2143 namespace Bar { 2144 } 2145 } 2146 2147 If it does not fit on a single line, the overflowing namespaces get 2148 wrapped: 2149 2150 .. code-block:: c++ 2151 2152 namespace Foo { namespace Bar { 2153 namespace Extra { 2154 }}} 2155 2156**ConstructorInitializerAllOnOneLineOrOnePerLine** (``Boolean``) :versionbadge:`clang-format 3.7` 2157 This option is **deprecated**. See ``CurrentLine`` of 2158 ``PackConstructorInitializers``. 2159 2160**ConstructorInitializerIndentWidth** (``Unsigned``) :versionbadge:`clang-format 3.7` 2161 The number of characters to use for indentation of constructor 2162 initializer lists as well as inheritance lists. 2163 2164**ContinuationIndentWidth** (``Unsigned``) :versionbadge:`clang-format 3.7` 2165 Indent width for line continuations. 2166 2167 .. code-block:: c++ 2168 2169 ContinuationIndentWidth: 2 2170 2171 int i = // VeryVeryVeryVeryVeryLongComment 2172 longFunction( // Again a long comment 2173 arg); 2174 2175**Cpp11BracedListStyle** (``Boolean``) :versionbadge:`clang-format 3.4` 2176 If ``true``, format braced lists as best suited for C++11 braced 2177 lists. 2178 2179 Important differences: 2180 - No spaces inside the braced list. 2181 - No line break before the closing brace. 2182 - Indentation with the continuation indent, not with the block indent. 2183 2184 Fundamentally, C++11 braced lists are formatted exactly like function 2185 calls would be formatted in their place. If the braced list follows a name 2186 (e.g. a type or variable name), clang-format formats as if the ``{}`` were 2187 the parentheses of a function call with that name. If there is no name, 2188 a zero-length name is assumed. 2189 2190 .. code-block:: c++ 2191 2192 true: false: 2193 vector<int> x{1, 2, 3, 4}; vs. vector<int> x{ 1, 2, 3, 4 }; 2194 vector<T> x{{}, {}, {}, {}}; vector<T> x{ {}, {}, {}, {} }; 2195 f(MyMap[{composite, key}]); f(MyMap[{ composite, key }]); 2196 new int[3]{1, 2, 3}; new int[3]{ 1, 2, 3 }; 2197 2198**DeriveLineEnding** (``Boolean``) :versionbadge:`clang-format 11` 2199 Analyze the formatted file for the most used line ending (``\r\n`` 2200 or ``\n``). ``UseCRLF`` is only used as a fallback if none can be derived. 2201 2202**DerivePointerAlignment** (``Boolean``) :versionbadge:`clang-format 3.7` 2203 If ``true``, analyze the formatted file for the most common 2204 alignment of ``&`` and ``*``. 2205 Pointer and reference alignment styles are going to be updated according 2206 to the preferences found in the file. 2207 ``PointerAlignment`` is then used only as fallback. 2208 2209**DisableFormat** (``Boolean``) :versionbadge:`clang-format 3.7` 2210 Disables formatting completely. 2211 2212**EmptyLineAfterAccessModifier** (``EmptyLineAfterAccessModifierStyle``) :versionbadge:`clang-format 13` 2213 Defines when to put an empty line after access modifiers. 2214 ``EmptyLineBeforeAccessModifier`` configuration handles the number of 2215 empty lines between two access modifiers. 2216 2217 Possible values: 2218 2219 * ``ELAAMS_Never`` (in configuration: ``Never``) 2220 Remove all empty lines after access modifiers. 2221 2222 .. code-block:: c++ 2223 2224 struct foo { 2225 private: 2226 int i; 2227 protected: 2228 int j; 2229 /* comment */ 2230 public: 2231 foo() {} 2232 private: 2233 protected: 2234 }; 2235 2236 * ``ELAAMS_Leave`` (in configuration: ``Leave``) 2237 Keep existing empty lines after access modifiers. 2238 MaxEmptyLinesToKeep is applied instead. 2239 2240 * ``ELAAMS_Always`` (in configuration: ``Always``) 2241 Always add empty line after access modifiers if there are none. 2242 MaxEmptyLinesToKeep is applied also. 2243 2244 .. code-block:: c++ 2245 2246 struct foo { 2247 private: 2248 2249 int i; 2250 protected: 2251 2252 int j; 2253 /* comment */ 2254 public: 2255 2256 foo() {} 2257 private: 2258 2259 protected: 2260 2261 }; 2262 2263 2264 2265**EmptyLineBeforeAccessModifier** (``EmptyLineBeforeAccessModifierStyle``) :versionbadge:`clang-format 13` 2266 Defines in which cases to put empty line before access modifiers. 2267 2268 Possible values: 2269 2270 * ``ELBAMS_Never`` (in configuration: ``Never``) 2271 Remove all empty lines before access modifiers. 2272 2273 .. code-block:: c++ 2274 2275 struct foo { 2276 private: 2277 int i; 2278 protected: 2279 int j; 2280 /* comment */ 2281 public: 2282 foo() {} 2283 private: 2284 protected: 2285 }; 2286 2287 * ``ELBAMS_Leave`` (in configuration: ``Leave``) 2288 Keep existing empty lines before access modifiers. 2289 2290 * ``ELBAMS_LogicalBlock`` (in configuration: ``LogicalBlock``) 2291 Add empty line only when access modifier starts a new logical block. 2292 Logical block is a group of one or more member fields or functions. 2293 2294 .. code-block:: c++ 2295 2296 struct foo { 2297 private: 2298 int i; 2299 2300 protected: 2301 int j; 2302 /* comment */ 2303 public: 2304 foo() {} 2305 2306 private: 2307 protected: 2308 }; 2309 2310 * ``ELBAMS_Always`` (in configuration: ``Always``) 2311 Always add empty line before access modifiers unless access modifier 2312 is at the start of struct or class definition. 2313 2314 .. code-block:: c++ 2315 2316 struct foo { 2317 private: 2318 int i; 2319 2320 protected: 2321 int j; 2322 /* comment */ 2323 2324 public: 2325 foo() {} 2326 2327 private: 2328 2329 protected: 2330 }; 2331 2332 2333 2334**ExperimentalAutoDetectBinPacking** (``Boolean``) :versionbadge:`clang-format 3.7` 2335 If ``true``, clang-format detects whether function calls and 2336 definitions are formatted with one parameter per line. 2337 2338 Each call can be bin-packed, one-per-line or inconclusive. If it is 2339 inconclusive, e.g. completely on one line, but a decision needs to be 2340 made, clang-format analyzes whether there are other bin-packed cases in 2341 the input file and act accordingly. 2342 2343 NOTE: This is an experimental flag, that might go away or be renamed. Do 2344 not use this in config files, etc. Use at your own risk. 2345 2346**FixNamespaceComments** (``Boolean``) :versionbadge:`clang-format 5` 2347 If ``true``, clang-format adds missing namespace end comments for 2348 short namespaces and fixes invalid existing ones. Short ones are 2349 controlled by "ShortNamespaceLines". 2350 2351 .. code-block:: c++ 2352 2353 true: false: 2354 namespace a { vs. namespace a { 2355 foo(); foo(); 2356 bar(); bar(); 2357 } // namespace a } 2358 2359**ForEachMacros** (``List of Strings``) :versionbadge:`clang-format 3.7` 2360 A vector of macros that should be interpreted as foreach loops 2361 instead of as function calls. 2362 2363 These are expected to be macros of the form: 2364 2365 .. code-block:: c++ 2366 2367 FOREACH(<variable-declaration>, ...) 2368 <loop-body> 2369 2370 In the .clang-format configuration file, this can be configured like: 2371 2372 .. code-block:: yaml 2373 2374 ForEachMacros: ['RANGES_FOR', 'FOREACH'] 2375 2376 For example: BOOST_FOREACH. 2377 2378**IfMacros** (``List of Strings``) :versionbadge:`clang-format 13` 2379 A vector of macros that should be interpreted as conditionals 2380 instead of as function calls. 2381 2382 These are expected to be macros of the form: 2383 2384 .. code-block:: c++ 2385 2386 IF(...) 2387 <conditional-body> 2388 else IF(...) 2389 <conditional-body> 2390 2391 In the .clang-format configuration file, this can be configured like: 2392 2393 .. code-block:: yaml 2394 2395 IfMacros: ['IF'] 2396 2397 For example: `KJ_IF_MAYBE 2398 <https://github.com/capnproto/capnproto/blob/master/kjdoc/tour.md#maybes>`_ 2399 2400**IncludeBlocks** (``IncludeBlocksStyle``) :versionbadge:`clang-format 7` 2401 Dependent on the value, multiple ``#include`` blocks can be sorted 2402 as one and divided based on category. 2403 2404 Possible values: 2405 2406 * ``IBS_Preserve`` (in configuration: ``Preserve``) 2407 Sort each ``#include`` block separately. 2408 2409 .. code-block:: c++ 2410 2411 #include "b.h" into #include "b.h" 2412 2413 #include <lib/main.h> #include "a.h" 2414 #include "a.h" #include <lib/main.h> 2415 2416 * ``IBS_Merge`` (in configuration: ``Merge``) 2417 Merge multiple ``#include`` blocks together and sort as one. 2418 2419 .. code-block:: c++ 2420 2421 #include "b.h" into #include "a.h" 2422 #include "b.h" 2423 #include <lib/main.h> #include <lib/main.h> 2424 #include "a.h" 2425 2426 * ``IBS_Regroup`` (in configuration: ``Regroup``) 2427 Merge multiple ``#include`` blocks together and sort as one. 2428 Then split into groups based on category priority. See 2429 ``IncludeCategories``. 2430 2431 .. code-block:: c++ 2432 2433 #include "b.h" into #include "a.h" 2434 #include "b.h" 2435 #include <lib/main.h> 2436 #include "a.h" #include <lib/main.h> 2437 2438 2439 2440**IncludeCategories** (``List of IncludeCategories``) :versionbadge:`clang-format 7` 2441 Regular expressions denoting the different ``#include`` categories 2442 used for ordering ``#includes``. 2443 2444 `POSIX extended 2445 <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html>`_ 2446 regular expressions are supported. 2447 2448 These regular expressions are matched against the filename of an include 2449 (including the <> or "") in order. The value belonging to the first 2450 matching regular expression is assigned and ``#includes`` are sorted first 2451 according to increasing category number and then alphabetically within 2452 each category. 2453 2454 If none of the regular expressions match, INT_MAX is assigned as 2455 category. The main header for a source file automatically gets category 0. 2456 so that it is generally kept at the beginning of the ``#includes`` 2457 (https://llvm.org/docs/CodingStandards.html#include-style). However, you 2458 can also assign negative priorities if you have certain headers that 2459 always need to be first. 2460 2461 There is a third and optional field ``SortPriority`` which can used while 2462 ``IncludeBlocks = IBS_Regroup`` to define the priority in which 2463 ``#includes`` should be ordered. The value of ``Priority`` defines the 2464 order of ``#include blocks`` and also allows the grouping of ``#includes`` 2465 of different priority. ``SortPriority`` is set to the value of 2466 ``Priority`` as default if it is not assigned. 2467 2468 Each regular expression can be marked as case sensitive with the field 2469 ``CaseSensitive``, per default it is not. 2470 2471 To configure this in the .clang-format file, use: 2472 2473 .. code-block:: yaml 2474 2475 IncludeCategories: 2476 - Regex: '^"(llvm|llvm-c|clang|clang-c)/' 2477 Priority: 2 2478 SortPriority: 2 2479 CaseSensitive: true 2480 - Regex: '^((<|")(gtest|gmock|isl|json)/)' 2481 Priority: 3 2482 - Regex: '<[[:alnum:].]+>' 2483 Priority: 4 2484 - Regex: '.*' 2485 Priority: 1 2486 SortPriority: 0 2487 2488**IncludeIsMainRegex** (``String``) :versionbadge:`clang-format 7` 2489 Specify a regular expression of suffixes that are allowed in the 2490 file-to-main-include mapping. 2491 2492 When guessing whether a #include is the "main" include (to assign 2493 category 0, see above), use this regex of allowed suffixes to the header 2494 stem. A partial match is done, so that: 2495 - "" means "arbitrary suffix" 2496 - "$" means "no suffix" 2497 2498 For example, if configured to "(_test)?$", then a header a.h would be seen 2499 as the "main" include in both a.cc and a_test.cc. 2500 2501**IncludeIsMainSourceRegex** (``String``) :versionbadge:`clang-format 7` 2502 Specify a regular expression for files being formatted 2503 that are allowed to be considered "main" in the 2504 file-to-main-include mapping. 2505 2506 By default, clang-format considers files as "main" only when they end 2507 with: ``.c``, ``.cc``, ``.cpp``, ``.c++``, ``.cxx``, ``.m`` or ``.mm`` 2508 extensions. 2509 For these files a guessing of "main" include takes place 2510 (to assign category 0, see above). This config option allows for 2511 additional suffixes and extensions for files to be considered as "main". 2512 2513 For example, if this option is configured to ``(Impl\.hpp)$``, 2514 then a file ``ClassImpl.hpp`` is considered "main" (in addition to 2515 ``Class.c``, ``Class.cc``, ``Class.cpp`` and so on) and "main 2516 include file" logic will be executed (with *IncludeIsMainRegex* setting 2517 also being respected in later phase). Without this option set, 2518 ``ClassImpl.hpp`` would not have the main include file put on top 2519 before any other include. 2520 2521**IndentAccessModifiers** (``Boolean``) :versionbadge:`clang-format 13` 2522 Specify whether access modifiers should have their own indentation level. 2523 2524 When ``false``, access modifiers are indented (or outdented) relative to 2525 the record members, respecting the ``AccessModifierOffset``. Record 2526 members are indented one level below the record. 2527 When ``true``, access modifiers get their own indentation level. As a 2528 consequence, record members are always indented 2 levels below the record, 2529 regardless of the access modifier presence. Value of the 2530 ``AccessModifierOffset`` is ignored. 2531 2532 .. code-block:: c++ 2533 2534 false: true: 2535 class C { vs. class C { 2536 class D { class D { 2537 void bar(); void bar(); 2538 protected: protected: 2539 D(); D(); 2540 }; }; 2541 public: public: 2542 C(); C(); 2543 }; }; 2544 void foo() { void foo() { 2545 return 1; return 1; 2546 } } 2547 2548**IndentCaseBlocks** (``Boolean``) :versionbadge:`clang-format 11` 2549 Indent case label blocks one level from the case label. 2550 2551 When ``false``, the block following the case label uses the same 2552 indentation level as for the case label, treating the case label the same 2553 as an if-statement. 2554 When ``true``, the block gets indented as a scope block. 2555 2556 .. code-block:: c++ 2557 2558 false: true: 2559 switch (fool) { vs. switch (fool) { 2560 case 1: { case 1: 2561 bar(); { 2562 } break; bar(); 2563 default: { } 2564 plop(); break; 2565 } default: 2566 } { 2567 plop(); 2568 } 2569 } 2570 2571**IndentCaseLabels** (``Boolean``) :versionbadge:`clang-format 3.3` 2572 Indent case labels one level from the switch statement. 2573 2574 When ``false``, use the same indentation level as for the switch 2575 statement. Switch statement body is always indented one level more than 2576 case labels (except the first block following the case label, which 2577 itself indents the code - unless IndentCaseBlocks is enabled). 2578 2579 .. code-block:: c++ 2580 2581 false: true: 2582 switch (fool) { vs. switch (fool) { 2583 case 1: case 1: 2584 bar(); bar(); 2585 break; break; 2586 default: default: 2587 plop(); plop(); 2588 } } 2589 2590**IndentExternBlock** (``IndentExternBlockStyle``) :versionbadge:`clang-format 12` 2591 IndentExternBlockStyle is the type of indenting of extern blocks. 2592 2593 Possible values: 2594 2595 * ``IEBS_AfterExternBlock`` (in configuration: ``AfterExternBlock``) 2596 Backwards compatible with AfterExternBlock's indenting. 2597 2598 .. code-block:: c++ 2599 2600 IndentExternBlock: AfterExternBlock 2601 BraceWrapping.AfterExternBlock: true 2602 extern "C" 2603 { 2604 void foo(); 2605 } 2606 2607 2608 .. code-block:: c++ 2609 2610 IndentExternBlock: AfterExternBlock 2611 BraceWrapping.AfterExternBlock: false 2612 extern "C" { 2613 void foo(); 2614 } 2615 2616 * ``IEBS_NoIndent`` (in configuration: ``NoIndent``) 2617 Does not indent extern blocks. 2618 2619 .. code-block:: c++ 2620 2621 extern "C" { 2622 void foo(); 2623 } 2624 2625 * ``IEBS_Indent`` (in configuration: ``Indent``) 2626 Indents extern blocks. 2627 2628 .. code-block:: c++ 2629 2630 extern "C" { 2631 void foo(); 2632 } 2633 2634 2635 2636**IndentGotoLabels** (``Boolean``) :versionbadge:`clang-format 10` 2637 Indent goto labels. 2638 2639 When ``false``, goto labels are flushed left. 2640 2641 .. code-block:: c++ 2642 2643 true: false: 2644 int f() { vs. int f() { 2645 if (foo()) { if (foo()) { 2646 label1: label1: 2647 bar(); bar(); 2648 } } 2649 label2: label2: 2650 return 1; return 1; 2651 } } 2652 2653**IndentPPDirectives** (``PPDirectiveIndentStyle``) :versionbadge:`clang-format 6` 2654 The preprocessor directive indenting style to use. 2655 2656 Possible values: 2657 2658 * ``PPDIS_None`` (in configuration: ``None``) 2659 Does not indent any directives. 2660 2661 .. code-block:: c++ 2662 2663 #if FOO 2664 #if BAR 2665 #include <foo> 2666 #endif 2667 #endif 2668 2669 * ``PPDIS_AfterHash`` (in configuration: ``AfterHash``) 2670 Indents directives after the hash. 2671 2672 .. code-block:: c++ 2673 2674 #if FOO 2675 # if BAR 2676 # include <foo> 2677 # endif 2678 #endif 2679 2680 * ``PPDIS_BeforeHash`` (in configuration: ``BeforeHash``) 2681 Indents directives before the hash. 2682 2683 .. code-block:: c++ 2684 2685 #if FOO 2686 #if BAR 2687 #include <foo> 2688 #endif 2689 #endif 2690 2691 2692 2693**IndentRequires** (``Boolean``) :versionbadge:`clang-format 13` 2694 Indent the requires clause in a template 2695 2696 .. code-block:: c++ 2697 2698 true: 2699 template <typename It> 2700 requires Iterator<It> 2701 void sort(It begin, It end) { 2702 //.... 2703 } 2704 2705 false: 2706 template <typename It> 2707 requires Iterator<It> 2708 void sort(It begin, It end) { 2709 //.... 2710 } 2711 2712**IndentWidth** (``Unsigned``) :versionbadge:`clang-format 3.7` 2713 The number of columns to use for indentation. 2714 2715 .. code-block:: c++ 2716 2717 IndentWidth: 3 2718 2719 void f() { 2720 someFunction(); 2721 if (true, false) { 2722 f(); 2723 } 2724 } 2725 2726**IndentWrappedFunctionNames** (``Boolean``) :versionbadge:`clang-format 3.7` 2727 Indent if a function definition or declaration is wrapped after the 2728 type. 2729 2730 .. code-block:: c++ 2731 2732 true: 2733 LoooooooooooooooooooooooooooooooooooooooongReturnType 2734 LoooooooooooooooooooooooooooooooongFunctionDeclaration(); 2735 2736 false: 2737 LoooooooooooooooooooooooooooooooooooooooongReturnType 2738 LoooooooooooooooooooooooooooooooongFunctionDeclaration(); 2739 2740**InsertTrailingCommas** (``TrailingCommaStyle``) :versionbadge:`clang-format 12` 2741 If set to ``TCS_Wrapped`` will insert trailing commas in container 2742 literals (arrays and objects) that wrap across multiple lines. 2743 It is currently only available for JavaScript 2744 and disabled by default ``TCS_None``. 2745 ``InsertTrailingCommas`` cannot be used together with ``BinPackArguments`` 2746 as inserting the comma disables bin-packing. 2747 2748 .. code-block:: c++ 2749 2750 TSC_Wrapped: 2751 const someArray = [ 2752 aaaaaaaaaaaaaaaaaaaaaaaaaa, 2753 aaaaaaaaaaaaaaaaaaaaaaaaaa, 2754 aaaaaaaaaaaaaaaaaaaaaaaaaa, 2755 // ^ inserted 2756 ] 2757 2758 Possible values: 2759 2760 * ``TCS_None`` (in configuration: ``None``) 2761 Do not insert trailing commas. 2762 2763 * ``TCS_Wrapped`` (in configuration: ``Wrapped``) 2764 Insert trailing commas in container literals that were wrapped over 2765 multiple lines. Note that this is conceptually incompatible with 2766 bin-packing, because the trailing comma is used as an indicator 2767 that a container should be formatted one-per-line (i.e. not bin-packed). 2768 So inserting a trailing comma counteracts bin-packing. 2769 2770 2771 2772**JavaImportGroups** (``List of Strings``) :versionbadge:`clang-format 8` 2773 A vector of prefixes ordered by the desired groups for Java imports. 2774 2775 One group's prefix can be a subset of another - the longest prefix is 2776 always matched. Within a group, the imports are ordered lexicographically. 2777 Static imports are grouped separately and follow the same group rules. 2778 By default, static imports are placed before non-static imports, 2779 but this behavior is changed by another option, 2780 ``SortJavaStaticImport``. 2781 2782 In the .clang-format configuration file, this can be configured like 2783 in the following yaml example. This will result in imports being 2784 formatted as in the Java example below. 2785 2786 .. code-block:: yaml 2787 2788 JavaImportGroups: ['com.example', 'com', 'org'] 2789 2790 2791 .. code-block:: java 2792 2793 import static com.example.function1; 2794 2795 import static com.test.function2; 2796 2797 import static org.example.function3; 2798 2799 import com.example.ClassA; 2800 import com.example.Test; 2801 import com.example.a.ClassB; 2802 2803 import com.test.ClassC; 2804 2805 import org.example.ClassD; 2806 2807**JavaScriptQuotes** (``JavaScriptQuoteStyle``) :versionbadge:`clang-format 3.9` 2808 The JavaScriptQuoteStyle to use for JavaScript strings. 2809 2810 Possible values: 2811 2812 * ``JSQS_Leave`` (in configuration: ``Leave``) 2813 Leave string quotes as they are. 2814 2815 .. code-block:: js 2816 2817 string1 = "foo"; 2818 string2 = 'bar'; 2819 2820 * ``JSQS_Single`` (in configuration: ``Single``) 2821 Always use single quotes. 2822 2823 .. code-block:: js 2824 2825 string1 = 'foo'; 2826 string2 = 'bar'; 2827 2828 * ``JSQS_Double`` (in configuration: ``Double``) 2829 Always use double quotes. 2830 2831 .. code-block:: js 2832 2833 string1 = "foo"; 2834 string2 = "bar"; 2835 2836 2837 2838**JavaScriptWrapImports** (``Boolean``) :versionbadge:`clang-format 3.9` 2839 Whether to wrap JavaScript import/export statements. 2840 2841 .. code-block:: js 2842 2843 true: 2844 import { 2845 VeryLongImportsAreAnnoying, 2846 VeryLongImportsAreAnnoying, 2847 VeryLongImportsAreAnnoying, 2848 } from 'some/module.js' 2849 2850 false: 2851 import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js" 2852 2853**KeepEmptyLinesAtTheStartOfBlocks** (``Boolean``) :versionbadge:`clang-format 3.7` 2854 If true, the empty line at the start of blocks is kept. 2855 2856 .. code-block:: c++ 2857 2858 true: false: 2859 if (foo) { vs. if (foo) { 2860 bar(); 2861 bar(); } 2862 } 2863 2864**LambdaBodyIndentation** (``LambdaBodyIndentationKind``) :versionbadge:`clang-format 13` 2865 The indentation style of lambda bodies. ``Signature`` (the default) 2866 causes the lambda body to be indented one additional level relative to 2867 the indentation level of the signature. ``OuterScope`` forces the lambda 2868 body to be indented one additional level relative to the parent scope 2869 containing the lambda signature. For callback-heavy code, it may improve 2870 readability to have the signature indented two levels and to use 2871 ``OuterScope``. The KJ style guide requires ``OuterScope``. 2872 `KJ style guide 2873 <https://github.com/capnproto/capnproto/blob/master/style-guide.md>`_ 2874 2875 Possible values: 2876 2877 * ``LBI_Signature`` (in configuration: ``Signature``) 2878 Align lambda body relative to the lambda signature. This is the default. 2879 2880 .. code-block:: c++ 2881 2882 someMethod( 2883 [](SomeReallyLongLambdaSignatureArgument foo) { 2884 return; 2885 }); 2886 2887 * ``LBI_OuterScope`` (in configuration: ``OuterScope``) 2888 Align lambda body relative to the indentation level of the outer scope 2889 the lambda signature resides in. 2890 2891 .. code-block:: c++ 2892 2893 someMethod( 2894 [](SomeReallyLongLambdaSignatureArgument foo) { 2895 return; 2896 }); 2897 2898 2899 2900**Language** (``LanguageKind``) :versionbadge:`clang-format 3.5` 2901 Language, this format style is targeted at. 2902 2903 Possible values: 2904 2905 * ``LK_None`` (in configuration: ``None``) 2906 Do not use. 2907 2908 * ``LK_Cpp`` (in configuration: ``Cpp``) 2909 Should be used for C, C++. 2910 2911 * ``LK_CSharp`` (in configuration: ``CSharp``) 2912 Should be used for C#. 2913 2914 * ``LK_Java`` (in configuration: ``Java``) 2915 Should be used for Java. 2916 2917 * ``LK_JavaScript`` (in configuration: ``JavaScript``) 2918 Should be used for JavaScript. 2919 2920 * ``LK_Json`` (in configuration: ``Json``) 2921 Should be used for JSON. 2922 2923 * ``LK_ObjC`` (in configuration: ``ObjC``) 2924 Should be used for Objective-C, Objective-C++. 2925 2926 * ``LK_Proto`` (in configuration: ``Proto``) 2927 Should be used for Protocol Buffers 2928 (https://developers.google.com/protocol-buffers/). 2929 2930 * ``LK_TableGen`` (in configuration: ``TableGen``) 2931 Should be used for TableGen code. 2932 2933 * ``LK_TextProto`` (in configuration: ``TextProto``) 2934 Should be used for Protocol Buffer messages in text format 2935 (https://developers.google.com/protocol-buffers/). 2936 2937 2938 2939**MacroBlockBegin** (``String``) :versionbadge:`clang-format 3.7` 2940 A regular expression matching macros that start a block. 2941 2942 .. code-block:: c++ 2943 2944 # With: 2945 MacroBlockBegin: "^NS_MAP_BEGIN|\ 2946 NS_TABLE_HEAD$" 2947 MacroBlockEnd: "^\ 2948 NS_MAP_END|\ 2949 NS_TABLE_.*_END$" 2950 2951 NS_MAP_BEGIN 2952 foo(); 2953 NS_MAP_END 2954 2955 NS_TABLE_HEAD 2956 bar(); 2957 NS_TABLE_FOO_END 2958 2959 # Without: 2960 NS_MAP_BEGIN 2961 foo(); 2962 NS_MAP_END 2963 2964 NS_TABLE_HEAD 2965 bar(); 2966 NS_TABLE_FOO_END 2967 2968**MacroBlockEnd** (``String``) :versionbadge:`clang-format 3.7` 2969 A regular expression matching macros that end a block. 2970 2971**MaxEmptyLinesToKeep** (``Unsigned``) :versionbadge:`clang-format 3.7` 2972 The maximum number of consecutive empty lines to keep. 2973 2974 .. code-block:: c++ 2975 2976 MaxEmptyLinesToKeep: 1 vs. MaxEmptyLinesToKeep: 0 2977 int f() { int f() { 2978 int = 1; int i = 1; 2979 i = foo(); 2980 i = foo(); return i; 2981 } 2982 return i; 2983 } 2984 2985**NamespaceIndentation** (``NamespaceIndentationKind``) :versionbadge:`clang-format 3.7` 2986 The indentation used for namespaces. 2987 2988 Possible values: 2989 2990 * ``NI_None`` (in configuration: ``None``) 2991 Don't indent in namespaces. 2992 2993 .. code-block:: c++ 2994 2995 namespace out { 2996 int i; 2997 namespace in { 2998 int i; 2999 } 3000 } 3001 3002 * ``NI_Inner`` (in configuration: ``Inner``) 3003 Indent only in inner namespaces (nested in other namespaces). 3004 3005 .. code-block:: c++ 3006 3007 namespace out { 3008 int i; 3009 namespace in { 3010 int i; 3011 } 3012 } 3013 3014 * ``NI_All`` (in configuration: ``All``) 3015 Indent in all namespaces. 3016 3017 .. code-block:: c++ 3018 3019 namespace out { 3020 int i; 3021 namespace in { 3022 int i; 3023 } 3024 } 3025 3026 3027 3028**NamespaceMacros** (``List of Strings``) :versionbadge:`clang-format 9` 3029 A vector of macros which are used to open namespace blocks. 3030 3031 These are expected to be macros of the form: 3032 3033 .. code-block:: c++ 3034 3035 NAMESPACE(<namespace-name>, ...) { 3036 <namespace-content> 3037 } 3038 3039 For example: TESTSUITE 3040 3041**ObjCBinPackProtocolList** (``BinPackStyle``) :versionbadge:`clang-format 7` 3042 Controls bin-packing Objective-C protocol conformance list 3043 items into as few lines as possible when they go over ``ColumnLimit``. 3044 3045 If ``Auto`` (the default), delegates to the value in 3046 ``BinPackParameters``. If that is ``true``, bin-packs Objective-C 3047 protocol conformance list items into as few lines as possible 3048 whenever they go over ``ColumnLimit``. 3049 3050 If ``Always``, always bin-packs Objective-C protocol conformance 3051 list items into as few lines as possible whenever they go over 3052 ``ColumnLimit``. 3053 3054 If ``Never``, lays out Objective-C protocol conformance list items 3055 onto individual lines whenever they go over ``ColumnLimit``. 3056 3057 3058 .. code-block:: objc 3059 3060 Always (or Auto, if BinPackParameters=true): 3061 @interface ccccccccccccc () < 3062 ccccccccccccc, ccccccccccccc, 3063 ccccccccccccc, ccccccccccccc> { 3064 } 3065 3066 Never (or Auto, if BinPackParameters=false): 3067 @interface ddddddddddddd () < 3068 ddddddddddddd, 3069 ddddddddddddd, 3070 ddddddddddddd, 3071 ddddddddddddd> { 3072 } 3073 3074 Possible values: 3075 3076 * ``BPS_Auto`` (in configuration: ``Auto``) 3077 Automatically determine parameter bin-packing behavior. 3078 3079 * ``BPS_Always`` (in configuration: ``Always``) 3080 Always bin-pack parameters. 3081 3082 * ``BPS_Never`` (in configuration: ``Never``) 3083 Never bin-pack parameters. 3084 3085 3086 3087**ObjCBlockIndentWidth** (``Unsigned``) :versionbadge:`clang-format 3.7` 3088 The number of characters to use for indentation of ObjC blocks. 3089 3090 .. code-block:: objc 3091 3092 ObjCBlockIndentWidth: 4 3093 3094 [operation setCompletionBlock:^{ 3095 [self onOperationDone]; 3096 }]; 3097 3098**ObjCBreakBeforeNestedBlockParam** (``Boolean``) :versionbadge:`clang-format 12` 3099 Break parameters list into lines when there is nested block 3100 parameters in a function call. 3101 3102 .. code-block:: c++ 3103 3104 false: 3105 - (void)_aMethod 3106 { 3107 [self.test1 t:self w:self callback:^(typeof(self) self, NSNumber 3108 *u, NSNumber *v) { 3109 u = c; 3110 }] 3111 } 3112 true: 3113 - (void)_aMethod 3114 { 3115 [self.test1 t:self 3116 w:self 3117 callback:^(typeof(self) self, NSNumber *u, NSNumber *v) { 3118 u = c; 3119 }] 3120 } 3121 3122**ObjCSpaceAfterProperty** (``Boolean``) :versionbadge:`clang-format 3.7` 3123 Add a space after ``@property`` in Objective-C, i.e. use 3124 ``@property (readonly)`` instead of ``@property(readonly)``. 3125 3126**ObjCSpaceBeforeProtocolList** (``Boolean``) :versionbadge:`clang-format 3.7` 3127 Add a space in front of an Objective-C protocol list, i.e. use 3128 ``Foo <Protocol>`` instead of ``Foo<Protocol>``. 3129 3130**PPIndentWidth** (``Integer``) :versionbadge:`clang-format 13` 3131 The number of columns to use for indentation of preprocessor statements. 3132 When set to -1 (default) ``IndentWidth`` is used also for preprocessor 3133 statements. 3134 3135 .. code-block:: c++ 3136 3137 PPIndentWidth: 1 3138 3139 #ifdef __linux__ 3140 # define FOO 3141 #else 3142 # define BAR 3143 #endif 3144 3145**PackConstructorInitializers** (``PackConstructorInitializersStyle``) :versionbadge:`clang-format 14` 3146 The pack constructor initializers style to use. 3147 3148 Possible values: 3149 3150 * ``PCIS_Never`` (in configuration: ``Never``) 3151 Always put each constructor initializer on its own line. 3152 3153 .. code-block:: c++ 3154 3155 Constructor() 3156 : a(), 3157 b() 3158 3159 * ``PCIS_BinPack`` (in configuration: ``BinPack``) 3160 Bin-pack constructor initializers. 3161 3162 .. code-block:: c++ 3163 3164 Constructor() 3165 : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), 3166 cccccccccccccccccccc() 3167 3168 * ``PCIS_CurrentLine`` (in configuration: ``CurrentLine``) 3169 Put all constructor initializers on the current line if they fit. 3170 Otherwise, put each one on its own line. 3171 3172 .. code-block:: c++ 3173 3174 Constructor() : a(), b() 3175 3176 Constructor() 3177 : aaaaaaaaaaaaaaaaaaaa(), 3178 bbbbbbbbbbbbbbbbbbbb(), 3179 ddddddddddddd() 3180 3181 * ``PCIS_NextLine`` (in configuration: ``NextLine``) 3182 Same as ``PCIS_CurrentLine`` except that if all constructor initializers 3183 do not fit on the current line, try to fit them on the next line. 3184 3185 .. code-block:: c++ 3186 3187 Constructor() : a(), b() 3188 3189 Constructor() 3190 : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), ddddddddddddd() 3191 3192 Constructor() 3193 : aaaaaaaaaaaaaaaaaaaa(), 3194 bbbbbbbbbbbbbbbbbbbb(), 3195 cccccccccccccccccccc() 3196 3197 3198 3199**PenaltyBreakAssignment** (``Unsigned``) :versionbadge:`clang-format 5` 3200 The penalty for breaking around an assignment operator. 3201 3202**PenaltyBreakBeforeFirstCallParameter** (``Unsigned``) :versionbadge:`clang-format 3.7` 3203 The penalty for breaking a function call after ``call(``. 3204 3205**PenaltyBreakComment** (``Unsigned``) :versionbadge:`clang-format 3.7` 3206 The penalty for each line break introduced inside a comment. 3207 3208**PenaltyBreakFirstLessLess** (``Unsigned``) :versionbadge:`clang-format 3.7` 3209 The penalty for breaking before the first ``<<``. 3210 3211**PenaltyBreakOpenParenthesis** (``Unsigned``) :versionbadge:`clang-format 14` 3212 The penalty for breaking after ``(``. 3213 3214**PenaltyBreakString** (``Unsigned``) :versionbadge:`clang-format 3.7` 3215 The penalty for each line break introduced inside a string literal. 3216 3217**PenaltyBreakTemplateDeclaration** (``Unsigned``) :versionbadge:`clang-format 7` 3218 The penalty for breaking after template declaration. 3219 3220**PenaltyExcessCharacter** (``Unsigned``) :versionbadge:`clang-format 3.7` 3221 The penalty for each character outside of the column limit. 3222 3223**PenaltyIndentedWhitespace** (``Unsigned``) :versionbadge:`clang-format 12` 3224 Penalty for each character of whitespace indentation 3225 (counted relative to leading non-whitespace column). 3226 3227**PenaltyReturnTypeOnItsOwnLine** (``Unsigned``) :versionbadge:`clang-format 3.7` 3228 Penalty for putting the return type of a function onto its own 3229 line. 3230 3231**PointerAlignment** (``PointerAlignmentStyle``) :versionbadge:`clang-format 3.7` 3232 Pointer and reference alignment style. 3233 3234 Possible values: 3235 3236 * ``PAS_Left`` (in configuration: ``Left``) 3237 Align pointer to the left. 3238 3239 .. code-block:: c++ 3240 3241 int* a; 3242 3243 * ``PAS_Right`` (in configuration: ``Right``) 3244 Align pointer to the right. 3245 3246 .. code-block:: c++ 3247 3248 int *a; 3249 3250 * ``PAS_Middle`` (in configuration: ``Middle``) 3251 Align pointer in the middle. 3252 3253 .. code-block:: c++ 3254 3255 int * a; 3256 3257 3258 3259**QualifierAlignment** (``QualifierAlignmentStyle``) :versionbadge:`clang-format 14` 3260 Different ways to arrange specifiers and qualifiers (e.g. const/volatile). 3261 3262 .. warning:: 3263 3264 Setting ``QualifierAlignment`` to something other than `Leave`, COULD 3265 lead to incorrect code formatting due to incorrect decisions made due to 3266 clang-formats lack of complete semantic information. 3267 As such extra care should be taken to review code changes made by the use 3268 of this option. 3269 3270 Possible values: 3271 3272 * ``QAS_Leave`` (in configuration: ``Leave``) 3273 Don't change specifiers/qualifiers to either Left or Right alignment 3274 (default). 3275 3276 .. code-block:: c++ 3277 3278 int const a; 3279 const int *a; 3280 3281 * ``QAS_Left`` (in configuration: ``Left``) 3282 Change specifiers/qualifiers to be left-aligned. 3283 3284 .. code-block:: c++ 3285 3286 const int a; 3287 const int *a; 3288 3289 * ``QAS_Right`` (in configuration: ``Right``) 3290 Change specifiers/qualifiers to be right-aligned. 3291 3292 .. code-block:: c++ 3293 3294 int const a; 3295 int const *a; 3296 3297 * ``QAS_Custom`` (in configuration: ``Custom``) 3298 Change specifiers/qualifiers to be aligned based on ``QualifierOrder``. 3299 With: 3300 3301 .. code-block:: yaml 3302 3303 QualifierOrder: ['inline', 'static' , 'type', 'const'] 3304 3305 3306 .. code-block:: c++ 3307 3308 3309 int const a; 3310 int const *a; 3311 3312 3313 3314**QualifierOrder** (``List of Strings``) :versionbadge:`clang-format 14` 3315 The order in which the qualifiers appear. 3316 Order is an array that can contain any of the following: 3317 3318 * const 3319 * inline 3320 * static 3321 * constexpr 3322 * volatile 3323 * restrict 3324 * type 3325 3326 Note: it MUST contain 'type'. 3327 Items to the left of 'type' will be placed to the left of the type and 3328 aligned in the order supplied. Items to the right of 'type' will be placed 3329 to the right of the type and aligned in the order supplied. 3330 3331 3332 .. code-block:: yaml 3333 3334 QualifierOrder: ['inline', 'static', 'type', 'const', 'volatile' ] 3335 3336**RawStringFormats** (``List of RawStringFormats``) :versionbadge:`clang-format 6` 3337 Defines hints for detecting supported languages code blocks in raw 3338 strings. 3339 3340 A raw string with a matching delimiter or a matching enclosing function 3341 name will be reformatted assuming the specified language based on the 3342 style for that language defined in the .clang-format file. If no style has 3343 been defined in the .clang-format file for the specific language, a 3344 predefined style given by 'BasedOnStyle' is used. If 'BasedOnStyle' is not 3345 found, the formatting is based on llvm style. A matching delimiter takes 3346 precedence over a matching enclosing function name for determining the 3347 language of the raw string contents. 3348 3349 If a canonical delimiter is specified, occurrences of other delimiters for 3350 the same language will be updated to the canonical if possible. 3351 3352 There should be at most one specification per language and each delimiter 3353 and enclosing function should not occur in multiple specifications. 3354 3355 To configure this in the .clang-format file, use: 3356 3357 .. code-block:: yaml 3358 3359 RawStringFormats: 3360 - Language: TextProto 3361 Delimiters: 3362 - 'pb' 3363 - 'proto' 3364 EnclosingFunctions: 3365 - 'PARSE_TEXT_PROTO' 3366 BasedOnStyle: google 3367 - Language: Cpp 3368 Delimiters: 3369 - 'cc' 3370 - 'cpp' 3371 BasedOnStyle: llvm 3372 CanonicalDelimiter: 'cc' 3373 3374**ReferenceAlignment** (``ReferenceAlignmentStyle``) :versionbadge:`clang-format 13` 3375 Reference alignment style (overrides ``PointerAlignment`` for 3376 references). 3377 3378 Possible values: 3379 3380 * ``RAS_Pointer`` (in configuration: ``Pointer``) 3381 Align reference like ``PointerAlignment``. 3382 3383 * ``RAS_Left`` (in configuration: ``Left``) 3384 Align reference to the left. 3385 3386 .. code-block:: c++ 3387 3388 int& a; 3389 3390 * ``RAS_Right`` (in configuration: ``Right``) 3391 Align reference to the right. 3392 3393 .. code-block:: c++ 3394 3395 int &a; 3396 3397 * ``RAS_Middle`` (in configuration: ``Middle``) 3398 Align reference in the middle. 3399 3400 .. code-block:: c++ 3401 3402 int & a; 3403 3404 3405 3406**ReflowComments** (``Boolean``) :versionbadge:`clang-format 4` 3407 If ``true``, clang-format will attempt to re-flow comments. 3408 3409 .. code-block:: c++ 3410 3411 false: 3412 // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information 3413 /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */ 3414 3415 true: 3416 // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of 3417 // information 3418 /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of 3419 * information */ 3420 3421**RemoveBracesLLVM** (``Boolean``) :versionbadge:`clang-format 14` 3422 Remove optional braces of control statements (``if``, ``else``, ``for``, 3423 and ``while``) in C++ according to the LLVM coding style. 3424 3425 .. warning:: 3426 3427 This option will be renamed and expanded to support other styles. 3428 3429 .. warning:: 3430 3431 Setting this option to `true` could lead to incorrect code formatting due 3432 to clang-format's lack of complete semantic information. As such, extra 3433 care should be taken to review code changes made by this option. 3434 3435 .. code-block:: c++ 3436 3437 false: true: 3438 3439 if (isa<FunctionDecl>(D)) { vs. if (isa<FunctionDecl>(D)) 3440 handleFunctionDecl(D); handleFunctionDecl(D); 3441 } else if (isa<VarDecl>(D)) { else if (isa<VarDecl>(D)) 3442 handleVarDecl(D); handleVarDecl(D); 3443 } 3444 3445 if (isa<VarDecl>(D)) { vs. if (isa<VarDecl>(D)) { 3446 for (auto *A : D.attrs()) { for (auto *A : D.attrs()) 3447 if (shouldProcessAttr(A)) { if (shouldProcessAttr(A)) 3448 handleAttr(A); handleAttr(A); 3449 } } 3450 } 3451 } 3452 3453 if (isa<FunctionDecl>(D)) { vs. if (isa<FunctionDecl>(D)) 3454 for (auto *A : D.attrs()) { for (auto *A : D.attrs()) 3455 handleAttr(A); handleAttr(A); 3456 } 3457 } 3458 3459 if (auto *D = (T)(D)) { vs. if (auto *D = (T)(D)) { 3460 if (shouldProcess(D)) { if (shouldProcess(D)) 3461 handleVarDecl(D); handleVarDecl(D); 3462 } else { else 3463 markAsIgnored(D); markAsIgnored(D); 3464 } } 3465 } 3466 3467 if (a) { vs. if (a) 3468 b(); b(); 3469 } else { else if (c) 3470 if (c) { d(); 3471 d(); else 3472 } else { e(); 3473 e(); 3474 } 3475 } 3476 3477**SeparateDefinitionBlocks** (``SeparateDefinitionStyle``) :versionbadge:`clang-format 14` 3478 Specifies the use of empty lines to separate definition blocks, including 3479 classes, structs, enums, and functions. 3480 3481 .. code-block:: c++ 3482 3483 Never v.s. Always 3484 #include <cstring> #include <cstring> 3485 struct Foo { 3486 int a, b, c; struct Foo { 3487 }; int a, b, c; 3488 namespace Ns { }; 3489 class Bar { 3490 public: namespace Ns { 3491 struct Foobar { class Bar { 3492 int a; public: 3493 int b; struct Foobar { 3494 }; int a; 3495 private: int b; 3496 int t; }; 3497 int method1() { 3498 // ... private: 3499 } int t; 3500 enum List { 3501 ITEM1, int method1() { 3502 ITEM2 // ... 3503 }; } 3504 template<typename T> 3505 int method2(T x) { enum List { 3506 // ... ITEM1, 3507 } ITEM2 3508 int i, j, k; }; 3509 int method3(int par) { 3510 // ... template<typename T> 3511 } int method2(T x) { 3512 }; // ... 3513 class C {}; } 3514 } 3515 int i, j, k; 3516 3517 int method3(int par) { 3518 // ... 3519 } 3520 }; 3521 3522 class C {}; 3523 } 3524 3525 Possible values: 3526 3527 * ``SDS_Leave`` (in configuration: ``Leave``) 3528 Leave definition blocks as they are. 3529 3530 * ``SDS_Always`` (in configuration: ``Always``) 3531 Insert an empty line between definition blocks. 3532 3533 * ``SDS_Never`` (in configuration: ``Never``) 3534 Remove any empty line between definition blocks. 3535 3536 3537 3538**ShortNamespaceLines** (``Unsigned``) :versionbadge:`clang-format 13` 3539 The maximal number of unwrapped lines that a short namespace spans. 3540 Defaults to 1. 3541 3542 This determines the maximum length of short namespaces by counting 3543 unwrapped lines (i.e. containing neither opening nor closing 3544 namespace brace) and makes "FixNamespaceComments" omit adding 3545 end comments for those. 3546 3547 .. code-block:: c++ 3548 3549 ShortNamespaceLines: 1 vs. ShortNamespaceLines: 0 3550 namespace a { namespace a { 3551 int foo; int foo; 3552 } } // namespace a 3553 3554 ShortNamespaceLines: 1 vs. ShortNamespaceLines: 0 3555 namespace b { namespace b { 3556 int foo; int foo; 3557 int bar; int bar; 3558 } // namespace b } // namespace b 3559 3560**SortIncludes** (``SortIncludesOptions``) :versionbadge:`clang-format 4` 3561 Controls if and how clang-format will sort ``#includes``. 3562 If ``Never``, includes are never sorted. 3563 If ``CaseInsensitive``, includes are sorted in an ASCIIbetical or case 3564 insensitive fashion. 3565 If ``CaseSensitive``, includes are sorted in an alphabetical or case 3566 sensitive fashion. 3567 3568 Possible values: 3569 3570 * ``SI_Never`` (in configuration: ``Never``) 3571 Includes are never sorted. 3572 3573 .. code-block:: c++ 3574 3575 #include "B/A.h" 3576 #include "A/B.h" 3577 #include "a/b.h" 3578 #include "A/b.h" 3579 #include "B/a.h" 3580 3581 * ``SI_CaseSensitive`` (in configuration: ``CaseSensitive``) 3582 Includes are sorted in an ASCIIbetical or case sensitive fashion. 3583 3584 .. code-block:: c++ 3585 3586 #include "A/B.h" 3587 #include "A/b.h" 3588 #include "B/A.h" 3589 #include "B/a.h" 3590 #include "a/b.h" 3591 3592 * ``SI_CaseInsensitive`` (in configuration: ``CaseInsensitive``) 3593 Includes are sorted in an alphabetical or case insensitive fashion. 3594 3595 .. code-block:: c++ 3596 3597 #include "A/B.h" 3598 #include "A/b.h" 3599 #include "a/b.h" 3600 #include "B/A.h" 3601 #include "B/a.h" 3602 3603 3604 3605**SortJavaStaticImport** (``SortJavaStaticImportOptions``) :versionbadge:`clang-format 12` 3606 When sorting Java imports, by default static imports are placed before 3607 non-static imports. If ``JavaStaticImportAfterImport`` is ``After``, 3608 static imports are placed after non-static imports. 3609 3610 Possible values: 3611 3612 * ``SJSIO_Before`` (in configuration: ``Before``) 3613 Static imports are placed before non-static imports. 3614 3615 .. code-block:: java 3616 3617 import static org.example.function1; 3618 3619 import org.example.ClassA; 3620 3621 * ``SJSIO_After`` (in configuration: ``After``) 3622 Static imports are placed after non-static imports. 3623 3624 .. code-block:: java 3625 3626 import org.example.ClassA; 3627 3628 import static org.example.function1; 3629 3630 3631 3632**SortUsingDeclarations** (``Boolean``) :versionbadge:`clang-format 5` 3633 If ``true``, clang-format will sort using declarations. 3634 3635 The order of using declarations is defined as follows: 3636 Split the strings by "::" and discard any initial empty strings. The last 3637 element of each list is a non-namespace name; all others are namespace 3638 names. Sort the lists of names lexicographically, where the sort order of 3639 individual names is that all non-namespace names come before all namespace 3640 names, and within those groups, names are in case-insensitive 3641 lexicographic order. 3642 3643 .. code-block:: c++ 3644 3645 false: true: 3646 using std::cout; vs. using std::cin; 3647 using std::cin; using std::cout; 3648 3649**SpaceAfterCStyleCast** (``Boolean``) :versionbadge:`clang-format 3.5` 3650 If ``true``, a space is inserted after C style casts. 3651 3652 .. code-block:: c++ 3653 3654 true: false: 3655 (int) i; vs. (int)i; 3656 3657**SpaceAfterLogicalNot** (``Boolean``) :versionbadge:`clang-format 9` 3658 If ``true``, a space is inserted after the logical not operator (``!``). 3659 3660 .. code-block:: c++ 3661 3662 true: false: 3663 ! someExpression(); vs. !someExpression(); 3664 3665**SpaceAfterTemplateKeyword** (``Boolean``) :versionbadge:`clang-format 4` 3666 If ``true``, a space will be inserted after the 'template' keyword. 3667 3668 .. code-block:: c++ 3669 3670 true: false: 3671 template <int> void foo(); vs. template<int> void foo(); 3672 3673**SpaceAroundPointerQualifiers** (``SpaceAroundPointerQualifiersStyle``) :versionbadge:`clang-format 12` 3674 Defines in which cases to put a space before or after pointer qualifiers 3675 3676 Possible values: 3677 3678 * ``SAPQ_Default`` (in configuration: ``Default``) 3679 Don't ensure spaces around pointer qualifiers and use PointerAlignment 3680 instead. 3681 3682 .. code-block:: c++ 3683 3684 PointerAlignment: Left PointerAlignment: Right 3685 void* const* x = NULL; vs. void *const *x = NULL; 3686 3687 * ``SAPQ_Before`` (in configuration: ``Before``) 3688 Ensure that there is a space before pointer qualifiers. 3689 3690 .. code-block:: c++ 3691 3692 PointerAlignment: Left PointerAlignment: Right 3693 void* const* x = NULL; vs. void * const *x = NULL; 3694 3695 * ``SAPQ_After`` (in configuration: ``After``) 3696 Ensure that there is a space after pointer qualifiers. 3697 3698 .. code-block:: c++ 3699 3700 PointerAlignment: Left PointerAlignment: Right 3701 void* const * x = NULL; vs. void *const *x = NULL; 3702 3703 * ``SAPQ_Both`` (in configuration: ``Both``) 3704 Ensure that there is a space both before and after pointer qualifiers. 3705 3706 .. code-block:: c++ 3707 3708 PointerAlignment: Left PointerAlignment: Right 3709 void* const * x = NULL; vs. void * const *x = NULL; 3710 3711 3712 3713**SpaceBeforeAssignmentOperators** (``Boolean``) :versionbadge:`clang-format 3.7` 3714 If ``false``, spaces will be removed before assignment operators. 3715 3716 .. code-block:: c++ 3717 3718 true: false: 3719 int a = 5; vs. int a= 5; 3720 a += 42; a+= 42; 3721 3722**SpaceBeforeCaseColon** (``Boolean``) :versionbadge:`clang-format 12` 3723 If ``false``, spaces will be removed before case colon. 3724 3725 .. code-block:: c++ 3726 3727 true: false 3728 switch (x) { vs. switch (x) { 3729 case 1 : break; case 1: break; 3730 } } 3731 3732**SpaceBeforeCpp11BracedList** (``Boolean``) :versionbadge:`clang-format 7` 3733 If ``true``, a space will be inserted before a C++11 braced list 3734 used to initialize an object (after the preceding identifier or type). 3735 3736 .. code-block:: c++ 3737 3738 true: false: 3739 Foo foo { bar }; vs. Foo foo{ bar }; 3740 Foo {}; Foo{}; 3741 vector<int> { 1, 2, 3 }; vector<int>{ 1, 2, 3 }; 3742 new int[3] { 1, 2, 3 }; new int[3]{ 1, 2, 3 }; 3743 3744**SpaceBeforeCtorInitializerColon** (``Boolean``) :versionbadge:`clang-format 7` 3745 If ``false``, spaces will be removed before constructor initializer 3746 colon. 3747 3748 .. code-block:: c++ 3749 3750 true: false: 3751 Foo::Foo() : a(a) {} Foo::Foo(): a(a) {} 3752 3753**SpaceBeforeInheritanceColon** (``Boolean``) :versionbadge:`clang-format 7` 3754 If ``false``, spaces will be removed before inheritance colon. 3755 3756 .. code-block:: c++ 3757 3758 true: false: 3759 class Foo : Bar {} vs. class Foo: Bar {} 3760 3761**SpaceBeforeParens** (``SpaceBeforeParensStyle``) :versionbadge:`clang-format 3.5` 3762 Defines in which cases to put a space before opening parentheses. 3763 3764 Possible values: 3765 3766 * ``SBPO_Never`` (in configuration: ``Never``) 3767 Never put a space before opening parentheses. 3768 3769 .. code-block:: c++ 3770 3771 void f() { 3772 if(true) { 3773 f(); 3774 } 3775 } 3776 3777 * ``SBPO_ControlStatements`` (in configuration: ``ControlStatements``) 3778 Put a space before opening parentheses only after control statement 3779 keywords (``for/if/while...``). 3780 3781 .. code-block:: c++ 3782 3783 void f() { 3784 if (true) { 3785 f(); 3786 } 3787 } 3788 3789 * ``SBPO_ControlStatementsExceptControlMacros`` (in configuration: ``ControlStatementsExceptControlMacros``) 3790 Same as ``SBPO_ControlStatements`` except this option doesn't apply to 3791 ForEach and If macros. This is useful in projects where ForEach/If 3792 macros are treated as function calls instead of control statements. 3793 ``SBPO_ControlStatementsExceptForEachMacros`` remains an alias for 3794 backward compatibility. 3795 3796 .. code-block:: c++ 3797 3798 void f() { 3799 Q_FOREACH(...) { 3800 f(); 3801 } 3802 } 3803 3804 * ``SBPO_NonEmptyParentheses`` (in configuration: ``NonEmptyParentheses``) 3805 Put a space before opening parentheses only if the parentheses are not 3806 empty i.e. '()' 3807 3808 .. code-block:: c++ 3809 3810 void() { 3811 if (true) { 3812 f(); 3813 g (x, y, z); 3814 } 3815 } 3816 3817 * ``SBPO_Always`` (in configuration: ``Always``) 3818 Always put a space before opening parentheses, except when it's 3819 prohibited by the syntax rules (in function-like macro definitions) or 3820 when determined by other style rules (after unary operators, opening 3821 parentheses, etc.) 3822 3823 .. code-block:: c++ 3824 3825 void f () { 3826 if (true) { 3827 f (); 3828 } 3829 } 3830 3831 * ``SBPO_Custom`` (in configuration: ``Custom``) 3832 Configure each individual space before parentheses in 3833 `SpaceBeforeParensOptions`. 3834 3835 3836 3837**SpaceBeforeParensOptions** (``SpaceBeforeParensCustom``) :versionbadge:`clang-format 14` 3838 Control of individual space before parentheses. 3839 3840 If ``SpaceBeforeParens`` is set to ``Custom``, use this to specify 3841 how each individual space before parentheses case should be handled. 3842 Otherwise, this is ignored. 3843 3844 .. code-block:: yaml 3845 3846 # Example of usage: 3847 SpaceBeforeParens: Custom 3848 SpaceBeforeParensOptions: 3849 AfterControlStatements: true 3850 AfterFunctionDefinitionName: true 3851 3852 Nested configuration flags: 3853 3854 3855 * ``bool AfterControlStatements`` If ``true``, put space betwee control statement keywords 3856 (for/if/while...) and opening parentheses. 3857 3858 .. code-block:: c++ 3859 3860 true: false: 3861 if (...) {} vs. if(...) {} 3862 3863 * ``bool AfterForeachMacros`` If ``true``, put space between foreach macros and opening parentheses. 3864 3865 .. code-block:: c++ 3866 3867 true: false: 3868 FOREACH (...) vs. FOREACH(...) 3869 <loop-body> <loop-body> 3870 3871 * ``bool AfterFunctionDeclarationName`` If ``true``, put a space between function declaration name and opening 3872 parentheses. 3873 3874 .. code-block:: c++ 3875 3876 true: false: 3877 void f (); vs. void f(); 3878 3879 * ``bool AfterFunctionDefinitionName`` If ``true``, put a space between function definition name and opening 3880 parentheses. 3881 3882 .. code-block:: c++ 3883 3884 true: false: 3885 void f () {} vs. void f() {} 3886 3887 * ``bool AfterIfMacros`` If ``true``, put space between if macros and opening parentheses. 3888 3889 .. code-block:: c++ 3890 3891 true: false: 3892 IF (...) vs. IF(...) 3893 <conditional-body> <conditional-body> 3894 3895 * ``bool AfterOverloadedOperator`` If ``true``, put a space between operator overloading and opening 3896 parentheses. 3897 3898 .. code-block:: c++ 3899 3900 true: false: 3901 void operator++ (int a); vs. void operator++(int a); 3902 object.operator++ (10); object.operator++(10); 3903 3904 * ``bool BeforeNonEmptyParentheses`` If ``true``, put a space before opening parentheses only if the 3905 parentheses are not empty. 3906 3907 .. code-block:: c++ 3908 3909 true: false: 3910 void f (int a); vs. void f(); 3911 f (a); f(); 3912 3913 3914**SpaceBeforeRangeBasedForLoopColon** (``Boolean``) :versionbadge:`clang-format 7` 3915 If ``false``, spaces will be removed before range-based for loop 3916 colon. 3917 3918 .. code-block:: c++ 3919 3920 true: false: 3921 for (auto v : values) {} vs. for(auto v: values) {} 3922 3923**SpaceBeforeSquareBrackets** (``Boolean``) :versionbadge:`clang-format 11` 3924 If ``true``, spaces will be before ``[``. 3925 Lambdas will not be affected. Only the first ``[`` will get a space added. 3926 3927 .. code-block:: c++ 3928 3929 true: false: 3930 int a [5]; vs. int a[5]; 3931 int a [5][5]; vs. int a[5][5]; 3932 3933**SpaceInEmptyBlock** (``Boolean``) :versionbadge:`clang-format 11` 3934 If ``true``, spaces will be inserted into ``{}``. 3935 3936 .. code-block:: c++ 3937 3938 true: false: 3939 void f() { } vs. void f() {} 3940 while (true) { } while (true) {} 3941 3942**SpaceInEmptyParentheses** (``Boolean``) :versionbadge:`clang-format 3.7` 3943 If ``true``, spaces may be inserted into ``()``. 3944 3945 .. code-block:: c++ 3946 3947 true: false: 3948 void f( ) { vs. void f() { 3949 int x[] = {foo( ), bar( )}; int x[] = {foo(), bar()}; 3950 if (true) { if (true) { 3951 f( ); f(); 3952 } } 3953 } } 3954 3955**SpacesBeforeTrailingComments** (``Unsigned``) :versionbadge:`clang-format 3.7` 3956 The number of spaces before trailing line comments 3957 (``//`` - comments). 3958 3959 This does not affect trailing block comments (``/*`` - comments) as 3960 those commonly have different usage patterns and a number of special 3961 cases. 3962 3963 .. code-block:: c++ 3964 3965 SpacesBeforeTrailingComments: 3 3966 void f() { 3967 if (true) { // foo1 3968 f(); // bar 3969 } // foo 3970 } 3971 3972**SpacesInAngles** (``SpacesInAnglesStyle``) :versionbadge:`clang-format 3.4` 3973 The SpacesInAnglesStyle to use for template argument lists. 3974 3975 Possible values: 3976 3977 * ``SIAS_Never`` (in configuration: ``Never``) 3978 Remove spaces after ``<`` and before ``>``. 3979 3980 .. code-block:: c++ 3981 3982 static_cast<int>(arg); 3983 std::function<void(int)> fct; 3984 3985 * ``SIAS_Always`` (in configuration: ``Always``) 3986 Add spaces after ``<`` and before ``>``. 3987 3988 .. code-block:: c++ 3989 3990 static_cast< int >(arg); 3991 std::function< void(int) > fct; 3992 3993 * ``SIAS_Leave`` (in configuration: ``Leave``) 3994 Keep a single space after ``<`` and before ``>`` if any spaces were 3995 present. Option ``Standard: Cpp03`` takes precedence. 3996 3997 3998 3999**SpacesInCStyleCastParentheses** (``Boolean``) :versionbadge:`clang-format 3.7` 4000 If ``true``, spaces may be inserted into C style casts. 4001 4002 .. code-block:: c++ 4003 4004 true: false: 4005 x = ( int32 )y vs. x = (int32)y 4006 4007**SpacesInConditionalStatement** (``Boolean``) :versionbadge:`clang-format 11` 4008 If ``true``, spaces will be inserted around if/for/switch/while 4009 conditions. 4010 4011 .. code-block:: c++ 4012 4013 true: false: 4014 if ( a ) { ... } vs. if (a) { ... } 4015 while ( i < 5 ) { ... } while (i < 5) { ... } 4016 4017**SpacesInContainerLiterals** (``Boolean``) :versionbadge:`clang-format 3.7` 4018 If ``true``, spaces are inserted inside container literals (e.g. 4019 ObjC and Javascript array and dict literals). 4020 4021 .. code-block:: js 4022 4023 true: false: 4024 var arr = [ 1, 2, 3 ]; vs. var arr = [1, 2, 3]; 4025 f({a : 1, b : 2, c : 3}); f({a: 1, b: 2, c: 3}); 4026 4027**SpacesInLineCommentPrefix** (``SpacesInLineComment``) :versionbadge:`clang-format 13` 4028 How many spaces are allowed at the start of a line comment. To disable the 4029 maximum set it to ``-1``, apart from that the maximum takes precedence 4030 over the minimum. 4031 4032 .. code-block:: c++ 4033 4034 Minimum = 1 4035 Maximum = -1 4036 // One space is forced 4037 4038 // but more spaces are possible 4039 4040 Minimum = 0 4041 Maximum = 0 4042 //Forces to start every comment directly after the slashes 4043 4044 Note that in line comment sections the relative indent of the subsequent 4045 lines is kept, that means the following: 4046 4047 .. code-block:: c++ 4048 4049 before: after: 4050 Minimum: 1 4051 //if (b) { // if (b) { 4052 // return true; // return true; 4053 //} // } 4054 4055 Maximum: 0 4056 /// List: ///List: 4057 /// - Foo /// - Foo 4058 /// - Bar /// - Bar 4059 4060 Nested configuration flags: 4061 4062 4063 * ``unsigned Minimum`` The minimum number of spaces at the start of the comment. 4064 4065 * ``unsigned Maximum`` The maximum number of spaces at the start of the comment. 4066 4067 4068**SpacesInParentheses** (``Boolean``) :versionbadge:`clang-format 3.7` 4069 If ``true``, spaces will be inserted after ``(`` and before ``)``. 4070 4071 .. code-block:: c++ 4072 4073 true: false: 4074 t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete; 4075 4076**SpacesInSquareBrackets** (``Boolean``) :versionbadge:`clang-format 3.7` 4077 If ``true``, spaces will be inserted after ``[`` and before ``]``. 4078 Lambdas without arguments or unspecified size array declarations will not 4079 be affected. 4080 4081 .. code-block:: c++ 4082 4083 true: false: 4084 int a[ 5 ]; vs. int a[5]; 4085 std::unique_ptr<int[]> foo() {} // Won't be affected 4086 4087**Standard** (``LanguageStandard``) :versionbadge:`clang-format 3.7` 4088 Parse and format C++ constructs compatible with this standard. 4089 4090 .. code-block:: c++ 4091 4092 c++03: latest: 4093 vector<set<int> > x; vs. vector<set<int>> x; 4094 4095 Possible values: 4096 4097 * ``LS_Cpp03`` (in configuration: ``c++03``) 4098 Parse and format as C++03. 4099 ``Cpp03`` is a deprecated alias for ``c++03`` 4100 4101 * ``LS_Cpp11`` (in configuration: ``c++11``) 4102 Parse and format as C++11. 4103 4104 * ``LS_Cpp14`` (in configuration: ``c++14``) 4105 Parse and format as C++14. 4106 4107 * ``LS_Cpp17`` (in configuration: ``c++17``) 4108 Parse and format as C++17. 4109 4110 * ``LS_Cpp20`` (in configuration: ``c++20``) 4111 Parse and format as C++20. 4112 4113 * ``LS_Latest`` (in configuration: ``Latest``) 4114 Parse and format using the latest supported language version. 4115 ``Cpp11`` is a deprecated alias for ``Latest`` 4116 4117 * ``LS_Auto`` (in configuration: ``Auto``) 4118 Automatic detection based on the input. 4119 4120 4121 4122**StatementAttributeLikeMacros** (``List of Strings``) :versionbadge:`clang-format 12` 4123 Macros which are ignored in front of a statement, as if they were an 4124 attribute. So that they are not parsed as identifier, for example for Qts 4125 emit. 4126 4127 .. code-block:: c++ 4128 4129 AlignConsecutiveDeclarations: true 4130 StatementAttributeLikeMacros: [] 4131 unsigned char data = 'x'; 4132 emit signal(data); // This is parsed as variable declaration. 4133 4134 AlignConsecutiveDeclarations: true 4135 StatementAttributeLikeMacros: [emit] 4136 unsigned char data = 'x'; 4137 emit signal(data); // Now it's fine again. 4138 4139**StatementMacros** (``List of Strings``) :versionbadge:`clang-format 8` 4140 A vector of macros that should be interpreted as complete 4141 statements. 4142 4143 Typical macros are expressions, and require a semi-colon to be 4144 added; sometimes this is not the case, and this allows to make 4145 clang-format aware of such cases. 4146 4147 For example: Q_UNUSED 4148 4149**TabWidth** (``Unsigned``) :versionbadge:`clang-format 3.7` 4150 The number of columns used for tab stops. 4151 4152**TypenameMacros** (``List of Strings``) :versionbadge:`clang-format 9` 4153 A vector of macros that should be interpreted as type declarations 4154 instead of as function calls. 4155 4156 These are expected to be macros of the form: 4157 4158 .. code-block:: c++ 4159 4160 STACK_OF(...) 4161 4162 In the .clang-format configuration file, this can be configured like: 4163 4164 .. code-block:: yaml 4165 4166 TypenameMacros: ['STACK_OF', 'LIST'] 4167 4168 For example: OpenSSL STACK_OF, BSD LIST_ENTRY. 4169 4170**UseCRLF** (``Boolean``) :versionbadge:`clang-format 11` 4171 Use ``\r\n`` instead of ``\n`` for line breaks. 4172 Also used as fallback if ``DeriveLineEnding`` is true. 4173 4174**UseTab** (``UseTabStyle``) :versionbadge:`clang-format 3.7` 4175 The way to use tab characters in the resulting file. 4176 4177 Possible values: 4178 4179 * ``UT_Never`` (in configuration: ``Never``) 4180 Never use tab. 4181 4182 * ``UT_ForIndentation`` (in configuration: ``ForIndentation``) 4183 Use tabs only for indentation. 4184 4185 * ``UT_ForContinuationAndIndentation`` (in configuration: ``ForContinuationAndIndentation``) 4186 Fill all leading whitespace with tabs, and use spaces for alignment that 4187 appears within a line (e.g. consecutive assignments and declarations). 4188 4189 * ``UT_AlignWithSpaces`` (in configuration: ``AlignWithSpaces``) 4190 Use tabs for line continuation and indentation, and spaces for 4191 alignment. 4192 4193 * ``UT_Always`` (in configuration: ``Always``) 4194 Use tabs whenever we need to fill whitespace that spans at least from 4195 one tab stop to the next one. 4196 4197 4198 4199**WhitespaceSensitiveMacros** (``List of Strings``) :versionbadge:`clang-format 12` 4200 A vector of macros which are whitespace-sensitive and should not 4201 be touched. 4202 4203 These are expected to be macros of the form: 4204 4205 .. code-block:: c++ 4206 4207 STRINGIZE(...) 4208 4209 In the .clang-format configuration file, this can be configured like: 4210 4211 .. code-block:: yaml 4212 4213 WhitespaceSensitiveMacros: ['STRINGIZE', 'PP_STRINGIZE'] 4214 4215 For example: BOOST_PP_STRINGIZE 4216 4217.. END_FORMAT_STYLE_OPTIONS 4218 4219Adding additional style options 4220=============================== 4221 4222Each additional style option adds costs to the clang-format project. Some of 4223these costs affect the clang-format development itself, as we need to make 4224sure that any given combination of options work and that new features don't 4225break any of the existing options in any way. There are also costs for end users 4226as options become less discoverable and people have to think about and make a 4227decision on options they don't really care about. 4228 4229The goal of the clang-format project is more on the side of supporting a 4230limited set of styles really well as opposed to supporting every single style 4231used by a codebase somewhere in the wild. Of course, we do want to support all 4232major projects and thus have established the following bar for adding style 4233options. Each new style option must .. 4234 4235 * be used in a project of significant size (have dozens of contributors) 4236 * have a publicly accessible style guide 4237 * have a person willing to contribute and maintain patches 4238 4239Examples 4240======== 4241 4242A style similar to the `Linux Kernel style 4243<https://www.kernel.org/doc/Documentation/CodingStyle>`_: 4244 4245.. code-block:: yaml 4246 4247 BasedOnStyle: LLVM 4248 IndentWidth: 8 4249 UseTab: Always 4250 BreakBeforeBraces: Linux 4251 AllowShortIfStatementsOnASingleLine: false 4252 IndentCaseLabels: false 4253 4254The result is (imagine that tabs are used for indentation here): 4255 4256.. code-block:: c++ 4257 4258 void test() 4259 { 4260 switch (x) { 4261 case 0: 4262 case 1: 4263 do_something(); 4264 break; 4265 case 2: 4266 do_something_else(); 4267 break; 4268 default: 4269 break; 4270 } 4271 if (condition) 4272 do_something_completely_different(); 4273 4274 if (x == y) { 4275 q(); 4276 } else if (x > y) { 4277 w(); 4278 } else { 4279 r(); 4280 } 4281 } 4282 4283A style similar to the default Visual Studio formatting style: 4284 4285.. code-block:: yaml 4286 4287 UseTab: Never 4288 IndentWidth: 4 4289 BreakBeforeBraces: Allman 4290 AllowShortIfStatementsOnASingleLine: false 4291 IndentCaseLabels: false 4292 ColumnLimit: 0 4293 4294The result is: 4295 4296.. code-block:: c++ 4297 4298 void test() 4299 { 4300 switch (suffix) 4301 { 4302 case 0: 4303 case 1: 4304 do_something(); 4305 break; 4306 case 2: 4307 do_something_else(); 4308 break; 4309 default: 4310 break; 4311 } 4312 if (condition) 4313 do_something_completely_different(); 4314 4315 if (x == y) 4316 { 4317 q(); 4318 } 4319 else if (x > y) 4320 { 4321 w(); 4322 } 4323 else 4324 { 4325 r(); 4326 } 4327 } 4328