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 Dependent on the value, ``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 788 if (b) 789 return; 790 else 791 return; 792 793 if (c) 794 return; 795 else { 796 return; 797 } 798 799 * ``SIS_WithoutElse`` (in configuration: ``WithoutElse``) 800 Put short ifs on the same line only if there is no else statement. 801 802 .. code-block:: c++ 803 804 if (a) return; 805 806 if (b) 807 return; 808 else 809 return; 810 811 if (c) 812 return; 813 else { 814 return; 815 } 816 817 * ``SIS_OnlyFirstIf`` (in configuration: ``OnlyFirstIf``) 818 Put short ifs, but not else ifs nor else statements, on the same line. 819 820 .. code-block:: c++ 821 822 if (a) return; 823 824 if (b) return; 825 else if (b) 826 return; 827 else 828 return; 829 830 if (c) return; 831 else { 832 return; 833 } 834 835 * ``SIS_AllIfsAndElse`` (in configuration: ``AllIfsAndElse``) 836 Always put short ifs, else ifs and else statements on the same 837 line. 838 839 .. code-block:: c++ 840 841 if (a) return; 842 843 if (b) return; 844 else return; 845 846 if (c) return; 847 else { 848 return; 849 } 850 851 852 853**AllowShortLambdasOnASingleLine** (``ShortLambdaStyle``) 854 Dependent on the value, ``auto lambda []() { return 0; }`` can be put on a 855 single line. 856 857 Possible values: 858 859 * ``SLS_None`` (in configuration: ``None``) 860 Never merge lambdas into a single line. 861 862 * ``SLS_Empty`` (in configuration: ``Empty``) 863 Only merge empty lambdas. 864 865 .. code-block:: c++ 866 867 auto lambda = [](int a) {} 868 auto lambda2 = [](int a) { 869 return a; 870 }; 871 872 * ``SLS_Inline`` (in configuration: ``Inline``) 873 Merge lambda into a single line if argument of a function. 874 875 .. code-block:: c++ 876 877 auto lambda = [](int a) { 878 return a; 879 }; 880 sort(a.begin(), a.end(), ()[] { return x < y; }) 881 882 * ``SLS_All`` (in configuration: ``All``) 883 Merge all lambdas fitting on a single line. 884 885 .. code-block:: c++ 886 887 auto lambda = [](int a) {} 888 auto lambda2 = [](int a) { return a; }; 889 890 891 892**AllowShortLoopsOnASingleLine** (``bool``) 893 If ``true``, ``while (true) continue;`` can be put on a single 894 line. 895 896**AlwaysBreakAfterDefinitionReturnType** (``DefinitionReturnTypeBreakingStyle``) 897 The function definition return type breaking style to use. This 898 option is **deprecated** and is retained for backwards compatibility. 899 900 Possible values: 901 902 * ``DRTBS_None`` (in configuration: ``None``) 903 Break after return type automatically. 904 ``PenaltyReturnTypeOnItsOwnLine`` is taken into account. 905 906 * ``DRTBS_All`` (in configuration: ``All``) 907 Always break after the return type. 908 909 * ``DRTBS_TopLevel`` (in configuration: ``TopLevel``) 910 Always break after the return types of top-level functions. 911 912 913 914**AlwaysBreakAfterReturnType** (``ReturnTypeBreakingStyle``) 915 The function declaration return type breaking style to use. 916 917 Possible values: 918 919 * ``RTBS_None`` (in configuration: ``None``) 920 Break after return type automatically. 921 ``PenaltyReturnTypeOnItsOwnLine`` is taken into account. 922 923 .. code-block:: c++ 924 925 class A { 926 int f() { return 0; }; 927 }; 928 int f(); 929 int f() { return 1; } 930 931 * ``RTBS_All`` (in configuration: ``All``) 932 Always break after the return type. 933 934 .. code-block:: c++ 935 936 class A { 937 int 938 f() { 939 return 0; 940 }; 941 }; 942 int 943 f(); 944 int 945 f() { 946 return 1; 947 } 948 949 * ``RTBS_TopLevel`` (in configuration: ``TopLevel``) 950 Always break after the return types of top-level functions. 951 952 .. code-block:: c++ 953 954 class A { 955 int f() { return 0; }; 956 }; 957 int 958 f(); 959 int 960 f() { 961 return 1; 962 } 963 964 * ``RTBS_AllDefinitions`` (in configuration: ``AllDefinitions``) 965 Always break after the return type of function definitions. 966 967 .. code-block:: c++ 968 969 class A { 970 int 971 f() { 972 return 0; 973 }; 974 }; 975 int f(); 976 int 977 f() { 978 return 1; 979 } 980 981 * ``RTBS_TopLevelDefinitions`` (in configuration: ``TopLevelDefinitions``) 982 Always break after the return type of top-level definitions. 983 984 .. code-block:: c++ 985 986 class A { 987 int f() { return 0; }; 988 }; 989 int f(); 990 int 991 f() { 992 return 1; 993 } 994 995 996 997**AlwaysBreakBeforeMultilineStrings** (``bool``) 998 If ``true``, always break before multiline string literals. 999 1000 This flag is mean to make cases where there are multiple multiline strings 1001 in a file look more consistent. Thus, it will only take effect if wrapping 1002 the string at that point leads to it being indented 1003 ``ContinuationIndentWidth`` spaces from the start of the line. 1004 1005 .. code-block:: c++ 1006 1007 true: false: 1008 aaaa = vs. aaaa = "bbbb" 1009 "bbbb" "cccc"; 1010 "cccc"; 1011 1012**AlwaysBreakTemplateDeclarations** (``BreakTemplateDeclarationsStyle``) 1013 The template declaration breaking style to use. 1014 1015 Possible values: 1016 1017 * ``BTDS_No`` (in configuration: ``No``) 1018 Do not force break before declaration. 1019 ``PenaltyBreakTemplateDeclaration`` is taken into account. 1020 1021 .. code-block:: c++ 1022 1023 template <typename T> T foo() { 1024 } 1025 template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa, 1026 int bbbbbbbbbbbbbbbbbbbbb) { 1027 } 1028 1029 * ``BTDS_MultiLine`` (in configuration: ``MultiLine``) 1030 Force break after template declaration only when the following 1031 declaration spans multiple lines. 1032 1033 .. code-block:: c++ 1034 1035 template <typename T> T foo() { 1036 } 1037 template <typename T> 1038 T foo(int aaaaaaaaaaaaaaaaaaaaa, 1039 int bbbbbbbbbbbbbbbbbbbbb) { 1040 } 1041 1042 * ``BTDS_Yes`` (in configuration: ``Yes``) 1043 Always break after template declaration. 1044 1045 .. code-block:: c++ 1046 1047 template <typename T> 1048 T foo() { 1049 } 1050 template <typename T> 1051 T foo(int aaaaaaaaaaaaaaaaaaaaa, 1052 int bbbbbbbbbbbbbbbbbbbbb) { 1053 } 1054 1055 1056 1057**AttributeMacros** (``std::vector<std::string>``) 1058 A vector of strings that should be interpreted as attributes/qualifiers 1059 instead of identifiers. This can be useful for language extensions or 1060 static analyzer annotations. 1061 1062 For example: 1063 1064 .. code-block:: c++ 1065 1066 x = (char *__capability)&y; 1067 int function(void) __ununsed; 1068 void only_writes_to_buffer(char *__output buffer); 1069 1070 In the .clang-format configuration file, this can be configured like: 1071 1072 .. code-block:: yaml 1073 1074 AttributeMacros: ['__capability', '__output', '__ununsed'] 1075 1076**BinPackArguments** (``bool``) 1077 If ``false``, a function call's arguments will either be all on the 1078 same line or will have one line each. 1079 1080 .. code-block:: c++ 1081 1082 true: 1083 void f() { 1084 f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa, 1085 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); 1086 } 1087 1088 false: 1089 void f() { 1090 f(aaaaaaaaaaaaaaaaaaaa, 1091 aaaaaaaaaaaaaaaaaaaa, 1092 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); 1093 } 1094 1095**BinPackParameters** (``bool``) 1096 If ``false``, a function declaration's or function definition's 1097 parameters will either all be on the same line or will have one line each. 1098 1099 .. code-block:: c++ 1100 1101 true: 1102 void f(int aaaaaaaaaaaaaaaaaaaa, int aaaaaaaaaaaaaaaaaaaa, 1103 int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {} 1104 1105 false: 1106 void f(int aaaaaaaaaaaaaaaaaaaa, 1107 int aaaaaaaaaaaaaaaaaaaa, 1108 int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {} 1109 1110**BitFieldColonSpacing** (``BitFieldColonSpacingStyle``) 1111 The BitFieldColonSpacingStyle to use for bitfields. 1112 1113 Possible values: 1114 1115 * ``BFCS_Both`` (in configuration: ``Both``) 1116 Add one space on each side of the ``:`` 1117 1118 .. code-block:: c++ 1119 1120 unsigned bf : 2; 1121 1122 * ``BFCS_None`` (in configuration: ``None``) 1123 Add no space around the ``:`` (except when needed for 1124 ``AlignConsecutiveBitFields``). 1125 1126 .. code-block:: c++ 1127 1128 unsigned bf:2; 1129 1130 * ``BFCS_Before`` (in configuration: ``Before``) 1131 Add space before the ``:`` only 1132 1133 .. code-block:: c++ 1134 1135 unsigned bf :2; 1136 1137 * ``BFCS_After`` (in configuration: ``After``) 1138 Add space after the ``:`` only (space may be added before if 1139 needed for ``AlignConsecutiveBitFields``). 1140 1141 .. code-block:: c++ 1142 1143 unsigned bf: 2; 1144 1145 1146 1147**BraceWrapping** (``BraceWrappingFlags``) 1148 Control of individual brace wrapping cases. 1149 1150 If ``BreakBeforeBraces`` is set to ``BS_Custom``, use this to specify how 1151 each individual brace case should be handled. Otherwise, this is ignored. 1152 1153 .. code-block:: yaml 1154 1155 # Example of usage: 1156 BreakBeforeBraces: Custom 1157 BraceWrapping: 1158 AfterEnum: true 1159 AfterStruct: false 1160 SplitEmptyFunction: false 1161 1162 Nested configuration flags: 1163 1164 1165 * ``bool AfterCaseLabel`` Wrap case labels. 1166 1167 .. code-block:: c++ 1168 1169 false: true: 1170 switch (foo) { vs. switch (foo) { 1171 case 1: { case 1: 1172 bar(); { 1173 break; bar(); 1174 } break; 1175 default: { } 1176 plop(); default: 1177 } { 1178 } plop(); 1179 } 1180 } 1181 1182 * ``bool AfterClass`` Wrap class definitions. 1183 1184 .. code-block:: c++ 1185 1186 true: 1187 class foo {}; 1188 1189 false: 1190 class foo 1191 {}; 1192 1193 * ``BraceWrappingAfterControlStatementStyle AfterControlStatement`` 1194 Wrap control statements (``if``/``for``/``while``/``switch``/..). 1195 1196 Possible values: 1197 1198 * ``BWACS_Never`` (in configuration: ``Never``) 1199 Never wrap braces after a control statement. 1200 1201 .. code-block:: c++ 1202 1203 if (foo()) { 1204 } else { 1205 } 1206 for (int i = 0; i < 10; ++i) { 1207 } 1208 1209 * ``BWACS_MultiLine`` (in configuration: ``MultiLine``) 1210 Only wrap braces after a multi-line control statement. 1211 1212 .. code-block:: c++ 1213 1214 if (foo && bar && 1215 baz) 1216 { 1217 quux(); 1218 } 1219 while (foo || bar) { 1220 } 1221 1222 * ``BWACS_Always`` (in configuration: ``Always``) 1223 Always wrap braces after a control statement. 1224 1225 .. code-block:: c++ 1226 1227 if (foo()) 1228 { 1229 } else 1230 {} 1231 for (int i = 0; i < 10; ++i) 1232 {} 1233 1234 1235 * ``bool AfterEnum`` Wrap enum definitions. 1236 1237 .. code-block:: c++ 1238 1239 true: 1240 enum X : int 1241 { 1242 B 1243 }; 1244 1245 false: 1246 enum X : int { B }; 1247 1248 * ``bool AfterFunction`` Wrap function definitions. 1249 1250 .. code-block:: c++ 1251 1252 true: 1253 void foo() 1254 { 1255 bar(); 1256 bar2(); 1257 } 1258 1259 false: 1260 void foo() { 1261 bar(); 1262 bar2(); 1263 } 1264 1265 * ``bool AfterNamespace`` Wrap namespace definitions. 1266 1267 .. code-block:: c++ 1268 1269 true: 1270 namespace 1271 { 1272 int foo(); 1273 int bar(); 1274 } 1275 1276 false: 1277 namespace { 1278 int foo(); 1279 int bar(); 1280 } 1281 1282 * ``bool AfterObjCDeclaration`` Wrap ObjC definitions (interfaces, implementations...). 1283 @autoreleasepool and @synchronized blocks are wrapped 1284 according to `AfterControlStatement` flag. 1285 1286 * ``bool AfterStruct`` Wrap struct definitions. 1287 1288 .. code-block:: c++ 1289 1290 true: 1291 struct foo 1292 { 1293 int x; 1294 }; 1295 1296 false: 1297 struct foo { 1298 int x; 1299 }; 1300 1301 * ``bool AfterUnion`` Wrap union definitions. 1302 1303 .. code-block:: c++ 1304 1305 true: 1306 union foo 1307 { 1308 int x; 1309 } 1310 1311 false: 1312 union foo { 1313 int x; 1314 } 1315 1316 * ``bool AfterExternBlock`` Wrap extern blocks. 1317 1318 .. code-block:: c++ 1319 1320 true: 1321 extern "C" 1322 { 1323 int foo(); 1324 } 1325 1326 false: 1327 extern "C" { 1328 int foo(); 1329 } 1330 1331 * ``bool BeforeCatch`` Wrap before ``catch``. 1332 1333 .. code-block:: c++ 1334 1335 true: 1336 try { 1337 foo(); 1338 } 1339 catch () { 1340 } 1341 1342 false: 1343 try { 1344 foo(); 1345 } catch () { 1346 } 1347 1348 * ``bool BeforeElse`` Wrap before ``else``. 1349 1350 .. code-block:: c++ 1351 1352 true: 1353 if (foo()) { 1354 } 1355 else { 1356 } 1357 1358 false: 1359 if (foo()) { 1360 } else { 1361 } 1362 1363 * ``bool BeforeLambdaBody`` Wrap lambda block. 1364 1365 .. code-block:: c++ 1366 1367 true: 1368 connect( 1369 []() 1370 { 1371 foo(); 1372 bar(); 1373 }); 1374 1375 false: 1376 connect([]() { 1377 foo(); 1378 bar(); 1379 }); 1380 1381 * ``bool BeforeWhile`` Wrap before ``while``. 1382 1383 .. code-block:: c++ 1384 1385 true: 1386 do { 1387 foo(); 1388 } 1389 while (1); 1390 1391 false: 1392 do { 1393 foo(); 1394 } while (1); 1395 1396 * ``bool IndentBraces`` Indent the wrapped braces themselves. 1397 1398 * ``bool SplitEmptyFunction`` If ``false``, empty function body can be put on a single line. 1399 This option is used only if the opening brace of the function has 1400 already been wrapped, i.e. the `AfterFunction` brace wrapping mode is 1401 set, and the function could/should not be put on a single line (as per 1402 `AllowShortFunctionsOnASingleLine` and constructor formatting options). 1403 1404 .. code-block:: c++ 1405 1406 int f() vs. int f() 1407 {} { 1408 } 1409 1410 * ``bool SplitEmptyRecord`` If ``false``, empty record (e.g. class, struct or union) body 1411 can be put on a single line. This option is used only if the opening 1412 brace of the record has already been wrapped, i.e. the `AfterClass` 1413 (for classes) brace wrapping mode is set. 1414 1415 .. code-block:: c++ 1416 1417 class Foo vs. class Foo 1418 {} { 1419 } 1420 1421 * ``bool SplitEmptyNamespace`` If ``false``, empty namespace body can be put on a single line. 1422 This option is used only if the opening brace of the namespace has 1423 already been wrapped, i.e. the `AfterNamespace` brace wrapping mode is 1424 set. 1425 1426 .. code-block:: c++ 1427 1428 namespace Foo vs. namespace Foo 1429 {} { 1430 } 1431 1432 1433**BreakAfterJavaFieldAnnotations** (``bool``) 1434 Break after each annotation on a field in Java files. 1435 1436 .. code-block:: java 1437 1438 true: false: 1439 @Partial vs. @Partial @Mock DataLoad loader; 1440 @Mock 1441 DataLoad loader; 1442 1443**BreakBeforeBinaryOperators** (``BinaryOperatorStyle``) 1444 The way to wrap binary operators. 1445 1446 Possible values: 1447 1448 * ``BOS_None`` (in configuration: ``None``) 1449 Break after operators. 1450 1451 .. code-block:: c++ 1452 1453 LooooooooooongType loooooooooooooooooooooongVariable = 1454 someLooooooooooooooooongFunction(); 1455 1456 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + 1457 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa == 1458 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa && 1459 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa > 1460 ccccccccccccccccccccccccccccccccccccccccc; 1461 1462 * ``BOS_NonAssignment`` (in configuration: ``NonAssignment``) 1463 Break before operators that aren't assignments. 1464 1465 .. code-block:: c++ 1466 1467 LooooooooooongType loooooooooooooooooooooongVariable = 1468 someLooooooooooooooooongFunction(); 1469 1470 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 1471 + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 1472 == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 1473 && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 1474 > ccccccccccccccccccccccccccccccccccccccccc; 1475 1476 * ``BOS_All`` (in configuration: ``All``) 1477 Break before operators. 1478 1479 .. code-block:: c++ 1480 1481 LooooooooooongType loooooooooooooooooooooongVariable 1482 = someLooooooooooooooooongFunction(); 1483 1484 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 1485 + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 1486 == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 1487 && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 1488 > ccccccccccccccccccccccccccccccccccccccccc; 1489 1490 1491 1492**BreakBeforeBraces** (``BraceBreakingStyle``) 1493 The brace breaking style to use. 1494 1495 Possible values: 1496 1497 * ``BS_Attach`` (in configuration: ``Attach``) 1498 Always attach braces to surrounding context. 1499 1500 .. code-block:: c++ 1501 1502 namespace N { 1503 enum E { 1504 E1, 1505 E2, 1506 }; 1507 1508 class C { 1509 public: 1510 C(); 1511 }; 1512 1513 bool baz(int i) { 1514 try { 1515 do { 1516 switch (i) { 1517 case 1: { 1518 foobar(); 1519 break; 1520 } 1521 default: { 1522 break; 1523 } 1524 } 1525 } while (--i); 1526 return true; 1527 } catch (...) { 1528 handleError(); 1529 return false; 1530 } 1531 } 1532 1533 void foo(bool b) { 1534 if (b) { 1535 baz(2); 1536 } else { 1537 baz(5); 1538 } 1539 } 1540 1541 void bar() { foo(true); } 1542 } // namespace N 1543 1544 * ``BS_Linux`` (in configuration: ``Linux``) 1545 Like ``Attach``, but break before braces on function, namespace and 1546 class definitions. 1547 1548 .. code-block:: c++ 1549 1550 namespace N 1551 { 1552 enum E { 1553 E1, 1554 E2, 1555 }; 1556 1557 class C 1558 { 1559 public: 1560 C(); 1561 }; 1562 1563 bool baz(int i) 1564 { 1565 try { 1566 do { 1567 switch (i) { 1568 case 1: { 1569 foobar(); 1570 break; 1571 } 1572 default: { 1573 break; 1574 } 1575 } 1576 } while (--i); 1577 return true; 1578 } catch (...) { 1579 handleError(); 1580 return false; 1581 } 1582 } 1583 1584 void foo(bool b) 1585 { 1586 if (b) { 1587 baz(2); 1588 } else { 1589 baz(5); 1590 } 1591 } 1592 1593 void bar() { foo(true); } 1594 } // namespace N 1595 1596 * ``BS_Mozilla`` (in configuration: ``Mozilla``) 1597 Like ``Attach``, but break before braces on enum, function, and record 1598 definitions. 1599 1600 .. code-block:: c++ 1601 1602 namespace N { 1603 enum E 1604 { 1605 E1, 1606 E2, 1607 }; 1608 1609 class C 1610 { 1611 public: 1612 C(); 1613 }; 1614 1615 bool baz(int i) 1616 { 1617 try { 1618 do { 1619 switch (i) { 1620 case 1: { 1621 foobar(); 1622 break; 1623 } 1624 default: { 1625 break; 1626 } 1627 } 1628 } while (--i); 1629 return true; 1630 } catch (...) { 1631 handleError(); 1632 return false; 1633 } 1634 } 1635 1636 void foo(bool b) 1637 { 1638 if (b) { 1639 baz(2); 1640 } else { 1641 baz(5); 1642 } 1643 } 1644 1645 void bar() { foo(true); } 1646 } // namespace N 1647 1648 * ``BS_Stroustrup`` (in configuration: ``Stroustrup``) 1649 Like ``Attach``, but break before function definitions, ``catch``, and 1650 ``else``. 1651 1652 .. code-block:: c++ 1653 1654 namespace N { 1655 enum E { 1656 E1, 1657 E2, 1658 }; 1659 1660 class C { 1661 public: 1662 C(); 1663 }; 1664 1665 bool baz(int i) 1666 { 1667 try { 1668 do { 1669 switch (i) { 1670 case 1: { 1671 foobar(); 1672 break; 1673 } 1674 default: { 1675 break; 1676 } 1677 } 1678 } while (--i); 1679 return true; 1680 } 1681 catch (...) { 1682 handleError(); 1683 return false; 1684 } 1685 } 1686 1687 void foo(bool b) 1688 { 1689 if (b) { 1690 baz(2); 1691 } 1692 else { 1693 baz(5); 1694 } 1695 } 1696 1697 void bar() { foo(true); } 1698 } // namespace N 1699 1700 * ``BS_Allman`` (in configuration: ``Allman``) 1701 Always break before braces. 1702 1703 .. code-block:: c++ 1704 1705 namespace N 1706 { 1707 enum E 1708 { 1709 E1, 1710 E2, 1711 }; 1712 1713 class C 1714 { 1715 public: 1716 C(); 1717 }; 1718 1719 bool baz(int i) 1720 { 1721 try 1722 { 1723 do 1724 { 1725 switch (i) 1726 { 1727 case 1: 1728 { 1729 foobar(); 1730 break; 1731 } 1732 default: 1733 { 1734 break; 1735 } 1736 } 1737 } while (--i); 1738 return true; 1739 } 1740 catch (...) 1741 { 1742 handleError(); 1743 return false; 1744 } 1745 } 1746 1747 void foo(bool b) 1748 { 1749 if (b) 1750 { 1751 baz(2); 1752 } 1753 else 1754 { 1755 baz(5); 1756 } 1757 } 1758 1759 void bar() { foo(true); } 1760 } // namespace N 1761 1762 * ``BS_Whitesmiths`` (in configuration: ``Whitesmiths``) 1763 Like ``Allman`` but always indent braces and line up code with braces. 1764 1765 .. code-block:: c++ 1766 1767 namespace N 1768 { 1769 enum E 1770 { 1771 E1, 1772 E2, 1773 }; 1774 1775 class C 1776 { 1777 public: 1778 C(); 1779 }; 1780 1781 bool baz(int i) 1782 { 1783 try 1784 { 1785 do 1786 { 1787 switch (i) 1788 { 1789 case 1: 1790 { 1791 foobar(); 1792 break; 1793 } 1794 default: 1795 { 1796 break; 1797 } 1798 } 1799 } while (--i); 1800 return true; 1801 } 1802 catch (...) 1803 { 1804 handleError(); 1805 return false; 1806 } 1807 } 1808 1809 void foo(bool b) 1810 { 1811 if (b) 1812 { 1813 baz(2); 1814 } 1815 else 1816 { 1817 baz(5); 1818 } 1819 } 1820 1821 void bar() { foo(true); } 1822 } // namespace N 1823 1824 * ``BS_GNU`` (in configuration: ``GNU``) 1825 Always break before braces and add an extra level of indentation to 1826 braces of control statements, not to those of class, function 1827 or other definitions. 1828 1829 .. code-block:: c++ 1830 1831 namespace N 1832 { 1833 enum E 1834 { 1835 E1, 1836 E2, 1837 }; 1838 1839 class C 1840 { 1841 public: 1842 C(); 1843 }; 1844 1845 bool baz(int i) 1846 { 1847 try 1848 { 1849 do 1850 { 1851 switch (i) 1852 { 1853 case 1: 1854 { 1855 foobar(); 1856 break; 1857 } 1858 default: 1859 { 1860 break; 1861 } 1862 } 1863 } 1864 while (--i); 1865 return true; 1866 } 1867 catch (...) 1868 { 1869 handleError(); 1870 return false; 1871 } 1872 } 1873 1874 void foo(bool b) 1875 { 1876 if (b) 1877 { 1878 baz(2); 1879 } 1880 else 1881 { 1882 baz(5); 1883 } 1884 } 1885 1886 void bar() { foo(true); } 1887 } // namespace N 1888 1889 * ``BS_WebKit`` (in configuration: ``WebKit``) 1890 Like ``Attach``, but break before functions. 1891 1892 .. code-block:: c++ 1893 1894 namespace N { 1895 enum E { 1896 E1, 1897 E2, 1898 }; 1899 1900 class C { 1901 public: 1902 C(); 1903 }; 1904 1905 bool baz(int i) 1906 { 1907 try { 1908 do { 1909 switch (i) { 1910 case 1: { 1911 foobar(); 1912 break; 1913 } 1914 default: { 1915 break; 1916 } 1917 } 1918 } while (--i); 1919 return true; 1920 } catch (...) { 1921 handleError(); 1922 return false; 1923 } 1924 } 1925 1926 void foo(bool b) 1927 { 1928 if (b) { 1929 baz(2); 1930 } else { 1931 baz(5); 1932 } 1933 } 1934 1935 void bar() { foo(true); } 1936 } // namespace N 1937 1938 * ``BS_Custom`` (in configuration: ``Custom``) 1939 Configure each individual brace in `BraceWrapping`. 1940 1941 1942 1943**BreakBeforeConceptDeclarations** (``bool``) 1944 If ``true``, concept will be placed on a new line. 1945 1946 .. code-block:: c++ 1947 1948 true: 1949 template<typename T> 1950 concept ... 1951 1952 false: 1953 template<typename T> concept ... 1954 1955**BreakBeforeTernaryOperators** (``bool``) 1956 If ``true``, ternary operators will be placed after line breaks. 1957 1958 .. code-block:: c++ 1959 1960 true: 1961 veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription 1962 ? firstValue 1963 : SecondValueVeryVeryVeryVeryLong; 1964 1965 false: 1966 veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ? 1967 firstValue : 1968 SecondValueVeryVeryVeryVeryLong; 1969 1970**BreakConstructorInitializers** (``BreakConstructorInitializersStyle``) 1971 The constructor initializers style to use. 1972 1973 Possible values: 1974 1975 * ``BCIS_BeforeColon`` (in configuration: ``BeforeColon``) 1976 Break constructor initializers before the colon and after the commas. 1977 1978 .. code-block:: c++ 1979 1980 Constructor() 1981 : initializer1(), 1982 initializer2() 1983 1984 * ``BCIS_BeforeComma`` (in configuration: ``BeforeComma``) 1985 Break constructor initializers before the colon and commas, and align 1986 the commas with the colon. 1987 1988 .. code-block:: c++ 1989 1990 Constructor() 1991 : initializer1() 1992 , initializer2() 1993 1994 * ``BCIS_AfterColon`` (in configuration: ``AfterColon``) 1995 Break constructor initializers after the colon and commas. 1996 1997 .. code-block:: c++ 1998 1999 Constructor() : 2000 initializer1(), 2001 initializer2() 2002 2003 2004 2005**BreakInheritanceList** (``BreakInheritanceListStyle``) 2006 The inheritance list style to use. 2007 2008 Possible values: 2009 2010 * ``BILS_BeforeColon`` (in configuration: ``BeforeColon``) 2011 Break inheritance list before the colon and after the commas. 2012 2013 .. code-block:: c++ 2014 2015 class Foo 2016 : Base1, 2017 Base2 2018 {}; 2019 2020 * ``BILS_BeforeComma`` (in configuration: ``BeforeComma``) 2021 Break inheritance list before the colon and commas, and align 2022 the commas with the colon. 2023 2024 .. code-block:: c++ 2025 2026 class Foo 2027 : Base1 2028 , Base2 2029 {}; 2030 2031 * ``BILS_AfterColon`` (in configuration: ``AfterColon``) 2032 Break inheritance list after the colon and commas. 2033 2034 .. code-block:: c++ 2035 2036 class Foo : 2037 Base1, 2038 Base2 2039 {}; 2040 2041 * ``BILS_AfterComma`` (in configuration: ``AfterComma``) 2042 Break inheritance list only after the commas. 2043 2044 .. code-block:: c++ 2045 2046 class Foo : Base1, 2047 Base2 2048 {}; 2049 2050 2051 2052**BreakStringLiterals** (``bool``) 2053 Allow breaking string literals when formatting. 2054 2055 .. code-block:: c++ 2056 2057 true: 2058 const char* x = "veryVeryVeryVeryVeryVe" 2059 "ryVeryVeryVeryVeryVery" 2060 "VeryLongString"; 2061 2062 false: 2063 const char* x = 2064 "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString"; 2065 2066**ColumnLimit** (``unsigned``) 2067 The column limit. 2068 2069 A column limit of ``0`` means that there is no column limit. In this case, 2070 clang-format will respect the input's line breaking decisions within 2071 statements unless they contradict other rules. 2072 2073**CommentPragmas** (``std::string``) 2074 A regular expression that describes comments with special meaning, 2075 which should not be split into lines or otherwise changed. 2076 2077 .. code-block:: c++ 2078 2079 // CommentPragmas: '^ FOOBAR pragma:' 2080 // Will leave the following line unaffected 2081 #include <vector> // FOOBAR pragma: keep 2082 2083**CompactNamespaces** (``bool``) 2084 If ``true``, consecutive namespace declarations will be on the same 2085 line. If ``false``, each namespace is declared on a new line. 2086 2087 .. code-block:: c++ 2088 2089 true: 2090 namespace Foo { namespace Bar { 2091 }} 2092 2093 false: 2094 namespace Foo { 2095 namespace Bar { 2096 } 2097 } 2098 2099 If it does not fit on a single line, the overflowing namespaces get 2100 wrapped: 2101 2102 .. code-block:: c++ 2103 2104 namespace Foo { namespace Bar { 2105 namespace Extra { 2106 }}} 2107 2108**ConstructorInitializerAllOnOneLineOrOnePerLine** (``bool``) 2109 If the constructor initializers don't fit on a line, put each 2110 initializer on its own line. 2111 2112 .. code-block:: c++ 2113 2114 true: 2115 SomeClass::Constructor() 2116 : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) { 2117 return 0; 2118 } 2119 2120 false: 2121 SomeClass::Constructor() 2122 : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa), 2123 aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) { 2124 return 0; 2125 } 2126 2127**ConstructorInitializerIndentWidth** (``unsigned``) 2128 The number of characters to use for indentation of constructor 2129 initializer lists as well as inheritance lists. 2130 2131**ContinuationIndentWidth** (``unsigned``) 2132 Indent width for line continuations. 2133 2134 .. code-block:: c++ 2135 2136 ContinuationIndentWidth: 2 2137 2138 int i = // VeryVeryVeryVeryVeryLongComment 2139 longFunction( // Again a long comment 2140 arg); 2141 2142**Cpp11BracedListStyle** (``bool``) 2143 If ``true``, format braced lists as best suited for C++11 braced 2144 lists. 2145 2146 Important differences: 2147 - No spaces inside the braced list. 2148 - No line break before the closing brace. 2149 - Indentation with the continuation indent, not with the block indent. 2150 2151 Fundamentally, C++11 braced lists are formatted exactly like function 2152 calls would be formatted in their place. If the braced list follows a name 2153 (e.g. a type or variable name), clang-format formats as if the ``{}`` were 2154 the parentheses of a function call with that name. If there is no name, 2155 a zero-length name is assumed. 2156 2157 .. code-block:: c++ 2158 2159 true: false: 2160 vector<int> x{1, 2, 3, 4}; vs. vector<int> x{ 1, 2, 3, 4 }; 2161 vector<T> x{{}, {}, {}, {}}; vector<T> x{ {}, {}, {}, {} }; 2162 f(MyMap[{composite, key}]); f(MyMap[{ composite, key }]); 2163 new int[3]{1, 2, 3}; new int[3]{ 1, 2, 3 }; 2164 2165**DeriveLineEnding** (``bool``) 2166 Analyze the formatted file for the most used line ending (``\r\n`` 2167 or ``\n``). ``UseCRLF`` is only used as a fallback if none can be derived. 2168 2169**DerivePointerAlignment** (``bool``) 2170 If ``true``, analyze the formatted file for the most common 2171 alignment of ``&`` and ``*``. 2172 Pointer and reference alignment styles are going to be updated according 2173 to the preferences found in the file. 2174 ``PointerAlignment`` is then used only as fallback. 2175 2176**DisableFormat** (``bool``) 2177 Disables formatting completely. 2178 2179**EmptyLineAfterAccessModifier** (``EmptyLineAfterAccessModifierStyle``) 2180 Defines when to put an empty line after access modifiers. 2181 ``EmptyLineBeforeAccessModifier`` configuration handles the number of 2182 empty lines between two access modifiers. 2183 2184 Possible values: 2185 2186 * ``ELAAMS_Never`` (in configuration: ``Never``) 2187 Remove all empty lines after access modifiers. 2188 2189 .. code-block:: c++ 2190 2191 struct foo { 2192 private: 2193 int i; 2194 protected: 2195 int j; 2196 /* comment */ 2197 public: 2198 foo() {} 2199 private: 2200 protected: 2201 }; 2202 2203 * ``ELAAMS_Leave`` (in configuration: ``Leave``) 2204 Keep existing empty lines after access modifiers. 2205 MaxEmptyLinesToKeep is applied instead. 2206 2207 * ``ELAAMS_Always`` (in configuration: ``Always``) 2208 Always add empty line after access modifiers if there are none. 2209 MaxEmptyLinesToKeep is applied also. 2210 2211 .. code-block:: c++ 2212 2213 struct foo { 2214 private: 2215 2216 int i; 2217 protected: 2218 2219 int j; 2220 /* comment */ 2221 public: 2222 2223 foo() {} 2224 private: 2225 2226 protected: 2227 2228 }; 2229 2230 2231 2232**EmptyLineBeforeAccessModifier** (``EmptyLineBeforeAccessModifierStyle``) 2233 Defines in which cases to put empty line before access modifiers. 2234 2235 Possible values: 2236 2237 * ``ELBAMS_Never`` (in configuration: ``Never``) 2238 Remove all empty lines before access modifiers. 2239 2240 .. code-block:: c++ 2241 2242 struct foo { 2243 private: 2244 int i; 2245 protected: 2246 int j; 2247 /* comment */ 2248 public: 2249 foo() {} 2250 private: 2251 protected: 2252 }; 2253 2254 * ``ELBAMS_Leave`` (in configuration: ``Leave``) 2255 Keep existing empty lines before access modifiers. 2256 2257 * ``ELBAMS_LogicalBlock`` (in configuration: ``LogicalBlock``) 2258 Add empty line only when access modifier starts a new logical block. 2259 Logical block is a group of one or more member fields or functions. 2260 2261 .. code-block:: c++ 2262 2263 struct foo { 2264 private: 2265 int i; 2266 2267 protected: 2268 int j; 2269 /* comment */ 2270 public: 2271 foo() {} 2272 2273 private: 2274 protected: 2275 }; 2276 2277 * ``ELBAMS_Always`` (in configuration: ``Always``) 2278 Always add empty line before access modifiers unless access modifier 2279 is at the start of struct or class definition. 2280 2281 .. code-block:: c++ 2282 2283 struct foo { 2284 private: 2285 int i; 2286 2287 protected: 2288 int j; 2289 /* comment */ 2290 2291 public: 2292 foo() {} 2293 2294 private: 2295 2296 protected: 2297 }; 2298 2299 2300 2301**ExperimentalAutoDetectBinPacking** (``bool``) 2302 If ``true``, clang-format detects whether function calls and 2303 definitions are formatted with one parameter per line. 2304 2305 Each call can be bin-packed, one-per-line or inconclusive. If it is 2306 inconclusive, e.g. completely on one line, but a decision needs to be 2307 made, clang-format analyzes whether there are other bin-packed cases in 2308 the input file and act accordingly. 2309 2310 NOTE: This is an experimental flag, that might go away or be renamed. Do 2311 not use this in config files, etc. Use at your own risk. 2312 2313**FixNamespaceComments** (``bool``) 2314 If ``true``, clang-format adds missing namespace end comments for 2315 short namespaces and fixes invalid existing ones. Short ones are 2316 controlled by "ShortNamespaceLines". 2317 2318 .. code-block:: c++ 2319 2320 true: false: 2321 namespace a { vs. namespace a { 2322 foo(); foo(); 2323 bar(); bar(); 2324 } // namespace a } 2325 2326**ForEachMacros** (``std::vector<std::string>``) 2327 A vector of macros that should be interpreted as foreach loops 2328 instead of as function calls. 2329 2330 These are expected to be macros of the form: 2331 2332 .. code-block:: c++ 2333 2334 FOREACH(<variable-declaration>, ...) 2335 <loop-body> 2336 2337 In the .clang-format configuration file, this can be configured like: 2338 2339 .. code-block:: yaml 2340 2341 ForEachMacros: ['RANGES_FOR', 'FOREACH'] 2342 2343 For example: BOOST_FOREACH. 2344 2345**IncludeBlocks** (``IncludeBlocksStyle``) 2346 Dependent on the value, multiple ``#include`` blocks can be sorted 2347 as one and divided based on category. 2348 2349 Possible values: 2350 2351 * ``IBS_Preserve`` (in configuration: ``Preserve``) 2352 Sort each ``#include`` block separately. 2353 2354 .. code-block:: c++ 2355 2356 #include "b.h" into #include "b.h" 2357 2358 #include <lib/main.h> #include "a.h" 2359 #include "a.h" #include <lib/main.h> 2360 2361 * ``IBS_Merge`` (in configuration: ``Merge``) 2362 Merge multiple ``#include`` blocks together and sort as one. 2363 2364 .. code-block:: c++ 2365 2366 #include "b.h" into #include "a.h" 2367 #include "b.h" 2368 #include <lib/main.h> #include <lib/main.h> 2369 #include "a.h" 2370 2371 * ``IBS_Regroup`` (in configuration: ``Regroup``) 2372 Merge multiple ``#include`` blocks together and sort as one. 2373 Then split into groups based on category priority. See 2374 ``IncludeCategories``. 2375 2376 .. code-block:: c++ 2377 2378 #include "b.h" into #include "a.h" 2379 #include "b.h" 2380 #include <lib/main.h> 2381 #include "a.h" #include <lib/main.h> 2382 2383 2384 2385**IncludeCategories** (``std::vector<IncludeCategory>``) 2386 Regular expressions denoting the different ``#include`` categories 2387 used for ordering ``#includes``. 2388 2389 `POSIX extended 2390 <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html>`_ 2391 regular expressions are supported. 2392 2393 These regular expressions are matched against the filename of an include 2394 (including the <> or "") in order. The value belonging to the first 2395 matching regular expression is assigned and ``#includes`` are sorted first 2396 according to increasing category number and then alphabetically within 2397 each category. 2398 2399 If none of the regular expressions match, INT_MAX is assigned as 2400 category. The main header for a source file automatically gets category 0. 2401 so that it is generally kept at the beginning of the ``#includes`` 2402 (https://llvm.org/docs/CodingStandards.html#include-style). However, you 2403 can also assign negative priorities if you have certain headers that 2404 always need to be first. 2405 2406 There is a third and optional field ``SortPriority`` which can used while 2407 ``IncludeBlocks = IBS_Regroup`` to define the priority in which 2408 ``#includes`` should be ordered. The value of ``Priority`` defines the 2409 order of ``#include blocks`` and also allows the grouping of ``#includes`` 2410 of different priority. ``SortPriority`` is set to the value of 2411 ``Priority`` as default if it is not assigned. 2412 2413 Each regular expression can be marked as case sensitive with the field 2414 ``CaseSensitive``, per default it is not. 2415 2416 To configure this in the .clang-format file, use: 2417 2418 .. code-block:: yaml 2419 2420 IncludeCategories: 2421 - Regex: '^"(llvm|llvm-c|clang|clang-c)/' 2422 Priority: 2 2423 SortPriority: 2 2424 CaseSensitive: true 2425 - Regex: '^(<|"(gtest|gmock|isl|json)/)' 2426 Priority: 3 2427 - Regex: '<[[:alnum:].]+>' 2428 Priority: 4 2429 - Regex: '.*' 2430 Priority: 1 2431 SortPriority: 0 2432 2433**IncludeIsMainRegex** (``std::string``) 2434 Specify a regular expression of suffixes that are allowed in the 2435 file-to-main-include mapping. 2436 2437 When guessing whether a #include is the "main" include (to assign 2438 category 0, see above), use this regex of allowed suffixes to the header 2439 stem. A partial match is done, so that: 2440 - "" means "arbitrary suffix" 2441 - "$" means "no suffix" 2442 2443 For example, if configured to "(_test)?$", then a header a.h would be seen 2444 as the "main" include in both a.cc and a_test.cc. 2445 2446**IncludeIsMainSourceRegex** (``std::string``) 2447 Specify a regular expression for files being formatted 2448 that are allowed to be considered "main" in the 2449 file-to-main-include mapping. 2450 2451 By default, clang-format considers files as "main" only when they end 2452 with: ``.c``, ``.cc``, ``.cpp``, ``.c++``, ``.cxx``, ``.m`` or ``.mm`` 2453 extensions. 2454 For these files a guessing of "main" include takes place 2455 (to assign category 0, see above). This config option allows for 2456 additional suffixes and extensions for files to be considered as "main". 2457 2458 For example, if this option is configured to ``(Impl\.hpp)$``, 2459 then a file ``ClassImpl.hpp`` is considered "main" (in addition to 2460 ``Class.c``, ``Class.cc``, ``Class.cpp`` and so on) and "main 2461 include file" logic will be executed (with *IncludeIsMainRegex* setting 2462 also being respected in later phase). Without this option set, 2463 ``ClassImpl.hpp`` would not have the main include file put on top 2464 before any other include. 2465 2466**IndentAccessModifiers** (``bool``) 2467 Specify whether access modifiers should have their own indentation level. 2468 2469 When ``false``, access modifiers are indented (or outdented) relative to 2470 the record members, respecting the ``AccessModifierOffset``. Record 2471 members are indented one level below the record. 2472 When ``true``, access modifiers get their own indentation level. As a 2473 consequence, record members are always indented 2 levels below the record, 2474 regardless of the access modifier presence. Value of the 2475 ``AccessModifierOffset`` is ignored. 2476 2477 .. code-block:: c++ 2478 2479 false: true: 2480 class C { vs. class C { 2481 class D { class D { 2482 void bar(); void bar(); 2483 protected: protected: 2484 D(); D(); 2485 }; }; 2486 public: public: 2487 C(); C(); 2488 }; }; 2489 void foo() { void foo() { 2490 return 1; return 1; 2491 } } 2492 2493**IndentCaseBlocks** (``bool``) 2494 Indent case label blocks one level from the case label. 2495 2496 When ``false``, the block following the case label uses the same 2497 indentation level as for the case label, treating the case label the same 2498 as an if-statement. 2499 When ``true``, the block gets indented as a scope block. 2500 2501 .. code-block:: c++ 2502 2503 false: true: 2504 switch (fool) { vs. switch (fool) { 2505 case 1: { case 1: 2506 bar(); { 2507 } break; bar(); 2508 default: { } 2509 plop(); break; 2510 } default: 2511 } { 2512 plop(); 2513 } 2514 } 2515 2516**IndentCaseLabels** (``bool``) 2517 Indent case labels one level from the switch statement. 2518 2519 When ``false``, use the same indentation level as for the switch 2520 statement. Switch statement body is always indented one level more than 2521 case labels (except the first block following the case label, which 2522 itself indents the code - unless IndentCaseBlocks is enabled). 2523 2524 .. code-block:: c++ 2525 2526 false: true: 2527 switch (fool) { vs. switch (fool) { 2528 case 1: case 1: 2529 bar(); bar(); 2530 break; break; 2531 default: default: 2532 plop(); plop(); 2533 } } 2534 2535**IndentExternBlock** (``IndentExternBlockStyle``) 2536 IndentExternBlockStyle is the type of indenting of extern blocks. 2537 2538 Possible values: 2539 2540 * ``IEBS_AfterExternBlock`` (in configuration: ``AfterExternBlock``) 2541 Backwards compatible with AfterExternBlock's indenting. 2542 2543 .. code-block:: c++ 2544 2545 IndentExternBlock: AfterExternBlock 2546 BraceWrapping.AfterExternBlock: true 2547 extern "C" 2548 { 2549 void foo(); 2550 } 2551 2552 2553 .. code-block:: c++ 2554 2555 IndentExternBlock: AfterExternBlock 2556 BraceWrapping.AfterExternBlock: false 2557 extern "C" { 2558 void foo(); 2559 } 2560 2561 * ``IEBS_NoIndent`` (in configuration: ``NoIndent``) 2562 Does not indent extern blocks. 2563 2564 .. code-block:: c++ 2565 2566 extern "C" { 2567 void foo(); 2568 } 2569 2570 * ``IEBS_Indent`` (in configuration: ``Indent``) 2571 Indents extern blocks. 2572 2573 .. code-block:: c++ 2574 2575 extern "C" { 2576 void foo(); 2577 } 2578 2579 2580 2581**IndentGotoLabels** (``bool``) 2582 Indent goto labels. 2583 2584 When ``false``, goto labels are flushed left. 2585 2586 .. code-block:: c++ 2587 2588 true: false: 2589 int f() { vs. int f() { 2590 if (foo()) { if (foo()) { 2591 label1: label1: 2592 bar(); bar(); 2593 } } 2594 label2: label2: 2595 return 1; return 1; 2596 } } 2597 2598**IndentPPDirectives** (``PPDirectiveIndentStyle``) 2599 The preprocessor directive indenting style to use. 2600 2601 Possible values: 2602 2603 * ``PPDIS_None`` (in configuration: ``None``) 2604 Does not indent any directives. 2605 2606 .. code-block:: c++ 2607 2608 #if FOO 2609 #if BAR 2610 #include <foo> 2611 #endif 2612 #endif 2613 2614 * ``PPDIS_AfterHash`` (in configuration: ``AfterHash``) 2615 Indents directives after the hash. 2616 2617 .. code-block:: c++ 2618 2619 #if FOO 2620 # if BAR 2621 # include <foo> 2622 # endif 2623 #endif 2624 2625 * ``PPDIS_BeforeHash`` (in configuration: ``BeforeHash``) 2626 Indents directives before the hash. 2627 2628 .. code-block:: c++ 2629 2630 #if FOO 2631 #if BAR 2632 #include <foo> 2633 #endif 2634 #endif 2635 2636 2637 2638**IndentRequires** (``bool``) 2639 Indent the requires clause in a template 2640 2641 .. code-block:: c++ 2642 2643 true: 2644 template <typename It> 2645 requires Iterator<It> 2646 void sort(It begin, It end) { 2647 //.... 2648 } 2649 2650 false: 2651 template <typename It> 2652 requires Iterator<It> 2653 void sort(It begin, It end) { 2654 //.... 2655 } 2656 2657**IndentWidth** (``unsigned``) 2658 The number of columns to use for indentation. 2659 2660 .. code-block:: c++ 2661 2662 IndentWidth: 3 2663 2664 void f() { 2665 someFunction(); 2666 if (true, false) { 2667 f(); 2668 } 2669 } 2670 2671**IndentWrappedFunctionNames** (``bool``) 2672 Indent if a function definition or declaration is wrapped after the 2673 type. 2674 2675 .. code-block:: c++ 2676 2677 true: 2678 LoooooooooooooooooooooooooooooooooooooooongReturnType 2679 LoooooooooooooooooooooooooooooooongFunctionDeclaration(); 2680 2681 false: 2682 LoooooooooooooooooooooooooooooooooooooooongReturnType 2683 LoooooooooooooooooooooooooooooooongFunctionDeclaration(); 2684 2685**InsertTrailingCommas** (``TrailingCommaStyle``) 2686 If set to ``TCS_Wrapped`` will insert trailing commas in container 2687 literals (arrays and objects) that wrap across multiple lines. 2688 It is currently only available for JavaScript 2689 and disabled by default ``TCS_None``. 2690 ``InsertTrailingCommas`` cannot be used together with ``BinPackArguments`` 2691 as inserting the comma disables bin-packing. 2692 2693 .. code-block:: c++ 2694 2695 TSC_Wrapped: 2696 const someArray = [ 2697 aaaaaaaaaaaaaaaaaaaaaaaaaa, 2698 aaaaaaaaaaaaaaaaaaaaaaaaaa, 2699 aaaaaaaaaaaaaaaaaaaaaaaaaa, 2700 // ^ inserted 2701 ] 2702 2703 Possible values: 2704 2705 * ``TCS_None`` (in configuration: ``None``) 2706 Do not insert trailing commas. 2707 2708 * ``TCS_Wrapped`` (in configuration: ``Wrapped``) 2709 Insert trailing commas in container literals that were wrapped over 2710 multiple lines. Note that this is conceptually incompatible with 2711 bin-packing, because the trailing comma is used as an indicator 2712 that a container should be formatted one-per-line (i.e. not bin-packed). 2713 So inserting a trailing comma counteracts bin-packing. 2714 2715 2716 2717**JavaImportGroups** (``std::vector<std::string>``) 2718 A vector of prefixes ordered by the desired groups for Java imports. 2719 2720 One group's prefix can be a subset of another - the longest prefix is 2721 always matched. Within a group, the imports are ordered lexicographically. 2722 Static imports are grouped separately and follow the same group rules. 2723 By default, static imports are placed before non-static imports, 2724 but this behavior is changed by another option, 2725 ``SortJavaStaticImport``. 2726 2727 In the .clang-format configuration file, this can be configured like 2728 in the following yaml example. This will result in imports being 2729 formatted as in the Java example below. 2730 2731 .. code-block:: yaml 2732 2733 JavaImportGroups: ['com.example', 'com', 'org'] 2734 2735 2736 .. code-block:: java 2737 2738 import static com.example.function1; 2739 2740 import static com.test.function2; 2741 2742 import static org.example.function3; 2743 2744 import com.example.ClassA; 2745 import com.example.Test; 2746 import com.example.a.ClassB; 2747 2748 import com.test.ClassC; 2749 2750 import org.example.ClassD; 2751 2752**JavaScriptQuotes** (``JavaScriptQuoteStyle``) 2753 The JavaScriptQuoteStyle to use for JavaScript strings. 2754 2755 Possible values: 2756 2757 * ``JSQS_Leave`` (in configuration: ``Leave``) 2758 Leave string quotes as they are. 2759 2760 .. code-block:: js 2761 2762 string1 = "foo"; 2763 string2 = 'bar'; 2764 2765 * ``JSQS_Single`` (in configuration: ``Single``) 2766 Always use single quotes. 2767 2768 .. code-block:: js 2769 2770 string1 = 'foo'; 2771 string2 = 'bar'; 2772 2773 * ``JSQS_Double`` (in configuration: ``Double``) 2774 Always use double quotes. 2775 2776 .. code-block:: js 2777 2778 string1 = "foo"; 2779 string2 = "bar"; 2780 2781 2782 2783**JavaScriptWrapImports** (``bool``) 2784 Whether to wrap JavaScript import/export statements. 2785 2786 .. code-block:: js 2787 2788 true: 2789 import { 2790 VeryLongImportsAreAnnoying, 2791 VeryLongImportsAreAnnoying, 2792 VeryLongImportsAreAnnoying, 2793 } from 'some/module.js' 2794 2795 false: 2796 import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js" 2797 2798**KeepEmptyLinesAtTheStartOfBlocks** (``bool``) 2799 If true, the empty line at the start of blocks is kept. 2800 2801 .. code-block:: c++ 2802 2803 true: false: 2804 if (foo) { vs. if (foo) { 2805 bar(); 2806 bar(); } 2807 } 2808 2809**Language** (``LanguageKind``) 2810 Language, this format style is targeted at. 2811 2812 Possible values: 2813 2814 * ``LK_None`` (in configuration: ``None``) 2815 Do not use. 2816 2817 * ``LK_Cpp`` (in configuration: ``Cpp``) 2818 Should be used for C, C++. 2819 2820 * ``LK_CSharp`` (in configuration: ``CSharp``) 2821 Should be used for C#. 2822 2823 * ``LK_Java`` (in configuration: ``Java``) 2824 Should be used for Java. 2825 2826 * ``LK_JavaScript`` (in configuration: ``JavaScript``) 2827 Should be used for JavaScript. 2828 2829 * ``LK_ObjC`` (in configuration: ``ObjC``) 2830 Should be used for Objective-C, Objective-C++. 2831 2832 * ``LK_Proto`` (in configuration: ``Proto``) 2833 Should be used for Protocol Buffers 2834 (https://developers.google.com/protocol-buffers/). 2835 2836 * ``LK_TableGen`` (in configuration: ``TableGen``) 2837 Should be used for TableGen code. 2838 2839 * ``LK_TextProto`` (in configuration: ``TextProto``) 2840 Should be used for Protocol Buffer messages in text format 2841 (https://developers.google.com/protocol-buffers/). 2842 2843 2844 2845**MacroBlockBegin** (``std::string``) 2846 A regular expression matching macros that start a block. 2847 2848 .. code-block:: c++ 2849 2850 # With: 2851 MacroBlockBegin: "^NS_MAP_BEGIN|\ 2852 NS_TABLE_HEAD$" 2853 MacroBlockEnd: "^\ 2854 NS_MAP_END|\ 2855 NS_TABLE_.*_END$" 2856 2857 NS_MAP_BEGIN 2858 foo(); 2859 NS_MAP_END 2860 2861 NS_TABLE_HEAD 2862 bar(); 2863 NS_TABLE_FOO_END 2864 2865 # Without: 2866 NS_MAP_BEGIN 2867 foo(); 2868 NS_MAP_END 2869 2870 NS_TABLE_HEAD 2871 bar(); 2872 NS_TABLE_FOO_END 2873 2874**MacroBlockEnd** (``std::string``) 2875 A regular expression matching macros that end a block. 2876 2877**MaxEmptyLinesToKeep** (``unsigned``) 2878 The maximum number of consecutive empty lines to keep. 2879 2880 .. code-block:: c++ 2881 2882 MaxEmptyLinesToKeep: 1 vs. MaxEmptyLinesToKeep: 0 2883 int f() { int f() { 2884 int = 1; int i = 1; 2885 i = foo(); 2886 i = foo(); return i; 2887 } 2888 return i; 2889 } 2890 2891**NamespaceIndentation** (``NamespaceIndentationKind``) 2892 The indentation used for namespaces. 2893 2894 Possible values: 2895 2896 * ``NI_None`` (in configuration: ``None``) 2897 Don't indent in namespaces. 2898 2899 .. code-block:: c++ 2900 2901 namespace out { 2902 int i; 2903 namespace in { 2904 int i; 2905 } 2906 } 2907 2908 * ``NI_Inner`` (in configuration: ``Inner``) 2909 Indent only in inner namespaces (nested in other namespaces). 2910 2911 .. code-block:: c++ 2912 2913 namespace out { 2914 int i; 2915 namespace in { 2916 int i; 2917 } 2918 } 2919 2920 * ``NI_All`` (in configuration: ``All``) 2921 Indent in all namespaces. 2922 2923 .. code-block:: c++ 2924 2925 namespace out { 2926 int i; 2927 namespace in { 2928 int i; 2929 } 2930 } 2931 2932 2933 2934**NamespaceMacros** (``std::vector<std::string>``) 2935 A vector of macros which are used to open namespace blocks. 2936 2937 These are expected to be macros of the form: 2938 2939 .. code-block:: c++ 2940 2941 NAMESPACE(<namespace-name>, ...) { 2942 <namespace-content> 2943 } 2944 2945 For example: TESTSUITE 2946 2947**ObjCBinPackProtocolList** (``BinPackStyle``) 2948 Controls bin-packing Objective-C protocol conformance list 2949 items into as few lines as possible when they go over ``ColumnLimit``. 2950 2951 If ``Auto`` (the default), delegates to the value in 2952 ``BinPackParameters``. If that is ``true``, bin-packs Objective-C 2953 protocol conformance list items into as few lines as possible 2954 whenever they go over ``ColumnLimit``. 2955 2956 If ``Always``, always bin-packs Objective-C protocol conformance 2957 list items into as few lines as possible whenever they go over 2958 ``ColumnLimit``. 2959 2960 If ``Never``, lays out Objective-C protocol conformance list items 2961 onto individual lines whenever they go over ``ColumnLimit``. 2962 2963 2964 .. code-block:: objc 2965 2966 Always (or Auto, if BinPackParameters=true): 2967 @interface ccccccccccccc () < 2968 ccccccccccccc, ccccccccccccc, 2969 ccccccccccccc, ccccccccccccc> { 2970 } 2971 2972 Never (or Auto, if BinPackParameters=false): 2973 @interface ddddddddddddd () < 2974 ddddddddddddd, 2975 ddddddddddddd, 2976 ddddddddddddd, 2977 ddddddddddddd> { 2978 } 2979 2980 Possible values: 2981 2982 * ``BPS_Auto`` (in configuration: ``Auto``) 2983 Automatically determine parameter bin-packing behavior. 2984 2985 * ``BPS_Always`` (in configuration: ``Always``) 2986 Always bin-pack parameters. 2987 2988 * ``BPS_Never`` (in configuration: ``Never``) 2989 Never bin-pack parameters. 2990 2991 2992 2993**ObjCBlockIndentWidth** (``unsigned``) 2994 The number of characters to use for indentation of ObjC blocks. 2995 2996 .. code-block:: objc 2997 2998 ObjCBlockIndentWidth: 4 2999 3000 [operation setCompletionBlock:^{ 3001 [self onOperationDone]; 3002 }]; 3003 3004**ObjCBreakBeforeNestedBlockParam** (``bool``) 3005 Break parameters list into lines when there is nested block 3006 parameters in a function call. 3007 3008 .. code-block:: c++ 3009 3010 false: 3011 - (void)_aMethod 3012 { 3013 [self.test1 t:self w:self callback:^(typeof(self) self, NSNumber 3014 *u, NSNumber *v) { 3015 u = c; 3016 }] 3017 } 3018 true: 3019 - (void)_aMethod 3020 { 3021 [self.test1 t:self 3022 w:self 3023 callback:^(typeof(self) self, NSNumber *u, NSNumber *v) { 3024 u = c; 3025 }] 3026 } 3027 3028**ObjCSpaceAfterProperty** (``bool``) 3029 Add a space after ``@property`` in Objective-C, i.e. use 3030 ``@property (readonly)`` instead of ``@property(readonly)``. 3031 3032**ObjCSpaceBeforeProtocolList** (``bool``) 3033 Add a space in front of an Objective-C protocol list, i.e. use 3034 ``Foo <Protocol>`` instead of ``Foo<Protocol>``. 3035 3036**PenaltyBreakAssignment** (``unsigned``) 3037 The penalty for breaking around an assignment operator. 3038 3039**PenaltyBreakBeforeFirstCallParameter** (``unsigned``) 3040 The penalty for breaking a function call after ``call(``. 3041 3042**PenaltyBreakComment** (``unsigned``) 3043 The penalty for each line break introduced inside a comment. 3044 3045**PenaltyBreakFirstLessLess** (``unsigned``) 3046 The penalty for breaking before the first ``<<``. 3047 3048**PenaltyBreakString** (``unsigned``) 3049 The penalty for each line break introduced inside a string literal. 3050 3051**PenaltyBreakTemplateDeclaration** (``unsigned``) 3052 The penalty for breaking after template declaration. 3053 3054**PenaltyExcessCharacter** (``unsigned``) 3055 The penalty for each character outside of the column limit. 3056 3057**PenaltyIndentedWhitespace** (``unsigned``) 3058 Penalty for each character of whitespace indentation 3059 (counted relative to leading non-whitespace column). 3060 3061**PenaltyReturnTypeOnItsOwnLine** (``unsigned``) 3062 Penalty for putting the return type of a function onto its own 3063 line. 3064 3065**PointerAlignment** (``PointerAlignmentStyle``) 3066 Pointer and reference alignment style. 3067 3068 Possible values: 3069 3070 * ``PAS_Left`` (in configuration: ``Left``) 3071 Align pointer to the left. 3072 3073 .. code-block:: c++ 3074 3075 int* a; 3076 3077 * ``PAS_Right`` (in configuration: ``Right``) 3078 Align pointer to the right. 3079 3080 .. code-block:: c++ 3081 3082 int *a; 3083 3084 * ``PAS_Middle`` (in configuration: ``Middle``) 3085 Align pointer in the middle. 3086 3087 .. code-block:: c++ 3088 3089 int * a; 3090 3091 3092 3093**RawStringFormats** (``std::vector<RawStringFormat>``) 3094 Defines hints for detecting supported languages code blocks in raw 3095 strings. 3096 3097 A raw string with a matching delimiter or a matching enclosing function 3098 name will be reformatted assuming the specified language based on the 3099 style for that language defined in the .clang-format file. If no style has 3100 been defined in the .clang-format file for the specific language, a 3101 predefined style given by 'BasedOnStyle' is used. If 'BasedOnStyle' is not 3102 found, the formatting is based on llvm style. A matching delimiter takes 3103 precedence over a matching enclosing function name for determining the 3104 language of the raw string contents. 3105 3106 If a canonical delimiter is specified, occurrences of other delimiters for 3107 the same language will be updated to the canonical if possible. 3108 3109 There should be at most one specification per language and each delimiter 3110 and enclosing function should not occur in multiple specifications. 3111 3112 To configure this in the .clang-format file, use: 3113 3114 .. code-block:: yaml 3115 3116 RawStringFormats: 3117 - Language: TextProto 3118 Delimiters: 3119 - 'pb' 3120 - 'proto' 3121 EnclosingFunctions: 3122 - 'PARSE_TEXT_PROTO' 3123 BasedOnStyle: google 3124 - Language: Cpp 3125 Delimiters: 3126 - 'cc' 3127 - 'cpp' 3128 BasedOnStyle: llvm 3129 CanonicalDelimiter: 'cc' 3130 3131**ReflowComments** (``bool``) 3132 If ``true``, clang-format will attempt to re-flow comments. 3133 3134 .. code-block:: c++ 3135 3136 false: 3137 // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information 3138 /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */ 3139 3140 true: 3141 // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of 3142 // information 3143 /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of 3144 * information */ 3145 3146**ShortNamespaceLines** (``unsigned``) 3147 The maximal number of unwrapped lines that a short namespace spans. 3148 Defaults to 1. 3149 3150 This determines the maximum length of short namespaces by counting 3151 unwrapped lines (i.e. containing neither opening nor closing 3152 namespace brace) and makes "FixNamespaceComments" omit adding 3153 end comments for those. 3154 3155 .. code-block:: c++ 3156 3157 ShortNamespaceLines: 1 vs. ShortNamespaceLines: 0 3158 namespace a { namespace a { 3159 int foo; int foo; 3160 } } // namespace a 3161 3162 ShortNamespaceLines: 1 vs. ShortNamespaceLines: 0 3163 namespace b { namespace b { 3164 int foo; int foo; 3165 int bar; int bar; 3166 } // namespace b } // namespace b 3167 3168**SortIncludes** (``SortIncludesOptions``) 3169 Controls if and how clang-format will sort ``#includes``. 3170 If ``Never``, includes are never sorted. 3171 If ``CaseInsensitive``, includes are sorted in an ASCIIbetical or case 3172 insensitive fashion. 3173 If ``CaseSensitive``, includes are sorted in an alphabetical or case 3174 sensitive fashion. 3175 3176 Possible values: 3177 3178 * ``SI_Never`` (in configuration: ``Never``) 3179 Includes are never sorted. 3180 3181 .. code-block:: c++ 3182 3183 #include "B/A.h" 3184 #include "A/B.h" 3185 #include "a/b.h" 3186 #include "A/b.h" 3187 #include "B/a.h" 3188 3189 * ``SI_CaseSensitive`` (in configuration: ``CaseSensitive``) 3190 Includes are sorted in an ASCIIbetical or case sensitive fashion. 3191 3192 .. code-block:: c++ 3193 3194 #include "A/B.h" 3195 #include "A/b.h" 3196 #include "B/A.h" 3197 #include "B/a.h" 3198 #include "a/b.h" 3199 3200 * ``SI_CaseInsensitive`` (in configuration: ``CaseInsensitive``) 3201 Includes are sorted in an alphabetical or case insensitive fashion. 3202 3203 .. code-block:: c++ 3204 3205 #include "A/B.h" 3206 #include "A/b.h" 3207 #include "a/b.h" 3208 #include "B/A.h" 3209 #include "B/a.h" 3210 3211 3212 3213**SortJavaStaticImport** (``SortJavaStaticImportOptions``) 3214 When sorting Java imports, by default static imports are placed before 3215 non-static imports. If ``JavaStaticImportAfterImport`` is ``After``, 3216 static imports are placed after non-static imports. 3217 3218 Possible values: 3219 3220 * ``SJSIO_Before`` (in configuration: ``Before``) 3221 Static imports are placed before non-static imports. 3222 3223 .. code-block:: java 3224 3225 import static org.example.function1; 3226 3227 import org.example.ClassA; 3228 3229 * ``SJSIO_After`` (in configuration: ``After``) 3230 Static imports are placed after non-static imports. 3231 3232 .. code-block:: java 3233 3234 import org.example.ClassA; 3235 3236 import static org.example.function1; 3237 3238 3239 3240**SortUsingDeclarations** (``bool``) 3241 If ``true``, clang-format will sort using declarations. 3242 3243 The order of using declarations is defined as follows: 3244 Split the strings by "::" and discard any initial empty strings. The last 3245 element of each list is a non-namespace name; all others are namespace 3246 names. Sort the lists of names lexicographically, where the sort order of 3247 individual names is that all non-namespace names come before all namespace 3248 names, and within those groups, names are in case-insensitive 3249 lexicographic order. 3250 3251 .. code-block:: c++ 3252 3253 false: true: 3254 using std::cout; vs. using std::cin; 3255 using std::cin; using std::cout; 3256 3257**SpaceAfterCStyleCast** (``bool``) 3258 If ``true``, a space is inserted after C style casts. 3259 3260 .. code-block:: c++ 3261 3262 true: false: 3263 (int) i; vs. (int)i; 3264 3265**SpaceAfterLogicalNot** (``bool``) 3266 If ``true``, a space is inserted after the logical not operator (``!``). 3267 3268 .. code-block:: c++ 3269 3270 true: false: 3271 ! someExpression(); vs. !someExpression(); 3272 3273**SpaceAfterTemplateKeyword** (``bool``) 3274 If ``true``, a space will be inserted after the 'template' keyword. 3275 3276 .. code-block:: c++ 3277 3278 true: false: 3279 template <int> void foo(); vs. template<int> void foo(); 3280 3281**SpaceAroundPointerQualifiers** (``SpaceAroundPointerQualifiersStyle``) 3282 Defines in which cases to put a space before or after pointer qualifiers 3283 3284 Possible values: 3285 3286 * ``SAPQ_Default`` (in configuration: ``Default``) 3287 Don't ensure spaces around pointer qualifiers and use PointerAlignment 3288 instead. 3289 3290 .. code-block:: c++ 3291 3292 PointerAlignment: Left PointerAlignment: Right 3293 void* const* x = NULL; vs. void *const *x = NULL; 3294 3295 * ``SAPQ_Before`` (in configuration: ``Before``) 3296 Ensure that there is a space before pointer qualifiers. 3297 3298 .. code-block:: c++ 3299 3300 PointerAlignment: Left PointerAlignment: Right 3301 void* const* x = NULL; vs. void * const *x = NULL; 3302 3303 * ``SAPQ_After`` (in configuration: ``After``) 3304 Ensure that there is a space after pointer qualifiers. 3305 3306 .. code-block:: c++ 3307 3308 PointerAlignment: Left PointerAlignment: Right 3309 void* const * x = NULL; vs. void *const *x = NULL; 3310 3311 * ``SAPQ_Both`` (in configuration: ``Both``) 3312 Ensure that there is a space both before and after pointer qualifiers. 3313 3314 .. code-block:: c++ 3315 3316 PointerAlignment: Left PointerAlignment: Right 3317 void* const * x = NULL; vs. void * const *x = NULL; 3318 3319 3320 3321**SpaceBeforeAssignmentOperators** (``bool``) 3322 If ``false``, spaces will be removed before assignment operators. 3323 3324 .. code-block:: c++ 3325 3326 true: false: 3327 int a = 5; vs. int a= 5; 3328 a += 42; a+= 42; 3329 3330**SpaceBeforeCaseColon** (``bool``) 3331 If ``false``, spaces will be removed before case colon. 3332 3333 .. code-block:: c++ 3334 3335 true: false 3336 switch (x) { vs. switch (x) { 3337 case 1 : break; case 1: break; 3338 } } 3339 3340**SpaceBeforeCpp11BracedList** (``bool``) 3341 If ``true``, a space will be inserted before a C++11 braced list 3342 used to initialize an object (after the preceding identifier or type). 3343 3344 .. code-block:: c++ 3345 3346 true: false: 3347 Foo foo { bar }; vs. Foo foo{ bar }; 3348 Foo {}; Foo{}; 3349 vector<int> { 1, 2, 3 }; vector<int>{ 1, 2, 3 }; 3350 new int[3] { 1, 2, 3 }; new int[3]{ 1, 2, 3 }; 3351 3352**SpaceBeforeCtorInitializerColon** (``bool``) 3353 If ``false``, spaces will be removed before constructor initializer 3354 colon. 3355 3356 .. code-block:: c++ 3357 3358 true: false: 3359 Foo::Foo() : a(a) {} Foo::Foo(): a(a) {} 3360 3361**SpaceBeforeInheritanceColon** (``bool``) 3362 If ``false``, spaces will be removed before inheritance colon. 3363 3364 .. code-block:: c++ 3365 3366 true: false: 3367 class Foo : Bar {} vs. class Foo: Bar {} 3368 3369**SpaceBeforeParens** (``SpaceBeforeParensOptions``) 3370 Defines in which cases to put a space before opening parentheses. 3371 3372 Possible values: 3373 3374 * ``SBPO_Never`` (in configuration: ``Never``) 3375 Never put a space before opening parentheses. 3376 3377 .. code-block:: c++ 3378 3379 void f() { 3380 if(true) { 3381 f(); 3382 } 3383 } 3384 3385 * ``SBPO_ControlStatements`` (in configuration: ``ControlStatements``) 3386 Put a space before opening parentheses only after control statement 3387 keywords (``for/if/while...``). 3388 3389 .. code-block:: c++ 3390 3391 void f() { 3392 if (true) { 3393 f(); 3394 } 3395 } 3396 3397 * ``SBPO_ControlStatementsExceptForEachMacros`` (in configuration: ``ControlStatementsExceptForEachMacros``) 3398 Same as ``SBPO_ControlStatements`` except this option doesn't apply to 3399 ForEach macros. This is useful in projects where ForEach macros are 3400 treated as function calls instead of control statements. 3401 3402 .. code-block:: c++ 3403 3404 void f() { 3405 Q_FOREACH(...) { 3406 f(); 3407 } 3408 } 3409 3410 * ``SBPO_NonEmptyParentheses`` (in configuration: ``NonEmptyParentheses``) 3411 Put a space before opening parentheses only if the parentheses are not 3412 empty i.e. '()' 3413 3414 .. code-block:: c++ 3415 3416 void() { 3417 if (true) { 3418 f(); 3419 g (x, y, z); 3420 } 3421 } 3422 3423 * ``SBPO_Always`` (in configuration: ``Always``) 3424 Always put a space before opening parentheses, except when it's 3425 prohibited by the syntax rules (in function-like macro definitions) or 3426 when determined by other style rules (after unary operators, opening 3427 parentheses, etc.) 3428 3429 .. code-block:: c++ 3430 3431 void f () { 3432 if (true) { 3433 f (); 3434 } 3435 } 3436 3437 3438 3439**SpaceBeforeRangeBasedForLoopColon** (``bool``) 3440 If ``false``, spaces will be removed before range-based for loop 3441 colon. 3442 3443 .. code-block:: c++ 3444 3445 true: false: 3446 for (auto v : values) {} vs. for(auto v: values) {} 3447 3448**SpaceBeforeSquareBrackets** (``bool``) 3449 If ``true``, spaces will be before ``[``. 3450 Lambdas will not be affected. Only the first ``[`` will get a space added. 3451 3452 .. code-block:: c++ 3453 3454 true: false: 3455 int a [5]; vs. int a[5]; 3456 int a [5][5]; vs. int a[5][5]; 3457 3458**SpaceInEmptyBlock** (``bool``) 3459 If ``true``, spaces will be inserted into ``{}``. 3460 3461 .. code-block:: c++ 3462 3463 true: false: 3464 void f() { } vs. void f() {} 3465 while (true) { } while (true) {} 3466 3467**SpaceInEmptyParentheses** (``bool``) 3468 If ``true``, spaces may be inserted into ``()``. 3469 3470 .. code-block:: c++ 3471 3472 true: false: 3473 void f( ) { vs. void f() { 3474 int x[] = {foo( ), bar( )}; int x[] = {foo(), bar()}; 3475 if (true) { if (true) { 3476 f( ); f(); 3477 } } 3478 } } 3479 3480**SpacesBeforeTrailingComments** (``unsigned``) 3481 The number of spaces before trailing line comments 3482 (``//`` - comments). 3483 3484 This does not affect trailing block comments (``/*`` - comments) as 3485 those commonly have different usage patterns and a number of special 3486 cases. 3487 3488 .. code-block:: c++ 3489 3490 SpacesBeforeTrailingComments: 3 3491 void f() { 3492 if (true) { // foo1 3493 f(); // bar 3494 } // foo 3495 } 3496 3497**SpacesInAngles** (``SpacesInAnglesStyle``) 3498 The SpacesInAnglesStyle to use for template argument lists. 3499 3500 Possible values: 3501 3502 * ``SIAS_Never`` (in configuration: ``Never``) 3503 Remove spaces after ``<`` and before ``>``. 3504 3505 .. code-block:: c++ 3506 3507 static_cast<int>(arg); 3508 std::function<void(int)> fct; 3509 3510 * ``SIAS_Always`` (in configuration: ``Always``) 3511 Add spaces after ``<`` and before ``>``. 3512 3513 .. code-block:: c++ 3514 3515 static_cast< int >(arg); 3516 std::function< void(int) > fct; 3517 3518 * ``SIAS_Leave`` (in configuration: ``Leave``) 3519 Keep a single space after ``<`` and before ``>`` if any spaces were 3520 present. Option ``Standard: Cpp03`` takes precedence. 3521 3522 3523 3524**SpacesInCStyleCastParentheses** (``bool``) 3525 If ``true``, spaces may be inserted into C style casts. 3526 3527 .. code-block:: c++ 3528 3529 true: false: 3530 x = ( int32 )y vs. x = (int32)y 3531 3532**SpacesInConditionalStatement** (``bool``) 3533 If ``true``, spaces will be inserted around if/for/switch/while 3534 conditions. 3535 3536 .. code-block:: c++ 3537 3538 true: false: 3539 if ( a ) { ... } vs. if (a) { ... } 3540 while ( i < 5 ) { ... } while (i < 5) { ... } 3541 3542**SpacesInContainerLiterals** (``bool``) 3543 If ``true``, spaces are inserted inside container literals (e.g. 3544 ObjC and Javascript array and dict literals). 3545 3546 .. code-block:: js 3547 3548 true: false: 3549 var arr = [ 1, 2, 3 ]; vs. var arr = [1, 2, 3]; 3550 f({a : 1, b : 2, c : 3}); f({a: 1, b: 2, c: 3}); 3551 3552**SpacesInLineCommentPrefix** (``SpacesInLineComment``) 3553 How many spaces are allowed at the start of a line comment. To disable the 3554 maximum set it to ``-1``, apart from that the maximum takes precedence 3555 over the minimum. 3556 Minimum = 1 Maximum = -1 3557 // One space is forced 3558 3559 // but more spaces are possible 3560 3561 Minimum = 0 3562 Maximum = 0 3563 //Forces to start every comment directly after the slashes 3564 3565 Note that in line comment sections the relative indent of the subsequent 3566 lines is kept, that means the following: 3567 3568 .. code-block:: c++ 3569 3570 before: after: 3571 Minimum: 1 3572 //if (b) { // if (b) { 3573 // return true; // return true; 3574 //} // } 3575 3576 Maximum: 0 3577 /// List: ///List: 3578 /// - Foo /// - Foo 3579 /// - Bar /// - Bar 3580 3581 Nested configuration flags: 3582 3583 3584 * ``unsigned Minimum`` The minimum number of spaces at the start of the comment. 3585 3586 * ``unsigned Maximum`` The maximum number of spaces at the start of the comment. 3587 3588 3589**SpacesInParentheses** (``bool``) 3590 If ``true``, spaces will be inserted after ``(`` and before ``)``. 3591 3592 .. code-block:: c++ 3593 3594 true: false: 3595 t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete; 3596 3597**SpacesInSquareBrackets** (``bool``) 3598 If ``true``, spaces will be inserted after ``[`` and before ``]``. 3599 Lambdas without arguments or unspecified size array declarations will not 3600 be affected. 3601 3602 .. code-block:: c++ 3603 3604 true: false: 3605 int a[ 5 ]; vs. int a[5]; 3606 std::unique_ptr<int[]> foo() {} // Won't be affected 3607 3608**Standard** (``LanguageStandard``) 3609 Parse and format C++ constructs compatible with this standard. 3610 3611 .. code-block:: c++ 3612 3613 c++03: latest: 3614 vector<set<int> > x; vs. vector<set<int>> x; 3615 3616 Possible values: 3617 3618 * ``LS_Cpp03`` (in configuration: ``c++03``) 3619 Parse and format as C++03. 3620 ``Cpp03`` is a deprecated alias for ``c++03`` 3621 3622 * ``LS_Cpp11`` (in configuration: ``c++11``) 3623 Parse and format as C++11. 3624 3625 * ``LS_Cpp14`` (in configuration: ``c++14``) 3626 Parse and format as C++14. 3627 3628 * ``LS_Cpp17`` (in configuration: ``c++17``) 3629 Parse and format as C++17. 3630 3631 * ``LS_Cpp20`` (in configuration: ``c++20``) 3632 Parse and format as C++20. 3633 3634 * ``LS_Latest`` (in configuration: ``Latest``) 3635 Parse and format using the latest supported language version. 3636 ``Cpp11`` is a deprecated alias for ``Latest`` 3637 3638 * ``LS_Auto`` (in configuration: ``Auto``) 3639 Automatic detection based on the input. 3640 3641 3642 3643**StatementAttributeLikeMacros** (``std::vector<std::string>``) 3644 Macros which are ignored in front of a statement, as if they were an 3645 attribute. So that they are not parsed as identifier, for example for Qts 3646 emit. 3647 3648 .. code-block:: c++ 3649 3650 AlignConsecutiveDeclarations: true 3651 StatementAttributeLikeMacros: [] 3652 unsigned char data = 'x'; 3653 emit signal(data); // This is parsed as variable declaration. 3654 3655 AlignConsecutiveDeclarations: true 3656 StatementAttributeLikeMacros: [emit] 3657 unsigned char data = 'x'; 3658 emit signal(data); // Now it's fine again. 3659 3660**StatementMacros** (``std::vector<std::string>``) 3661 A vector of macros that should be interpreted as complete 3662 statements. 3663 3664 Typical macros are expressions, and require a semi-colon to be 3665 added; sometimes this is not the case, and this allows to make 3666 clang-format aware of such cases. 3667 3668 For example: Q_UNUSED 3669 3670**TabWidth** (``unsigned``) 3671 The number of columns used for tab stops. 3672 3673**TypenameMacros** (``std::vector<std::string>``) 3674 A vector of macros that should be interpreted as type declarations 3675 instead of as function calls. 3676 3677 These are expected to be macros of the form: 3678 3679 .. code-block:: c++ 3680 3681 STACK_OF(...) 3682 3683 In the .clang-format configuration file, this can be configured like: 3684 3685 .. code-block:: yaml 3686 3687 TypenameMacros: ['STACK_OF', 'LIST'] 3688 3689 For example: OpenSSL STACK_OF, BSD LIST_ENTRY. 3690 3691**UseCRLF** (``bool``) 3692 Use ``\r\n`` instead of ``\n`` for line breaks. 3693 Also used as fallback if ``DeriveLineEnding`` is true. 3694 3695**UseTab** (``UseTabStyle``) 3696 The way to use tab characters in the resulting file. 3697 3698 Possible values: 3699 3700 * ``UT_Never`` (in configuration: ``Never``) 3701 Never use tab. 3702 3703 * ``UT_ForIndentation`` (in configuration: ``ForIndentation``) 3704 Use tabs only for indentation. 3705 3706 * ``UT_ForContinuationAndIndentation`` (in configuration: ``ForContinuationAndIndentation``) 3707 Fill all leading whitespace with tabs, and use spaces for alignment that 3708 appears within a line (e.g. consecutive assignments and declarations). 3709 3710 * ``UT_AlignWithSpaces`` (in configuration: ``AlignWithSpaces``) 3711 Use tabs for line continuation and indentation, and spaces for 3712 alignment. 3713 3714 * ``UT_Always`` (in configuration: ``Always``) 3715 Use tabs whenever we need to fill whitespace that spans at least from 3716 one tab stop to the next one. 3717 3718 3719 3720**WhitespaceSensitiveMacros** (``std::vector<std::string>``) 3721 A vector of macros which are whitespace-sensitive and should not 3722 be touched. 3723 3724 These are expected to be macros of the form: 3725 3726 .. code-block:: c++ 3727 3728 STRINGIZE(...) 3729 3730 In the .clang-format configuration file, this can be configured like: 3731 3732 .. code-block:: yaml 3733 3734 WhitespaceSensitiveMacros: ['STRINGIZE', 'PP_STRINGIZE'] 3735 3736 For example: BOOST_PP_STRINGIZE 3737 3738.. END_FORMAT_STYLE_OPTIONS 3739 3740Adding additional style options 3741=============================== 3742 3743Each additional style option adds costs to the clang-format project. Some of 3744these costs affect the clang-format development itself, as we need to make 3745sure that any given combination of options work and that new features don't 3746break any of the existing options in any way. There are also costs for end users 3747as options become less discoverable and people have to think about and make a 3748decision on options they don't really care about. 3749 3750The goal of the clang-format project is more on the side of supporting a 3751limited set of styles really well as opposed to supporting every single style 3752used by a codebase somewhere in the wild. Of course, we do want to support all 3753major projects and thus have established the following bar for adding style 3754options. Each new style option must .. 3755 3756 * be used in a project of significant size (have dozens of contributors) 3757 * have a publicly accessible style guide 3758 * have a person willing to contribute and maintain patches 3759 3760Examples 3761======== 3762 3763A style similar to the `Linux Kernel style 3764<https://www.kernel.org/doc/Documentation/CodingStyle>`_: 3765 3766.. code-block:: yaml 3767 3768 BasedOnStyle: LLVM 3769 IndentWidth: 8 3770 UseTab: Always 3771 BreakBeforeBraces: Linux 3772 AllowShortIfStatementsOnASingleLine: false 3773 IndentCaseLabels: false 3774 3775The result is (imagine that tabs are used for indentation here): 3776 3777.. code-block:: c++ 3778 3779 void test() 3780 { 3781 switch (x) { 3782 case 0: 3783 case 1: 3784 do_something(); 3785 break; 3786 case 2: 3787 do_something_else(); 3788 break; 3789 default: 3790 break; 3791 } 3792 if (condition) 3793 do_something_completely_different(); 3794 3795 if (x == y) { 3796 q(); 3797 } else if (x > y) { 3798 w(); 3799 } else { 3800 r(); 3801 } 3802 } 3803 3804A style similar to the default Visual Studio formatting style: 3805 3806.. code-block:: yaml 3807 3808 UseTab: Never 3809 IndentWidth: 4 3810 BreakBeforeBraces: Allman 3811 AllowShortIfStatementsOnASingleLine: false 3812 IndentCaseLabels: false 3813 ColumnLimit: 0 3814 3815The result is: 3816 3817.. code-block:: c++ 3818 3819 void test() 3820 { 3821 switch (suffix) 3822 { 3823 case 0: 3824 case 1: 3825 do_something(); 3826 break; 3827 case 2: 3828 do_something_else(); 3829 break; 3830 default: 3831 break; 3832 } 3833 if (condition) 3834 do_something_completely_different(); 3835 3836 if (x == y) 3837 { 3838 q(); 3839 } 3840 else if (x > y) 3841 { 3842 w(); 3843 } 3844 else 3845 { 3846 r(); 3847 } 3848 } 3849