7536 lines · plain
1..2 !!!!NOTE!!!!3 This file is automatically generated, in part. Do not edit the style options4 in this file directly. Instead, modify them in include/clang/Format/Format.h5 and run the docs/tools/dump_format_style.py script to update this file.6 7.. raw:: html8 9 <style type="text/css">10 .versionbadge { background-color: #1c913d; height: 20px; display: inline-block; min-width: 120px; text-align: center; border-radius: 5px; color: #FFFFFF; font-family: "Verdana,Geneva,DejaVu Sans,sans-serif"; }11 </style>12 13.. role:: versionbadge14 15==========================16Clang-Format Style Options17==========================18 19:doc:`ClangFormatStyleOptions` describes configurable formatting style options20supported by :doc:`LibFormat` and :doc:`ClangFormat`.21 22When using :program:`clang-format` command line utility or23``clang::format::reformat(...)`` functions from code, one can either use one of24the predefined styles (LLVM, Google, Chromium, Mozilla, WebKit, Microsoft) or25create a custom style by configuring specific style options.26 27 28Configuring Style with clang-format29===================================30 31:program:`clang-format` supports two ways to provide custom style options:32directly specify style configuration in the ``-style=`` command line option or33use ``-style=file`` and put style configuration in the ``.clang-format`` or34``_clang-format`` file in the project directory.35 36When using ``-style=file``, :program:`clang-format` for each input file will37try to find the ``.clang-format`` file located in the closest parent directory38of the input file. When the standard input is used, the search is started from39the current directory.40 41When using ``-style=file:<format_file_path>``, :program:`clang-format` for42each input file will use the format file located at `<format_file_path>`.43The path may be absolute or relative to the working directory.44 45The ``.clang-format`` file uses YAML format:46 47.. code-block:: yaml48 49 key1: value150 key2: value251 # A comment.52 ...53 54The configuration file can consist of several sections each having different55``Language:`` parameter denoting the programming language this section of the56configuration is targeted at. See the description of the **Language** option57below for the list of supported languages. The first section may have no58language set, it will set the default style options for all languages.59Configuration sections for specific language will override options set in the60default section.61 62When :program:`clang-format` formats a file, it auto-detects the language using63the file name. When formatting standard input or a file that doesn't have the64extension corresponding to its language, ``-assume-filename=`` option can be65used to override the file name :program:`clang-format` uses to detect the66language.67 68An example of a configuration file for multiple languages:69 70.. code-block:: yaml71 72 ---73 # We'll use defaults from the LLVM style, but with 4 columns indentation.74 BasedOnStyle: LLVM75 IndentWidth: 476 ---77 Language: Cpp78 # Force pointers to the type for C++.79 DerivePointerAlignment: false80 PointerAlignment: Left81 ---82 Language: JavaScript83 # Use 100 columns for JS.84 ColumnLimit: 10085 ---86 Language: Proto87 # Don't format .proto files.88 DisableFormat: true89 ---90 Language: CSharp91 # Use 100 columns for C#.92 ColumnLimit: 10093 ...94 95An easy way to get a valid ``.clang-format`` file containing all configuration96options of a certain predefined style is:97 98.. code-block:: console99 100 clang-format -style=llvm -dump-config > .clang-format101 102When specifying configuration in the ``-style=`` option, the same configuration103is applied for all input files. The format of the configuration is:104 105.. code-block:: console106 107 -style='{key1: value1, key2: value2, ...}'108 109 110Disabling Formatting on a Piece of Code111=======================================112 113Clang-format understands also special comments that switch formatting in a114delimited range. The code between a comment ``// clang-format off`` or115``/* clang-format off */`` up to a comment ``// clang-format on`` or116``/* clang-format on */`` will not be formatted. The comments themselves will be117formatted (aligned) normally. Also, a colon (``:``) and additional text may118follow ``// clang-format off`` or ``// clang-format on`` to explain why119clang-format is turned off or back on.120 121.. code-block:: c++122 123 int formatted_code;124 // clang-format off125 void unformatted_code ;126 // clang-format on127 void formatted_code_again;128 129In addition, the ``OneLineFormatOffRegex`` option gives you a concise way to130disable formatting for all of the lines that match the regular expression.131 132 133Configuring Style in Code134=========================135 136When using ``clang::format::reformat(...)`` functions, the format is specified137by supplying the `clang::format::FormatStyle138<https://clang.llvm.org/doxygen/structclang_1_1format_1_1FormatStyle.html>`_139structure.140 141 142Configurable Format Style Options143=================================144 145This section lists the supported style options. Value type is specified for146each option. For enumeration types possible values are specified both as a C++147enumeration member (with a prefix, e.g. ``LS_Auto``), and as a value usable in148the configuration (without a prefix: ``Auto``).149 150.. _BasedOnStyle:151 152**BasedOnStyle** (``String``) :ref:`¶ <BasedOnStyle>`153 The style used for all options not specifically set in the configuration.154 155 This option is supported only in the :program:`clang-format` configuration156 (both within ``-style='{...}'`` and the ``.clang-format`` file).157 158 Possible values:159 160 * ``LLVM``161 A style complying with the `LLVM coding standards162 <https://llvm.org/docs/CodingStandards.html>`_163 * ``Google``164 A style complying with `Google's C++ style guide165 <https://google.github.io/styleguide/cppguide.html>`_166 * ``Chromium``167 A style complying with `Chromium's style guide168 <https://chromium.googlesource.com/chromium/src/+/refs/heads/main/styleguide/styleguide.md>`_169 * ``Mozilla``170 A style complying with `Mozilla's style guide171 <https://firefox-source-docs.mozilla.org/code-quality/coding-style/index.html>`_172 * ``WebKit``173 A style complying with `WebKit's style guide174 <https://www.webkit.org/coding/coding-style.html>`_175 * ``Microsoft``176 A style complying with `Microsoft's style guide177 <https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference>`_178 * ``GNU``179 A style complying with the `GNU coding standards180 <https://www.gnu.org/prep/standards/standards.html>`_181 * ``InheritParentConfig``182 Not a real style, but allows to use the ``.clang-format`` file from the183 parent directory (or its parent if there is none). If there is no parent184 file found it falls back to the ``fallback`` style, and applies the changes185 to that.186 187 With this option you can overwrite some parts of your main style for your188 subdirectories. This is also possible through the command line, e.g.:189 ``--style={BasedOnStyle: InheritParentConfig, ColumnLimit: 20}``190 191.. START_FORMAT_STYLE_OPTIONS192 193.. _AccessModifierOffset:194 195**AccessModifierOffset** (``Integer``) :versionbadge:`clang-format 3.3` :ref:`¶ <AccessModifierOffset>`196 The extra indent or outdent of access modifiers, e.g. ``public:``.197 198.. _AlignAfterOpenBracket:199 200**AlignAfterOpenBracket** (``Boolean``) :versionbadge:`clang-format 3.8` :ref:`¶ <AlignAfterOpenBracket>`201 If ``true``, horizontally aligns arguments after an open bracket.202 203 204 .. code-block:: c++205 206 true: vs. false207 someLongFunction(argument1, someLongFunction(argument1,208 argument2); argument2);209 210 211 .. note::212 213 As of clang-format 22 this option is a bool with the previous214 option of ``Align`` replaced with ``true``, ``DontAlign`` replaced215 with ``false``, and the options of ``AlwaysBreak`` and ``BlockIndent``216 replaced with ``true`` and with setting of new style options using217 ``BreakAfterOpenBracketBracedList``, ``BreakAfterOpenBracketFunction``,218 ``BreakAfterOpenBracketIf``, ``BreakBeforeCloseBracketBracedList``,219 ``BreakBeforeCloseBracketFunction``, and ``BreakBeforeCloseBracketIf``.220 221 This applies to round brackets (parentheses), angle brackets and square222 brackets.223 224.. _AlignArrayOfStructures:225 226**AlignArrayOfStructures** (``ArrayInitializerAlignmentStyle``) :versionbadge:`clang-format 13` :ref:`¶ <AlignArrayOfStructures>`227 If not ``None``, when using initialization for an array of structs228 aligns the fields into columns.229 230 231 .. note::232 233 As of clang-format 15 this option only applied to arrays with equal234 number of columns per row.235 236 Possible values:237 238 * ``AIAS_Left`` (in configuration: ``Left``)239 Align array column and left justify the columns e.g.:240 241 .. code-block:: c++242 243 struct test demo[] =244 {245 {56, 23, "hello"},246 {-1, 93463, "world"},247 {7, 5, "!!" }248 };249 250 * ``AIAS_Right`` (in configuration: ``Right``)251 Align array column and right justify the columns e.g.:252 253 .. code-block:: c++254 255 struct test demo[] =256 {257 {56, 23, "hello"},258 {-1, 93463, "world"},259 { 7, 5, "!!"}260 };261 262 * ``AIAS_None`` (in configuration: ``None``)263 Don't align array initializer columns.264 265 266 267.. _AlignConsecutiveAssignments:268 269**AlignConsecutiveAssignments** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 3.8` :ref:`¶ <AlignConsecutiveAssignments>`270 Style of aligning consecutive assignments.271 272 ``Consecutive`` will result in formattings like:273 274 .. code-block:: c++275 276 int a = 1;277 int somelongname = 2;278 double c = 3;279 280 Nested configuration flags:281 282 Alignment options.283 284 They can also be read as a whole for compatibility. The choices are:285 286 * ``None``287 * ``Consecutive``288 * ``AcrossEmptyLines``289 * ``AcrossComments``290 * ``AcrossEmptyLinesAndComments``291 292 For example, to align across empty lines and not across comments, either293 of these work.294 295 .. code-block:: c++296 297 AlignConsecutiveAssignments: AcrossEmptyLines298 299 AlignConsecutiveAssignments:300 Enabled: true301 AcrossEmptyLines: true302 AcrossComments: false303 304 * ``bool Enabled`` Whether aligning is enabled.305 306 .. code-block:: c++307 308 #define SHORT_NAME 42309 #define LONGER_NAME 0x007f310 #define EVEN_LONGER_NAME (2)311 #define foo(x) (x * x)312 #define bar(y, z) (y + z)313 314 int a = 1;315 int somelongname = 2;316 double c = 3;317 318 int aaaa : 1;319 int b : 12;320 int ccc : 8;321 322 int aaaa = 12;323 float b = 23;324 std::string ccc;325 326 * ``bool AcrossEmptyLines`` Whether to align across empty lines.327 328 .. code-block:: c++329 330 true:331 int a = 1;332 int somelongname = 2;333 double c = 3;334 335 int d = 3;336 337 false:338 int a = 1;339 int somelongname = 2;340 double c = 3;341 342 int d = 3;343 344 * ``bool AcrossComments`` Whether to align across comments.345 346 .. code-block:: c++347 348 true:349 int d = 3;350 /* A comment. */351 double e = 4;352 353 false:354 int d = 3;355 /* A comment. */356 double e = 4;357 358 * ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound assignments359 like ``+=`` are aligned along with ``=``.360 361 .. code-block:: c++362 363 true:364 a &= 2;365 bbb = 2;366 367 false:368 a &= 2;369 bbb = 2;370 371 * ``bool AlignFunctionDeclarations`` Only for ``AlignConsecutiveDeclarations``. Whether function declarations372 are aligned.373 374 .. code-block:: c++375 376 true:377 unsigned int f1(void);378 void f2(void);379 size_t f3(void);380 381 false:382 unsigned int f1(void);383 void f2(void);384 size_t f3(void);385 386 * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are387 aligned.388 389 .. code-block:: c++390 391 true:392 unsigned i;393 int &r;394 int *p;395 int (*f)();396 397 false:398 unsigned i;399 int &r;400 int *p;401 int (*f)();402 403 * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment404 operators are left-padded to the same length as long ones in order to405 put all assignment operators to the right of the left hand side.406 407 .. code-block:: c++408 409 true:410 a >>= 2;411 bbb = 2;412 413 a = 2;414 bbb >>= 2;415 416 false:417 a >>= 2;418 bbb = 2;419 420 a = 2;421 bbb >>= 2;422 423 424.. _AlignConsecutiveBitFields:425 426**AlignConsecutiveBitFields** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 11` :ref:`¶ <AlignConsecutiveBitFields>`427 Style of aligning consecutive bit fields.428 429 ``Consecutive`` will align the bitfield separators of consecutive lines.430 This will result in formattings like:431 432 .. code-block:: c++433 434 int aaaa : 1;435 int b : 12;436 int ccc : 8;437 438 Nested configuration flags:439 440 Alignment options.441 442 They can also be read as a whole for compatibility. The choices are:443 444 * ``None``445 * ``Consecutive``446 * ``AcrossEmptyLines``447 * ``AcrossComments``448 * ``AcrossEmptyLinesAndComments``449 450 For example, to align across empty lines and not across comments, either451 of these work.452 453 .. code-block:: c++454 455 AlignConsecutiveBitFields: AcrossEmptyLines456 457 AlignConsecutiveBitFields:458 Enabled: true459 AcrossEmptyLines: true460 AcrossComments: false461 462 * ``bool Enabled`` Whether aligning is enabled.463 464 .. code-block:: c++465 466 #define SHORT_NAME 42467 #define LONGER_NAME 0x007f468 #define EVEN_LONGER_NAME (2)469 #define foo(x) (x * x)470 #define bar(y, z) (y + z)471 472 int a = 1;473 int somelongname = 2;474 double c = 3;475 476 int aaaa : 1;477 int b : 12;478 int ccc : 8;479 480 int aaaa = 12;481 float b = 23;482 std::string ccc;483 484 * ``bool AcrossEmptyLines`` Whether to align across empty lines.485 486 .. code-block:: c++487 488 true:489 int a = 1;490 int somelongname = 2;491 double c = 3;492 493 int d = 3;494 495 false:496 int a = 1;497 int somelongname = 2;498 double c = 3;499 500 int d = 3;501 502 * ``bool AcrossComments`` Whether to align across comments.503 504 .. code-block:: c++505 506 true:507 int d = 3;508 /* A comment. */509 double e = 4;510 511 false:512 int d = 3;513 /* A comment. */514 double e = 4;515 516 * ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound assignments517 like ``+=`` are aligned along with ``=``.518 519 .. code-block:: c++520 521 true:522 a &= 2;523 bbb = 2;524 525 false:526 a &= 2;527 bbb = 2;528 529 * ``bool AlignFunctionDeclarations`` Only for ``AlignConsecutiveDeclarations``. Whether function declarations530 are aligned.531 532 .. code-block:: c++533 534 true:535 unsigned int f1(void);536 void f2(void);537 size_t f3(void);538 539 false:540 unsigned int f1(void);541 void f2(void);542 size_t f3(void);543 544 * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are545 aligned.546 547 .. code-block:: c++548 549 true:550 unsigned i;551 int &r;552 int *p;553 int (*f)();554 555 false:556 unsigned i;557 int &r;558 int *p;559 int (*f)();560 561 * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment562 operators are left-padded to the same length as long ones in order to563 put all assignment operators to the right of the left hand side.564 565 .. code-block:: c++566 567 true:568 a >>= 2;569 bbb = 2;570 571 a = 2;572 bbb >>= 2;573 574 false:575 a >>= 2;576 bbb = 2;577 578 a = 2;579 bbb >>= 2;580 581 582.. _AlignConsecutiveDeclarations:583 584**AlignConsecutiveDeclarations** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 3.8` :ref:`¶ <AlignConsecutiveDeclarations>`585 Style of aligning consecutive declarations.586 587 ``Consecutive`` will align the declaration names of consecutive lines.588 This will result in formattings like:589 590 .. code-block:: c++591 592 int aaaa = 12;593 float b = 23;594 std::string ccc;595 596 Nested configuration flags:597 598 Alignment options.599 600 They can also be read as a whole for compatibility. The choices are:601 602 * ``None``603 * ``Consecutive``604 * ``AcrossEmptyLines``605 * ``AcrossComments``606 * ``AcrossEmptyLinesAndComments``607 608 For example, to align across empty lines and not across comments, either609 of these work.610 611 .. code-block:: c++612 613 AlignConsecutiveDeclarations: AcrossEmptyLines614 615 AlignConsecutiveDeclarations:616 Enabled: true617 AcrossEmptyLines: true618 AcrossComments: false619 620 * ``bool Enabled`` Whether aligning is enabled.621 622 .. code-block:: c++623 624 #define SHORT_NAME 42625 #define LONGER_NAME 0x007f626 #define EVEN_LONGER_NAME (2)627 #define foo(x) (x * x)628 #define bar(y, z) (y + z)629 630 int a = 1;631 int somelongname = 2;632 double c = 3;633 634 int aaaa : 1;635 int b : 12;636 int ccc : 8;637 638 int aaaa = 12;639 float b = 23;640 std::string ccc;641 642 * ``bool AcrossEmptyLines`` Whether to align across empty lines.643 644 .. code-block:: c++645 646 true:647 int a = 1;648 int somelongname = 2;649 double c = 3;650 651 int d = 3;652 653 false:654 int a = 1;655 int somelongname = 2;656 double c = 3;657 658 int d = 3;659 660 * ``bool AcrossComments`` Whether to align across comments.661 662 .. code-block:: c++663 664 true:665 int d = 3;666 /* A comment. */667 double e = 4;668 669 false:670 int d = 3;671 /* A comment. */672 double e = 4;673 674 * ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound assignments675 like ``+=`` are aligned along with ``=``.676 677 .. code-block:: c++678 679 true:680 a &= 2;681 bbb = 2;682 683 false:684 a &= 2;685 bbb = 2;686 687 * ``bool AlignFunctionDeclarations`` Only for ``AlignConsecutiveDeclarations``. Whether function declarations688 are aligned.689 690 .. code-block:: c++691 692 true:693 unsigned int f1(void);694 void f2(void);695 size_t f3(void);696 697 false:698 unsigned int f1(void);699 void f2(void);700 size_t f3(void);701 702 * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are703 aligned.704 705 .. code-block:: c++706 707 true:708 unsigned i;709 int &r;710 int *p;711 int (*f)();712 713 false:714 unsigned i;715 int &r;716 int *p;717 int (*f)();718 719 * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment720 operators are left-padded to the same length as long ones in order to721 put all assignment operators to the right of the left hand side.722 723 .. code-block:: c++724 725 true:726 a >>= 2;727 bbb = 2;728 729 a = 2;730 bbb >>= 2;731 732 false:733 a >>= 2;734 bbb = 2;735 736 a = 2;737 bbb >>= 2;738 739 740.. _AlignConsecutiveMacros:741 742**AlignConsecutiveMacros** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 9` :ref:`¶ <AlignConsecutiveMacros>`743 Style of aligning consecutive macro definitions.744 745 ``Consecutive`` will result in formattings like:746 747 .. code-block:: c++748 749 #define SHORT_NAME 42750 #define LONGER_NAME 0x007f751 #define EVEN_LONGER_NAME (2)752 #define foo(x) (x * x)753 #define bar(y, z) (y + z)754 755 Nested configuration flags:756 757 Alignment options.758 759 They can also be read as a whole for compatibility. The choices are:760 761 * ``None``762 * ``Consecutive``763 * ``AcrossEmptyLines``764 * ``AcrossComments``765 * ``AcrossEmptyLinesAndComments``766 767 For example, to align across empty lines and not across comments, either768 of these work.769 770 .. code-block:: c++771 772 AlignConsecutiveMacros: AcrossEmptyLines773 774 AlignConsecutiveMacros:775 Enabled: true776 AcrossEmptyLines: true777 AcrossComments: false778 779 * ``bool Enabled`` Whether aligning is enabled.780 781 .. code-block:: c++782 783 #define SHORT_NAME 42784 #define LONGER_NAME 0x007f785 #define EVEN_LONGER_NAME (2)786 #define foo(x) (x * x)787 #define bar(y, z) (y + z)788 789 int a = 1;790 int somelongname = 2;791 double c = 3;792 793 int aaaa : 1;794 int b : 12;795 int ccc : 8;796 797 int aaaa = 12;798 float b = 23;799 std::string ccc;800 801 * ``bool AcrossEmptyLines`` Whether to align across empty lines.802 803 .. code-block:: c++804 805 true:806 int a = 1;807 int somelongname = 2;808 double c = 3;809 810 int d = 3;811 812 false:813 int a = 1;814 int somelongname = 2;815 double c = 3;816 817 int d = 3;818 819 * ``bool AcrossComments`` Whether to align across comments.820 821 .. code-block:: c++822 823 true:824 int d = 3;825 /* A comment. */826 double e = 4;827 828 false:829 int d = 3;830 /* A comment. */831 double e = 4;832 833 * ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound assignments834 like ``+=`` are aligned along with ``=``.835 836 .. code-block:: c++837 838 true:839 a &= 2;840 bbb = 2;841 842 false:843 a &= 2;844 bbb = 2;845 846 * ``bool AlignFunctionDeclarations`` Only for ``AlignConsecutiveDeclarations``. Whether function declarations847 are aligned.848 849 .. code-block:: c++850 851 true:852 unsigned int f1(void);853 void f2(void);854 size_t f3(void);855 856 false:857 unsigned int f1(void);858 void f2(void);859 size_t f3(void);860 861 * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are862 aligned.863 864 .. code-block:: c++865 866 true:867 unsigned i;868 int &r;869 int *p;870 int (*f)();871 872 false:873 unsigned i;874 int &r;875 int *p;876 int (*f)();877 878 * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment879 operators are left-padded to the same length as long ones in order to880 put all assignment operators to the right of the left hand side.881 882 .. code-block:: c++883 884 true:885 a >>= 2;886 bbb = 2;887 888 a = 2;889 bbb >>= 2;890 891 false:892 a >>= 2;893 bbb = 2;894 895 a = 2;896 bbb >>= 2;897 898 899.. _AlignConsecutiveShortCaseStatements:900 901**AlignConsecutiveShortCaseStatements** (``ShortCaseStatementsAlignmentStyle``) :versionbadge:`clang-format 17` :ref:`¶ <AlignConsecutiveShortCaseStatements>`902 Style of aligning consecutive short case labels.903 Only applies if ``AllowShortCaseExpressionOnASingleLine`` or904 ``AllowShortCaseLabelsOnASingleLine`` is ``true``.905 906 907 .. code-block:: yaml908 909 # Example of usage:910 AlignConsecutiveShortCaseStatements:911 Enabled: true912 AcrossEmptyLines: true913 AcrossComments: true914 AlignCaseColons: false915 916 Nested configuration flags:917 918 Alignment options.919 920 * ``bool Enabled`` Whether aligning is enabled.921 922 .. code-block:: c++923 924 true:925 switch (level) {926 case log::info: return "info:";927 case log::warning: return "warning:";928 default: return "";929 }930 931 false:932 switch (level) {933 case log::info: return "info:";934 case log::warning: return "warning:";935 default: return "";936 }937 938 * ``bool AcrossEmptyLines`` Whether to align across empty lines.939 940 .. code-block:: c++941 942 true:943 switch (level) {944 case log::info: return "info:";945 case log::warning: return "warning:";946 947 default: return "";948 }949 950 false:951 switch (level) {952 case log::info: return "info:";953 case log::warning: return "warning:";954 955 default: return "";956 }957 958 * ``bool AcrossComments`` Whether to align across comments.959 960 .. code-block:: c++961 962 true:963 switch (level) {964 case log::info: return "info:";965 case log::warning: return "warning:";966 /* A comment. */967 default: return "";968 }969 970 false:971 switch (level) {972 case log::info: return "info:";973 case log::warning: return "warning:";974 /* A comment. */975 default: return "";976 }977 978 * ``bool AlignCaseArrows`` Whether to align the case arrows when aligning short case expressions.979 980 .. code-block:: java981 982 true:983 i = switch (day) {984 case THURSDAY, SATURDAY -> 8;985 case WEDNESDAY -> 9;986 default -> 0;987 };988 989 false:990 i = switch (day) {991 case THURSDAY, SATURDAY -> 8;992 case WEDNESDAY -> 9;993 default -> 0;994 };995 996 * ``bool AlignCaseColons`` Whether aligned case labels are aligned on the colon, or on the tokens997 after the colon.998 999 .. code-block:: c++1000 1001 true:1002 switch (level) {1003 case log::info : return "info:";1004 case log::warning: return "warning:";1005 default : return "";1006 }1007 1008 false:1009 switch (level) {1010 case log::info: return "info:";1011 case log::warning: return "warning:";1012 default: return "";1013 }1014 1015 1016.. _AlignConsecutiveTableGenBreakingDAGArgColons:1017 1018**AlignConsecutiveTableGenBreakingDAGArgColons** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 19` :ref:`¶ <AlignConsecutiveTableGenBreakingDAGArgColons>`1019 Style of aligning consecutive TableGen DAGArg operator colons.1020 If enabled, align the colon inside DAGArg which have line break inside.1021 This works only when TableGenBreakInsideDAGArg is BreakElements or1022 BreakAll and the DAGArg is not excepted by1023 TableGenBreakingDAGArgOperators's effect.1024 1025 .. code-block:: c++1026 1027 let dagarg = (ins1028 a :$src1,1029 aa :$src2,1030 aaa:$src31031 )1032 1033 Nested configuration flags:1034 1035 Alignment options.1036 1037 They can also be read as a whole for compatibility. The choices are:1038 1039 * ``None``1040 * ``Consecutive``1041 * ``AcrossEmptyLines``1042 * ``AcrossComments``1043 * ``AcrossEmptyLinesAndComments``1044 1045 For example, to align across empty lines and not across comments, either1046 of these work.1047 1048 .. code-block:: c++1049 1050 AlignConsecutiveTableGenBreakingDAGArgColons: AcrossEmptyLines1051 1052 AlignConsecutiveTableGenBreakingDAGArgColons:1053 Enabled: true1054 AcrossEmptyLines: true1055 AcrossComments: false1056 1057 * ``bool Enabled`` Whether aligning is enabled.1058 1059 .. code-block:: c++1060 1061 #define SHORT_NAME 421062 #define LONGER_NAME 0x007f1063 #define EVEN_LONGER_NAME (2)1064 #define foo(x) (x * x)1065 #define bar(y, z) (y + z)1066 1067 int a = 1;1068 int somelongname = 2;1069 double c = 3;1070 1071 int aaaa : 1;1072 int b : 12;1073 int ccc : 8;1074 1075 int aaaa = 12;1076 float b = 23;1077 std::string ccc;1078 1079 * ``bool AcrossEmptyLines`` Whether to align across empty lines.1080 1081 .. code-block:: c++1082 1083 true:1084 int a = 1;1085 int somelongname = 2;1086 double c = 3;1087 1088 int d = 3;1089 1090 false:1091 int a = 1;1092 int somelongname = 2;1093 double c = 3;1094 1095 int d = 3;1096 1097 * ``bool AcrossComments`` Whether to align across comments.1098 1099 .. code-block:: c++1100 1101 true:1102 int d = 3;1103 /* A comment. */1104 double e = 4;1105 1106 false:1107 int d = 3;1108 /* A comment. */1109 double e = 4;1110 1111 * ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound assignments1112 like ``+=`` are aligned along with ``=``.1113 1114 .. code-block:: c++1115 1116 true:1117 a &= 2;1118 bbb = 2;1119 1120 false:1121 a &= 2;1122 bbb = 2;1123 1124 * ``bool AlignFunctionDeclarations`` Only for ``AlignConsecutiveDeclarations``. Whether function declarations1125 are aligned.1126 1127 .. code-block:: c++1128 1129 true:1130 unsigned int f1(void);1131 void f2(void);1132 size_t f3(void);1133 1134 false:1135 unsigned int f1(void);1136 void f2(void);1137 size_t f3(void);1138 1139 * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are1140 aligned.1141 1142 .. code-block:: c++1143 1144 true:1145 unsigned i;1146 int &r;1147 int *p;1148 int (*f)();1149 1150 false:1151 unsigned i;1152 int &r;1153 int *p;1154 int (*f)();1155 1156 * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment1157 operators are left-padded to the same length as long ones in order to1158 put all assignment operators to the right of the left hand side.1159 1160 .. code-block:: c++1161 1162 true:1163 a >>= 2;1164 bbb = 2;1165 1166 a = 2;1167 bbb >>= 2;1168 1169 false:1170 a >>= 2;1171 bbb = 2;1172 1173 a = 2;1174 bbb >>= 2;1175 1176 1177.. _AlignConsecutiveTableGenCondOperatorColons:1178 1179**AlignConsecutiveTableGenCondOperatorColons** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 19` :ref:`¶ <AlignConsecutiveTableGenCondOperatorColons>`1180 Style of aligning consecutive TableGen cond operator colons.1181 Align the colons of cases inside !cond operators.1182 1183 .. code-block:: c++1184 1185 !cond(!eq(size, 1) : 1,1186 !eq(size, 16): 1,1187 true : 0)1188 1189 Nested configuration flags:1190 1191 Alignment options.1192 1193 They can also be read as a whole for compatibility. The choices are:1194 1195 * ``None``1196 * ``Consecutive``1197 * ``AcrossEmptyLines``1198 * ``AcrossComments``1199 * ``AcrossEmptyLinesAndComments``1200 1201 For example, to align across empty lines and not across comments, either1202 of these work.1203 1204 .. code-block:: c++1205 1206 AlignConsecutiveTableGenCondOperatorColons: AcrossEmptyLines1207 1208 AlignConsecutiveTableGenCondOperatorColons:1209 Enabled: true1210 AcrossEmptyLines: true1211 AcrossComments: false1212 1213 * ``bool Enabled`` Whether aligning is enabled.1214 1215 .. code-block:: c++1216 1217 #define SHORT_NAME 421218 #define LONGER_NAME 0x007f1219 #define EVEN_LONGER_NAME (2)1220 #define foo(x) (x * x)1221 #define bar(y, z) (y + z)1222 1223 int a = 1;1224 int somelongname = 2;1225 double c = 3;1226 1227 int aaaa : 1;1228 int b : 12;1229 int ccc : 8;1230 1231 int aaaa = 12;1232 float b = 23;1233 std::string ccc;1234 1235 * ``bool AcrossEmptyLines`` Whether to align across empty lines.1236 1237 .. code-block:: c++1238 1239 true:1240 int a = 1;1241 int somelongname = 2;1242 double c = 3;1243 1244 int d = 3;1245 1246 false:1247 int a = 1;1248 int somelongname = 2;1249 double c = 3;1250 1251 int d = 3;1252 1253 * ``bool AcrossComments`` Whether to align across comments.1254 1255 .. code-block:: c++1256 1257 true:1258 int d = 3;1259 /* A comment. */1260 double e = 4;1261 1262 false:1263 int d = 3;1264 /* A comment. */1265 double e = 4;1266 1267 * ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound assignments1268 like ``+=`` are aligned along with ``=``.1269 1270 .. code-block:: c++1271 1272 true:1273 a &= 2;1274 bbb = 2;1275 1276 false:1277 a &= 2;1278 bbb = 2;1279 1280 * ``bool AlignFunctionDeclarations`` Only for ``AlignConsecutiveDeclarations``. Whether function declarations1281 are aligned.1282 1283 .. code-block:: c++1284 1285 true:1286 unsigned int f1(void);1287 void f2(void);1288 size_t f3(void);1289 1290 false:1291 unsigned int f1(void);1292 void f2(void);1293 size_t f3(void);1294 1295 * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are1296 aligned.1297 1298 .. code-block:: c++1299 1300 true:1301 unsigned i;1302 int &r;1303 int *p;1304 int (*f)();1305 1306 false:1307 unsigned i;1308 int &r;1309 int *p;1310 int (*f)();1311 1312 * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment1313 operators are left-padded to the same length as long ones in order to1314 put all assignment operators to the right of the left hand side.1315 1316 .. code-block:: c++1317 1318 true:1319 a >>= 2;1320 bbb = 2;1321 1322 a = 2;1323 bbb >>= 2;1324 1325 false:1326 a >>= 2;1327 bbb = 2;1328 1329 a = 2;1330 bbb >>= 2;1331 1332 1333.. _AlignConsecutiveTableGenDefinitionColons:1334 1335**AlignConsecutiveTableGenDefinitionColons** (``AlignConsecutiveStyle``) :versionbadge:`clang-format 19` :ref:`¶ <AlignConsecutiveTableGenDefinitionColons>`1336 Style of aligning consecutive TableGen definition colons.1337 This aligns the inheritance colons of consecutive definitions.1338 1339 .. code-block:: c++1340 1341 def Def : Parent {}1342 def DefDef : Parent {}1343 def DefDefDef : Parent {}1344 1345 Nested configuration flags:1346 1347 Alignment options.1348 1349 They can also be read as a whole for compatibility. The choices are:1350 1351 * ``None``1352 * ``Consecutive``1353 * ``AcrossEmptyLines``1354 * ``AcrossComments``1355 * ``AcrossEmptyLinesAndComments``1356 1357 For example, to align across empty lines and not across comments, either1358 of these work.1359 1360 .. code-block:: c++1361 1362 AlignConsecutiveTableGenDefinitionColons: AcrossEmptyLines1363 1364 AlignConsecutiveTableGenDefinitionColons:1365 Enabled: true1366 AcrossEmptyLines: true1367 AcrossComments: false1368 1369 * ``bool Enabled`` Whether aligning is enabled.1370 1371 .. code-block:: c++1372 1373 #define SHORT_NAME 421374 #define LONGER_NAME 0x007f1375 #define EVEN_LONGER_NAME (2)1376 #define foo(x) (x * x)1377 #define bar(y, z) (y + z)1378 1379 int a = 1;1380 int somelongname = 2;1381 double c = 3;1382 1383 int aaaa : 1;1384 int b : 12;1385 int ccc : 8;1386 1387 int aaaa = 12;1388 float b = 23;1389 std::string ccc;1390 1391 * ``bool AcrossEmptyLines`` Whether to align across empty lines.1392 1393 .. code-block:: c++1394 1395 true:1396 int a = 1;1397 int somelongname = 2;1398 double c = 3;1399 1400 int d = 3;1401 1402 false:1403 int a = 1;1404 int somelongname = 2;1405 double c = 3;1406 1407 int d = 3;1408 1409 * ``bool AcrossComments`` Whether to align across comments.1410 1411 .. code-block:: c++1412 1413 true:1414 int d = 3;1415 /* A comment. */1416 double e = 4;1417 1418 false:1419 int d = 3;1420 /* A comment. */1421 double e = 4;1422 1423 * ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound assignments1424 like ``+=`` are aligned along with ``=``.1425 1426 .. code-block:: c++1427 1428 true:1429 a &= 2;1430 bbb = 2;1431 1432 false:1433 a &= 2;1434 bbb = 2;1435 1436 * ``bool AlignFunctionDeclarations`` Only for ``AlignConsecutiveDeclarations``. Whether function declarations1437 are aligned.1438 1439 .. code-block:: c++1440 1441 true:1442 unsigned int f1(void);1443 void f2(void);1444 size_t f3(void);1445 1446 false:1447 unsigned int f1(void);1448 void f2(void);1449 size_t f3(void);1450 1451 * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are1452 aligned.1453 1454 .. code-block:: c++1455 1456 true:1457 unsigned i;1458 int &r;1459 int *p;1460 int (*f)();1461 1462 false:1463 unsigned i;1464 int &r;1465 int *p;1466 int (*f)();1467 1468 * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment1469 operators are left-padded to the same length as long ones in order to1470 put all assignment operators to the right of the left hand side.1471 1472 .. code-block:: c++1473 1474 true:1475 a >>= 2;1476 bbb = 2;1477 1478 a = 2;1479 bbb >>= 2;1480 1481 false:1482 a >>= 2;1483 bbb = 2;1484 1485 a = 2;1486 bbb >>= 2;1487 1488 1489.. _AlignEscapedNewlines:1490 1491**AlignEscapedNewlines** (``EscapedNewlineAlignmentStyle``) :versionbadge:`clang-format 5` :ref:`¶ <AlignEscapedNewlines>`1492 Options for aligning backslashes in escaped newlines.1493 1494 Possible values:1495 1496 * ``ENAS_DontAlign`` (in configuration: ``DontAlign``)1497 Don't align escaped newlines.1498 1499 .. code-block:: c++1500 1501 #define A \1502 int aaaa; \1503 int b; \1504 int dddddddddd;1505 1506 * ``ENAS_Left`` (in configuration: ``Left``)1507 Align escaped newlines as far left as possible.1508 1509 .. code-block:: c++1510 1511 #define A \1512 int aaaa; \1513 int b; \1514 int dddddddddd;1515 1516 * ``ENAS_LeftWithLastLine`` (in configuration: ``LeftWithLastLine``)1517 Align escaped newlines as far left as possible, using the last line of1518 the preprocessor directive as the reference if it's the longest.1519 1520 .. code-block:: c++1521 1522 #define A \1523 int aaaa; \1524 int b; \1525 int dddddddddd;1526 1527 * ``ENAS_Right`` (in configuration: ``Right``)1528 Align escaped newlines in the right-most column.1529 1530 .. code-block:: c++1531 1532 #define A \1533 int aaaa; \1534 int b; \1535 int dddddddddd;1536 1537 1538 1539.. _AlignOperands:1540 1541**AlignOperands** (``OperandAlignmentStyle``) :versionbadge:`clang-format 3.5` :ref:`¶ <AlignOperands>`1542 If ``true``, horizontally align operands of binary and ternary1543 expressions.1544 1545 Possible values:1546 1547 * ``OAS_DontAlign`` (in configuration: ``DontAlign``)1548 Do not align operands of binary and ternary expressions.1549 The wrapped lines are indented ``ContinuationIndentWidth`` spaces from1550 the start of the line.1551 1552 * ``OAS_Align`` (in configuration: ``Align``)1553 Horizontally align operands of binary and ternary expressions.1554 1555 Specifically, this aligns operands of a single expression that needs1556 to be split over multiple lines, e.g.:1557 1558 .. code-block:: c++1559 1560 int aaa = bbbbbbbbbbbbbbb +1561 ccccccccccccccc;1562 1563 When ``BreakBeforeBinaryOperators`` is set, the wrapped operator is1564 aligned with the operand on the first line.1565 1566 .. code-block:: c++1567 1568 int aaa = bbbbbbbbbbbbbbb1569 + ccccccccccccccc;1570 1571 * ``OAS_AlignAfterOperator`` (in configuration: ``AlignAfterOperator``)1572 Horizontally align operands of binary and ternary expressions.1573 1574 This is similar to ``OAS_Align``, except when1575 ``BreakBeforeBinaryOperators`` is set, the operator is un-indented so1576 that the wrapped operand is aligned with the operand on the first line.1577 1578 .. code-block:: c++1579 1580 int aaa = bbbbbbbbbbbbbbb1581 + ccccccccccccccc;1582 1583 1584 1585.. _AlignTrailingComments:1586 1587**AlignTrailingComments** (``TrailingCommentsAlignmentStyle``) :versionbadge:`clang-format 3.7` :ref:`¶ <AlignTrailingComments>`1588 Control of trailing comments.1589 1590 The alignment stops at closing braces after a line break, and only1591 followed by other closing braces, a (``do-``) ``while``, a lambda call, or1592 a semicolon.1593 1594 1595 .. note::1596 1597 As of clang-format 16 this option is not a bool but can be set1598 to the options. Conventional bool options still can be parsed as before.1599 1600 1601 .. code-block:: yaml1602 1603 # Example of usage:1604 AlignTrailingComments:1605 Kind: Always1606 OverEmptyLines: 21607 1608 Nested configuration flags:1609 1610 Alignment options1611 1612 * ``TrailingCommentsAlignmentKinds Kind``1613 Specifies the way to align trailing comments.1614 1615 Possible values:1616 1617 * ``TCAS_Leave`` (in configuration: ``Leave``)1618 Leave trailing comments as they are.1619 1620 .. code-block:: c++1621 1622 int a; // comment1623 int ab; // comment1624 1625 int abc; // comment1626 int abcd; // comment1627 1628 * ``TCAS_Always`` (in configuration: ``Always``)1629 Align trailing comments.1630 1631 .. code-block:: c++1632 1633 int a; // comment1634 int ab; // comment1635 1636 int abc; // comment1637 int abcd; // comment1638 1639 * ``TCAS_Never`` (in configuration: ``Never``)1640 Don't align trailing comments but other formatter applies.1641 1642 .. code-block:: c++1643 1644 int a; // comment1645 int ab; // comment1646 1647 int abc; // comment1648 int abcd; // comment1649 1650 1651 * ``unsigned OverEmptyLines`` How many empty lines to apply alignment.1652 When both ``MaxEmptyLinesToKeep`` and ``OverEmptyLines`` are set to 2,1653 it formats like below.1654 1655 .. code-block:: c++1656 1657 int a; // all these1658 1659 int ab; // comments are1660 1661 1662 int abcdef; // aligned1663 1664 When ``MaxEmptyLinesToKeep`` is set to 2 and ``OverEmptyLines`` is set1665 to 1, it formats like below.1666 1667 .. code-block:: c++1668 1669 int a; // these are1670 1671 int ab; // aligned1672 1673 1674 int abcdef; // but this isn't1675 1676 * ``bool AlignPPAndNotPP`` If comments following preprocessor directive should be aligned with1677 comments that don't.1678 1679 .. code-block:: c++1680 1681 true: false:1682 #define A // Comment vs. #define A // Comment1683 #define AB // Aligned #define AB // Aligned1684 int i; // Aligned int i; // Not aligned1685 1686 1687.. _AllowAllArgumentsOnNextLine:1688 1689**AllowAllArgumentsOnNextLine** (``Boolean``) :versionbadge:`clang-format 9` :ref:`¶ <AllowAllArgumentsOnNextLine>`1690 If a function call or braced initializer list doesn't fit on a line, allow1691 putting all arguments onto the next line, even if ``BinPackArguments`` is1692 ``false``.1693 1694 .. code-block:: c++1695 1696 true:1697 callFunction(1698 a, b, c, d);1699 1700 false:1701 callFunction(a,1702 b,1703 c,1704 d);1705 1706.. _AllowAllConstructorInitializersOnNextLine:1707 1708**AllowAllConstructorInitializersOnNextLine** (``Boolean``) :versionbadge:`clang-format 9` :ref:`¶ <AllowAllConstructorInitializersOnNextLine>`1709 This option is **deprecated**. See ``NextLine`` of1710 ``PackConstructorInitializers``.1711 1712.. _AllowAllParametersOfDeclarationOnNextLine:1713 1714**AllowAllParametersOfDeclarationOnNextLine** (``Boolean``) :versionbadge:`clang-format 3.3` :ref:`¶ <AllowAllParametersOfDeclarationOnNextLine>`1715 If the function declaration doesn't fit on a line,1716 allow putting all parameters of a function declaration onto1717 the next line even if ``BinPackParameters`` is ``OnePerLine``.1718 1719 .. code-block:: c++1720 1721 true:1722 void myFunction(1723 int a, int b, int c, int d, int e);1724 1725 false:1726 void myFunction(int a,1727 int b,1728 int c,1729 int d,1730 int e);1731 1732.. _AllowBreakBeforeNoexceptSpecifier:1733 1734**AllowBreakBeforeNoexceptSpecifier** (``BreakBeforeNoexceptSpecifierStyle``) :versionbadge:`clang-format 18` :ref:`¶ <AllowBreakBeforeNoexceptSpecifier>`1735 Controls if there could be a line break before a ``noexcept`` specifier.1736 1737 Possible values:1738 1739 * ``BBNSS_Never`` (in configuration: ``Never``)1740 No line break allowed.1741 1742 .. code-block:: c++1743 1744 void foo(int arg1,1745 double arg2) noexcept;1746 1747 void bar(int arg1, double arg2) noexcept(1748 noexcept(baz(arg1)) &&1749 noexcept(baz(arg2)));1750 1751 * ``BBNSS_OnlyWithParen`` (in configuration: ``OnlyWithParen``)1752 For a simple ``noexcept`` there is no line break allowed, but when we1753 have a condition it is.1754 1755 .. code-block:: c++1756 1757 void foo(int arg1,1758 double arg2) noexcept;1759 1760 void bar(int arg1, double arg2)1761 noexcept(noexcept(baz(arg1)) &&1762 noexcept(baz(arg2)));1763 1764 * ``BBNSS_Always`` (in configuration: ``Always``)1765 Line breaks are allowed. But note that because of the associated1766 penalties ``clang-format`` often prefers not to break before the1767 ``noexcept``.1768 1769 .. code-block:: c++1770 1771 void foo(int arg1,1772 double arg2) noexcept;1773 1774 void bar(int arg1, double arg2)1775 noexcept(noexcept(baz(arg1)) &&1776 noexcept(baz(arg2)));1777 1778 1779 1780.. _AllowBreakBeforeQtProperty:1781 1782**AllowBreakBeforeQtProperty** (``Boolean``) :versionbadge:`clang-format 22` :ref:`¶ <AllowBreakBeforeQtProperty>`1783 Allow breaking before ``Q_Property`` keywords ``READ``, ``WRITE``, etc. as1784 if they were preceded by a comma (``,``). This allows them to be formatted1785 according to ``BinPackParameters``.1786 1787.. _AllowShortBlocksOnASingleLine:1788 1789**AllowShortBlocksOnASingleLine** (``ShortBlockStyle``) :versionbadge:`clang-format 3.5` :ref:`¶ <AllowShortBlocksOnASingleLine>`1790 Dependent on the value, ``while (true) { continue; }`` can be put on a1791 single line.1792 1793 Possible values:1794 1795 * ``SBS_Never`` (in configuration: ``Never``)1796 Never merge blocks into a single line.1797 1798 .. code-block:: c++1799 1800 while (true) {1801 }1802 while (true) {1803 continue;1804 }1805 1806 * ``SBS_Empty`` (in configuration: ``Empty``)1807 Only merge empty blocks.1808 1809 .. code-block:: c++1810 1811 while (true) {}1812 while (true) {1813 continue;1814 }1815 1816 * ``SBS_Always`` (in configuration: ``Always``)1817 Always merge short blocks into a single line.1818 1819 .. code-block:: c++1820 1821 while (true) {}1822 while (true) { continue; }1823 1824 1825 1826.. _AllowShortCaseExpressionOnASingleLine:1827 1828**AllowShortCaseExpressionOnASingleLine** (``Boolean``) :versionbadge:`clang-format 19` :ref:`¶ <AllowShortCaseExpressionOnASingleLine>`1829 Whether to merge a short switch labeled rule into a single line.1830 1831 .. code-block:: java1832 1833 true: false:1834 switch (a) { vs. switch (a) {1835 case 1 -> 1; case 1 ->1836 default -> 0; 1;1837 }; default ->1838 0;1839 };1840 1841.. _AllowShortCaseLabelsOnASingleLine:1842 1843**AllowShortCaseLabelsOnASingleLine** (``Boolean``) :versionbadge:`clang-format 3.6` :ref:`¶ <AllowShortCaseLabelsOnASingleLine>`1844 If ``true``, short case labels will be contracted to a single line.1845 1846 .. code-block:: c++1847 1848 true: false:1849 switch (a) { vs. switch (a) {1850 case 1: x = 1; break; case 1:1851 case 2: return; x = 1;1852 } break;1853 case 2:1854 return;1855 }1856 1857.. _AllowShortCompoundRequirementOnASingleLine:1858 1859**AllowShortCompoundRequirementOnASingleLine** (``Boolean``) :versionbadge:`clang-format 18` :ref:`¶ <AllowShortCompoundRequirementOnASingleLine>`1860 Allow short compound requirement on a single line.1861 1862 .. code-block:: c++1863 1864 true:1865 template <typename T>1866 concept c = requires(T x) {1867 { x + 1 } -> std::same_as<int>;1868 };1869 1870 false:1871 template <typename T>1872 concept c = requires(T x) {1873 {1874 x + 11875 } -> std::same_as<int>;1876 };1877 1878.. _AllowShortEnumsOnASingleLine:1879 1880**AllowShortEnumsOnASingleLine** (``Boolean``) :versionbadge:`clang-format 11` :ref:`¶ <AllowShortEnumsOnASingleLine>`1881 Allow short enums on a single line.1882 1883 .. code-block:: c++1884 1885 true:1886 enum { A, B } myEnum;1887 1888 false:1889 enum {1890 A,1891 B1892 } myEnum;1893 1894.. _AllowShortFunctionsOnASingleLine:1895 1896**AllowShortFunctionsOnASingleLine** (``ShortFunctionStyle``) :versionbadge:`clang-format 3.5` :ref:`¶ <AllowShortFunctionsOnASingleLine>`1897 Dependent on the value, ``int f() { return 0; }`` can be put on a1898 single line.1899 1900 Possible values:1901 1902 * ``SFS_None`` (in configuration: ``None``)1903 Never merge functions into a single line.1904 1905 * ``SFS_InlineOnly`` (in configuration: ``InlineOnly``)1906 Only merge functions defined inside a class. Same as ``inline``,1907 except it does not imply ``empty``: i.e. top level empty functions1908 are not merged either.1909 1910 .. code-block:: c++1911 1912 class Foo {1913 void f() { foo(); }1914 };1915 void f() {1916 foo();1917 }1918 void f() {1919 }1920 1921 * ``SFS_Empty`` (in configuration: ``Empty``)1922 Only merge empty functions.1923 1924 .. code-block:: c++1925 1926 void f() {}1927 void f2() {1928 bar2();1929 }1930 1931 * ``SFS_Inline`` (in configuration: ``Inline``)1932 Only merge functions defined inside a class. Implies ``empty``.1933 1934 .. code-block:: c++1935 1936 class Foo {1937 void f() { foo(); }1938 };1939 void f() {1940 foo();1941 }1942 void f() {}1943 1944 * ``SFS_All`` (in configuration: ``All``)1945 Merge all functions fitting on a single line.1946 1947 .. code-block:: c++1948 1949 class Foo {1950 void f() { foo(); }1951 };1952 void f() { bar(); }1953 1954 1955 1956.. _AllowShortIfStatementsOnASingleLine:1957 1958**AllowShortIfStatementsOnASingleLine** (``ShortIfStyle``) :versionbadge:`clang-format 3.3` :ref:`¶ <AllowShortIfStatementsOnASingleLine>`1959 Dependent on the value, ``if (a) return;`` can be put on a single line.1960 1961 Possible values:1962 1963 * ``SIS_Never`` (in configuration: ``Never``)1964 Never put short ifs on the same line.1965 1966 .. code-block:: c++1967 1968 if (a)1969 return;1970 1971 if (b)1972 return;1973 else1974 return;1975 1976 if (c)1977 return;1978 else {1979 return;1980 }1981 1982 * ``SIS_WithoutElse`` (in configuration: ``WithoutElse``)1983 Put short ifs on the same line only if there is no else statement.1984 1985 .. code-block:: c++1986 1987 if (a) return;1988 1989 if (b)1990 return;1991 else1992 return;1993 1994 if (c)1995 return;1996 else {1997 return;1998 }1999 2000 * ``SIS_OnlyFirstIf`` (in configuration: ``OnlyFirstIf``)2001 Put short ifs, but not else ifs nor else statements, on the same line.2002 2003 .. code-block:: c++2004 2005 if (a) return;2006 2007 if (b) return;2008 else if (b)2009 return;2010 else2011 return;2012 2013 if (c) return;2014 else {2015 return;2016 }2017 2018 * ``SIS_AllIfsAndElse`` (in configuration: ``AllIfsAndElse``)2019 Always put short ifs, else ifs and else statements on the same2020 line.2021 2022 .. code-block:: c++2023 2024 if (a) return;2025 2026 if (b) return;2027 else return;2028 2029 if (c) return;2030 else {2031 return;2032 }2033 2034 2035 2036.. _AllowShortLambdasOnASingleLine:2037 2038**AllowShortLambdasOnASingleLine** (``ShortLambdaStyle``) :versionbadge:`clang-format 9` :ref:`¶ <AllowShortLambdasOnASingleLine>`2039 Dependent on the value, ``auto lambda []() { return 0; }`` can be put on a2040 single line.2041 2042 Possible values:2043 2044 * ``SLS_None`` (in configuration: ``None``)2045 Never merge lambdas into a single line.2046 2047 * ``SLS_Empty`` (in configuration: ``Empty``)2048 Only merge empty lambdas.2049 2050 .. code-block:: c++2051 2052 auto lambda = [](int a) {};2053 auto lambda2 = [](int a) {2054 return a;2055 };2056 2057 * ``SLS_Inline`` (in configuration: ``Inline``)2058 Merge lambda into a single line if the lambda is argument of a function.2059 2060 .. code-block:: c++2061 2062 auto lambda = [](int x, int y) {2063 return x < y;2064 };2065 sort(a.begin(), a.end(), [](int x, int y) { return x < y; });2066 2067 * ``SLS_All`` (in configuration: ``All``)2068 Merge all lambdas fitting on a single line.2069 2070 .. code-block:: c++2071 2072 auto lambda = [](int a) {};2073 auto lambda2 = [](int a) { return a; };2074 2075 2076 2077.. _AllowShortLoopsOnASingleLine:2078 2079**AllowShortLoopsOnASingleLine** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <AllowShortLoopsOnASingleLine>`2080 If ``true``, ``while (true) continue;`` can be put on a single2081 line.2082 2083.. _AllowShortNamespacesOnASingleLine:2084 2085**AllowShortNamespacesOnASingleLine** (``Boolean``) :versionbadge:`clang-format 20` :ref:`¶ <AllowShortNamespacesOnASingleLine>`2086 If ``true``, ``namespace a { class b; }`` can be put on a single line.2087 2088.. _AlwaysBreakAfterDefinitionReturnType:2089 2090**AlwaysBreakAfterDefinitionReturnType** (``DefinitionReturnTypeBreakingStyle``) :versionbadge:`clang-format 3.7` :ref:`¶ <AlwaysBreakAfterDefinitionReturnType>`2091 The function definition return type breaking style to use. This2092 option is **deprecated** and is retained for backwards compatibility.2093 2094 Possible values:2095 2096 * ``DRTBS_None`` (in configuration: ``None``)2097 Break after return type automatically.2098 ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.2099 2100 * ``DRTBS_All`` (in configuration: ``All``)2101 Always break after the return type.2102 2103 * ``DRTBS_TopLevel`` (in configuration: ``TopLevel``)2104 Always break after the return types of top-level functions.2105 2106 2107 2108.. _AlwaysBreakAfterReturnType:2109 2110**AlwaysBreakAfterReturnType** (``deprecated``) :versionbadge:`clang-format 3.8` :ref:`¶ <AlwaysBreakAfterReturnType>`2111 This option is renamed to ``BreakAfterReturnType``.2112 2113.. _AlwaysBreakBeforeMultilineStrings:2114 2115**AlwaysBreakBeforeMultilineStrings** (``Boolean``) :versionbadge:`clang-format 3.4` :ref:`¶ <AlwaysBreakBeforeMultilineStrings>`2116 If ``true``, always break before multiline string literals.2117 2118 This flag is mean to make cases where there are multiple multiline strings2119 in a file look more consistent. Thus, it will only take effect if wrapping2120 the string at that point leads to it being indented2121 ``ContinuationIndentWidth`` spaces from the start of the line.2122 2123 .. code-block:: c++2124 2125 true: false:2126 aaaa = vs. aaaa = "bbbb"2127 "bbbb" "cccc";2128 "cccc";2129 2130.. _AlwaysBreakTemplateDeclarations:2131 2132**AlwaysBreakTemplateDeclarations** (``deprecated``) :versionbadge:`clang-format 3.4` :ref:`¶ <AlwaysBreakTemplateDeclarations>`2133 This option is renamed to ``BreakTemplateDeclarations``.2134 2135.. _AttributeMacros:2136 2137**AttributeMacros** (``List of Strings``) :versionbadge:`clang-format 12` :ref:`¶ <AttributeMacros>`2138 A vector of strings that should be interpreted as attributes/qualifiers2139 instead of identifiers. This can be useful for language extensions or2140 static analyzer annotations.2141 2142 For example:2143 2144 .. code-block:: c++2145 2146 x = (char *__capability)&y;2147 int function(void) __unused;2148 void only_writes_to_buffer(char *__output buffer);2149 2150 In the .clang-format configuration file, this can be configured like:2151 2152 .. code-block:: yaml2153 2154 AttributeMacros: [__capability, __output, __unused]2155 2156.. _BinPackArguments:2157 2158**BinPackArguments** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <BinPackArguments>`2159 If ``false``, a function call's arguments will either be all on the2160 same line or will have one line each.2161 2162 .. code-block:: c++2163 2164 true:2165 void f() {2166 f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa,2167 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);2168 }2169 2170 false:2171 void f() {2172 f(aaaaaaaaaaaaaaaaaaaa,2173 aaaaaaaaaaaaaaaaaaaa,2174 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);2175 }2176 2177.. _BinPackLongBracedList:2178 2179**BinPackLongBracedList** (``Boolean``) :versionbadge:`clang-format 21` :ref:`¶ <BinPackLongBracedList>`2180 If ``BinPackLongBracedList`` is ``true`` it overrides2181 ``BinPackArguments`` if there are 20 or more items in a braced2182 initializer list.2183 2184 .. code-block:: c++2185 2186 BinPackLongBracedList: false vs. BinPackLongBracedList: true2187 vector<int> x{ vector<int> x{1, 2, ...,2188 20, 21};2189 1,2190 2,2191 ...,2192 20,2193 21};2194 2195.. _BinPackParameters:2196 2197**BinPackParameters** (``BinPackParametersStyle``) :versionbadge:`clang-format 3.7` :ref:`¶ <BinPackParameters>`2198 The bin pack parameters style to use.2199 2200 Possible values:2201 2202 * ``BPPS_BinPack`` (in configuration: ``BinPack``)2203 Bin-pack parameters.2204 2205 .. code-block:: c++2206 2207 void f(int a, int bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,2208 int ccccccccccccccccccccccccccccccccccccccccccc);2209 2210 * ``BPPS_OnePerLine`` (in configuration: ``OnePerLine``)2211 Put all parameters on the current line if they fit.2212 Otherwise, put each one on its own line.2213 2214 .. code-block:: c++2215 2216 void f(int a, int b, int c);2217 2218 void f(int a,2219 int b,2220 int ccccccccccccccccccccccccccccccccccccc);2221 2222 * ``BPPS_AlwaysOnePerLine`` (in configuration: ``AlwaysOnePerLine``)2223 Always put each parameter on its own line.2224 2225 .. code-block:: c++2226 2227 void f(int a,2228 int b,2229 int c);2230 2231 2232 2233.. _BitFieldColonSpacing:2234 2235**BitFieldColonSpacing** (``BitFieldColonSpacingStyle``) :versionbadge:`clang-format 12` :ref:`¶ <BitFieldColonSpacing>`2236 The BitFieldColonSpacingStyle to use for bitfields.2237 2238 Possible values:2239 2240 * ``BFCS_Both`` (in configuration: ``Both``)2241 Add one space on each side of the ``:``2242 2243 .. code-block:: c++2244 2245 unsigned bf : 2;2246 2247 * ``BFCS_None`` (in configuration: ``None``)2248 Add no space around the ``:`` (except when needed for2249 ``AlignConsecutiveBitFields``).2250 2251 .. code-block:: c++2252 2253 unsigned bf:2;2254 2255 * ``BFCS_Before`` (in configuration: ``Before``)2256 Add space before the ``:`` only2257 2258 .. code-block:: c++2259 2260 unsigned bf :2;2261 2262 * ``BFCS_After`` (in configuration: ``After``)2263 Add space after the ``:`` only (space may be added before if2264 needed for ``AlignConsecutiveBitFields``).2265 2266 .. code-block:: c++2267 2268 unsigned bf: 2;2269 2270 2271 2272.. _BraceWrapping:2273 2274**BraceWrapping** (``BraceWrappingFlags``) :versionbadge:`clang-format 3.8` :ref:`¶ <BraceWrapping>`2275 Control of individual brace wrapping cases.2276 2277 If ``BreakBeforeBraces`` is set to ``Custom``, use this to specify how2278 each individual brace case should be handled. Otherwise, this is ignored.2279 2280 .. code-block:: yaml2281 2282 # Example of usage:2283 BreakBeforeBraces: Custom2284 BraceWrapping:2285 AfterEnum: true2286 AfterStruct: false2287 SplitEmptyFunction: false2288 2289 Nested configuration flags:2290 2291 Precise control over the wrapping of braces.2292 2293 .. code-block:: c++2294 2295 # Should be declared this way:2296 BreakBeforeBraces: Custom2297 BraceWrapping:2298 AfterClass: true2299 2300 * ``bool AfterCaseLabel`` Wrap case labels.2301 2302 .. code-block:: c++2303 2304 false: true:2305 switch (foo) { vs. switch (foo) {2306 case 1: { case 1:2307 bar(); {2308 break; bar();2309 } break;2310 default: { }2311 plop(); default:2312 } {2313 } plop();2314 }2315 }2316 2317 * ``bool AfterClass`` Wrap class definitions.2318 2319 .. code-block:: c++2320 2321 true:2322 class foo2323 {};2324 2325 false:2326 class foo {};2327 2328 * ``BraceWrappingAfterControlStatementStyle AfterControlStatement``2329 Wrap control statements (``if``/``for``/``while``/``switch``/..).2330 2331 Possible values:2332 2333 * ``BWACS_Never`` (in configuration: ``Never``)2334 Never wrap braces after a control statement.2335 2336 .. code-block:: c++2337 2338 if (foo()) {2339 } else {2340 }2341 for (int i = 0; i < 10; ++i) {2342 }2343 2344 * ``BWACS_MultiLine`` (in configuration: ``MultiLine``)2345 Only wrap braces after a multi-line control statement.2346 2347 .. code-block:: c++2348 2349 if (foo && bar &&2350 baz)2351 {2352 quux();2353 }2354 while (foo || bar) {2355 }2356 2357 * ``BWACS_Always`` (in configuration: ``Always``)2358 Always wrap braces after a control statement.2359 2360 .. code-block:: c++2361 2362 if (foo())2363 {2364 } else2365 {}2366 for (int i = 0; i < 10; ++i)2367 {}2368 2369 2370 * ``bool AfterEnum`` Wrap enum definitions.2371 2372 .. code-block:: c++2373 2374 true:2375 enum X : int2376 {2377 B2378 };2379 2380 false:2381 enum X : int { B };2382 2383 * ``bool AfterFunction`` Wrap function definitions.2384 2385 .. code-block:: c++2386 2387 true:2388 void foo()2389 {2390 bar();2391 bar2();2392 }2393 2394 false:2395 void foo() {2396 bar();2397 bar2();2398 }2399 2400 * ``bool AfterNamespace`` Wrap namespace definitions.2401 2402 .. code-block:: c++2403 2404 true:2405 namespace2406 {2407 int foo();2408 int bar();2409 }2410 2411 false:2412 namespace {2413 int foo();2414 int bar();2415 }2416 2417 * ``bool AfterObjCDeclaration`` Wrap ObjC definitions (interfaces, implementations...).2418 2419 .. note::2420 2421 @autoreleasepool and @synchronized blocks are wrapped2422 according to ``AfterControlStatement`` flag.2423 2424 * ``bool AfterStruct`` Wrap struct definitions.2425 2426 .. code-block:: c++2427 2428 true:2429 struct foo2430 {2431 int x;2432 };2433 2434 false:2435 struct foo {2436 int x;2437 };2438 2439 * ``bool AfterUnion`` Wrap union definitions.2440 2441 .. code-block:: c++2442 2443 true:2444 union foo2445 {2446 int x;2447 }2448 2449 false:2450 union foo {2451 int x;2452 }2453 2454 * ``bool AfterExternBlock`` Wrap extern blocks.2455 2456 .. code-block:: c++2457 2458 true:2459 extern "C"2460 {2461 int foo();2462 }2463 2464 false:2465 extern "C" {2466 int foo();2467 }2468 2469 * ``bool BeforeCatch`` Wrap before ``catch``.2470 2471 .. code-block:: c++2472 2473 true:2474 try {2475 foo();2476 }2477 catch () {2478 }2479 2480 false:2481 try {2482 foo();2483 } catch () {2484 }2485 2486 * ``bool BeforeElse`` Wrap before ``else``.2487 2488 .. code-block:: c++2489 2490 true:2491 if (foo()) {2492 }2493 else {2494 }2495 2496 false:2497 if (foo()) {2498 } else {2499 }2500 2501 * ``bool BeforeLambdaBody`` Wrap lambda block.2502 2503 .. code-block:: c++2504 2505 true:2506 connect(2507 []()2508 {2509 foo();2510 bar();2511 });2512 2513 false:2514 connect([]() {2515 foo();2516 bar();2517 });2518 2519 * ``bool BeforeWhile`` Wrap before ``while``.2520 2521 .. code-block:: c++2522 2523 true:2524 do {2525 foo();2526 }2527 while (1);2528 2529 false:2530 do {2531 foo();2532 } while (1);2533 2534 * ``bool IndentBraces`` Indent the wrapped braces themselves.2535 2536 * ``bool SplitEmptyFunction`` If ``false``, empty function body can be put on a single line.2537 This option is used only if the opening brace of the function has2538 already been wrapped, i.e. the ``AfterFunction`` brace wrapping mode is2539 set, and the function could/should not be put on a single line (as per2540 ``AllowShortFunctionsOnASingleLine`` and constructor formatting2541 options).2542 2543 .. code-block:: c++2544 2545 false: true:2546 int f() vs. int f()2547 {} {2548 }2549 2550 * ``bool SplitEmptyRecord`` If ``false``, empty record (e.g. class, struct or union) body2551 can be put on a single line. This option is used only if the opening2552 brace of the record has already been wrapped, i.e. the ``AfterClass``2553 (for classes) brace wrapping mode is set.2554 2555 .. code-block:: c++2556 2557 false: true:2558 class Foo vs. class Foo2559 {} {2560 }2561 2562 * ``bool SplitEmptyNamespace`` If ``false``, empty namespace body can be put on a single line.2563 This option is used only if the opening brace of the namespace has2564 already been wrapped, i.e. the ``AfterNamespace`` brace wrapping mode is2565 set.2566 2567 .. code-block:: c++2568 2569 false: true:2570 namespace Foo vs. namespace Foo2571 {} {2572 }2573 2574 2575.. _BracedInitializerIndentWidth:2576 2577**BracedInitializerIndentWidth** (``Integer``) :versionbadge:`clang-format 17` :ref:`¶ <BracedInitializerIndentWidth>`2578 The number of columns to use to indent the contents of braced init lists.2579 If unset or negative, ``ContinuationIndentWidth`` is used.2580 2581 .. code-block:: c++2582 2583 AlignAfterOpenBracket: AlwaysBreak2584 BracedInitializerIndentWidth: 22585 2586 void f() {2587 SomeClass c{2588 "foo",2589 "bar",2590 "baz",2591 };2592 auto s = SomeStruct{2593 .foo = "foo",2594 .bar = "bar",2595 .baz = "baz",2596 };2597 SomeArrayT a[3] = {2598 {2599 foo,2600 bar,2601 },2602 {2603 foo,2604 bar,2605 },2606 SomeArrayT{},2607 };2608 }2609 2610.. _BreakAdjacentStringLiterals:2611 2612**BreakAdjacentStringLiterals** (``Boolean``) :versionbadge:`clang-format 18` :ref:`¶ <BreakAdjacentStringLiterals>`2613 Break between adjacent string literals.2614 2615 .. code-block:: c++2616 2617 true:2618 return "Code"2619 "\0\52\26\55\55\0"2620 "x013"2621 "\02\xBA";2622 false:2623 return "Code" "\0\52\26\55\55\0" "x013" "\02\xBA";2624 2625.. _BreakAfterAttributes:2626 2627**BreakAfterAttributes** (``AttributeBreakingStyle``) :versionbadge:`clang-format 16` :ref:`¶ <BreakAfterAttributes>`2628 Break after a group of C++11 attributes before variable or function2629 (including constructor/destructor) declaration/definition names or before2630 control statements, i.e. ``if``, ``switch`` (including ``case`` and2631 ``default`` labels), ``for``, and ``while`` statements.2632 2633 Possible values:2634 2635 * ``ABS_Always`` (in configuration: ``Always``)2636 Always break after attributes.2637 2638 .. code-block:: c++2639 2640 [[maybe_unused]]2641 const int i;2642 [[gnu::const]] [[maybe_unused]]2643 int j;2644 2645 [[nodiscard]]2646 inline int f();2647 [[gnu::const]] [[nodiscard]]2648 int g();2649 2650 [[likely]]2651 if (a)2652 f();2653 else2654 g();2655 2656 switch (b) {2657 [[unlikely]]2658 case 1:2659 ++b;2660 break;2661 [[likely]]2662 default:2663 return;2664 }2665 2666 * ``ABS_Leave`` (in configuration: ``Leave``)2667 Leave the line breaking after attributes as is.2668 2669 .. code-block:: c++2670 2671 [[maybe_unused]] const int i;2672 [[gnu::const]] [[maybe_unused]]2673 int j;2674 2675 [[nodiscard]] inline int f();2676 [[gnu::const]] [[nodiscard]]2677 int g();2678 2679 [[likely]] if (a)2680 f();2681 else2682 g();2683 2684 switch (b) {2685 [[unlikely]] case 1:2686 ++b;2687 break;2688 [[likely]]2689 default:2690 return;2691 }2692 2693 * ``ABS_Never`` (in configuration: ``Never``)2694 Never break after attributes.2695 2696 .. code-block:: c++2697 2698 [[maybe_unused]] const int i;2699 [[gnu::const]] [[maybe_unused]] int j;2700 2701 [[nodiscard]] inline int f();2702 [[gnu::const]] [[nodiscard]] int g();2703 2704 [[likely]] if (a)2705 f();2706 else2707 g();2708 2709 switch (b) {2710 [[unlikely]] case 1:2711 ++b;2712 break;2713 [[likely]] default:2714 return;2715 }2716 2717 2718 2719.. _BreakAfterJavaFieldAnnotations:2720 2721**BreakAfterJavaFieldAnnotations** (``Boolean``) :versionbadge:`clang-format 3.8` :ref:`¶ <BreakAfterJavaFieldAnnotations>`2722 Break after each annotation on a field in Java files.2723 2724 .. code-block:: java2725 2726 true: false:2727 @Partial vs. @Partial @Mock DataLoad loader;2728 @Mock2729 DataLoad loader;2730 2731.. _BreakAfterOpenBracketBracedList:2732 2733**BreakAfterOpenBracketBracedList** (``Boolean``) :versionbadge:`clang-format 22` :ref:`¶ <BreakAfterOpenBracketBracedList>`2734 Force break after the left bracket of a braced initializer list (when2735 ``Cpp11BracedListStyle`` is ``true``) when the list exceeds the column2736 limit.2737 2738 .. code-block:: c++2739 2740 true: false:2741 vector<int> x { vs. vector<int> x {1,2742 1, 2, 3} 2, 3}2743 2744.. _BreakAfterOpenBracketFunction:2745 2746**BreakAfterOpenBracketFunction** (``Boolean``) :versionbadge:`clang-format 22` :ref:`¶ <BreakAfterOpenBracketFunction>`2747 Force break after the left parenthesis of a function (declaration,2748 definition, call) when the parameters exceed the column limit.2749 2750 .. code-block:: c++2751 2752 true: false:2753 foo ( vs. foo (a,2754 a , b) b)2755 2756.. _BreakAfterOpenBracketIf:2757 2758**BreakAfterOpenBracketIf** (``Boolean``) :versionbadge:`clang-format 22` :ref:`¶ <BreakAfterOpenBracketIf>`2759 Force break after the left parenthesis of an if control statement2760 when the expression exceeds the column limit.2761 2762 .. code-block:: c++2763 2764 true: false:2765 if constexpr ( vs. if constexpr (a ||2766 a || b) b)2767 2768.. _BreakAfterOpenBracketLoop:2769 2770**BreakAfterOpenBracketLoop** (``Boolean``) :versionbadge:`clang-format 22` :ref:`¶ <BreakAfterOpenBracketLoop>`2771 Force break after the left parenthesis of a loop control statement2772 when the expression exceeds the column limit.2773 2774 .. code-block:: c++2775 2776 true: false:2777 while ( vs. while (a &&2778 a && b) { b) {2779 2780.. _BreakAfterOpenBracketSwitch:2781 2782**BreakAfterOpenBracketSwitch** (``Boolean``) :versionbadge:`clang-format 22` :ref:`¶ <BreakAfterOpenBracketSwitch>`2783 Force break after the left parenthesis of a switch control statement2784 when the expression exceeds the column limit.2785 2786 .. code-block:: c++2787 2788 true: false:2789 switch ( vs. switch (a +2790 a + b) { b) {2791 2792.. _BreakAfterReturnType:2793 2794**BreakAfterReturnType** (``ReturnTypeBreakingStyle``) :versionbadge:`clang-format 19` :ref:`¶ <BreakAfterReturnType>`2795 The function declaration return type breaking style to use.2796 2797 Possible values:2798 2799 * ``RTBS_None`` (in configuration: ``None``)2800 This is **deprecated**. See ``Automatic`` below.2801 2802 * ``RTBS_Automatic`` (in configuration: ``Automatic``)2803 Break after return type based on ``PenaltyReturnTypeOnItsOwnLine``.2804 2805 .. code-block:: c++2806 2807 class A {2808 int f() { return 0; };2809 };2810 int f();2811 int f() { return 1; }2812 int2813 LongName::AnotherLongName();2814 2815 * ``RTBS_ExceptShortType`` (in configuration: ``ExceptShortType``)2816 Same as ``Automatic`` above, except that there is no break after short2817 return types.2818 2819 .. code-block:: c++2820 2821 class A {2822 int f() { return 0; };2823 };2824 int f();2825 int f() { return 1; }2826 int LongName::2827 AnotherLongName();2828 2829 * ``RTBS_All`` (in configuration: ``All``)2830 Always break after the return type.2831 2832 .. code-block:: c++2833 2834 class A {2835 int2836 f() {2837 return 0;2838 };2839 };2840 int2841 f();2842 int2843 f() {2844 return 1;2845 }2846 int2847 LongName::AnotherLongName();2848 2849 * ``RTBS_TopLevel`` (in configuration: ``TopLevel``)2850 Always break after the return types of top-level functions.2851 2852 .. code-block:: c++2853 2854 class A {2855 int f() { return 0; };2856 };2857 int2858 f();2859 int2860 f() {2861 return 1;2862 }2863 int2864 LongName::AnotherLongName();2865 2866 * ``RTBS_AllDefinitions`` (in configuration: ``AllDefinitions``)2867 Always break after the return type of function definitions.2868 2869 .. code-block:: c++2870 2871 class A {2872 int2873 f() {2874 return 0;2875 };2876 };2877 int f();2878 int2879 f() {2880 return 1;2881 }2882 int2883 LongName::AnotherLongName();2884 2885 * ``RTBS_TopLevelDefinitions`` (in configuration: ``TopLevelDefinitions``)2886 Always break after the return type of top-level definitions.2887 2888 .. code-block:: c++2889 2890 class A {2891 int f() { return 0; };2892 };2893 int f();2894 int2895 f() {2896 return 1;2897 }2898 int2899 LongName::AnotherLongName();2900 2901 2902 2903.. _BreakArrays:2904 2905**BreakArrays** (``Boolean``) :versionbadge:`clang-format 16` :ref:`¶ <BreakArrays>`2906 If ``true``, clang-format will always break after a Json array ``[``2907 otherwise it will scan until the closing ``]`` to determine if it should2908 add newlines between elements (prettier compatible).2909 2910 2911 .. note::2912 2913 This is currently only for formatting JSON.2914 2915 .. code-block:: c++2916 2917 true: false:2918 [ vs. [1, 2, 3, 4]2919 1,2920 2,2921 3,2922 42923 ]2924 2925.. _BreakBeforeBinaryOperators:2926 2927**BreakBeforeBinaryOperators** (``BinaryOperatorStyle``) :versionbadge:`clang-format 3.6` :ref:`¶ <BreakBeforeBinaryOperators>`2928 The way to wrap binary operators.2929 2930 Possible values:2931 2932 * ``BOS_None`` (in configuration: ``None``)2933 Break after operators.2934 2935 .. code-block:: c++2936 2937 LooooooooooongType loooooooooooooooooooooongVariable =2938 someLooooooooooooooooongFunction();2939 2940 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +2941 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ==2942 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&2943 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa >2944 ccccccccccccccccccccccccccccccccccccccccc;2945 2946 * ``BOS_NonAssignment`` (in configuration: ``NonAssignment``)2947 Break before operators that aren't assignments.2948 2949 .. code-block:: c++2950 2951 LooooooooooongType loooooooooooooooooooooongVariable =2952 someLooooooooooooooooongFunction();2953 2954 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa2955 + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa2956 == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa2957 && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa2958 > ccccccccccccccccccccccccccccccccccccccccc;2959 2960 * ``BOS_All`` (in configuration: ``All``)2961 Break before operators.2962 2963 .. code-block:: c++2964 2965 LooooooooooongType loooooooooooooooooooooongVariable2966 = someLooooooooooooooooongFunction();2967 2968 bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa2969 + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa2970 == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa2971 && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa2972 > ccccccccccccccccccccccccccccccccccccccccc;2973 2974 2975 2976.. _BreakBeforeBraces:2977 2978**BreakBeforeBraces** (``BraceBreakingStyle``) :versionbadge:`clang-format 3.7` :ref:`¶ <BreakBeforeBraces>`2979 The brace breaking style to use.2980 2981 Possible values:2982 2983 * ``BS_Attach`` (in configuration: ``Attach``)2984 Always attach braces to surrounding context.2985 2986 .. code-block:: c++2987 2988 namespace N {2989 enum E {2990 E1,2991 E2,2992 };2993 2994 class C {2995 public:2996 C();2997 };2998 2999 bool baz(int i) {3000 try {3001 do {3002 switch (i) {3003 case 1: {3004 foobar();3005 break;3006 }3007 default: {3008 break;3009 }3010 }3011 } while (--i);3012 return true;3013 } catch (...) {3014 handleError();3015 return false;3016 }3017 }3018 3019 void foo(bool b) {3020 if (b) {3021 baz(2);3022 } else {3023 baz(5);3024 }3025 }3026 3027 void bar() { foo(true); }3028 } // namespace N3029 3030 * ``BS_Linux`` (in configuration: ``Linux``)3031 Like ``Attach``, but break before braces on function, namespace and3032 class definitions.3033 3034 .. code-block:: c++3035 3036 namespace N3037 {3038 enum E {3039 E1,3040 E2,3041 };3042 3043 class C3044 {3045 public:3046 C();3047 };3048 3049 bool baz(int i)3050 {3051 try {3052 do {3053 switch (i) {3054 case 1: {3055 foobar();3056 break;3057 }3058 default: {3059 break;3060 }3061 }3062 } while (--i);3063 return true;3064 } catch (...) {3065 handleError();3066 return false;3067 }3068 }3069 3070 void foo(bool b)3071 {3072 if (b) {3073 baz(2);3074 } else {3075 baz(5);3076 }3077 }3078 3079 void bar() { foo(true); }3080 } // namespace N3081 3082 * ``BS_Mozilla`` (in configuration: ``Mozilla``)3083 Like ``Attach``, but break before braces on enum, function, and record3084 definitions.3085 3086 .. code-block:: c++3087 3088 namespace N {3089 enum E3090 {3091 E1,3092 E2,3093 };3094 3095 class C3096 {3097 public:3098 C();3099 };3100 3101 bool baz(int i)3102 {3103 try {3104 do {3105 switch (i) {3106 case 1: {3107 foobar();3108 break;3109 }3110 default: {3111 break;3112 }3113 }3114 } while (--i);3115 return true;3116 } catch (...) {3117 handleError();3118 return false;3119 }3120 }3121 3122 void foo(bool b)3123 {3124 if (b) {3125 baz(2);3126 } else {3127 baz(5);3128 }3129 }3130 3131 void bar() { foo(true); }3132 } // namespace N3133 3134 * ``BS_Stroustrup`` (in configuration: ``Stroustrup``)3135 Like ``Attach``, but break before function definitions, ``catch``, and3136 ``else``.3137 3138 .. code-block:: c++3139 3140 namespace N {3141 enum E {3142 E1,3143 E2,3144 };3145 3146 class C {3147 public:3148 C();3149 };3150 3151 bool baz(int i)3152 {3153 try {3154 do {3155 switch (i) {3156 case 1: {3157 foobar();3158 break;3159 }3160 default: {3161 break;3162 }3163 }3164 } while (--i);3165 return true;3166 }3167 catch (...) {3168 handleError();3169 return false;3170 }3171 }3172 3173 void foo(bool b)3174 {3175 if (b) {3176 baz(2);3177 }3178 else {3179 baz(5);3180 }3181 }3182 3183 void bar() { foo(true); }3184 } // namespace N3185 3186 * ``BS_Allman`` (in configuration: ``Allman``)3187 Always break before braces.3188 3189 .. code-block:: c++3190 3191 namespace N3192 {3193 enum E3194 {3195 E1,3196 E2,3197 };3198 3199 class C3200 {3201 public:3202 C();3203 };3204 3205 bool baz(int i)3206 {3207 try3208 {3209 do3210 {3211 switch (i)3212 {3213 case 1:3214 {3215 foobar();3216 break;3217 }3218 default:3219 {3220 break;3221 }3222 }3223 } while (--i);3224 return true;3225 }3226 catch (...)3227 {3228 handleError();3229 return false;3230 }3231 }3232 3233 void foo(bool b)3234 {3235 if (b)3236 {3237 baz(2);3238 }3239 else3240 {3241 baz(5);3242 }3243 }3244 3245 void bar() { foo(true); }3246 } // namespace N3247 3248 * ``BS_Whitesmiths`` (in configuration: ``Whitesmiths``)3249 Like ``Allman`` but always indent braces and line up code with braces.3250 3251 .. code-block:: c++3252 3253 namespace N3254 {3255 enum E3256 {3257 E1,3258 E2,3259 };3260 3261 class C3262 {3263 public:3264 C();3265 };3266 3267 bool baz(int i)3268 {3269 try3270 {3271 do3272 {3273 switch (i)3274 {3275 case 1:3276 {3277 foobar();3278 break;3279 }3280 default:3281 {3282 break;3283 }3284 }3285 } while (--i);3286 return true;3287 }3288 catch (...)3289 {3290 handleError();3291 return false;3292 }3293 }3294 3295 void foo(bool b)3296 {3297 if (b)3298 {3299 baz(2);3300 }3301 else3302 {3303 baz(5);3304 }3305 }3306 3307 void bar() { foo(true); }3308 } // namespace N3309 3310 * ``BS_GNU`` (in configuration: ``GNU``)3311 Always break before braces and add an extra level of indentation to3312 braces of control statements, not to those of class, function3313 or other definitions.3314 3315 .. code-block:: c++3316 3317 namespace N3318 {3319 enum E3320 {3321 E1,3322 E2,3323 };3324 3325 class C3326 {3327 public:3328 C();3329 };3330 3331 bool baz(int i)3332 {3333 try3334 {3335 do3336 {3337 switch (i)3338 {3339 case 1:3340 {3341 foobar();3342 break;3343 }3344 default:3345 {3346 break;3347 }3348 }3349 }3350 while (--i);3351 return true;3352 }3353 catch (...)3354 {3355 handleError();3356 return false;3357 }3358 }3359 3360 void foo(bool b)3361 {3362 if (b)3363 {3364 baz(2);3365 }3366 else3367 {3368 baz(5);3369 }3370 }3371 3372 void bar() { foo(true); }3373 } // namespace N3374 3375 * ``BS_WebKit`` (in configuration: ``WebKit``)3376 Like ``Attach``, but break before functions.3377 3378 .. code-block:: c++3379 3380 namespace N {3381 enum E {3382 E1,3383 E2,3384 };3385 3386 class C {3387 public:3388 C();3389 };3390 3391 bool baz(int i)3392 {3393 try {3394 do {3395 switch (i) {3396 case 1: {3397 foobar();3398 break;3399 }3400 default: {3401 break;3402 }3403 }3404 } while (--i);3405 return true;3406 } catch (...) {3407 handleError();3408 return false;3409 }3410 }3411 3412 void foo(bool b)3413 {3414 if (b) {3415 baz(2);3416 } else {3417 baz(5);3418 }3419 }3420 3421 void bar() { foo(true); }3422 } // namespace N3423 3424 * ``BS_Custom`` (in configuration: ``Custom``)3425 Configure each individual brace in ``BraceWrapping``.3426 3427 3428 3429.. _BreakBeforeCloseBracketBracedList:3430 3431**BreakBeforeCloseBracketBracedList** (``Boolean``) :versionbadge:`clang-format 22` :ref:`¶ <BreakBeforeCloseBracketBracedList>`3432 Force break before the right bracket of a braced initializer list (when3433 ``Cpp11BracedListStyle`` is ``true``) when the list exceeds the column3434 limit. The break before the right bracket is only made if there is a3435 break after the opening bracket.3436 3437 .. code-block:: c++3438 3439 true: false:3440 vector<int> x { vs. vector<int> x {3441 1, 2, 3 1, 2, 3}3442 }3443 3444.. _BreakBeforeCloseBracketFunction:3445 3446**BreakBeforeCloseBracketFunction** (``Boolean``) :versionbadge:`clang-format 22` :ref:`¶ <BreakBeforeCloseBracketFunction>`3447 Force break before the right parenthesis of a function (declaration,3448 definition, call) when the parameters exceed the column limit.3449 3450 .. code-block:: c++3451 3452 true: false:3453 foo ( vs. foo (3454 a , b a , b)3455 )3456 3457.. _BreakBeforeCloseBracketIf:3458 3459**BreakBeforeCloseBracketIf** (``Boolean``) :versionbadge:`clang-format 22` :ref:`¶ <BreakBeforeCloseBracketIf>`3460 Force break before the right parenthesis of an if control statement3461 when the expression exceeds the column limit. The break before the3462 closing parenthesis is only made if there is a break after the opening3463 parenthesis.3464 3465 .. code-block:: c++3466 3467 true: false:3468 if constexpr ( vs. if constexpr (3469 a || b a || b )3470 )3471 3472.. _BreakBeforeCloseBracketLoop:3473 3474**BreakBeforeCloseBracketLoop** (``Boolean``) :versionbadge:`clang-format 22` :ref:`¶ <BreakBeforeCloseBracketLoop>`3475 Force break before the right parenthesis of a loop control statement3476 when the expression exceeds the column limit. The break before the3477 closing parenthesis is only made if there is a break after the opening3478 parenthesis.3479 3480 .. code-block:: c++3481 3482 true: false:3483 while ( vs. while (3484 a && b a && b) {3485 ) {3486 3487.. _BreakBeforeCloseBracketSwitch:3488 3489**BreakBeforeCloseBracketSwitch** (``Boolean``) :versionbadge:`clang-format 22` :ref:`¶ <BreakBeforeCloseBracketSwitch>`3490 Force break before the right parenthesis of a switch control statement3491 when the expression exceeds the column limit. The break before the3492 closing parenthesis is only made if there is a break after the opening3493 parenthesis.3494 3495 .. code-block:: c++3496 3497 true: false:3498 switch ( vs. switch (3499 a + b a + b) {3500 ) {3501 3502.. _BreakBeforeConceptDeclarations:3503 3504**BreakBeforeConceptDeclarations** (``BreakBeforeConceptDeclarationsStyle``) :versionbadge:`clang-format 12` :ref:`¶ <BreakBeforeConceptDeclarations>`3505 The concept declaration style to use.3506 3507 Possible values:3508 3509 * ``BBCDS_Never`` (in configuration: ``Never``)3510 Keep the template declaration line together with ``concept``.3511 3512 .. code-block:: c++3513 3514 template <typename T> concept C = ...;3515 3516 * ``BBCDS_Allowed`` (in configuration: ``Allowed``)3517 Breaking between template declaration and ``concept`` is allowed. The3518 actual behavior depends on the content and line breaking rules and3519 penalties.3520 3521 * ``BBCDS_Always`` (in configuration: ``Always``)3522 Always break before ``concept``, putting it in the line after the3523 template declaration.3524 3525 .. code-block:: c++3526 3527 template <typename T>3528 concept C = ...;3529 3530 3531 3532.. _BreakBeforeInlineASMColon:3533 3534**BreakBeforeInlineASMColon** (``BreakBeforeInlineASMColonStyle``) :versionbadge:`clang-format 16` :ref:`¶ <BreakBeforeInlineASMColon>`3535 The inline ASM colon style to use.3536 3537 Possible values:3538 3539 * ``BBIAS_Never`` (in configuration: ``Never``)3540 No break before inline ASM colon.3541 3542 .. code-block:: c++3543 3544 asm volatile("string", : : val);3545 3546 * ``BBIAS_OnlyMultiline`` (in configuration: ``OnlyMultiline``)3547 Break before inline ASM colon if the line length is longer than column3548 limit.3549 3550 .. code-block:: c++3551 3552 asm volatile("string", : : val);3553 asm("cmoveq %1, %2, %[result]"3554 : [result] "=r"(result)3555 : "r"(test), "r"(new), "[result]"(old));3556 3557 * ``BBIAS_Always`` (in configuration: ``Always``)3558 Always break before inline ASM colon.3559 3560 .. code-block:: c++3561 3562 asm volatile("string",3563 :3564 : val);3565 3566 3567 3568.. _BreakBeforeTemplateCloser:3569 3570**BreakBeforeTemplateCloser** (``Boolean``) :versionbadge:`clang-format 21` :ref:`¶ <BreakBeforeTemplateCloser>`3571 If ``true``, break before a template closing bracket (``>``) when there is3572 a line break after the matching opening bracket (``<``).3573 3574 .. code-block:: c++3575 3576 true:3577 template <typename Foo, typename Bar>3578 3579 template <typename Foo,3580 typename Bar>3581 3582 template <3583 typename Foo,3584 typename Bar3585 >3586 3587 false:3588 template <typename Foo, typename Bar>3589 3590 template <typename Foo,3591 typename Bar>3592 3593 template <3594 typename Foo,3595 typename Bar>3596 3597.. _BreakBeforeTernaryOperators:3598 3599**BreakBeforeTernaryOperators** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <BreakBeforeTernaryOperators>`3600 If ``true``, ternary operators will be placed after line breaks.3601 3602 .. code-block:: c++3603 3604 true:3605 veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription3606 ? firstValue3607 : SecondValueVeryVeryVeryVeryLong;3608 3609 false:3610 veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ?3611 firstValue :3612 SecondValueVeryVeryVeryVeryLong;3613 3614.. _BreakBinaryOperations:3615 3616**BreakBinaryOperations** (``BreakBinaryOperationsStyle``) :versionbadge:`clang-format 20` :ref:`¶ <BreakBinaryOperations>`3617 The break binary operations style to use.3618 3619 Possible values:3620 3621 * ``BBO_Never`` (in configuration: ``Never``)3622 Don't break binary operations3623 3624 .. code-block:: c++3625 3626 aaa + bbbb * ccccc - ddddd +3627 eeeeeeeeeeeeeeee;3628 3629 * ``BBO_OnePerLine`` (in configuration: ``OnePerLine``)3630 Binary operations will either be all on the same line, or each operation3631 will have one line each.3632 3633 .. code-block:: c++3634 3635 aaa +3636 bbbb *3637 ccccc -3638 ddddd +3639 eeeeeeeeeeeeeeee;3640 3641 * ``BBO_RespectPrecedence`` (in configuration: ``RespectPrecedence``)3642 Binary operations of a particular precedence that exceed the column3643 limit will have one line each.3644 3645 .. code-block:: c++3646 3647 aaa +3648 bbbb * ccccc -3649 ddddd +3650 eeeeeeeeeeeeeeee;3651 3652 3653 3654.. _BreakConstructorInitializers:3655 3656**BreakConstructorInitializers** (``BreakConstructorInitializersStyle``) :versionbadge:`clang-format 5` :ref:`¶ <BreakConstructorInitializers>`3657 The break constructor initializers style to use.3658 3659 Possible values:3660 3661 * ``BCIS_BeforeColon`` (in configuration: ``BeforeColon``)3662 Break constructor initializers before the colon and after the commas.3663 3664 .. code-block:: c++3665 3666 Constructor()3667 : initializer1(),3668 initializer2()3669 3670 * ``BCIS_BeforeComma`` (in configuration: ``BeforeComma``)3671 Break constructor initializers before the colon and commas, and align3672 the commas with the colon.3673 3674 .. code-block:: c++3675 3676 Constructor()3677 : initializer1()3678 , initializer2()3679 3680 * ``BCIS_AfterColon`` (in configuration: ``AfterColon``)3681 Break constructor initializers after the colon and commas.3682 3683 .. code-block:: c++3684 3685 Constructor() :3686 initializer1(),3687 initializer2()3688 3689 3690 3691.. _BreakFunctionDefinitionParameters:3692 3693**BreakFunctionDefinitionParameters** (``Boolean``) :versionbadge:`clang-format 19` :ref:`¶ <BreakFunctionDefinitionParameters>`3694 If ``true``, clang-format will always break before function definition3695 parameters.3696 3697 .. code-block:: c++3698 3699 true:3700 void functionDefinition(3701 int A, int B) {}3702 3703 false:3704 void functionDefinition(int A, int B) {}3705 3706.. _BreakInheritanceList:3707 3708**BreakInheritanceList** (``BreakInheritanceListStyle``) :versionbadge:`clang-format 7` :ref:`¶ <BreakInheritanceList>`3709 The inheritance list style to use.3710 3711 Possible values:3712 3713 * ``BILS_BeforeColon`` (in configuration: ``BeforeColon``)3714 Break inheritance list before the colon and after the commas.3715 3716 .. code-block:: c++3717 3718 class Foo3719 : Base1,3720 Base23721 {};3722 3723 * ``BILS_BeforeComma`` (in configuration: ``BeforeComma``)3724 Break inheritance list before the colon and commas, and align3725 the commas with the colon.3726 3727 .. code-block:: c++3728 3729 class Foo3730 : Base13731 , Base23732 {};3733 3734 * ``BILS_AfterColon`` (in configuration: ``AfterColon``)3735 Break inheritance list after the colon and commas.3736 3737 .. code-block:: c++3738 3739 class Foo :3740 Base1,3741 Base23742 {};3743 3744 * ``BILS_AfterComma`` (in configuration: ``AfterComma``)3745 Break inheritance list only after the commas.3746 3747 .. code-block:: c++3748 3749 class Foo : Base1,3750 Base23751 {};3752 3753 3754 3755.. _BreakStringLiterals:3756 3757**BreakStringLiterals** (``Boolean``) :versionbadge:`clang-format 3.9` :ref:`¶ <BreakStringLiterals>`3758 Allow breaking string literals when formatting.3759 3760 In C, C++, and Objective-C:3761 3762 .. code-block:: c++3763 3764 true:3765 const char* x = "veryVeryVeryVeryVeryVe"3766 "ryVeryVeryVeryVeryVery"3767 "VeryLongString";3768 3769 false:3770 const char* x =3771 "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";3772 3773 In C# and Java:3774 3775 .. code-block:: c++3776 3777 true:3778 string x = "veryVeryVeryVeryVeryVe" +3779 "ryVeryVeryVeryVeryVery" +3780 "VeryLongString";3781 3782 false:3783 string x =3784 "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";3785 3786 C# interpolated strings are not broken.3787 3788 In Verilog:3789 3790 .. code-block:: c++3791 3792 true:3793 string x = {"veryVeryVeryVeryVeryVe",3794 "ryVeryVeryVeryVeryVery",3795 "VeryLongString"};3796 3797 false:3798 string x =3799 "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";3800 3801.. _BreakTemplateDeclarations:3802 3803**BreakTemplateDeclarations** (``BreakTemplateDeclarationsStyle``) :versionbadge:`clang-format 19` :ref:`¶ <BreakTemplateDeclarations>`3804 The template declaration breaking style to use.3805 3806 Possible values:3807 3808 * ``BTDS_Leave`` (in configuration: ``Leave``)3809 Do not change the line breaking before the declaration.3810 3811 .. code-block:: c++3812 3813 template <typename T>3814 T foo() {3815 }3816 template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa,3817 int bbbbbbbbbbbbbbbbbbbbb) {3818 }3819 3820 * ``BTDS_No`` (in configuration: ``No``)3821 Do not force break before declaration.3822 ``PenaltyBreakTemplateDeclaration`` is taken into account.3823 3824 .. code-block:: c++3825 3826 template <typename T> T foo() {3827 }3828 template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa,3829 int bbbbbbbbbbbbbbbbbbbbb) {3830 }3831 3832 * ``BTDS_MultiLine`` (in configuration: ``MultiLine``)3833 Force break after template declaration only when the following3834 declaration spans multiple lines.3835 3836 .. code-block:: c++3837 3838 template <typename T> T foo() {3839 }3840 template <typename T>3841 T foo(int aaaaaaaaaaaaaaaaaaaaa,3842 int bbbbbbbbbbbbbbbbbbbbb) {3843 }3844 3845 * ``BTDS_Yes`` (in configuration: ``Yes``)3846 Always break after template declaration.3847 3848 .. code-block:: c++3849 3850 template <typename T>3851 T foo() {3852 }3853 template <typename T>3854 T foo(int aaaaaaaaaaaaaaaaaaaaa,3855 int bbbbbbbbbbbbbbbbbbbbb) {3856 }3857 3858 3859 3860.. _ColumnLimit:3861 3862**ColumnLimit** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <ColumnLimit>`3863 The column limit.3864 3865 A column limit of ``0`` means that there is no column limit. In this case,3866 clang-format will respect the input's line breaking decisions within3867 statements unless they contradict other rules.3868 3869.. _CommentPragmas:3870 3871**CommentPragmas** (``String``) :versionbadge:`clang-format 3.7` :ref:`¶ <CommentPragmas>`3872 A regular expression that describes comments with special meaning,3873 which should not be split into lines or otherwise changed.3874 3875 .. code-block:: c++3876 3877 // CommentPragmas: '^ FOOBAR pragma:'3878 // Will leave the following line unaffected3879 #include <vector> // FOOBAR pragma: keep3880 3881.. _CompactNamespaces:3882 3883**CompactNamespaces** (``Boolean``) :versionbadge:`clang-format 5` :ref:`¶ <CompactNamespaces>`3884 If ``true``, consecutive namespace declarations will be on the same3885 line. If ``false``, each namespace is declared on a new line.3886 3887 .. code-block:: c++3888 3889 true:3890 namespace Foo { namespace Bar {3891 }}3892 3893 false:3894 namespace Foo {3895 namespace Bar {3896 }3897 }3898 3899 If it does not fit on a single line, the overflowing namespaces get3900 wrapped:3901 3902 .. code-block:: c++3903 3904 namespace Foo { namespace Bar {3905 namespace Extra {3906 }}}3907 3908.. _ConstructorInitializerAllOnOneLineOrOnePerLine:3909 3910**ConstructorInitializerAllOnOneLineOrOnePerLine** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <ConstructorInitializerAllOnOneLineOrOnePerLine>`3911 This option is **deprecated**. See ``CurrentLine`` of3912 ``PackConstructorInitializers``.3913 3914.. _ConstructorInitializerIndentWidth:3915 3916**ConstructorInitializerIndentWidth** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <ConstructorInitializerIndentWidth>`3917 The number of characters to use for indentation of constructor3918 initializer lists as well as inheritance lists.3919 3920.. _ContinuationIndentWidth:3921 3922**ContinuationIndentWidth** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <ContinuationIndentWidth>`3923 Indent width for line continuations.3924 3925 .. code-block:: c++3926 3927 ContinuationIndentWidth: 23928 3929 int i = // VeryVeryVeryVeryVeryLongComment3930 longFunction( // Again a long comment3931 arg);3932 3933.. _Cpp11BracedListStyle:3934 3935**Cpp11BracedListStyle** (``BracedListStyle``) :versionbadge:`clang-format 3.4` :ref:`¶ <Cpp11BracedListStyle>`3936 The style to handle braced lists.3937 3938 Possible values:3939 3940 * ``BLS_Block`` (in configuration: ``Block``)3941 Best suited for pre C++11 braced lists.3942 3943 * Spaces inside the braced list.3944 * Line break before the closing brace.3945 * Indentation with the block indent.3946 3947 3948 .. code-block:: c++3949 3950 vector<int> x{ 1, 2, 3, 4 };3951 vector<T> x{ {}, {}, {}, {} };3952 f(MyMap[{ composite, key }]);3953 new int[3]{ 1, 2, 3 };3954 Type name{ // Comment3955 value3956 };3957 3958 * ``BLS_FunctionCall`` (in configuration: ``FunctionCall``)3959 Best suited for C++11 braced lists.3960 3961 * No spaces inside the braced list.3962 * No line break before the closing brace.3963 * Indentation with the continuation indent.3964 3965 Fundamentally, C++11 braced lists are formatted exactly like function3966 calls would be formatted in their place. If the braced list follows a3967 name (e.g. a type or variable name), clang-format formats as if the3968 ``{}`` were the parentheses of a function call with that name. If there3969 is no name, a zero-length name is assumed.3970 3971 .. code-block:: c++3972 3973 vector<int> x{1, 2, 3, 4};3974 vector<T> x{{}, {}, {}, {}};3975 f(MyMap[{composite, key}]);3976 new int[3]{1, 2, 3};3977 Type name{ // Comment3978 value};3979 3980 * ``BLS_AlignFirstComment`` (in configuration: ``AlignFirstComment``)3981 Same as ``FunctionCall``, except for the handling of a comment at the3982 begin, it then aligns everything following with the comment.3983 3984 * No spaces inside the braced list. (Even for a comment at the first3985 position.)3986 * No line break before the closing brace.3987 * Indentation with the continuation indent, except when followed by a3988 line comment, then it uses the block indent.3989 3990 3991 .. code-block:: c++3992 3993 vector<int> x{1, 2, 3, 4};3994 vector<T> x{{}, {}, {}, {}};3995 f(MyMap[{composite, key}]);3996 new int[3]{1, 2, 3};3997 Type name{// Comment3998 value};3999 4000 4001 4002.. _DeriveLineEnding:4003 4004**DeriveLineEnding** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ <DeriveLineEnding>`4005 This option is **deprecated**. See ``DeriveLF`` and ``DeriveCRLF`` of4006 ``LineEnding``.4007 4008.. _DerivePointerAlignment:4009 4010**DerivePointerAlignment** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <DerivePointerAlignment>`4011 If ``true``, analyze the formatted file for the most common4012 alignment of ``&`` and ``*``.4013 Pointer and reference alignment styles are going to be updated according4014 to the preferences found in the file.4015 ``PointerAlignment`` is then used only as fallback.4016 4017.. _DisableFormat:4018 4019**DisableFormat** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <DisableFormat>`4020 Disables formatting completely.4021 4022.. _EmptyLineAfterAccessModifier:4023 4024**EmptyLineAfterAccessModifier** (``EmptyLineAfterAccessModifierStyle``) :versionbadge:`clang-format 13` :ref:`¶ <EmptyLineAfterAccessModifier>`4025 Defines when to put an empty line after access modifiers.4026 ``EmptyLineBeforeAccessModifier`` configuration handles the number of4027 empty lines between two access modifiers.4028 4029 Possible values:4030 4031 * ``ELAAMS_Never`` (in configuration: ``Never``)4032 Remove all empty lines after access modifiers.4033 4034 .. code-block:: c++4035 4036 struct foo {4037 private:4038 int i;4039 protected:4040 int j;4041 /* comment */4042 public:4043 foo() {}4044 private:4045 protected:4046 };4047 4048 * ``ELAAMS_Leave`` (in configuration: ``Leave``)4049 Keep existing empty lines after access modifiers.4050 MaxEmptyLinesToKeep is applied instead.4051 4052 * ``ELAAMS_Always`` (in configuration: ``Always``)4053 Always add empty line after access modifiers if there are none.4054 MaxEmptyLinesToKeep is applied also.4055 4056 .. code-block:: c++4057 4058 struct foo {4059 private:4060 4061 int i;4062 protected:4063 4064 int j;4065 /* comment */4066 public:4067 4068 foo() {}4069 private:4070 4071 protected:4072 4073 };4074 4075 4076 4077.. _EmptyLineBeforeAccessModifier:4078 4079**EmptyLineBeforeAccessModifier** (``EmptyLineBeforeAccessModifierStyle``) :versionbadge:`clang-format 12` :ref:`¶ <EmptyLineBeforeAccessModifier>`4080 Defines in which cases to put empty line before access modifiers.4081 4082 Possible values:4083 4084 * ``ELBAMS_Never`` (in configuration: ``Never``)4085 Remove all empty lines before access modifiers.4086 4087 .. code-block:: c++4088 4089 struct foo {4090 private:4091 int i;4092 protected:4093 int j;4094 /* comment */4095 public:4096 foo() {}4097 private:4098 protected:4099 };4100 4101 * ``ELBAMS_Leave`` (in configuration: ``Leave``)4102 Keep existing empty lines before access modifiers.4103 4104 * ``ELBAMS_LogicalBlock`` (in configuration: ``LogicalBlock``)4105 Add empty line only when access modifier starts a new logical block.4106 Logical block is a group of one or more member fields or functions.4107 4108 .. code-block:: c++4109 4110 struct foo {4111 private:4112 int i;4113 4114 protected:4115 int j;4116 /* comment */4117 public:4118 foo() {}4119 4120 private:4121 protected:4122 };4123 4124 * ``ELBAMS_Always`` (in configuration: ``Always``)4125 Always add empty line before access modifiers unless access modifier4126 is at the start of struct or class definition.4127 4128 .. code-block:: c++4129 4130 struct foo {4131 private:4132 int i;4133 4134 protected:4135 int j;4136 /* comment */4137 4138 public:4139 foo() {}4140 4141 private:4142 4143 protected:4144 };4145 4146 4147 4148.. _EnumTrailingComma:4149 4150**EnumTrailingComma** (``EnumTrailingCommaStyle``) :versionbadge:`clang-format 21` :ref:`¶ <EnumTrailingComma>`4151 Insert a comma (if missing) or remove the comma at the end of an ``enum``4152 enumerator list.4153 4154 .. warning::4155 4156 Setting this option to any value other than ``Leave`` could lead to4157 incorrect code formatting due to clang-format's lack of complete semantic4158 information. As such, extra care should be taken to review code changes4159 made by this option.4160 4161 Possible values:4162 4163 * ``ETC_Leave`` (in configuration: ``Leave``)4164 Don't insert or remove trailing commas.4165 4166 .. code-block:: c++4167 4168 enum { a, b, c, };4169 enum Color { red, green, blue };4170 4171 * ``ETC_Insert`` (in configuration: ``Insert``)4172 Insert trailing commas.4173 4174 .. code-block:: c++4175 4176 enum { a, b, c, };4177 enum Color { red, green, blue, };4178 4179 * ``ETC_Remove`` (in configuration: ``Remove``)4180 Remove trailing commas.4181 4182 .. code-block:: c++4183 4184 enum { a, b, c };4185 enum Color { red, green, blue };4186 4187 4188 4189.. _ExperimentalAutoDetectBinPacking:4190 4191**ExperimentalAutoDetectBinPacking** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <ExperimentalAutoDetectBinPacking>`4192 If ``true``, clang-format detects whether function calls and4193 definitions are formatted with one parameter per line.4194 4195 Each call can be bin-packed, one-per-line or inconclusive. If it is4196 inconclusive, e.g. completely on one line, but a decision needs to be4197 made, clang-format analyzes whether there are other bin-packed cases in4198 the input file and act accordingly.4199 4200 4201 .. note::4202 4203 This is an experimental flag, that might go away or be renamed. Do4204 not use this in config files, etc. Use at your own risk.4205 4206.. _FixNamespaceComments:4207 4208**FixNamespaceComments** (``Boolean``) :versionbadge:`clang-format 5` :ref:`¶ <FixNamespaceComments>`4209 If ``true``, clang-format adds missing namespace end comments for4210 namespaces and fixes invalid existing ones. This doesn't affect short4211 namespaces, which are controlled by ``ShortNamespaceLines``.4212 4213 .. code-block:: c++4214 4215 true: false:4216 namespace longNamespace { vs. namespace longNamespace {4217 void foo(); void foo();4218 void bar(); void bar();4219 } // namespace a }4220 namespace shortNamespace { namespace shortNamespace {4221 void baz(); void baz();4222 } }4223 4224.. _ForEachMacros:4225 4226**ForEachMacros** (``List of Strings``) :versionbadge:`clang-format 3.7` :ref:`¶ <ForEachMacros>`4227 A vector of macros that should be interpreted as foreach loops4228 instead of as function calls.4229 4230 These are expected to be macros of the form:4231 4232 .. code-block:: c++4233 4234 FOREACH(<variable-declaration>, ...)4235 <loop-body>4236 4237 In the .clang-format configuration file, this can be configured like:4238 4239 .. code-block:: yaml4240 4241 ForEachMacros: [RANGES_FOR, FOREACH]4242 4243 For example: BOOST_FOREACH.4244 4245.. _IfMacros:4246 4247**IfMacros** (``List of Strings``) :versionbadge:`clang-format 13` :ref:`¶ <IfMacros>`4248 A vector of macros that should be interpreted as conditionals4249 instead of as function calls.4250 4251 These are expected to be macros of the form:4252 4253 .. code-block:: c++4254 4255 IF(...)4256 <conditional-body>4257 else IF(...)4258 <conditional-body>4259 4260 In the .clang-format configuration file, this can be configured like:4261 4262 .. code-block:: yaml4263 4264 IfMacros: [IF]4265 4266 For example: `KJ_IF_MAYBE4267 <https://github.com/capnproto/capnproto/blob/master/kjdoc/tour.md#maybes>`_4268 4269.. _IncludeBlocks:4270 4271**IncludeBlocks** (``IncludeBlocksStyle``) :versionbadge:`clang-format 6` :ref:`¶ <IncludeBlocks>`4272 Dependent on the value, multiple ``#include`` blocks can be sorted4273 as one and divided based on category.4274 4275 Possible values:4276 4277 * ``IBS_Preserve`` (in configuration: ``Preserve``)4278 Sort each ``#include`` block separately.4279 4280 .. code-block:: c++4281 4282 #include "b.h" into #include "b.h"4283 4284 #include <lib/main.h> #include "a.h"4285 #include "a.h" #include <lib/main.h>4286 4287 * ``IBS_Merge`` (in configuration: ``Merge``)4288 Merge multiple ``#include`` blocks together and sort as one.4289 4290 .. code-block:: c++4291 4292 #include "b.h" into #include "a.h"4293 #include "b.h"4294 #include <lib/main.h> #include <lib/main.h>4295 #include "a.h"4296 4297 * ``IBS_Regroup`` (in configuration: ``Regroup``)4298 Merge multiple ``#include`` blocks together and sort as one.4299 Then split into groups based on category priority. See4300 ``IncludeCategories``.4301 4302 .. code-block:: c++4303 4304 #include "b.h" into #include "a.h"4305 #include "b.h"4306 #include <lib/main.h>4307 #include "a.h" #include <lib/main.h>4308 4309 4310 4311.. _IncludeCategories:4312 4313**IncludeCategories** (``List of IncludeCategories``) :versionbadge:`clang-format 3.8` :ref:`¶ <IncludeCategories>`4314 Regular expressions denoting the different ``#include`` categories4315 used for ordering ``#includes``.4316 4317 `POSIX extended4318 <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html>`_4319 regular expressions are supported.4320 4321 These regular expressions are matched against the filename of an include4322 (including the <> or "") in order. The value belonging to the first4323 matching regular expression is assigned and ``#includes`` are sorted first4324 according to increasing category number and then alphabetically within4325 each category.4326 4327 If none of the regular expressions match, INT_MAX is assigned as4328 category. The main header for a source file automatically gets category 0.4329 so that it is generally kept at the beginning of the ``#includes``4330 (https://llvm.org/docs/CodingStandards.html#include-style). However, you4331 can also assign negative priorities if you have certain headers that4332 always need to be first.4333 4334 There is a third and optional field ``SortPriority`` which can used while4335 ``IncludeBlocks = IBS_Regroup`` to define the priority in which4336 ``#includes`` should be ordered. The value of ``Priority`` defines the4337 order of ``#include blocks`` and also allows the grouping of ``#includes``4338 of different priority. ``SortPriority`` is set to the value of4339 ``Priority`` as default if it is not assigned.4340 4341 Each regular expression can be marked as case sensitive with the field4342 ``CaseSensitive``, per default it is not.4343 4344 To configure this in the .clang-format file, use:4345 4346 .. code-block:: yaml4347 4348 IncludeCategories:4349 - Regex: '^"(llvm|llvm-c|clang|clang-c)/'4350 Priority: 24351 SortPriority: 24352 CaseSensitive: true4353 - Regex: '^((<|")(gtest|gmock|isl|json)/)'4354 Priority: 34355 - Regex: '<[[:alnum:].]+>'4356 Priority: 44357 - Regex: '.*'4358 Priority: 14359 SortPriority: 04360 4361.. _IncludeIsMainRegex:4362 4363**IncludeIsMainRegex** (``String``) :versionbadge:`clang-format 3.9` :ref:`¶ <IncludeIsMainRegex>`4364 Specify a regular expression of suffixes that are allowed in the4365 file-to-main-include mapping.4366 4367 When guessing whether a #include is the "main" include (to assign4368 category 0, see above), use this regex of allowed suffixes to the header4369 stem. A partial match is done, so that:4370 * ``""`` means "arbitrary suffix"4371 * ``"$"`` means "no suffix"4372 4373 For example, if configured to ``"(_test)?$"``, then a header a.h would be4374 seen as the "main" include in both a.cc and a_test.cc.4375 4376.. _IncludeIsMainSourceRegex:4377 4378**IncludeIsMainSourceRegex** (``String``) :versionbadge:`clang-format 10` :ref:`¶ <IncludeIsMainSourceRegex>`4379 Specify a regular expression for files being formatted4380 that are allowed to be considered "main" in the4381 file-to-main-include mapping.4382 4383 By default, clang-format considers files as "main" only when they end4384 with: ``.c``, ``.cc``, ``.cpp``, ``.c++``, ``.cxx``, ``.m`` or ``.mm``4385 extensions.4386 For these files a guessing of "main" include takes place4387 (to assign category 0, see above). This config option allows for4388 additional suffixes and extensions for files to be considered as "main".4389 4390 For example, if this option is configured to ``(Impl\.hpp)$``,4391 then a file ``ClassImpl.hpp`` is considered "main" (in addition to4392 ``Class.c``, ``Class.cc``, ``Class.cpp`` and so on) and "main4393 include file" logic will be executed (with *IncludeIsMainRegex* setting4394 also being respected in later phase). Without this option set,4395 ``ClassImpl.hpp`` would not have the main include file put on top4396 before any other include.4397 4398.. _IndentAccessModifiers:4399 4400**IndentAccessModifiers** (``Boolean``) :versionbadge:`clang-format 13` :ref:`¶ <IndentAccessModifiers>`4401 Specify whether access modifiers should have their own indentation level.4402 4403 When ``false``, access modifiers are indented (or outdented) relative to4404 the record members, respecting the ``AccessModifierOffset``. Record4405 members are indented one level below the record.4406 When ``true``, access modifiers get their own indentation level. As a4407 consequence, record members are always indented 2 levels below the record,4408 regardless of the access modifier presence. Value of the4409 ``AccessModifierOffset`` is ignored.4410 4411 .. code-block:: c++4412 4413 false: true:4414 class C { vs. class C {4415 class D { class D {4416 void bar(); void bar();4417 protected: protected:4418 D(); D();4419 }; };4420 public: public:4421 C(); C();4422 }; };4423 void foo() { void foo() {4424 return 1; return 1;4425 } }4426 4427.. _IndentCaseBlocks:4428 4429**IndentCaseBlocks** (``Boolean``) :versionbadge:`clang-format 11` :ref:`¶ <IndentCaseBlocks>`4430 Indent case label blocks one level from the case label.4431 4432 When ``false``, the block following the case label uses the same4433 indentation level as for the case label, treating the case label the same4434 as an if-statement.4435 When ``true``, the block gets indented as a scope block.4436 4437 .. code-block:: c++4438 4439 false: true:4440 switch (fool) { vs. switch (fool) {4441 case 1: { case 1:4442 bar(); {4443 } break; bar();4444 default: { }4445 plop(); break;4446 } default:4447 } {4448 plop();4449 }4450 }4451 4452.. _IndentCaseLabels:4453 4454**IndentCaseLabels** (``Boolean``) :versionbadge:`clang-format 3.3` :ref:`¶ <IndentCaseLabels>`4455 Indent case labels one level from the switch statement.4456 4457 When ``false``, use the same indentation level as for the switch4458 statement. Switch statement body is always indented one level more than4459 case labels (except the first block following the case label, which4460 itself indents the code - unless IndentCaseBlocks is enabled).4461 4462 .. code-block:: c++4463 4464 false: true:4465 switch (fool) { vs. switch (fool) {4466 case 1: case 1:4467 bar(); bar();4468 break; break;4469 default: default:4470 plop(); plop();4471 } }4472 4473.. _IndentExportBlock:4474 4475**IndentExportBlock** (``Boolean``) :versionbadge:`clang-format 20` :ref:`¶ <IndentExportBlock>`4476 If ``true``, clang-format will indent the body of an ``export { ... }``4477 block. This doesn't affect the formatting of anything else related to4478 exported declarations.4479 4480 .. code-block:: c++4481 4482 true: false:4483 export { vs. export {4484 void foo(); void foo();4485 void bar(); void bar();4486 } }4487 4488.. _IndentExternBlock:4489 4490**IndentExternBlock** (``IndentExternBlockStyle``) :versionbadge:`clang-format 11` :ref:`¶ <IndentExternBlock>`4491 IndentExternBlockStyle is the type of indenting of extern blocks.4492 4493 Possible values:4494 4495 * ``IEBS_AfterExternBlock`` (in configuration: ``AfterExternBlock``)4496 Backwards compatible with AfterExternBlock's indenting.4497 4498 .. code-block:: c++4499 4500 IndentExternBlock: AfterExternBlock4501 BraceWrapping.AfterExternBlock: true4502 extern "C"4503 {4504 void foo();4505 }4506 4507 4508 .. code-block:: c++4509 4510 IndentExternBlock: AfterExternBlock4511 BraceWrapping.AfterExternBlock: false4512 extern "C" {4513 void foo();4514 }4515 4516 * ``IEBS_NoIndent`` (in configuration: ``NoIndent``)4517 Does not indent extern blocks.4518 4519 .. code-block:: c++4520 4521 extern "C" {4522 void foo();4523 }4524 4525 * ``IEBS_Indent`` (in configuration: ``Indent``)4526 Indents extern blocks.4527 4528 .. code-block:: c++4529 4530 extern "C" {4531 void foo();4532 }4533 4534 4535 4536.. _IndentGotoLabels:4537 4538**IndentGotoLabels** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ <IndentGotoLabels>`4539 Indent goto labels.4540 4541 When ``false``, goto labels are flushed left.4542 4543 .. code-block:: c++4544 4545 true: false:4546 int f() { vs. int f() {4547 if (foo()) { if (foo()) {4548 label1: label1:4549 bar(); bar();4550 } }4551 label2: label2:4552 return 1; return 1;4553 } }4554 4555.. _IndentPPDirectives:4556 4557**IndentPPDirectives** (``PPDirectiveIndentStyle``) :versionbadge:`clang-format 6` :ref:`¶ <IndentPPDirectives>`4558 The preprocessor directive indenting style to use.4559 4560 Possible values:4561 4562 * ``PPDIS_None`` (in configuration: ``None``)4563 Does not indent any directives.4564 4565 .. code-block:: c++4566 4567 #if FOO4568 #if BAR4569 #include <foo>4570 #endif4571 #endif4572 4573 * ``PPDIS_AfterHash`` (in configuration: ``AfterHash``)4574 Indents directives after the hash.4575 4576 .. code-block:: c++4577 4578 #if FOO4579 # if BAR4580 # include <foo>4581 # endif4582 #endif4583 4584 * ``PPDIS_BeforeHash`` (in configuration: ``BeforeHash``)4585 Indents directives before the hash.4586 4587 .. code-block:: c++4588 4589 #if FOO4590 #if BAR4591 #include <foo>4592 #endif4593 #endif4594 4595 * ``PPDIS_Leave`` (in configuration: ``Leave``)4596 Leaves indentation of directives as-is.4597 4598 .. note::4599 4600 Ignores ``PPIndentWidth``.4601 4602 .. code-block:: c++4603 4604 #if FOO4605 #if BAR4606 #include <foo>4607 #endif4608 #endif4609 4610 4611 4612.. _IndentRequiresClause:4613 4614**IndentRequiresClause** (``Boolean``) :versionbadge:`clang-format 15` :ref:`¶ <IndentRequiresClause>`4615 Indent the requires clause in a template. This only applies when4616 ``RequiresClausePosition`` is ``OwnLine``, ``OwnLineWithBrace``,4617 or ``WithFollowing``.4618 4619 In clang-format 12, 13 and 14 it was named ``IndentRequires``.4620 4621 .. code-block:: c++4622 4623 true:4624 template <typename It>4625 requires Iterator<It>4626 void sort(It begin, It end) {4627 //....4628 }4629 4630 false:4631 template <typename It>4632 requires Iterator<It>4633 void sort(It begin, It end) {4634 //....4635 }4636 4637.. _IndentWidth:4638 4639**IndentWidth** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <IndentWidth>`4640 The number of columns to use for indentation.4641 4642 .. code-block:: c++4643 4644 IndentWidth: 34645 4646 void f() {4647 someFunction();4648 if (true, false) {4649 f();4650 }4651 }4652 4653.. _IndentWrappedFunctionNames:4654 4655**IndentWrappedFunctionNames** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <IndentWrappedFunctionNames>`4656 Indent if a function definition or declaration is wrapped after the4657 type.4658 4659 .. code-block:: c++4660 4661 true:4662 LoooooooooooooooooooooooooooooooooooooooongReturnType4663 LoooooooooooooooooooooooooooooooongFunctionDeclaration();4664 4665 false:4666 LoooooooooooooooooooooooooooooooooooooooongReturnType4667 LoooooooooooooooooooooooooooooooongFunctionDeclaration();4668 4669.. _InsertBraces:4670 4671**InsertBraces** (``Boolean``) :versionbadge:`clang-format 15` :ref:`¶ <InsertBraces>`4672 Insert braces after control statements (``if``, ``else``, ``for``, ``do``,4673 and ``while``) in C++ unless the control statements are inside macro4674 definitions or the braces would enclose preprocessor directives.4675 4676 .. warning::4677 4678 Setting this option to ``true`` could lead to incorrect code formatting4679 due to clang-format's lack of complete semantic information. As such,4680 extra care should be taken to review code changes made by this option.4681 4682 .. code-block:: c++4683 4684 false: true:4685 4686 if (isa<FunctionDecl>(D)) vs. if (isa<FunctionDecl>(D)) {4687 handleFunctionDecl(D); handleFunctionDecl(D);4688 else if (isa<VarDecl>(D)) } else if (isa<VarDecl>(D)) {4689 handleVarDecl(D); handleVarDecl(D);4690 else } else {4691 return; return;4692 }4693 4694 while (i--) vs. while (i--) {4695 for (auto *A : D.attrs()) for (auto *A : D.attrs()) {4696 handleAttr(A); handleAttr(A);4697 }4698 }4699 4700 do vs. do {4701 --i; --i;4702 while (i); } while (i);4703 4704.. _InsertNewlineAtEOF:4705 4706**InsertNewlineAtEOF** (``Boolean``) :versionbadge:`clang-format 16` :ref:`¶ <InsertNewlineAtEOF>`4707 Insert a newline at end of file if missing.4708 4709.. _InsertTrailingCommas:4710 4711**InsertTrailingCommas** (``TrailingCommaStyle``) :versionbadge:`clang-format 11` :ref:`¶ <InsertTrailingCommas>`4712 If set to ``TCS_Wrapped`` will insert trailing commas in container4713 literals (arrays and objects) that wrap across multiple lines.4714 It is currently only available for JavaScript4715 and disabled by default ``TCS_None``.4716 ``InsertTrailingCommas`` cannot be used together with ``BinPackArguments``4717 as inserting the comma disables bin-packing.4718 4719 .. code-block:: c++4720 4721 TSC_Wrapped:4722 const someArray = [4723 aaaaaaaaaaaaaaaaaaaaaaaaaa,4724 aaaaaaaaaaaaaaaaaaaaaaaaaa,4725 aaaaaaaaaaaaaaaaaaaaaaaaaa,4726 // ^ inserted4727 ]4728 4729 Possible values:4730 4731 * ``TCS_None`` (in configuration: ``None``)4732 Do not insert trailing commas.4733 4734 * ``TCS_Wrapped`` (in configuration: ``Wrapped``)4735 Insert trailing commas in container literals that were wrapped over4736 multiple lines. Note that this is conceptually incompatible with4737 bin-packing, because the trailing comma is used as an indicator4738 that a container should be formatted one-per-line (i.e. not bin-packed).4739 So inserting a trailing comma counteracts bin-packing.4740 4741 4742 4743.. _IntegerLiteralSeparator:4744 4745**IntegerLiteralSeparator** (``IntegerLiteralSeparatorStyle``) :versionbadge:`clang-format 16` :ref:`¶ <IntegerLiteralSeparator>`4746 Format integer literal separators (``'`` for C++ and ``_`` for C#, Java,4747 and JavaScript).4748 4749 Nested configuration flags:4750 4751 Separator format of integer literals of different bases.4752 4753 If negative, remove separators. If ``0``, leave the literal as is. If4754 positive, insert separators between digits starting from the rightmost4755 digit.4756 4757 For example, the config below will leave separators in binary literals4758 alone, insert separators in decimal literals to separate the digits into4759 groups of 3, and remove separators in hexadecimal literals.4760 4761 .. code-block:: c++4762 4763 IntegerLiteralSeparator:4764 Binary: 04765 Decimal: 34766 Hex: -14767 4768 You can also specify a minimum number of digits4769 (``BinaryMinDigitsInsert``, ``DecimalMinDigitsInsert``, and4770 ``HexMinDigitsInsert``) the integer literal must have in order for the4771 separators to be inserted, and a maximum number of digits4772 (``BinaryMaxDigitsRemove``, ``DecimalMaxDigitsRemove``, and4773 ``HexMaxDigitsRemove``) until the separators are removed. This divides the4774 literals in 3 regions, always without separator (up until including4775 ``xxxMaxDigitsRemove``), maybe with, or without separators (up until4776 excluding ``xxxMinDigitsInsert``), and finally always with separators.4777 4778 .. note::4779 4780 ``BinaryMinDigits``, ``DecimalMinDigits``, and ``HexMinDigits`` are4781 deprecated and renamed to ``BinaryMinDigitsInsert``,4782 ``DecimalMinDigitsInsert``, and ``HexMinDigitsInsert``, respectively.4783 4784 * ``int8_t Binary`` Format separators in binary literals.4785 4786 .. code-block:: text4787 4788 /* -1: */ b = 0b100111101101;4789 /* 0: */ b = 0b10011'11'0110'1;4790 /* 3: */ b = 0b100'111'101'101;4791 /* 4: */ b = 0b1001'1110'1101;4792 4793 * ``int8_t BinaryMinDigitsInsert`` Format separators in binary literals with a minimum number of digits.4794 4795 .. code-block:: text4796 4797 // Binary: 34798 // BinaryMinDigitsInsert: 74799 b1 = 0b101101;4800 b2 = 0b1'101'101;4801 4802 * ``int8_t BinaryMaxDigitsRemove`` Remove separators in binary literals with a maximum number of digits.4803 4804 .. code-block:: text4805 4806 // Binary: 34807 // BinaryMinDigitsInsert: 74808 // BinaryMaxDigitsRemove: 44809 b0 = 0b1011; // Always removed.4810 b1 = 0b101101; // Not added.4811 b2 = 0b1'01'101; // Not removed, not corrected.4812 b3 = 0b1'101'101; // Always added.4813 b4 = 0b10'1101; // Corrected to 0b101'101.4814 4815 * ``int8_t Decimal`` Format separators in decimal literals.4816 4817 .. code-block:: text4818 4819 /* -1: */ d = 18446744073709550592ull;4820 /* 0: */ d = 184467'440737'0'95505'92ull;4821 /* 3: */ d = 18'446'744'073'709'550'592ull;4822 4823 * ``int8_t DecimalMinDigitsInsert`` Format separators in decimal literals with a minimum number of digits.4824 4825 .. code-block:: text4826 4827 // Decimal: 34828 // DecimalMinDigitsInsert: 54829 d1 = 2023;4830 d2 = 10'000;4831 4832 * ``int8_t DecimalMaxDigitsRemove`` Remove separators in decimal literals with a maximum number of digits.4833 4834 .. code-block:: text4835 4836 // Decimal: 34837 // DecimalMinDigitsInsert: 74838 // DecimalMaxDigitsRemove: 44839 d0 = 2023; // Always removed.4840 d1 = 123456; // Not added.4841 d2 = 1'23'456; // Not removed, not corrected.4842 d3 = 5'000'000; // Always added.4843 d4 = 1'23'45; // Corrected to 12'345.4844 4845 * ``int8_t Hex`` Format separators in hexadecimal literals.4846 4847 .. code-block:: text4848 4849 /* -1: */ h = 0xDEADBEEFDEADBEEFuz;4850 /* 0: */ h = 0xDEAD'BEEF'DE'AD'BEE'Fuz;4851 /* 2: */ h = 0xDE'AD'BE'EF'DE'AD'BE'EFuz;4852 4853 * ``int8_t HexMinDigitsInsert`` Format separators in hexadecimal literals with a minimum number of4854 digits.4855 4856 .. code-block:: text4857 4858 // Hex: 24859 // HexMinDigitsInsert: 64860 h1 = 0xABCDE;4861 h2 = 0xAB'CD'EF;4862 4863 * ``int8_t HexMaxDigitsRemove`` Remove separators in hexadecimal literals with a maximum number of4864 digits.4865 4866 .. code-block:: text4867 4868 // Hex: 24869 // HexMinDigitsInsert: 64870 // HexMaxDigitsRemove: 44871 h0 = 0xAFFE; // Always removed.4872 h1 = 0xABCDE; // Not added.4873 h2 = 0xABC'DE; // Not removed, not corrected.4874 h3 = 0xAB'CD'EF; // Always added.4875 h4 = 0xABCD'E; // Corrected to 0xA'BC'DE.4876 4877 4878.. _JavaImportGroups:4879 4880**JavaImportGroups** (``List of Strings``) :versionbadge:`clang-format 8` :ref:`¶ <JavaImportGroups>`4881 A vector of prefixes ordered by the desired groups for Java imports.4882 4883 One group's prefix can be a subset of another - the longest prefix is4884 always matched. Within a group, the imports are ordered lexicographically.4885 Static imports are grouped separately and follow the same group rules.4886 By default, static imports are placed before non-static imports,4887 but this behavior is changed by another option,4888 ``SortJavaStaticImport``.4889 4890 In the .clang-format configuration file, this can be configured like4891 in the following yaml example. This will result in imports being4892 formatted as in the Java example below.4893 4894 .. code-block:: yaml4895 4896 JavaImportGroups: [com.example, com, org]4897 4898 4899 .. code-block:: java4900 4901 import static com.example.function1;4902 4903 import static com.test.function2;4904 4905 import static org.example.function3;4906 4907 import com.example.ClassA;4908 import com.example.Test;4909 import com.example.a.ClassB;4910 4911 import com.test.ClassC;4912 4913 import org.example.ClassD;4914 4915.. _JavaScriptQuotes:4916 4917**JavaScriptQuotes** (``JavaScriptQuoteStyle``) :versionbadge:`clang-format 3.9` :ref:`¶ <JavaScriptQuotes>`4918 The JavaScriptQuoteStyle to use for JavaScript strings.4919 4920 Possible values:4921 4922 * ``JSQS_Leave`` (in configuration: ``Leave``)4923 Leave string quotes as they are.4924 4925 .. code-block:: js4926 4927 string1 = "foo";4928 string2 = 'bar';4929 4930 * ``JSQS_Single`` (in configuration: ``Single``)4931 Always use single quotes.4932 4933 .. code-block:: js4934 4935 string1 = 'foo';4936 string2 = 'bar';4937 4938 * ``JSQS_Double`` (in configuration: ``Double``)4939 Always use double quotes.4940 4941 .. code-block:: js4942 4943 string1 = "foo";4944 string2 = "bar";4945 4946 4947 4948.. _JavaScriptWrapImports:4949 4950**JavaScriptWrapImports** (``Boolean``) :versionbadge:`clang-format 3.9` :ref:`¶ <JavaScriptWrapImports>`4951 Whether to wrap JavaScript import/export statements.4952 4953 .. code-block:: js4954 4955 true:4956 import {4957 VeryLongImportsAreAnnoying,4958 VeryLongImportsAreAnnoying,4959 VeryLongImportsAreAnnoying,4960 } from "some/module.js"4961 4962 false:4963 import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js"4964 4965.. _KeepEmptyLines:4966 4967**KeepEmptyLines** (``KeepEmptyLinesStyle``) :versionbadge:`clang-format 19` :ref:`¶ <KeepEmptyLines>`4968 Which empty lines are kept. See ``MaxEmptyLinesToKeep`` for how many4969 consecutive empty lines are kept.4970 4971 Nested configuration flags:4972 4973 Options regarding which empty lines are kept.4974 4975 For example, the config below will remove empty lines at start of the4976 file, end of the file, and start of blocks.4977 4978 4979 .. code-block:: c++4980 4981 KeepEmptyLines:4982 AtEndOfFile: false4983 AtStartOfBlock: false4984 AtStartOfFile: false4985 4986 * ``bool AtEndOfFile`` Keep empty lines at end of file.4987 4988 * ``bool AtStartOfBlock`` Keep empty lines at start of a block.4989 4990 .. code-block:: c++4991 4992 true: false:4993 if (foo) { vs. if (foo) {4994 bar();4995 bar(); }4996 }4997 4998 * ``bool AtStartOfFile`` Keep empty lines at start of file.4999 5000 5001.. _KeepEmptyLinesAtEOF:5002 5003**KeepEmptyLinesAtEOF** (``Boolean``) :versionbadge:`clang-format 17` :ref:`¶ <KeepEmptyLinesAtEOF>`5004 This option is **deprecated**. See ``AtEndOfFile`` of ``KeepEmptyLines``.5005 5006.. _KeepEmptyLinesAtTheStartOfBlocks:5007 5008**KeepEmptyLinesAtTheStartOfBlocks** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <KeepEmptyLinesAtTheStartOfBlocks>`5009 This option is **deprecated**. See ``AtStartOfBlock`` of5010 ``KeepEmptyLines``.5011 5012.. _KeepFormFeed:5013 5014**KeepFormFeed** (``Boolean``) :versionbadge:`clang-format 20` :ref:`¶ <KeepFormFeed>`5015 Keep the form feed character if it's immediately preceded and followed by5016 a newline. Multiple form feeds and newlines within a whitespace range are5017 replaced with a single newline and form feed followed by the remaining5018 newlines.5019 5020.. _LambdaBodyIndentation:5021 5022**LambdaBodyIndentation** (``LambdaBodyIndentationKind``) :versionbadge:`clang-format 13` :ref:`¶ <LambdaBodyIndentation>`5023 The indentation style of lambda bodies. ``Signature`` (the default)5024 causes the lambda body to be indented one additional level relative to5025 the indentation level of the signature. ``OuterScope`` forces the lambda5026 body to be indented one additional level relative to the parent scope5027 containing the lambda signature.5028 5029 Possible values:5030 5031 * ``LBI_Signature`` (in configuration: ``Signature``)5032 Align lambda body relative to the lambda signature. This is the default.5033 5034 .. code-block:: c++5035 5036 someMethod(5037 [](SomeReallyLongLambdaSignatureArgument foo) {5038 return;5039 });5040 5041 * ``LBI_OuterScope`` (in configuration: ``OuterScope``)5042 For statements within block scope, align lambda body relative to the5043 indentation level of the outer scope the lambda signature resides in.5044 5045 .. code-block:: c++5046 5047 someMethod(5048 [](SomeReallyLongLambdaSignatureArgument foo) {5049 return;5050 });5051 5052 someMethod(someOtherMethod(5053 [](SomeReallyLongLambdaSignatureArgument foo) {5054 return;5055 }));5056 5057 5058 5059.. _Language:5060 5061**Language** (``LanguageKind``) :versionbadge:`clang-format 3.5` :ref:`¶ <Language>`5062 The language that this format style targets.5063 5064 .. note::5065 5066 You can specify the language (``C``, ``Cpp``, or ``ObjC``) for ``.h``5067 files by adding a ``// clang-format Language:`` line before the first5068 non-comment (and non-empty) line, e.g. ``// clang-format Language: Cpp``.5069 5070 Possible values:5071 5072 * ``LK_None`` (in configuration: ``None``)5073 Do not use.5074 5075 * ``LK_C`` (in configuration: ``C``)5076 Should be used for C.5077 5078 * ``LK_Cpp`` (in configuration: ``Cpp``)5079 Should be used for C++.5080 5081 * ``LK_CSharp`` (in configuration: ``CSharp``)5082 Should be used for C#.5083 5084 * ``LK_Java`` (in configuration: ``Java``)5085 Should be used for Java.5086 5087 * ``LK_JavaScript`` (in configuration: ``JavaScript``)5088 Should be used for JavaScript.5089 5090 * ``LK_Json`` (in configuration: ``Json``)5091 Should be used for JSON.5092 5093 * ``LK_ObjC`` (in configuration: ``ObjC``)5094 Should be used for Objective-C, Objective-C++.5095 5096 * ``LK_Proto`` (in configuration: ``Proto``)5097 Should be used for Protocol Buffers5098 (https://developers.google.com/protocol-buffers/).5099 5100 * ``LK_TableGen`` (in configuration: ``TableGen``)5101 Should be used for TableGen code.5102 5103 * ``LK_TextProto`` (in configuration: ``TextProto``)5104 Should be used for Protocol Buffer messages in text format5105 (https://developers.google.com/protocol-buffers/).5106 5107 * ``LK_Verilog`` (in configuration: ``Verilog``)5108 Should be used for Verilog and SystemVerilog.5109 https://standards.ieee.org/ieee/1800/6700/5110 https://sci-hub.st/10.1109/IEEESTD.2018.82995955111 5112 5113 5114.. _LineEnding:5115 5116**LineEnding** (``LineEndingStyle``) :versionbadge:`clang-format 16` :ref:`¶ <LineEnding>`5117 Line ending style (``\n`` or ``\r\n``) to use.5118 5119 Possible values:5120 5121 * ``LE_LF`` (in configuration: ``LF``)5122 Use ``\n``.5123 5124 * ``LE_CRLF`` (in configuration: ``CRLF``)5125 Use ``\r\n``.5126 5127 * ``LE_DeriveLF`` (in configuration: ``DeriveLF``)5128 Use ``\n`` unless the input has more lines ending in ``\r\n``.5129 5130 * ``LE_DeriveCRLF`` (in configuration: ``DeriveCRLF``)5131 Use ``\r\n`` unless the input has more lines ending in ``\n``.5132 5133 5134 5135.. _MacroBlockBegin:5136 5137**MacroBlockBegin** (``String``) :versionbadge:`clang-format 3.7` :ref:`¶ <MacroBlockBegin>`5138 A regular expression matching macros that start a block.5139 5140 .. code-block:: c++5141 5142 # With:5143 MacroBlockBegin: "^NS_MAP_BEGIN|\5144 NS_TABLE_HEAD$"5145 MacroBlockEnd: "^\5146 NS_MAP_END|\5147 NS_TABLE_.*_END$"5148 5149 NS_MAP_BEGIN5150 foo();5151 NS_MAP_END5152 5153 NS_TABLE_HEAD5154 bar();5155 NS_TABLE_FOO_END5156 5157 # Without:5158 NS_MAP_BEGIN5159 foo();5160 NS_MAP_END5161 5162 NS_TABLE_HEAD5163 bar();5164 NS_TABLE_FOO_END5165 5166.. _MacroBlockEnd:5167 5168**MacroBlockEnd** (``String``) :versionbadge:`clang-format 3.7` :ref:`¶ <MacroBlockEnd>`5169 A regular expression matching macros that end a block.5170 5171.. _Macros:5172 5173**Macros** (``List of Strings``) :versionbadge:`clang-format 17` :ref:`¶ <Macros>`5174 A list of macros of the form ``<definition>=<expansion>`` .5175 5176 Code will be parsed with macros expanded, in order to determine how to5177 interpret and format the macro arguments.5178 5179 For example, the code:5180 5181 .. code-block:: c++5182 5183 A(a*b);5184 5185 will usually be interpreted as a call to a function A, and the5186 multiplication expression will be formatted as ``a * b``.5187 5188 If we specify the macro definition:5189 5190 .. code-block:: yaml5191 5192 Macros:5193 - A(x)=x5194 5195 the code will now be parsed as a declaration of the variable b of type a*,5196 and formatted as ``a* b`` (depending on pointer-binding rules).5197 5198 Features and restrictions:5199 * Both function-like macros and object-like macros are supported.5200 * Macro arguments must be used exactly once in the expansion.5201 * No recursive expansion; macros referencing other macros will be5202 ignored.5203 * Overloading by arity is supported: for example, given the macro5204 definitions A=x, A()=y, A(a)=a5205 5206 5207 .. code-block:: c++5208 5209 A; -> x;5210 A(); -> y;5211 A(z); -> z;5212 A(a, b); // will not be expanded.5213 5214.. _MacrosSkippedByRemoveParentheses:5215 5216**MacrosSkippedByRemoveParentheses** (``List of Strings``) :versionbadge:`clang-format 21` :ref:`¶ <MacrosSkippedByRemoveParentheses>`5217 A vector of function-like macros whose invocations should be skipped by5218 ``RemoveParentheses``.5219 5220.. _MainIncludeChar:5221 5222**MainIncludeChar** (``MainIncludeCharDiscriminator``) :versionbadge:`clang-format 19` :ref:`¶ <MainIncludeChar>`5223 When guessing whether a #include is the "main" include, only the include5224 directives that use the specified character are considered.5225 5226 Possible values:5227 5228 * ``MICD_Quote`` (in configuration: ``Quote``)5229 Main include uses quotes: ``#include "foo.hpp"`` (the default).5230 5231 * ``MICD_AngleBracket`` (in configuration: ``AngleBracket``)5232 Main include uses angle brackets: ``#include <foo.hpp>``.5233 5234 * ``MICD_Any`` (in configuration: ``Any``)5235 Main include uses either quotes or angle brackets.5236 5237 5238 5239.. _MaxEmptyLinesToKeep:5240 5241**MaxEmptyLinesToKeep** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <MaxEmptyLinesToKeep>`5242 The maximum number of consecutive empty lines to keep.5243 5244 .. code-block:: c++5245 5246 MaxEmptyLinesToKeep: 1 vs. MaxEmptyLinesToKeep: 05247 int f() { int f() {5248 int = 1; int i = 1;5249 i = foo();5250 i = foo(); return i;5251 }5252 return i;5253 }5254 5255.. _NamespaceIndentation:5256 5257**NamespaceIndentation** (``NamespaceIndentationKind``) :versionbadge:`clang-format 3.7` :ref:`¶ <NamespaceIndentation>`5258 The indentation used for namespaces.5259 5260 Possible values:5261 5262 * ``NI_None`` (in configuration: ``None``)5263 Don't indent in namespaces.5264 5265 .. code-block:: c++5266 5267 namespace out {5268 int i;5269 namespace in {5270 int i;5271 }5272 }5273 5274 * ``NI_Inner`` (in configuration: ``Inner``)5275 Indent only in inner namespaces (nested in other namespaces).5276 5277 .. code-block:: c++5278 5279 namespace out {5280 int i;5281 namespace in {5282 int i;5283 }5284 }5285 5286 * ``NI_All`` (in configuration: ``All``)5287 Indent in all namespaces.5288 5289 .. code-block:: c++5290 5291 namespace out {5292 int i;5293 namespace in {5294 int i;5295 }5296 }5297 5298 5299 5300.. _NamespaceMacros:5301 5302**NamespaceMacros** (``List of Strings``) :versionbadge:`clang-format 9` :ref:`¶ <NamespaceMacros>`5303 A vector of macros which are used to open namespace blocks.5304 5305 These are expected to be macros of the form:5306 5307 .. code-block:: c++5308 5309 NAMESPACE(<namespace-name>, ...) {5310 <namespace-content>5311 }5312 5313 For example: TESTSUITE5314 5315.. _NumericLiteralCase:5316 5317**NumericLiteralCase** (``NumericLiteralCaseStyle``) :versionbadge:`clang-format 22` :ref:`¶ <NumericLiteralCase>`5318 Capitalization style for numeric literals.5319 5320 Nested configuration flags:5321 5322 Separate control for each numeric literal component.5323 5324 For example, the config below will leave exponent letters alone, reformat5325 hexadecimal digits in lowercase, reformat numeric literal prefixes in5326 uppercase, and reformat suffixes in lowercase.5327 5328 .. code-block:: c++5329 5330 NumericLiteralCase:5331 ExponentLetter: Leave5332 HexDigit: Lower5333 Prefix: Upper5334 Suffix: Lower5335 5336 * ``NumericLiteralComponentStyle ExponentLetter``5337 Format floating point exponent separator letter case.5338 5339 .. code-block:: c++5340 5341 float a = 6.02e23 + 1.0E10; // Leave5342 float a = 6.02E23 + 1.0E10; // Upper5343 float a = 6.02e23 + 1.0e10; // Lower5344 5345 Possible values:5346 5347 * ``NLCS_Leave`` (in configuration: ``Leave``)5348 Leave this component of the literal as is.5349 5350 * ``NLCS_Upper`` (in configuration: ``Upper``)5351 Format this component with uppercase characters.5352 5353 * ``NLCS_Lower`` (in configuration: ``Lower``)5354 Format this component with lowercase characters.5355 5356 5357 * ``NumericLiteralComponentStyle HexDigit``5358 Format hexadecimal digit case.5359 5360 .. code-block:: c++5361 5362 a = 0xaBcDeF; // Leave5363 a = 0xABCDEF; // Upper5364 a = 0xabcdef; // Lower5365 5366 Possible values:5367 5368 * ``NLCS_Leave`` (in configuration: ``Leave``)5369 Leave this component of the literal as is.5370 5371 * ``NLCS_Upper`` (in configuration: ``Upper``)5372 Format this component with uppercase characters.5373 5374 * ``NLCS_Lower`` (in configuration: ``Lower``)5375 Format this component with lowercase characters.5376 5377 5378 * ``NumericLiteralComponentStyle Prefix``5379 Format integer prefix case.5380 5381 .. code-block:: c++5382 5383 a = 0XF0 | 0b1; // Leave5384 a = 0XF0 | 0B1; // Upper5385 a = 0xF0 | 0b1; // Lower5386 5387 Possible values:5388 5389 * ``NLCS_Leave`` (in configuration: ``Leave``)5390 Leave this component of the literal as is.5391 5392 * ``NLCS_Upper`` (in configuration: ``Upper``)5393 Format this component with uppercase characters.5394 5395 * ``NLCS_Lower`` (in configuration: ``Lower``)5396 Format this component with lowercase characters.5397 5398 5399 * ``NumericLiteralComponentStyle Suffix``5400 Format suffix case. This option excludes case-sensitive reserved5401 suffixes, such as ``min`` in C++.5402 5403 .. code-block:: c++5404 5405 a = 1uLL; // Leave5406 a = 1ULL; // Upper5407 a = 1ull; // Lower5408 5409 Possible values:5410 5411 * ``NLCS_Leave`` (in configuration: ``Leave``)5412 Leave this component of the literal as is.5413 5414 * ``NLCS_Upper`` (in configuration: ``Upper``)5415 Format this component with uppercase characters.5416 5417 * ``NLCS_Lower`` (in configuration: ``Lower``)5418 Format this component with lowercase characters.5419 5420 5421 5422.. _ObjCBinPackProtocolList:5423 5424**ObjCBinPackProtocolList** (``BinPackStyle``) :versionbadge:`clang-format 7` :ref:`¶ <ObjCBinPackProtocolList>`5425 Controls bin-packing Objective-C protocol conformance list5426 items into as few lines as possible when they go over ``ColumnLimit``.5427 5428 If ``Auto`` (the default), delegates to the value in5429 ``BinPackParameters``. If that is ``BinPack``, bin-packs Objective-C5430 protocol conformance list items into as few lines as possible5431 whenever they go over ``ColumnLimit``.5432 5433 If ``Always``, always bin-packs Objective-C protocol conformance5434 list items into as few lines as possible whenever they go over5435 ``ColumnLimit``.5436 5437 If ``Never``, lays out Objective-C protocol conformance list items5438 onto individual lines whenever they go over ``ColumnLimit``.5439 5440 5441 .. code-block:: objc5442 5443 Always (or Auto, if BinPackParameters==BinPack):5444 @interface ccccccccccccc () <5445 ccccccccccccc, ccccccccccccc,5446 ccccccccccccc, ccccccccccccc> {5447 }5448 5449 Never (or Auto, if BinPackParameters!=BinPack):5450 @interface ddddddddddddd () <5451 ddddddddddddd,5452 ddddddddddddd,5453 ddddddddddddd,5454 ddddddddddddd> {5455 }5456 5457 Possible values:5458 5459 * ``BPS_Auto`` (in configuration: ``Auto``)5460 Automatically determine parameter bin-packing behavior.5461 5462 * ``BPS_Always`` (in configuration: ``Always``)5463 Always bin-pack parameters.5464 5465 * ``BPS_Never`` (in configuration: ``Never``)5466 Never bin-pack parameters.5467 5468 5469 5470.. _ObjCBlockIndentWidth:5471 5472**ObjCBlockIndentWidth** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <ObjCBlockIndentWidth>`5473 The number of characters to use for indentation of ObjC blocks.5474 5475 .. code-block:: objc5476 5477 ObjCBlockIndentWidth: 45478 5479 [operation setCompletionBlock:^{5480 [self onOperationDone];5481 }];5482 5483.. _ObjCBreakBeforeNestedBlockParam:5484 5485**ObjCBreakBeforeNestedBlockParam** (``Boolean``) :versionbadge:`clang-format 11` :ref:`¶ <ObjCBreakBeforeNestedBlockParam>`5486 Break parameters list into lines when there is nested block5487 parameters in a function call.5488 5489 .. code-block:: c++5490 5491 false:5492 - (void)_aMethod5493 {5494 [self.test1 t:self w:self callback:^(typeof(self) self, NSNumber5495 *u, NSNumber *v) {5496 u = c;5497 }]5498 }5499 true:5500 - (void)_aMethod5501 {5502 [self.test1 t:self5503 w:self5504 callback:^(typeof(self) self, NSNumber *u, NSNumber *v) {5505 u = c;5506 }]5507 }5508 5509.. _ObjCPropertyAttributeOrder:5510 5511**ObjCPropertyAttributeOrder** (``List of Strings``) :versionbadge:`clang-format 18` :ref:`¶ <ObjCPropertyAttributeOrder>`5512 The order in which ObjC property attributes should appear.5513 5514 Attributes in code will be sorted in the order specified. Any attributes5515 encountered that are not mentioned in this array will be sorted last, in5516 stable order. Comments between attributes will leave the attributes5517 untouched.5518 5519 .. warning::5520 5521 Using this option could lead to incorrect code formatting due to5522 clang-format's lack of complete semantic information. As such, extra5523 care should be taken to review code changes made by this option.5524 5525 .. code-block:: yaml5526 5527 ObjCPropertyAttributeOrder: [5528 class, direct,5529 atomic, nonatomic,5530 assign, retain, strong, copy, weak, unsafe_unretained,5531 readonly, readwrite, getter, setter,5532 nullable, nonnull, null_resettable, null_unspecified5533 ]5534 5535.. _ObjCSpaceAfterProperty:5536 5537**ObjCSpaceAfterProperty** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <ObjCSpaceAfterProperty>`5538 Add a space after ``@property`` in Objective-C, i.e. use5539 ``@property (readonly)`` instead of ``@property(readonly)``.5540 5541.. _ObjCSpaceBeforeProtocolList:5542 5543**ObjCSpaceBeforeProtocolList** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <ObjCSpaceBeforeProtocolList>`5544 Add a space in front of an Objective-C protocol list, i.e. use5545 ``Foo <Protocol>`` instead of ``Foo<Protocol>``.5546 5547.. _OneLineFormatOffRegex:5548 5549**OneLineFormatOffRegex** (``String``) :versionbadge:`clang-format 21` :ref:`¶ <OneLineFormatOffRegex>`5550 A regular expression that describes markers for turning formatting off for5551 one line. If it matches a comment that is the only token of a line,5552 clang-format skips the comment and the next line. Otherwise, clang-format5553 skips lines containing a matched token.5554 5555 .. code-block:: c++5556 5557 // OneLineFormatOffRegex: ^(// NOLINT|logger$)5558 // results in the output below:5559 int a;5560 int b ; // NOLINT5561 int c;5562 // NOLINTNEXTLINE5563 int d ;5564 int e;5565 s = "// NOLINT";5566 logger() ;5567 logger2();5568 my_logger();5569 5570.. _PPIndentWidth:5571 5572**PPIndentWidth** (``Integer``) :versionbadge:`clang-format 13` :ref:`¶ <PPIndentWidth>`5573 The number of columns to use for indentation of preprocessor statements.5574 When set to -1 (default) ``IndentWidth`` is used also for preprocessor5575 statements.5576 5577 .. code-block:: c++5578 5579 PPIndentWidth: 15580 5581 #ifdef __linux__5582 # define FOO5583 #else5584 # define BAR5585 #endif5586 5587.. _PackConstructorInitializers:5588 5589**PackConstructorInitializers** (``PackConstructorInitializersStyle``) :versionbadge:`clang-format 14` :ref:`¶ <PackConstructorInitializers>`5590 The pack constructor initializers style to use.5591 5592 Possible values:5593 5594 * ``PCIS_Never`` (in configuration: ``Never``)5595 Always put each constructor initializer on its own line.5596 5597 .. code-block:: c++5598 5599 Constructor()5600 : a(),5601 b()5602 5603 * ``PCIS_BinPack`` (in configuration: ``BinPack``)5604 Bin-pack constructor initializers.5605 5606 .. code-block:: c++5607 5608 Constructor()5609 : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(),5610 cccccccccccccccccccc()5611 5612 * ``PCIS_CurrentLine`` (in configuration: ``CurrentLine``)5613 Put all constructor initializers on the current line if they fit.5614 Otherwise, put each one on its own line.5615 5616 .. code-block:: c++5617 5618 Constructor() : a(), b()5619 5620 Constructor()5621 : aaaaaaaaaaaaaaaaaaaa(),5622 bbbbbbbbbbbbbbbbbbbb(),5623 ddddddddddddd()5624 5625 * ``PCIS_NextLine`` (in configuration: ``NextLine``)5626 Same as ``PCIS_CurrentLine`` except that if all constructor initializers5627 do not fit on the current line, try to fit them on the next line.5628 5629 .. code-block:: c++5630 5631 Constructor() : a(), b()5632 5633 Constructor()5634 : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), ddddddddddddd()5635 5636 Constructor()5637 : aaaaaaaaaaaaaaaaaaaa(),5638 bbbbbbbbbbbbbbbbbbbb(),5639 cccccccccccccccccccc()5640 5641 * ``PCIS_NextLineOnly`` (in configuration: ``NextLineOnly``)5642 Put all constructor initializers on the next line if they fit.5643 Otherwise, put each one on its own line.5644 5645 .. code-block:: c++5646 5647 Constructor()5648 : a(), b()5649 5650 Constructor()5651 : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), ddddddddddddd()5652 5653 Constructor()5654 : aaaaaaaaaaaaaaaaaaaa(),5655 bbbbbbbbbbbbbbbbbbbb(),5656 cccccccccccccccccccc()5657 5658 5659 5660.. _PenaltyBreakAssignment:5661 5662**PenaltyBreakAssignment** (``Unsigned``) :versionbadge:`clang-format 5` :ref:`¶ <PenaltyBreakAssignment>`5663 The penalty for breaking around an assignment operator.5664 5665.. _PenaltyBreakBeforeFirstCallParameter:5666 5667**PenaltyBreakBeforeFirstCallParameter** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <PenaltyBreakBeforeFirstCallParameter>`5668 The penalty for breaking a function call after ``call(``.5669 5670.. _PenaltyBreakBeforeMemberAccess:5671 5672**PenaltyBreakBeforeMemberAccess** (``Unsigned``) :versionbadge:`clang-format 20` :ref:`¶ <PenaltyBreakBeforeMemberAccess>`5673 The penalty for breaking before a member access operator (``.``, ``->``).5674 5675.. _PenaltyBreakComment:5676 5677**PenaltyBreakComment** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <PenaltyBreakComment>`5678 The penalty for each line break introduced inside a comment.5679 5680.. _PenaltyBreakFirstLessLess:5681 5682**PenaltyBreakFirstLessLess** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <PenaltyBreakFirstLessLess>`5683 The penalty for breaking before the first ``<<``.5684 5685.. _PenaltyBreakOpenParenthesis:5686 5687**PenaltyBreakOpenParenthesis** (``Unsigned``) :versionbadge:`clang-format 14` :ref:`¶ <PenaltyBreakOpenParenthesis>`5688 The penalty for breaking after ``(``.5689 5690.. _PenaltyBreakScopeResolution:5691 5692**PenaltyBreakScopeResolution** (``Unsigned``) :versionbadge:`clang-format 18` :ref:`¶ <PenaltyBreakScopeResolution>`5693 The penalty for breaking after ``::``.5694 5695.. _PenaltyBreakString:5696 5697**PenaltyBreakString** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <PenaltyBreakString>`5698 The penalty for each line break introduced inside a string literal.5699 5700.. _PenaltyBreakTemplateDeclaration:5701 5702**PenaltyBreakTemplateDeclaration** (``Unsigned``) :versionbadge:`clang-format 7` :ref:`¶ <PenaltyBreakTemplateDeclaration>`5703 The penalty for breaking after template declaration.5704 5705.. _PenaltyExcessCharacter:5706 5707**PenaltyExcessCharacter** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <PenaltyExcessCharacter>`5708 The penalty for each character outside of the column limit.5709 5710.. _PenaltyIndentedWhitespace:5711 5712**PenaltyIndentedWhitespace** (``Unsigned``) :versionbadge:`clang-format 12` :ref:`¶ <PenaltyIndentedWhitespace>`5713 Penalty for each character of whitespace indentation5714 (counted relative to leading non-whitespace column).5715 5716.. _PenaltyReturnTypeOnItsOwnLine:5717 5718**PenaltyReturnTypeOnItsOwnLine** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <PenaltyReturnTypeOnItsOwnLine>`5719 Penalty for putting the return type of a function onto its own line.5720 5721.. _PointerAlignment:5722 5723**PointerAlignment** (``PointerAlignmentStyle``) :versionbadge:`clang-format 3.7` :ref:`¶ <PointerAlignment>`5724 Pointer and reference alignment style.5725 5726 Possible values:5727 5728 * ``PAS_Left`` (in configuration: ``Left``)5729 Align pointer to the left.5730 5731 .. code-block:: c++5732 5733 int* a;5734 5735 * ``PAS_Right`` (in configuration: ``Right``)5736 Align pointer to the right.5737 5738 .. code-block:: c++5739 5740 int *a;5741 5742 * ``PAS_Middle`` (in configuration: ``Middle``)5743 Align pointer in the middle.5744 5745 .. code-block:: c++5746 5747 int * a;5748 5749 5750 5751.. _QualifierAlignment:5752 5753**QualifierAlignment** (``QualifierAlignmentStyle``) :versionbadge:`clang-format 14` :ref:`¶ <QualifierAlignment>`5754 Different ways to arrange specifiers and qualifiers (e.g. const/volatile).5755 5756 .. warning::5757 5758 Setting ``QualifierAlignment`` to something other than ``Leave``, COULD5759 lead to incorrect code formatting due to incorrect decisions made due to5760 clang-formats lack of complete semantic information.5761 As such extra care should be taken to review code changes made by the use5762 of this option.5763 5764 Possible values:5765 5766 * ``QAS_Leave`` (in configuration: ``Leave``)5767 Don't change specifiers/qualifiers to either Left or Right alignment5768 (default).5769 5770 .. code-block:: c++5771 5772 int const a;5773 const int *a;5774 5775 * ``QAS_Left`` (in configuration: ``Left``)5776 Change specifiers/qualifiers to be left-aligned.5777 5778 .. code-block:: c++5779 5780 const int a;5781 const int *a;5782 5783 * ``QAS_Right`` (in configuration: ``Right``)5784 Change specifiers/qualifiers to be right-aligned.5785 5786 .. code-block:: c++5787 5788 int const a;5789 int const *a;5790 5791 * ``QAS_Custom`` (in configuration: ``Custom``)5792 Change specifiers/qualifiers to be aligned based on ``QualifierOrder``.5793 With:5794 5795 .. code-block:: yaml5796 5797 QualifierOrder: [inline, static, type, const]5798 5799 5800 .. code-block:: c++5801 5802 5803 int const a;5804 int const *a;5805 5806 5807 5808.. _QualifierOrder:5809 5810**QualifierOrder** (``List of Strings``) :versionbadge:`clang-format 14` :ref:`¶ <QualifierOrder>`5811 The order in which the qualifiers appear.5812 The order is an array that can contain any of the following:5813 5814 * ``const``5815 * ``inline``5816 * ``static``5817 * ``friend``5818 * ``constexpr``5819 * ``volatile``5820 * ``restrict``5821 * ``type``5822 5823 5824 .. note::5825 5826 It must contain ``type``.5827 5828 Items to the left of ``type`` will be placed to the left of the type and5829 aligned in the order supplied. Items to the right of ``type`` will be5830 placed to the right of the type and aligned in the order supplied.5831 5832 5833 .. code-block:: yaml5834 5835 QualifierOrder: [inline, static, type, const, volatile]5836 5837.. _RawStringFormats:5838 5839**RawStringFormats** (``List of RawStringFormats``) :versionbadge:`clang-format 6` :ref:`¶ <RawStringFormats>`5840 Defines hints for detecting supported languages code blocks in raw5841 strings.5842 5843 A raw string with a matching delimiter or a matching enclosing function5844 name will be reformatted assuming the specified language based on the5845 style for that language defined in the .clang-format file. If no style has5846 been defined in the .clang-format file for the specific language, a5847 predefined style given by ``BasedOnStyle`` is used. If ``BasedOnStyle`` is5848 not found, the formatting is based on ``LLVM`` style. A matching delimiter5849 takes precedence over a matching enclosing function name for determining5850 the language of the raw string contents.5851 5852 If a canonical delimiter is specified, occurrences of other delimiters for5853 the same language will be updated to the canonical if possible.5854 5855 There should be at most one specification per language and each delimiter5856 and enclosing function should not occur in multiple specifications.5857 5858 To configure this in the .clang-format file, use:5859 5860 .. code-block:: yaml5861 5862 RawStringFormats:5863 - Language: TextProto5864 Delimiters:5865 - pb5866 - proto5867 EnclosingFunctions:5868 - PARSE_TEXT_PROTO5869 BasedOnStyle: google5870 - Language: Cpp5871 Delimiters:5872 - cc5873 - cpp5874 BasedOnStyle: LLVM5875 CanonicalDelimiter: cc5876 5877.. _ReferenceAlignment:5878 5879**ReferenceAlignment** (``ReferenceAlignmentStyle``) :versionbadge:`clang-format 13` :ref:`¶ <ReferenceAlignment>`5880 Reference alignment style (overrides ``PointerAlignment`` for references).5881 5882 Possible values:5883 5884 * ``RAS_Pointer`` (in configuration: ``Pointer``)5885 Align reference like ``PointerAlignment``.5886 5887 * ``RAS_Left`` (in configuration: ``Left``)5888 Align reference to the left.5889 5890 .. code-block:: c++5891 5892 int& a;5893 5894 * ``RAS_Right`` (in configuration: ``Right``)5895 Align reference to the right.5896 5897 .. code-block:: c++5898 5899 int &a;5900 5901 * ``RAS_Middle`` (in configuration: ``Middle``)5902 Align reference in the middle.5903 5904 .. code-block:: c++5905 5906 int & a;5907 5908 5909 5910.. _ReflowComments:5911 5912**ReflowComments** (``ReflowCommentsStyle``) :versionbadge:`clang-format 3.8` :ref:`¶ <ReflowComments>`5913 Comment reformatting style.5914 5915 Possible values:5916 5917 * ``RCS_Never`` (in configuration: ``Never``)5918 Leave comments untouched.5919 5920 .. code-block:: c++5921 5922 // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information5923 /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */5924 /* third veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information5925 * and a misaligned second line */5926 5927 * ``RCS_IndentOnly`` (in configuration: ``IndentOnly``)5928 Only apply indentation rules, moving comments left or right, without5929 changing formatting inside the comments.5930 5931 .. code-block:: c++5932 5933 // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information5934 /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */5935 /* third veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information5936 * and a misaligned second line */5937 5938 * ``RCS_Always`` (in configuration: ``Always``)5939 Apply indentation rules and reflow long comments into new lines, trying5940 to obey the ``ColumnLimit``.5941 5942 .. code-block:: c++5943 5944 // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of5945 // information5946 /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of5947 * information */5948 /* third veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of5949 * information and a misaligned second line */5950 5951 5952 5953.. _RemoveBracesLLVM:5954 5955**RemoveBracesLLVM** (``Boolean``) :versionbadge:`clang-format 14` :ref:`¶ <RemoveBracesLLVM>`5956 Remove optional braces of control statements (``if``, ``else``, ``for``,5957 and ``while``) in C++ according to the LLVM coding style.5958 5959 .. warning::5960 5961 This option will be renamed and expanded to support other styles.5962 5963 .. warning::5964 5965 Setting this option to ``true`` could lead to incorrect code formatting5966 due to clang-format's lack of complete semantic information. As such,5967 extra care should be taken to review code changes made by this option.5968 5969 .. code-block:: c++5970 5971 false: true:5972 5973 if (isa<FunctionDecl>(D)) { vs. if (isa<FunctionDecl>(D))5974 handleFunctionDecl(D); handleFunctionDecl(D);5975 } else if (isa<VarDecl>(D)) { else if (isa<VarDecl>(D))5976 handleVarDecl(D); handleVarDecl(D);5977 }5978 5979 if (isa<VarDecl>(D)) { vs. if (isa<VarDecl>(D)) {5980 for (auto *A : D.attrs()) { for (auto *A : D.attrs())5981 if (shouldProcessAttr(A)) { if (shouldProcessAttr(A))5982 handleAttr(A); handleAttr(A);5983 } }5984 }5985 }5986 5987 if (isa<FunctionDecl>(D)) { vs. if (isa<FunctionDecl>(D))5988 for (auto *A : D.attrs()) { for (auto *A : D.attrs())5989 handleAttr(A); handleAttr(A);5990 }5991 }5992 5993 if (auto *D = (T)(D)) { vs. if (auto *D = (T)(D)) {5994 if (shouldProcess(D)) { if (shouldProcess(D))5995 handleVarDecl(D); handleVarDecl(D);5996 } else { else5997 markAsIgnored(D); markAsIgnored(D);5998 } }5999 }6000 6001 if (a) { vs. if (a)6002 b(); b();6003 } else { else if (c)6004 if (c) { d();6005 d(); else6006 } else { e();6007 e();6008 }6009 }6010 6011.. _RemoveEmptyLinesInUnwrappedLines:6012 6013**RemoveEmptyLinesInUnwrappedLines** (``Boolean``) :versionbadge:`clang-format 20` :ref:`¶ <RemoveEmptyLinesInUnwrappedLines>`6014 Remove empty lines within unwrapped lines.6015 6016 .. code-block:: c++6017 6018 false: true:6019 6020 int c vs. int c = a + b;6021 6022 = a + b;6023 6024 enum : unsigned vs. enum : unsigned {6025 AA = 0,6026 { BB6027 AA = 0, } myEnum;6028 BB6029 } myEnum;6030 6031 while ( vs. while (true) {6032 }6033 true) {6034 }6035 6036.. _RemoveParentheses:6037 6038**RemoveParentheses** (``RemoveParenthesesStyle``) :versionbadge:`clang-format 17` :ref:`¶ <RemoveParentheses>`6039 Remove redundant parentheses.6040 6041 .. warning::6042 6043 Setting this option to any value other than ``Leave`` could lead to6044 incorrect code formatting due to clang-format's lack of complete semantic6045 information. As such, extra care should be taken to review code changes6046 made by this option.6047 6048 Possible values:6049 6050 * ``RPS_Leave`` (in configuration: ``Leave``)6051 Do not remove parentheses.6052 6053 .. code-block:: c++6054 6055 class __declspec((dllimport)) X {};6056 co_return (((0)));6057 return ((a + b) - ((c + d)));6058 6059 * ``RPS_MultipleParentheses`` (in configuration: ``MultipleParentheses``)6060 Replace multiple parentheses with single parentheses.6061 6062 .. code-block:: c++6063 6064 class __declspec(dllimport) X {};6065 co_return (0);6066 return ((a + b) - (c + d));6067 6068 * ``RPS_ReturnStatement`` (in configuration: ``ReturnStatement``)6069 Also remove parentheses enclosing the expression in a6070 ``return``/``co_return`` statement.6071 6072 .. code-block:: c++6073 6074 class __declspec(dllimport) X {};6075 co_return 0;6076 return (a + b) - (c + d);6077 6078 6079 6080.. _RemoveSemicolon:6081 6082**RemoveSemicolon** (``Boolean``) :versionbadge:`clang-format 16` :ref:`¶ <RemoveSemicolon>`6083 Remove semicolons after the closing braces of functions and6084 constructors/destructors.6085 6086 .. warning::6087 6088 Setting this option to ``true`` could lead to incorrect code formatting6089 due to clang-format's lack of complete semantic information. As such,6090 extra care should be taken to review code changes made by this option.6091 6092 .. code-block:: c++6093 6094 false: true:6095 6096 int max(int a, int b) { int max(int a, int b) {6097 return a > b ? a : b; return a > b ? a : b;6098 }; }6099 6100.. _RequiresClausePosition:6101 6102**RequiresClausePosition** (``RequiresClausePositionStyle``) :versionbadge:`clang-format 15` :ref:`¶ <RequiresClausePosition>`6103 The position of the ``requires`` clause.6104 6105 Possible values:6106 6107 * ``RCPS_OwnLine`` (in configuration: ``OwnLine``)6108 Always put the ``requires`` clause on its own line (possibly followed by6109 a semicolon).6110 6111 .. code-block:: c++6112 6113 template <typename T>6114 requires C<T>6115 struct Foo {...6116 6117 template <typename T>6118 void bar(T t)6119 requires C<T>;6120 6121 template <typename T>6122 requires C<T>6123 void bar(T t) {...6124 6125 template <typename T>6126 void baz(T t)6127 requires C<T>6128 {...6129 6130 * ``RCPS_OwnLineWithBrace`` (in configuration: ``OwnLineWithBrace``)6131 As with ``OwnLine``, except, unless otherwise prohibited, place a6132 following open brace (of a function definition) to follow on the same6133 line.6134 6135 .. code-block:: c++6136 6137 void bar(T t)6138 requires C<T> {6139 return;6140 }6141 6142 void bar(T t)6143 requires C<T> {}6144 6145 template <typename T>6146 requires C<T>6147 void baz(T t) {6148 ...6149 6150 * ``RCPS_WithPreceding`` (in configuration: ``WithPreceding``)6151 Try to put the clause together with the preceding part of a declaration.6152 For class templates: stick to the template declaration.6153 For function templates: stick to the template declaration.6154 For function declaration followed by a requires clause: stick to the6155 parameter list.6156 6157 .. code-block:: c++6158 6159 template <typename T> requires C<T>6160 struct Foo {...6161 6162 template <typename T> requires C<T>6163 void bar(T t) {...6164 6165 template <typename T>6166 void baz(T t) requires C<T>6167 {...6168 6169 * ``RCPS_WithFollowing`` (in configuration: ``WithFollowing``)6170 Try to put the ``requires`` clause together with the class or function6171 declaration.6172 6173 .. code-block:: c++6174 6175 template <typename T>6176 requires C<T> struct Foo {...6177 6178 template <typename T>6179 requires C<T> void bar(T t) {...6180 6181 template <typename T>6182 void baz(T t)6183 requires C<T> {...6184 6185 * ``RCPS_SingleLine`` (in configuration: ``SingleLine``)6186 Try to put everything in the same line if possible. Otherwise normal6187 line breaking rules take over.6188 6189 .. code-block:: c++6190 6191 // Fitting:6192 template <typename T> requires C<T> struct Foo {...6193 6194 template <typename T> requires C<T> void bar(T t) {...6195 6196 template <typename T> void bar(T t) requires C<T> {...6197 6198 // Not fitting, one possible example:6199 template <typename LongName>6200 requires C<LongName>6201 struct Foo {...6202 6203 template <typename LongName>6204 requires C<LongName>6205 void bar(LongName ln) {6206 6207 template <typename LongName>6208 void bar(LongName ln)6209 requires C<LongName> {6210 6211 6212 6213.. _RequiresExpressionIndentation:6214 6215**RequiresExpressionIndentation** (``RequiresExpressionIndentationKind``) :versionbadge:`clang-format 16` :ref:`¶ <RequiresExpressionIndentation>`6216 The indentation used for requires expression bodies.6217 6218 Possible values:6219 6220 * ``REI_OuterScope`` (in configuration: ``OuterScope``)6221 Align requires expression body relative to the indentation level of the6222 outer scope the requires expression resides in.6223 This is the default.6224 6225 .. code-block:: c++6226 6227 template <typename T>6228 concept C = requires(T t) {6229 ...6230 }6231 6232 * ``REI_Keyword`` (in configuration: ``Keyword``)6233 Align requires expression body relative to the ``requires`` keyword.6234 6235 .. code-block:: c++6236 6237 template <typename T>6238 concept C = requires(T t) {6239 ...6240 }6241 6242 6243 6244.. _SeparateDefinitionBlocks:6245 6246**SeparateDefinitionBlocks** (``SeparateDefinitionStyle``) :versionbadge:`clang-format 14` :ref:`¶ <SeparateDefinitionBlocks>`6247 Specifies the use of empty lines to separate definition blocks, including6248 classes, structs, enums, and functions.6249 6250 .. code-block:: c++6251 6252 Never v.s. Always6253 #include <cstring> #include <cstring>6254 struct Foo {6255 int a, b, c; struct Foo {6256 }; int a, b, c;6257 namespace Ns { };6258 class Bar {6259 public: namespace Ns {6260 struct Foobar { class Bar {6261 int a; public:6262 int b; struct Foobar {6263 }; int a;6264 private: int b;6265 int t; };6266 int method1() {6267 // ... private:6268 } int t;6269 enum List {6270 ITEM1, int method1() {6271 ITEM2 // ...6272 }; }6273 template<typename T>6274 int method2(T x) { enum List {6275 // ... ITEM1,6276 } ITEM26277 int i, j, k; };6278 int method3(int par) {6279 // ... template<typename T>6280 } int method2(T x) {6281 }; // ...6282 class C {}; }6283 }6284 int i, j, k;6285 6286 int method3(int par) {6287 // ...6288 }6289 };6290 6291 class C {};6292 }6293 6294 Possible values:6295 6296 * ``SDS_Leave`` (in configuration: ``Leave``)6297 Leave definition blocks as they are.6298 6299 * ``SDS_Always`` (in configuration: ``Always``)6300 Insert an empty line between definition blocks.6301 6302 * ``SDS_Never`` (in configuration: ``Never``)6303 Remove any empty line between definition blocks.6304 6305 6306 6307.. _ShortNamespaceLines:6308 6309**ShortNamespaceLines** (``Unsigned``) :versionbadge:`clang-format 13` :ref:`¶ <ShortNamespaceLines>`6310 The maximal number of unwrapped lines that a short namespace spans.6311 Defaults to 1.6312 6313 This determines the maximum length of short namespaces by counting6314 unwrapped lines (i.e. containing neither opening nor closing6315 namespace brace) and makes ``FixNamespaceComments`` omit adding6316 end comments for those.6317 6318 .. code-block:: c++6319 6320 ShortNamespaceLines: 1 vs. ShortNamespaceLines: 06321 namespace a { namespace a {6322 int foo; int foo;6323 } } // namespace a6324 6325 ShortNamespaceLines: 1 vs. ShortNamespaceLines: 06326 namespace b { namespace b {6327 int foo; int foo;6328 int bar; int bar;6329 } // namespace b } // namespace b6330 6331.. _SkipMacroDefinitionBody:6332 6333**SkipMacroDefinitionBody** (``Boolean``) :versionbadge:`clang-format 18` :ref:`¶ <SkipMacroDefinitionBody>`6334 Do not format macro definition body.6335 6336.. _SortIncludes:6337 6338**SortIncludes** (``SortIncludesOptions``) :versionbadge:`clang-format 3.8` :ref:`¶ <SortIncludes>`6339 Controls if and how clang-format will sort ``#includes``.6340 6341 Nested configuration flags:6342 6343 Includes sorting options.6344 6345 * ``bool Enabled`` If ``true``, includes are sorted based on the other suboptions below.6346 (``Never`` is deprecated by ``Enabled: false``.)6347 6348 * ``bool IgnoreCase`` Whether or not includes are sorted in a case-insensitive fashion.6349 (``CaseSensitive`` and ``CaseInsensitive`` are deprecated by6350 ``IgnoreCase: false`` and ``IgnoreCase: true``, respectively.)6351 6352 .. code-block:: c++6353 6354 true: false:6355 #include "A/B.h" vs. #include "A/B.h"6356 #include "A/b.h" #include "A/b.h"6357 #include "a/b.h" #include "B/A.h"6358 #include "B/A.h" #include "B/a.h"6359 #include "B/a.h" #include "a/b.h"6360 6361 * ``bool IgnoreExtension`` When sorting includes in each block, only take file extensions into6362 account if two includes compare equal otherwise.6363 6364 .. code-block:: c++6365 6366 true: false:6367 # include "A.h" vs. # include "A-util.h"6368 # include "A.inc" # include "A.h"6369 # include "A-util.h" # include "A.inc"6370 6371 6372.. _SortJavaStaticImport:6373 6374**SortJavaStaticImport** (``SortJavaStaticImportOptions``) :versionbadge:`clang-format 12` :ref:`¶ <SortJavaStaticImport>`6375 When sorting Java imports, by default static imports are placed before6376 non-static imports. If ``JavaStaticImportAfterImport`` is ``After``,6377 static imports are placed after non-static imports.6378 6379 Possible values:6380 6381 * ``SJSIO_Before`` (in configuration: ``Before``)6382 Static imports are placed before non-static imports.6383 6384 .. code-block:: java6385 6386 import static org.example.function1;6387 6388 import org.example.ClassA;6389 6390 * ``SJSIO_After`` (in configuration: ``After``)6391 Static imports are placed after non-static imports.6392 6393 .. code-block:: java6394 6395 import org.example.ClassA;6396 6397 import static org.example.function1;6398 6399 6400 6401.. _SortUsingDeclarations:6402 6403**SortUsingDeclarations** (``SortUsingDeclarationsOptions``) :versionbadge:`clang-format 5` :ref:`¶ <SortUsingDeclarations>`6404 Controls if and how clang-format will sort using declarations.6405 6406 Possible values:6407 6408 * ``SUD_Never`` (in configuration: ``Never``)6409 Using declarations are never sorted.6410 6411 .. code-block:: c++6412 6413 using std::chrono::duration_cast;6414 using std::move;6415 using boost::regex;6416 using boost::regex_constants::icase;6417 using std::string;6418 6419 * ``SUD_Lexicographic`` (in configuration: ``Lexicographic``)6420 Using declarations are sorted in the order defined as follows:6421 Split the strings by ``::`` and discard any initial empty strings. Sort6422 the lists of names lexicographically, and within those groups, names are6423 in case-insensitive lexicographic order.6424 6425 .. code-block:: c++6426 6427 using boost::regex;6428 using boost::regex_constants::icase;6429 using std::chrono::duration_cast;6430 using std::move;6431 using std::string;6432 6433 * ``SUD_LexicographicNumeric`` (in configuration: ``LexicographicNumeric``)6434 Using declarations are sorted in the order defined as follows:6435 Split the strings by ``::`` and discard any initial empty strings. The6436 last element of each list is a non-namespace name; all others are6437 namespace names. Sort the lists of names lexicographically, where the6438 sort order of individual names is that all non-namespace names come6439 before all namespace names, and within those groups, names are in6440 case-insensitive lexicographic order.6441 6442 .. code-block:: c++6443 6444 using boost::regex;6445 using boost::regex_constants::icase;6446 using std::move;6447 using std::string;6448 using std::chrono::duration_cast;6449 6450 6451 6452.. _SpaceAfterCStyleCast:6453 6454**SpaceAfterCStyleCast** (``Boolean``) :versionbadge:`clang-format 3.5` :ref:`¶ <SpaceAfterCStyleCast>`6455 If ``true``, a space is inserted after C style casts.6456 6457 .. code-block:: c++6458 6459 true: false:6460 (int) i; vs. (int)i;6461 6462.. _SpaceAfterLogicalNot:6463 6464**SpaceAfterLogicalNot** (``Boolean``) :versionbadge:`clang-format 9` :ref:`¶ <SpaceAfterLogicalNot>`6465 If ``true``, a space is inserted after the logical not operator (``!``).6466 6467 .. code-block:: c++6468 6469 true: false:6470 ! someExpression(); vs. !someExpression();6471 6472.. _SpaceAfterOperatorKeyword:6473 6474**SpaceAfterOperatorKeyword** (``Boolean``) :versionbadge:`clang-format 21` :ref:`¶ <SpaceAfterOperatorKeyword>`6475 If ``true``, a space will be inserted after the ``operator`` keyword.6476 6477 .. code-block:: c++6478 6479 true: false:6480 bool operator ==(int a); vs. bool operator==(int a);6481 6482.. _SpaceAfterTemplateKeyword:6483 6484**SpaceAfterTemplateKeyword** (``Boolean``) :versionbadge:`clang-format 4` :ref:`¶ <SpaceAfterTemplateKeyword>`6485 If ``true``, a space will be inserted after the ``template`` keyword.6486 6487 .. code-block:: c++6488 6489 true: false:6490 template <int> void foo(); vs. template<int> void foo();6491 6492.. _SpaceAroundPointerQualifiers:6493 6494**SpaceAroundPointerQualifiers** (``SpaceAroundPointerQualifiersStyle``) :versionbadge:`clang-format 12` :ref:`¶ <SpaceAroundPointerQualifiers>`6495 Defines in which cases to put a space before or after pointer qualifiers6496 6497 Possible values:6498 6499 * ``SAPQ_Default`` (in configuration: ``Default``)6500 Don't ensure spaces around pointer qualifiers and use PointerAlignment6501 instead.6502 6503 .. code-block:: c++6504 6505 PointerAlignment: Left PointerAlignment: Right6506 void* const* x = NULL; vs. void *const *x = NULL;6507 6508 * ``SAPQ_Before`` (in configuration: ``Before``)6509 Ensure that there is a space before pointer qualifiers.6510 6511 .. code-block:: c++6512 6513 PointerAlignment: Left PointerAlignment: Right6514 void* const* x = NULL; vs. void * const *x = NULL;6515 6516 * ``SAPQ_After`` (in configuration: ``After``)6517 Ensure that there is a space after pointer qualifiers.6518 6519 .. code-block:: c++6520 6521 PointerAlignment: Left PointerAlignment: Right6522 void* const * x = NULL; vs. void *const *x = NULL;6523 6524 * ``SAPQ_Both`` (in configuration: ``Both``)6525 Ensure that there is a space both before and after pointer qualifiers.6526 6527 .. code-block:: c++6528 6529 PointerAlignment: Left PointerAlignment: Right6530 void* const * x = NULL; vs. void * const *x = NULL;6531 6532 6533 6534.. _SpaceBeforeAssignmentOperators:6535 6536**SpaceBeforeAssignmentOperators** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <SpaceBeforeAssignmentOperators>`6537 If ``false``, spaces will be removed before assignment operators.6538 6539 .. code-block:: c++6540 6541 true: false:6542 int a = 5; vs. int a= 5;6543 a += 42; a+= 42;6544 6545.. _SpaceBeforeCaseColon:6546 6547**SpaceBeforeCaseColon** (``Boolean``) :versionbadge:`clang-format 12` :ref:`¶ <SpaceBeforeCaseColon>`6548 If ``false``, spaces will be removed before case colon.6549 6550 .. code-block:: c++6551 6552 true: false6553 switch (x) { vs. switch (x) {6554 case 1 : break; case 1: break;6555 } }6556 6557.. _SpaceBeforeCpp11BracedList:6558 6559**SpaceBeforeCpp11BracedList** (``Boolean``) :versionbadge:`clang-format 7` :ref:`¶ <SpaceBeforeCpp11BracedList>`6560 If ``true``, a space will be inserted before a C++11 braced list6561 used to initialize an object (after the preceding identifier or type).6562 6563 .. code-block:: c++6564 6565 true: false:6566 Foo foo { bar }; vs. Foo foo{ bar };6567 Foo {}; Foo{};6568 vector<int> { 1, 2, 3 }; vector<int>{ 1, 2, 3 };6569 new int[3] { 1, 2, 3 }; new int[3]{ 1, 2, 3 };6570 6571.. _SpaceBeforeCtorInitializerColon:6572 6573**SpaceBeforeCtorInitializerColon** (``Boolean``) :versionbadge:`clang-format 7` :ref:`¶ <SpaceBeforeCtorInitializerColon>`6574 If ``false``, spaces will be removed before constructor initializer6575 colon.6576 6577 .. code-block:: c++6578 6579 true: false:6580 Foo::Foo() : a(a) {} Foo::Foo(): a(a) {}6581 6582.. _SpaceBeforeInheritanceColon:6583 6584**SpaceBeforeInheritanceColon** (``Boolean``) :versionbadge:`clang-format 7` :ref:`¶ <SpaceBeforeInheritanceColon>`6585 If ``false``, spaces will be removed before inheritance colon.6586 6587 .. code-block:: c++6588 6589 true: false:6590 class Foo : Bar {} vs. class Foo: Bar {}6591 6592.. _SpaceBeforeJsonColon:6593 6594**SpaceBeforeJsonColon** (``Boolean``) :versionbadge:`clang-format 17` :ref:`¶ <SpaceBeforeJsonColon>`6595 If ``true``, a space will be added before a JSON colon. For other6596 languages, e.g. JavaScript, use ``SpacesInContainerLiterals`` instead.6597 6598 .. code-block:: c++6599 6600 true: false:6601 { {6602 "key" : "value" vs. "key": "value"6603 } }6604 6605.. _SpaceBeforeParens:6606 6607**SpaceBeforeParens** (``SpaceBeforeParensStyle``) :versionbadge:`clang-format 3.5` :ref:`¶ <SpaceBeforeParens>`6608 Defines in which cases to put a space before opening parentheses.6609 6610 Possible values:6611 6612 * ``SBPO_Never`` (in configuration: ``Never``)6613 This is **deprecated** and replaced by ``Custom`` below, with all6614 ``SpaceBeforeParensOptions`` but ``AfterPlacementOperator`` set to6615 ``false``.6616 6617 * ``SBPO_ControlStatements`` (in configuration: ``ControlStatements``)6618 Put a space before opening parentheses only after control statement6619 keywords (``for/if/while...``).6620 6621 .. code-block:: c++6622 6623 void f() {6624 if (true) {6625 f();6626 }6627 }6628 6629 * ``SBPO_ControlStatementsExceptControlMacros`` (in configuration: ``ControlStatementsExceptControlMacros``)6630 Same as ``SBPO_ControlStatements`` except this option doesn't apply to6631 ForEach and If macros. This is useful in projects where ForEach/If6632 macros are treated as function calls instead of control statements.6633 ``SBPO_ControlStatementsExceptForEachMacros`` remains an alias for6634 backward compatibility.6635 6636 .. code-block:: c++6637 6638 void f() {6639 Q_FOREACH(...) {6640 f();6641 }6642 }6643 6644 * ``SBPO_NonEmptyParentheses`` (in configuration: ``NonEmptyParentheses``)6645 Put a space before opening parentheses only if the parentheses are not6646 empty.6647 6648 .. code-block:: c++6649 6650 void() {6651 if (true) {6652 f();6653 g (x, y, z);6654 }6655 }6656 6657 * ``SBPO_Always`` (in configuration: ``Always``)6658 Always put a space before opening parentheses, except when it's6659 prohibited by the syntax rules (in function-like macro definitions) or6660 when determined by other style rules (after unary operators, opening6661 parentheses, etc.)6662 6663 .. code-block:: c++6664 6665 void f () {6666 if (true) {6667 f ();6668 }6669 }6670 6671 * ``SBPO_Custom`` (in configuration: ``Custom``)6672 Configure each individual space before parentheses in6673 ``SpaceBeforeParensOptions``.6674 6675 6676 6677.. _SpaceBeforeParensOptions:6678 6679**SpaceBeforeParensOptions** (``SpaceBeforeParensCustom``) :versionbadge:`clang-format 14` :ref:`¶ <SpaceBeforeParensOptions>`6680 Control of individual space before parentheses.6681 6682 If ``SpaceBeforeParens`` is set to ``Custom``, use this to specify6683 how each individual space before parentheses case should be handled.6684 Otherwise, this is ignored.6685 6686 .. code-block:: yaml6687 6688 # Example of usage:6689 SpaceBeforeParens: Custom6690 SpaceBeforeParensOptions:6691 AfterControlStatements: true6692 AfterFunctionDefinitionName: true6693 6694 Nested configuration flags:6695 6696 Precise control over the spacing before parentheses.6697 6698 .. code-block:: c++6699 6700 # Should be declared this way:6701 SpaceBeforeParens: Custom6702 SpaceBeforeParensOptions:6703 AfterControlStatements: true6704 AfterFunctionDefinitionName: true6705 6706 * ``bool AfterControlStatements`` If ``true``, put space between control statement keywords6707 (for/if/while...) and opening parentheses.6708 6709 .. code-block:: c++6710 6711 true: false:6712 if (...) {} vs. if(...) {}6713 6714 * ``bool AfterForeachMacros`` If ``true``, put space between foreach macros and opening parentheses.6715 6716 .. code-block:: c++6717 6718 true: false:6719 FOREACH (...) vs. FOREACH(...)6720 <loop-body> <loop-body>6721 6722 * ``bool AfterFunctionDeclarationName`` If ``true``, put a space between function declaration name and opening6723 parentheses.6724 6725 .. code-block:: c++6726 6727 true: false:6728 void f (); vs. void f();6729 6730 * ``bool AfterFunctionDefinitionName`` If ``true``, put a space between function definition name and opening6731 parentheses.6732 6733 .. code-block:: c++6734 6735 true: false:6736 void f () {} vs. void f() {}6737 6738 * ``bool AfterIfMacros`` If ``true``, put space between if macros and opening parentheses.6739 6740 .. code-block:: c++6741 6742 true: false:6743 IF (...) vs. IF(...)6744 <conditional-body> <conditional-body>6745 6746 * ``bool AfterNot`` If ``true``, put a space between alternative operator ``not`` and the6747 opening parenthesis.6748 6749 .. code-block:: c++6750 6751 true: false:6752 return not (a || b); vs. return not(a || b);6753 6754 * ``bool AfterOverloadedOperator`` If ``true``, put a space between operator overloading and opening6755 parentheses.6756 6757 .. code-block:: c++6758 6759 true: false:6760 void operator++ (int a); vs. void operator++(int a);6761 object.operator++ (10); object.operator++(10);6762 6763 * ``bool AfterPlacementOperator`` If ``true``, put a space between operator ``new``/``delete`` and opening6764 parenthesis.6765 6766 .. code-block:: c++6767 6768 true: false:6769 new (buf) T; vs. new(buf) T;6770 delete (buf) T; delete(buf) T;6771 6772 * ``bool AfterRequiresInClause`` If ``true``, put space between requires keyword in a requires clause and6773 opening parentheses, if there is one.6774 6775 .. code-block:: c++6776 6777 true: false:6778 template<typename T> vs. template<typename T>6779 requires (A<T> && B<T>) requires(A<T> && B<T>)6780 ... ...6781 6782 * ``bool AfterRequiresInExpression`` If ``true``, put space between requires keyword in a requires expression6783 and opening parentheses.6784 6785 .. code-block:: c++6786 6787 true: false:6788 template<typename T> vs. template<typename T>6789 concept C = requires (T t) { concept C = requires(T t) {6790 ... ...6791 } }6792 6793 * ``bool BeforeNonEmptyParentheses`` If ``true``, put a space before opening parentheses only if the6794 parentheses are not empty.6795 6796 .. code-block:: c++6797 6798 true: false:6799 void f (int a); vs. void f();6800 f (a); f();6801 6802 6803.. _SpaceBeforeRangeBasedForLoopColon:6804 6805**SpaceBeforeRangeBasedForLoopColon** (``Boolean``) :versionbadge:`clang-format 7` :ref:`¶ <SpaceBeforeRangeBasedForLoopColon>`6806 If ``false``, spaces will be removed before range-based for loop6807 colon.6808 6809 .. code-block:: c++6810 6811 true: false:6812 for (auto v : values) {} vs. for(auto v: values) {}6813 6814.. _SpaceBeforeSquareBrackets:6815 6816**SpaceBeforeSquareBrackets** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ <SpaceBeforeSquareBrackets>`6817 If ``true``, spaces will be before ``[``.6818 Lambdas will not be affected. Only the first ``[`` will get a space added.6819 6820 .. code-block:: c++6821 6822 true: false:6823 int a [5]; vs. int a[5];6824 int a [5][5]; vs. int a[5][5];6825 6826.. _SpaceInEmptyBlock:6827 6828**SpaceInEmptyBlock** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ <SpaceInEmptyBlock>`6829 This option is **deprecated**. See ``Block`` of ``SpaceInEmptyBraces``.6830 6831.. _SpaceInEmptyBraces:6832 6833**SpaceInEmptyBraces** (``SpaceInEmptyBracesStyle``) :versionbadge:`clang-format 22` :ref:`¶ <SpaceInEmptyBraces>`6834 Specifies when to insert a space in empty braces.6835 6836 .. note::6837 6838 This option doesn't apply to initializer braces if6839 ``Cpp11BracedListStyle`` is not ``Block``.6840 6841 Possible values:6842 6843 * ``SIEB_Always`` (in configuration: ``Always``)6844 Always insert a space in empty braces.6845 6846 .. code-block:: c++6847 6848 void f() { }6849 class Unit { };6850 auto a = [] { };6851 int x{ };6852 6853 * ``SIEB_Block`` (in configuration: ``Block``)6854 Only insert a space in empty blocks.6855 6856 .. code-block:: c++6857 6858 void f() { }6859 class Unit { };6860 auto a = [] { };6861 int x{};6862 6863 * ``SIEB_Never`` (in configuration: ``Never``)6864 Never insert a space in empty braces.6865 6866 .. code-block:: c++6867 6868 void f() {}6869 class Unit {};6870 auto a = [] {};6871 int x{};6872 6873 6874 6875.. _SpaceInEmptyParentheses:6876 6877**SpaceInEmptyParentheses** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <SpaceInEmptyParentheses>`6878 If ``true``, spaces may be inserted into ``()``.6879 This option is **deprecated**. See ``InEmptyParentheses`` of6880 ``SpacesInParensOptions``.6881 6882.. _SpacesBeforeTrailingComments:6883 6884**SpacesBeforeTrailingComments** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <SpacesBeforeTrailingComments>`6885 The number of spaces before trailing line comments6886 (``//`` - comments).6887 6888 This does not affect trailing block comments (``/*`` - comments) as those6889 commonly have different usage patterns and a number of special cases. In6890 the case of Verilog, it doesn't affect a comment right after the opening6891 parenthesis in the port or parameter list in a module header, because it6892 is probably for the port on the following line instead of the parenthesis6893 it follows.6894 6895 .. code-block:: c++6896 6897 SpacesBeforeTrailingComments: 36898 void f() {6899 if (true) { // foo16900 f(); // bar6901 } // foo6902 }6903 6904.. _SpacesInAngles:6905 6906**SpacesInAngles** (``SpacesInAnglesStyle``) :versionbadge:`clang-format 3.4` :ref:`¶ <SpacesInAngles>`6907 The SpacesInAnglesStyle to use for template argument lists.6908 6909 Possible values:6910 6911 * ``SIAS_Never`` (in configuration: ``Never``)6912 Remove spaces after ``<`` and before ``>``.6913 6914 .. code-block:: c++6915 6916 static_cast<int>(arg);6917 std::function<void(int)> fct;6918 6919 * ``SIAS_Always`` (in configuration: ``Always``)6920 Add spaces after ``<`` and before ``>``.6921 6922 .. code-block:: c++6923 6924 static_cast< int >(arg);6925 std::function< void(int) > fct;6926 6927 * ``SIAS_Leave`` (in configuration: ``Leave``)6928 Keep a single space after ``<`` and before ``>`` if any spaces were6929 present. Option ``Standard: Cpp03`` takes precedence.6930 6931 6932 6933.. _SpacesInCStyleCastParentheses:6934 6935**SpacesInCStyleCastParentheses** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <SpacesInCStyleCastParentheses>`6936 If ``true``, spaces may be inserted into C style casts.6937 This option is **deprecated**. See ``InCStyleCasts`` of6938 ``SpacesInParensOptions``.6939 6940.. _SpacesInConditionalStatement:6941 6942**SpacesInConditionalStatement** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ <SpacesInConditionalStatement>`6943 If ``true``, spaces will be inserted around if/for/switch/while6944 conditions.6945 This option is **deprecated**. See ``InConditionalStatements`` of6946 ``SpacesInParensOptions``.6947 6948.. _SpacesInContainerLiterals:6949 6950**SpacesInContainerLiterals** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <SpacesInContainerLiterals>`6951 If ``true``, spaces are inserted inside container literals (e.g. ObjC and6952 Javascript array and dict literals). For JSON, use6953 ``SpaceBeforeJsonColon`` instead.6954 6955 .. code-block:: js6956 6957 true: false:6958 var arr = [ 1, 2, 3 ]; vs. var arr = [1, 2, 3];6959 f({a : 1, b : 2, c : 3}); f({a: 1, b: 2, c: 3});6960 6961.. _SpacesInLineCommentPrefix:6962 6963**SpacesInLineCommentPrefix** (``SpacesInLineComment``) :versionbadge:`clang-format 13` :ref:`¶ <SpacesInLineCommentPrefix>`6964 How many spaces are allowed at the start of a line comment. To disable the6965 maximum set it to ``-1``, apart from that the maximum takes precedence6966 over the minimum.6967 6968 .. code-block:: c++6969 6970 Minimum = 16971 Maximum = -16972 // One space is forced6973 6974 // but more spaces are possible6975 6976 Minimum = 06977 Maximum = 06978 //Forces to start every comment directly after the slashes6979 6980 Note that in line comment sections the relative indent of the subsequent6981 lines is kept, that means the following:6982 6983 .. code-block:: c++6984 6985 before: after:6986 Minimum: 16987 //if (b) { // if (b) {6988 // return true; // return true;6989 //} // }6990 6991 Maximum: 06992 /// List: ///List:6993 /// - Foo /// - Foo6994 /// - Bar /// - Bar6995 6996 This option has only effect if ``ReflowComments`` is set to ``true``.6997 6998 Nested configuration flags:6999 7000 Control of spaces within a single line comment.7001 7002 * ``unsigned Minimum`` The minimum number of spaces at the start of the comment.7003 7004 * ``unsigned Maximum`` The maximum number of spaces at the start of the comment.7005 7006 7007.. _SpacesInParens:7008 7009**SpacesInParens** (``SpacesInParensStyle``) :versionbadge:`clang-format 17` :ref:`¶ <SpacesInParens>`7010 Defines in which cases spaces will be inserted after ``(`` and before7011 ``)``.7012 7013 Possible values:7014 7015 * ``SIPO_Never`` (in configuration: ``Never``)7016 Never put a space in parentheses.7017 7018 .. code-block:: c++7019 7020 void f() {7021 if(true) {7022 f();7023 }7024 }7025 7026 * ``SIPO_Custom`` (in configuration: ``Custom``)7027 Configure each individual space in parentheses in7028 `SpacesInParensOptions`.7029 7030 7031 7032.. _SpacesInParensOptions:7033 7034**SpacesInParensOptions** (``SpacesInParensCustom``) :versionbadge:`clang-format 17` :ref:`¶ <SpacesInParensOptions>`7035 Control of individual spaces in parentheses.7036 7037 If ``SpacesInParens`` is set to ``Custom``, use this to specify7038 how each individual space in parentheses case should be handled.7039 Otherwise, this is ignored.7040 7041 .. code-block:: yaml7042 7043 # Example of usage:7044 SpacesInParens: Custom7045 SpacesInParensOptions:7046 ExceptDoubleParentheses: false7047 InConditionalStatements: true7048 InEmptyParentheses: true7049 7050 Nested configuration flags:7051 7052 Precise control over the spacing in parentheses.7053 7054 .. code-block:: c++7055 7056 # Should be declared this way:7057 SpacesInParens: Custom7058 SpacesInParensOptions:7059 ExceptDoubleParentheses: false7060 InConditionalStatements: true7061 Other: true7062 7063 * ``bool ExceptDoubleParentheses`` Override any of the following options to prevent addition of space7064 when both opening and closing parentheses use multiple parentheses.7065 7066 .. code-block:: c++7067 7068 true:7069 __attribute__(( noreturn ))7070 __decltype__(( x ))7071 if (( a = b ))7072 false:7073 Uses the applicable option.7074 7075 * ``bool InConditionalStatements`` Put a space in parentheses only inside conditional statements7076 (``for/if/while/switch...``).7077 7078 .. code-block:: c++7079 7080 true: false:7081 if ( a ) { ... } vs. if (a) { ... }7082 while ( i < 5 ) { ... } while (i < 5) { ... }7083 7084 * ``bool InCStyleCasts`` Put a space in C style casts.7085 7086 .. code-block:: c++7087 7088 true: false:7089 x = ( int32 )y vs. x = (int32)y7090 y = (( int (*)(int) )foo)(x); y = ((int (*)(int))foo)(x);7091 7092 * ``bool InEmptyParentheses`` Insert a space in empty parentheses, i.e. ``()``.7093 7094 .. code-block:: c++7095 7096 true: false:7097 void f( ) { vs. void f() {7098 int x[] = {foo( ), bar( )}; int x[] = {foo(), bar()};7099 if (true) { if (true) {7100 f( ); f();7101 } }7102 } }7103 7104 * ``bool Other`` Put a space in parentheses not covered by preceding options.7105 7106 .. code-block:: c++7107 7108 true: false:7109 t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete;7110 7111 7112.. _SpacesInParentheses:7113 7114**SpacesInParentheses** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <SpacesInParentheses>`7115 If ``true``, spaces will be inserted after ``(`` and before ``)``.7116 This option is **deprecated**. The previous behavior is preserved by using7117 ``SpacesInParens`` with ``Custom`` and by setting all7118 ``SpacesInParensOptions`` to ``true`` except for ``InCStyleCasts`` and7119 ``InEmptyParentheses``.7120 7121.. _SpacesInSquareBrackets:7122 7123**SpacesInSquareBrackets** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <SpacesInSquareBrackets>`7124 If ``true``, spaces will be inserted after ``[`` and before ``]``.7125 Lambdas without arguments or unspecified size array declarations will not7126 be affected.7127 7128 .. code-block:: c++7129 7130 true: false:7131 int a[ 5 ]; vs. int a[5];7132 std::unique_ptr<int[]> foo() {} // Won't be affected7133 7134.. _Standard:7135 7136**Standard** (``LanguageStandard``) :versionbadge:`clang-format 3.7` :ref:`¶ <Standard>`7137 Parse and format C++ constructs compatible with this standard.7138 7139 .. code-block:: c++7140 7141 c++03: latest:7142 vector<set<int> > x; vs. vector<set<int>> x;7143 7144 Possible values:7145 7146 * ``LS_Cpp03`` (in configuration: ``c++03``)7147 Parse and format as C++03.7148 ``Cpp03`` is a deprecated alias for ``c++03``7149 7150 * ``LS_Cpp11`` (in configuration: ``c++11``)7151 Parse and format as C++11.7152 7153 * ``LS_Cpp14`` (in configuration: ``c++14``)7154 Parse and format as C++14.7155 7156 * ``LS_Cpp17`` (in configuration: ``c++17``)7157 Parse and format as C++17.7158 7159 * ``LS_Cpp20`` (in configuration: ``c++20``)7160 Parse and format as C++20.7161 7162 * ``LS_Latest`` (in configuration: ``Latest``)7163 Parse and format using the latest supported language version.7164 ``Cpp11`` is a deprecated alias for ``Latest``7165 7166 * ``LS_Auto`` (in configuration: ``Auto``)7167 Automatic detection based on the input.7168 7169 7170 7171.. _StatementAttributeLikeMacros:7172 7173**StatementAttributeLikeMacros** (``List of Strings``) :versionbadge:`clang-format 12` :ref:`¶ <StatementAttributeLikeMacros>`7174 Macros which are ignored in front of a statement, as if they were an7175 attribute. So that they are not parsed as identifier, for example for Qts7176 emit.7177 7178 .. code-block:: c++7179 7180 AlignConsecutiveDeclarations: true7181 StatementAttributeLikeMacros: []7182 unsigned char data = 'x';7183 emit signal(data); // This is parsed as variable declaration.7184 7185 AlignConsecutiveDeclarations: true7186 StatementAttributeLikeMacros: [emit]7187 unsigned char data = 'x';7188 emit signal(data); // Now it's fine again.7189 7190.. _StatementMacros:7191 7192**StatementMacros** (``List of Strings``) :versionbadge:`clang-format 8` :ref:`¶ <StatementMacros>`7193 A vector of macros that should be interpreted as complete statements.7194 7195 Typical macros are expressions and require a semicolon to be added.7196 Sometimes this is not the case, and this allows to make clang-format aware7197 of such cases.7198 7199 For example: Q_UNUSED7200 7201.. _TabWidth:7202 7203**TabWidth** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <TabWidth>`7204 The number of columns used for tab stops.7205 7206.. _TableGenBreakInsideDAGArg:7207 7208**TableGenBreakInsideDAGArg** (``DAGArgStyle``) :versionbadge:`clang-format 19` :ref:`¶ <TableGenBreakInsideDAGArg>`7209 The styles of the line break inside the DAGArg in TableGen.7210 7211 Possible values:7212 7213 * ``DAS_DontBreak`` (in configuration: ``DontBreak``)7214 Never break inside DAGArg.7215 7216 .. code-block:: c++7217 7218 let DAGArgIns = (ins i32:$src1, i32:$src2);7219 7220 * ``DAS_BreakElements`` (in configuration: ``BreakElements``)7221 Break inside DAGArg after each list element but for the last.7222 This aligns to the first element.7223 7224 .. code-block:: c++7225 7226 let DAGArgIns = (ins i32:$src1,7227 i32:$src2);7228 7229 * ``DAS_BreakAll`` (in configuration: ``BreakAll``)7230 Break inside DAGArg after the operator and the all elements.7231 7232 .. code-block:: c++7233 7234 let DAGArgIns = (ins7235 i32:$src1,7236 i32:$src27237 );7238 7239 7240 7241.. _TableGenBreakingDAGArgOperators:7242 7243**TableGenBreakingDAGArgOperators** (``List of Strings``) :versionbadge:`clang-format 19` :ref:`¶ <TableGenBreakingDAGArgOperators>`7244 Works only when TableGenBreakInsideDAGArg is not DontBreak.7245 The string list needs to consist of identifiers in TableGen.7246 If any identifier is specified, this limits the line breaks by7247 TableGenBreakInsideDAGArg option only on DAGArg values beginning with7248 the specified identifiers.7249 7250 For example the configuration,7251 7252 .. code-block:: yaml7253 7254 TableGenBreakInsideDAGArg: BreakAll7255 TableGenBreakingDAGArgOperators: [ins, outs]7256 7257 makes the line break only occurs inside DAGArgs beginning with the7258 specified identifiers ``ins`` and ``outs``.7259 7260 7261 .. code-block:: c++7262 7263 let DAGArgIns = (ins7264 i32:$src1,7265 i32:$src27266 );7267 let DAGArgOtherID = (other i32:$other1, i32:$other2);7268 let DAGArgBang = (!cast<SomeType>("Some") i32:$src1, i32:$src2)7269 7270.. _TemplateNames:7271 7272**TemplateNames** (``List of Strings``) :versionbadge:`clang-format 20` :ref:`¶ <TemplateNames>`7273 A vector of non-keyword identifiers that should be interpreted as template7274 names.7275 7276 A ``<`` after a template name is annotated as a template opener instead of7277 a binary operator.7278 7279.. _TypeNames:7280 7281**TypeNames** (``List of Strings``) :versionbadge:`clang-format 17` :ref:`¶ <TypeNames>`7282 A vector of non-keyword identifiers that should be interpreted as type7283 names.7284 7285 A ``*``, ``&``, or ``&&`` between a type name and another non-keyword7286 identifier is annotated as a pointer or reference token instead of a7287 binary operator.7288 7289.. _TypenameMacros:7290 7291**TypenameMacros** (``List of Strings``) :versionbadge:`clang-format 9` :ref:`¶ <TypenameMacros>`7292 A vector of macros that should be interpreted as type declarations instead7293 of as function calls.7294 7295 These are expected to be macros of the form:7296 7297 .. code-block:: c++7298 7299 STACK_OF(...)7300 7301 In the .clang-format configuration file, this can be configured like:7302 7303 .. code-block:: yaml7304 7305 TypenameMacros: [STACK_OF, LIST]7306 7307 For example: OpenSSL STACK_OF, BSD LIST_ENTRY.7308 7309.. _UseCRLF:7310 7311**UseCRLF** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ <UseCRLF>`7312 This option is **deprecated**. See ``LF`` and ``CRLF`` of ``LineEnding``.7313 7314.. _UseTab:7315 7316**UseTab** (``UseTabStyle``) :versionbadge:`clang-format 3.7` :ref:`¶ <UseTab>`7317 The way to use tab characters in the resulting file.7318 7319 Possible values:7320 7321 * ``UT_Never`` (in configuration: ``Never``)7322 Never use tab.7323 7324 * ``UT_ForIndentation`` (in configuration: ``ForIndentation``)7325 Use tabs only for indentation.7326 7327 * ``UT_ForContinuationAndIndentation`` (in configuration: ``ForContinuationAndIndentation``)7328 Fill all leading whitespace with tabs, and use spaces for alignment that7329 appears within a line (e.g. consecutive assignments and declarations).7330 7331 * ``UT_AlignWithSpaces`` (in configuration: ``AlignWithSpaces``)7332 Use tabs for line continuation and indentation, and spaces for7333 alignment.7334 7335 * ``UT_Always`` (in configuration: ``Always``)7336 Use tabs whenever we need to fill whitespace that spans at least from7337 one tab stop to the next one.7338 7339 7340 7341.. _VariableTemplates:7342 7343**VariableTemplates** (``List of Strings``) :versionbadge:`clang-format 20` :ref:`¶ <VariableTemplates>`7344 A vector of non-keyword identifiers that should be interpreted as variable7345 template names.7346 7347 A ``)`` after a variable template instantiation is **not** annotated as7348 the closing parenthesis of C-style cast operator.7349 7350.. _VerilogBreakBetweenInstancePorts:7351 7352**VerilogBreakBetweenInstancePorts** (``Boolean``) :versionbadge:`clang-format 17` :ref:`¶ <VerilogBreakBetweenInstancePorts>`7353 For Verilog, put each port on its own line in module instantiations.7354 7355 .. code-block:: c++7356 7357 true:7358 ffnand ff1(.q(),7359 .qbar(out1),7360 .clear(in1),7361 .preset(in2));7362 7363 false:7364 ffnand ff1(.q(), .qbar(out1), .clear(in1), .preset(in2));7365 7366.. _WhitespaceSensitiveMacros:7367 7368**WhitespaceSensitiveMacros** (``List of Strings``) :versionbadge:`clang-format 11` :ref:`¶ <WhitespaceSensitiveMacros>`7369 A vector of macros which are whitespace-sensitive and should not7370 be touched.7371 7372 These are expected to be macros of the form:7373 7374 .. code-block:: c++7375 7376 STRINGIZE(...)7377 7378 In the .clang-format configuration file, this can be configured like:7379 7380 .. code-block:: yaml7381 7382 WhitespaceSensitiveMacros: [STRINGIZE, PP_STRINGIZE]7383 7384 For example: BOOST_PP_STRINGIZE7385 7386.. _WrapNamespaceBodyWithEmptyLines:7387 7388**WrapNamespaceBodyWithEmptyLines** (``WrapNamespaceBodyWithEmptyLinesStyle``) :versionbadge:`clang-format 20` :ref:`¶ <WrapNamespaceBodyWithEmptyLines>`7389 Wrap namespace body with empty lines.7390 7391 Possible values:7392 7393 * ``WNBWELS_Never`` (in configuration: ``Never``)7394 Remove all empty lines at the beginning and the end of namespace body.7395 7396 .. code-block:: c++7397 7398 namespace N1 {7399 namespace N2 {7400 function();7401 }7402 }7403 7404 * ``WNBWELS_Always`` (in configuration: ``Always``)7405 Always have at least one empty line at the beginning and the end of7406 namespace body except that the number of empty lines between consecutive7407 nested namespace definitions is not increased.7408 7409 .. code-block:: c++7410 7411 namespace N1 {7412 namespace N2 {7413 7414 function();7415 7416 }7417 }7418 7419 * ``WNBWELS_Leave`` (in configuration: ``Leave``)7420 Keep existing newlines at the beginning and the end of namespace body.7421 ``MaxEmptyLinesToKeep`` still applies.7422 7423 7424 7425.. END_FORMAT_STYLE_OPTIONS7426 7427Adding additional style options7428===============================7429 7430Each additional style option adds costs to the clang-format project. Some of7431these costs affect the clang-format development itself, as we need to make7432sure that any given combination of options work and that new features don't7433break any of the existing options in any way. There are also costs for end users7434as options become less discoverable and people have to think about and make a7435decision on options they don't really care about.7436 7437The goal of the clang-format project is more on the side of supporting a7438limited set of styles really well as opposed to supporting every single style7439used by a codebase somewhere in the wild. Of course, we do want to support all7440major projects and thus have established the following bar for adding style7441options. Each new style option must:7442 7443 * be used in a project of significant size (have dozens of contributors)7444 * have a publicly accessible style guide7445 * have a person willing to contribute and maintain patches7446 7447Examples7448========7449 7450A style similar to the `Linux Kernel style7451<https://www.kernel.org/doc/html/latest/process/coding-style.html>`_:7452 7453.. code-block:: yaml7454 7455 BasedOnStyle: LLVM7456 IndentWidth: 87457 UseTab: Always7458 BreakBeforeBraces: Linux7459 AllowShortIfStatementsOnASingleLine: false7460 IndentCaseLabels: false7461 7462The result is (imagine that tabs are used for indentation here):7463 7464.. code-block:: c++7465 7466 void test()7467 {7468 switch (x) {7469 case 0:7470 case 1:7471 do_something();7472 break;7473 case 2:7474 do_something_else();7475 break;7476 default:7477 break;7478 }7479 if (condition)7480 do_something_completely_different();7481 7482 if (x == y) {7483 q();7484 } else if (x > y) {7485 w();7486 } else {7487 r();7488 }7489 }7490 7491A style similar to the default Visual Studio formatting style:7492 7493.. code-block:: yaml7494 7495 UseTab: Never7496 IndentWidth: 47497 BreakBeforeBraces: Allman7498 AllowShortIfStatementsOnASingleLine: false7499 IndentCaseLabels: false7500 ColumnLimit: 07501 7502The result is:7503 7504.. code-block:: c++7505 7506 void test()7507 {7508 switch (suffix)7509 {7510 case 0:7511 case 1:7512 do_something();7513 break;7514 case 2:7515 do_something_else();7516 break;7517 default:7518 break;7519 }7520 if (condition)7521 do_something_completely_different();7522 7523 if (x == y)7524 {7525 q();7526 }7527 else if (x > y)7528 {7529 w();7530 }7531 else7532 {7533 r();7534 }7535 }7536