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