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