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