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