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 ``OAS_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 binary operations.
2236 /// Don't break binary operations
2237 /// \code
2238 /// aaa + bbbb * ccccc - ddddd +
2239 /// eeeeeeeeeeeeeeee;
2240 /// \endcode
2242
2243 /// Binary operations will either be all on the same line, or each operation
2244 /// will have one line each.
2245 /// \code
2246 /// aaa +
2247 /// bbbb *
2248 /// ccccc -
2249 /// ddddd +
2250 /// eeeeeeeeeeeeeeee;
2251 /// \endcode
2253
2254 /// Binary operations of a particular precedence that exceed the column
2255 /// limit will have one line each.
2256 /// \code
2257 /// aaa +
2258 /// bbbb * ccccc -
2259 /// ddddd +
2260 /// eeeeeeeeeeeeeeee;
2261 /// \endcode
2264
2265 /// The break constructor initializers style to use.
2266 /// \version 20
2268
2269 /// Different ways to break initializers.
2271 /// Break constructor initializers before the colon and after the commas.
2272 /// \code
2273 /// Constructor()
2274 /// : initializer1(),
2275 /// initializer2()
2276 /// \endcode
2278 /// Break constructor initializers before the colon and commas, and align
2279 /// the commas with the colon.
2280 /// \code
2281 /// Constructor()
2282 /// : initializer1()
2283 /// , initializer2()
2284 /// \endcode
2286 /// Break constructor initializers after the colon and commas.
2287 /// \code
2288 /// Constructor() :
2289 /// initializer1(),
2290 /// initializer2()
2291 /// \endcode
2294
2295 /// The break constructor initializers style to use.
2296 /// \version 5
2298
2299 /// If ``true``, clang-format will always break before function definition
2300 /// parameters.
2301 /// \code
2302 /// true:
2303 /// void functionDefinition(
2304 /// int A, int B) {}
2305 ///
2306 /// false:
2307 /// void functionDefinition(int A, int B) {}
2308 ///
2309 /// \endcode
2310 /// \version 19
2312
2313 /// Break after each annotation on a field in Java files.
2314 /// \code{.java}
2315 /// true: false:
2316 /// @Partial vs. @Partial @Mock DataLoad loader;
2317 /// @Mock
2318 /// DataLoad loader;
2319 /// \endcode
2320 /// \version 3.8
2322
2323 /// Allow breaking string literals when formatting.
2324 ///
2325 /// In C, C++, and Objective-C:
2326 /// \code
2327 /// true:
2328 /// const char* x = "veryVeryVeryVeryVeryVe"
2329 /// "ryVeryVeryVeryVeryVery"
2330 /// "VeryLongString";
2331 ///
2332 /// false:
2333 /// const char* x =
2334 /// "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
2335 /// \endcode
2336 ///
2337 /// In C# and Java:
2338 /// \code
2339 /// true:
2340 /// string x = "veryVeryVeryVeryVeryVe" +
2341 /// "ryVeryVeryVeryVeryVery" +
2342 /// "VeryLongString";
2343 ///
2344 /// false:
2345 /// string x =
2346 /// "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
2347 /// \endcode
2348 ///
2349 /// C# interpolated strings are not broken.
2350 ///
2351 /// In Verilog:
2352 /// \code
2353 /// true:
2354 /// string x = {"veryVeryVeryVeryVeryVe",
2355 /// "ryVeryVeryVeryVeryVery",
2356 /// "VeryLongString"};
2357 ///
2358 /// false:
2359 /// string x =
2360 /// "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
2361 /// \endcode
2362 ///
2363 /// \version 3.9
2365
2366 /// The column limit.
2367 ///
2368 /// A column limit of ``0`` means that there is no column limit. In this case,
2369 /// clang-format will respect the input's line breaking decisions within
2370 /// statements unless they contradict other rules.
2371 /// \version 3.7
2372 unsigned ColumnLimit;
2373
2374 /// A regular expression that describes comments with special meaning,
2375 /// which should not be split into lines or otherwise changed.
2376 /// \code
2377 /// // CommentPragmas: '^ FOOBAR pragma:'
2378 /// // Will leave the following line unaffected
2379 /// #include <vector> // FOOBAR pragma: keep
2380 /// \endcode
2381 /// \version 3.7
2382 std::string CommentPragmas;
2383
2384 /// Different ways to break inheritance list.
2386 /// Break inheritance list before the colon and after the commas.
2387 /// \code
2388 /// class Foo
2389 /// : Base1,
2390 /// Base2
2391 /// {};
2392 /// \endcode
2394 /// Break inheritance list before the colon and commas, and align
2395 /// the commas with the colon.
2396 /// \code
2397 /// class Foo
2398 /// : Base1
2399 /// , Base2
2400 /// {};
2401 /// \endcode
2403 /// Break inheritance list after the colon and commas.
2404 /// \code
2405 /// class Foo :
2406 /// Base1,
2407 /// Base2
2408 /// {};
2409 /// \endcode
2411 /// Break inheritance list only after the commas.
2412 /// \code
2413 /// class Foo : Base1,
2414 /// Base2
2415 /// {};
2416 /// \endcode
2418 };
2419
2420 /// The inheritance list style to use.
2421 /// \version 7
2423
2424 /// The template declaration breaking style to use.
2425 /// \version 19
2427
2428 /// If ``true``, consecutive namespace declarations will be on the same
2429 /// line. If ``false``, each namespace is declared on a new line.
2430 /// \code
2431 /// true:
2432 /// namespace Foo { namespace Bar {
2433 /// }}
2434 ///
2435 /// false:
2436 /// namespace Foo {
2437 /// namespace Bar {
2438 /// }
2439 /// }
2440 /// \endcode
2441 ///
2442 /// If it does not fit on a single line, the overflowing namespaces get
2443 /// wrapped:
2444 /// \code
2445 /// namespace Foo { namespace Bar {
2446 /// namespace Extra {
2447 /// }}}
2448 /// \endcode
2449 /// \version 5
2451
2452 /// This option is **deprecated**. See ``CurrentLine`` of
2453 /// ``PackConstructorInitializers``.
2454 /// \version 3.7
2455 // bool ConstructorInitializerAllOnOneLineOrOnePerLine;
2456
2457 /// The number of characters to use for indentation of constructor
2458 /// initializer lists as well as inheritance lists.
2459 /// \version 3.7
2461
2462 /// Indent width for line continuations.
2463 /// \code
2464 /// ContinuationIndentWidth: 2
2465 ///
2466 /// int i = // VeryVeryVeryVeryVeryLongComment
2467 /// longFunction( // Again a long comment
2468 /// arg);
2469 /// \endcode
2470 /// \version 3.7
2472
2473 /// If ``true``, format braced lists as best suited for C++11 braced
2474 /// lists.
2475 ///
2476 /// Important differences:
2477 /// - No spaces inside the braced list.
2478 /// - No line break before the closing brace.
2479 /// - Indentation with the continuation indent, not with the block indent.
2480 ///
2481 /// Fundamentally, C++11 braced lists are formatted exactly like function
2482 /// calls would be formatted in their place. If the braced list follows a name
2483 /// (e.g. a type or variable name), clang-format formats as if the ``{}`` were
2484 /// the parentheses of a function call with that name. If there is no name,
2485 /// a zero-length name is assumed.
2486 /// \code
2487 /// true: false:
2488 /// vector<int> x{1, 2, 3, 4}; vs. vector<int> x{ 1, 2, 3, 4 };
2489 /// vector<T> x{{}, {}, {}, {}}; vector<T> x{ {}, {}, {}, {} };
2490 /// f(MyMap[{composite, key}]); f(MyMap[{ composite, key }]);
2491 /// new int[3]{1, 2, 3}; new int[3]{ 1, 2, 3 };
2492 /// \endcode
2493 /// \version 3.4
2495
2496 /// This option is **deprecated**. See ``DeriveLF`` and ``DeriveCRLF`` of
2497 /// ``LineEnding``.
2498 /// \version 10
2499 // bool DeriveLineEnding;
2500
2501 /// If ``true``, analyze the formatted file for the most common
2502 /// alignment of ``&`` and ``*``.
2503 /// Pointer and reference alignment styles are going to be updated according
2504 /// to the preferences found in the file.
2505 /// ``PointerAlignment`` is then used only as fallback.
2506 /// \version 3.7
2508
2509 /// Disables formatting completely.
2510 /// \version 3.7
2512
2513 /// Different styles for empty line after access modifiers.
2514 /// ``EmptyLineBeforeAccessModifier`` configuration handles the number of
2515 /// empty lines between two access modifiers.
2517 /// Remove all empty lines after access modifiers.
2518 /// \code
2519 /// struct foo {
2520 /// private:
2521 /// int i;
2522 /// protected:
2523 /// int j;
2524 /// /* comment */
2525 /// public:
2526 /// foo() {}
2527 /// private:
2528 /// protected:
2529 /// };
2530 /// \endcode
2532 /// Keep existing empty lines after access modifiers.
2533 /// MaxEmptyLinesToKeep is applied instead.
2535 /// Always add empty line after access modifiers if there are none.
2536 /// MaxEmptyLinesToKeep is applied also.
2537 /// \code
2538 /// struct foo {
2539 /// private:
2540 ///
2541 /// int i;
2542 /// protected:
2543 ///
2544 /// int j;
2545 /// /* comment */
2546 /// public:
2547 ///
2548 /// foo() {}
2549 /// private:
2550 ///
2551 /// protected:
2552 ///
2553 /// };
2554 /// \endcode
2556 };
2557
2558 /// Defines when to put an empty line after access modifiers.
2559 /// ``EmptyLineBeforeAccessModifier`` configuration handles the number of
2560 /// empty lines between two access modifiers.
2561 /// \version 13
2563
2564 /// Different styles for empty line before access modifiers.
2566 /// Remove all empty lines before access modifiers.
2567 /// \code
2568 /// struct foo {
2569 /// private:
2570 /// int i;
2571 /// protected:
2572 /// int j;
2573 /// /* comment */
2574 /// public:
2575 /// foo() {}
2576 /// private:
2577 /// protected:
2578 /// };
2579 /// \endcode
2581 /// Keep existing empty lines before access modifiers.
2583 /// Add empty line only when access modifier starts a new logical block.
2584 /// Logical block is a group of one or more member fields or functions.
2585 /// \code
2586 /// struct foo {
2587 /// private:
2588 /// int i;
2589 ///
2590 /// protected:
2591 /// int j;
2592 /// /* comment */
2593 /// public:
2594 /// foo() {}
2595 ///
2596 /// private:
2597 /// protected:
2598 /// };
2599 /// \endcode
2601 /// Always add empty line before access modifiers unless access modifier
2602 /// is at the start of struct or class definition.
2603 /// \code
2604 /// struct foo {
2605 /// private:
2606 /// int i;
2607 ///
2608 /// protected:
2609 /// int j;
2610 /// /* comment */
2611 ///
2612 /// public:
2613 /// foo() {}
2614 ///
2615 /// private:
2616 ///
2617 /// protected:
2618 /// };
2619 /// \endcode
2621 };
2622
2623 /// Defines in which cases to put empty line before access modifiers.
2624 /// \version 12
2626
2627 /// If ``true``, clang-format detects whether function calls and
2628 /// definitions are formatted with one parameter per line.
2629 ///
2630 /// Each call can be bin-packed, one-per-line or inconclusive. If it is
2631 /// inconclusive, e.g. completely on one line, but a decision needs to be
2632 /// made, clang-format analyzes whether there are other bin-packed cases in
2633 /// the input file and act accordingly.
2634 ///
2635 /// \note
2636 /// This is an experimental flag, that might go away or be renamed. Do
2637 /// not use this in config files, etc. Use at your own risk.
2638 /// \endnote
2639 /// \version 3.7
2641
2642 /// If ``true``, clang-format adds missing namespace end comments for
2643 /// namespaces and fixes invalid existing ones. This doesn't affect short
2644 /// namespaces, which are controlled by ``ShortNamespaceLines``.
2645 /// \code
2646 /// true: false:
2647 /// namespace longNamespace { vs. namespace longNamespace {
2648 /// void foo(); void foo();
2649 /// void bar(); void bar();
2650 /// } // namespace a }
2651 /// namespace shortNamespace { namespace shortNamespace {
2652 /// void baz(); void baz();
2653 /// } }
2654 /// \endcode
2655 /// \version 5
2657
2658 /// A vector of macros that should be interpreted as foreach loops
2659 /// instead of as function calls.
2660 ///
2661 /// These are expected to be macros of the form:
2662 /// \code
2663 /// FOREACH(<variable-declaration>, ...)
2664 /// <loop-body>
2665 /// \endcode
2666 ///
2667 /// In the .clang-format configuration file, this can be configured like:
2668 /// \code{.yaml}
2669 /// ForEachMacros: [RANGES_FOR, FOREACH]
2670 /// \endcode
2671 ///
2672 /// For example: BOOST_FOREACH.
2673 /// \version 3.7
2674 std::vector<std::string> ForEachMacros;
2675
2677
2678 /// A vector of macros that should be interpreted as conditionals
2679 /// instead of as function calls.
2680 ///
2681 /// These are expected to be macros of the form:
2682 /// \code
2683 /// IF(...)
2684 /// <conditional-body>
2685 /// else IF(...)
2686 /// <conditional-body>
2687 /// \endcode
2688 ///
2689 /// In the .clang-format configuration file, this can be configured like:
2690 /// \code{.yaml}
2691 /// IfMacros: [IF]
2692 /// \endcode
2693 ///
2694 /// For example: `KJ_IF_MAYBE
2695 /// <https://github.com/capnproto/capnproto/blob/master/kjdoc/tour.md#maybes>`_
2696 /// \version 13
2697 std::vector<std::string> IfMacros;
2698
2699 /// Specify whether access modifiers should have their own indentation level.
2700 ///
2701 /// When ``false``, access modifiers are indented (or outdented) relative to
2702 /// the record members, respecting the ``AccessModifierOffset``. Record
2703 /// members are indented one level below the record.
2704 /// When ``true``, access modifiers get their own indentation level. As a
2705 /// consequence, record members are always indented 2 levels below the record,
2706 /// regardless of the access modifier presence. Value of the
2707 /// ``AccessModifierOffset`` is ignored.
2708 /// \code
2709 /// false: true:
2710 /// class C { vs. class C {
2711 /// class D { class D {
2712 /// void bar(); void bar();
2713 /// protected: protected:
2714 /// D(); D();
2715 /// }; };
2716 /// public: public:
2717 /// C(); C();
2718 /// }; };
2719 /// void foo() { void foo() {
2720 /// return 1; return 1;
2721 /// } }
2722 /// \endcode
2723 /// \version 13
2725
2726 /// Indent case label blocks one level from the case label.
2727 ///
2728 /// When ``false``, the block following the case label uses the same
2729 /// indentation level as for the case label, treating the case label the same
2730 /// as an if-statement.
2731 /// When ``true``, the block gets indented as a scope block.
2732 /// \code
2733 /// false: true:
2734 /// switch (fool) { vs. switch (fool) {
2735 /// case 1: { case 1:
2736 /// bar(); {
2737 /// } break; bar();
2738 /// default: { }
2739 /// plop(); break;
2740 /// } default:
2741 /// } {
2742 /// plop();
2743 /// }
2744 /// }
2745 /// \endcode
2746 /// \version 11
2748
2749 /// Indent case labels one level from the switch statement.
2750 ///
2751 /// When ``false``, use the same indentation level as for the switch
2752 /// statement. Switch statement body is always indented one level more than
2753 /// case labels (except the first block following the case label, which
2754 /// itself indents the code - unless IndentCaseBlocks is enabled).
2755 /// \code
2756 /// false: true:
2757 /// switch (fool) { vs. switch (fool) {
2758 /// case 1: case 1:
2759 /// bar(); bar();
2760 /// break; break;
2761 /// default: default:
2762 /// plop(); plop();
2763 /// } }
2764 /// \endcode
2765 /// \version 3.3
2767
2768 /// Indent goto labels.
2769 ///
2770 /// When ``false``, goto labels are flushed left.
2771 /// \code
2772 /// true: false:
2773 /// int f() { vs. int f() {
2774 /// if (foo()) { if (foo()) {
2775 /// label1: label1:
2776 /// bar(); bar();
2777 /// } }
2778 /// label2: label2:
2779 /// return 1; return 1;
2780 /// } }
2781 /// \endcode
2782 /// \version 10
2784
2785 /// Indents extern blocks
2787 /// Backwards compatible with AfterExternBlock's indenting.
2788 /// \code
2789 /// IndentExternBlock: AfterExternBlock
2790 /// BraceWrapping.AfterExternBlock: true
2791 /// extern "C"
2792 /// {
2793 /// void foo();
2794 /// }
2795 /// \endcode
2796 ///
2797 /// \code
2798 /// IndentExternBlock: AfterExternBlock
2799 /// BraceWrapping.AfterExternBlock: false
2800 /// extern "C" {
2801 /// void foo();
2802 /// }
2803 /// \endcode
2805 /// Does not indent extern blocks.
2806 /// \code
2807 /// extern "C" {
2808 /// void foo();
2809 /// }
2810 /// \endcode
2812 /// Indents extern blocks.
2813 /// \code
2814 /// extern "C" {
2815 /// void foo();
2816 /// }
2817 /// \endcode
2819 };
2820
2821 /// IndentExternBlockStyle is the type of indenting of extern blocks.
2822 /// \version 11
2824
2825 /// Options for indenting preprocessor directives.
2827 /// Does not indent any directives.
2828 /// \code
2829 /// #if FOO
2830 /// #if BAR
2831 /// #include <foo>
2832 /// #endif
2833 /// #endif
2834 /// \endcode
2836 /// Indents directives after the hash.
2837 /// \code
2838 /// #if FOO
2839 /// # if BAR
2840 /// # include <foo>
2841 /// # endif
2842 /// #endif
2843 /// \endcode
2845 /// Indents directives before the hash.
2846 /// \code
2847 /// #if FOO
2848 /// #if BAR
2849 /// #include <foo>
2850 /// #endif
2851 /// #endif
2852 /// \endcode
2855
2856 /// The preprocessor directive indenting style to use.
2857 /// \version 6
2859
2860 /// Indent the requires clause in a template. This only applies when
2861 /// ``RequiresClausePosition`` is ``OwnLine``, ``OwnLineWithBrace``,
2862 /// or ``WithFollowing``.
2863 ///
2864 /// In clang-format 12, 13 and 14 it was named ``IndentRequires``.
2865 /// \code
2866 /// true:
2867 /// template <typename It>
2868 /// requires Iterator<It>
2869 /// void sort(It begin, It end) {
2870 /// //....
2871 /// }
2872 ///
2873 /// false:
2874 /// template <typename It>
2875 /// requires Iterator<It>
2876 /// void sort(It begin, It end) {
2877 /// //....
2878 /// }
2879 /// \endcode
2880 /// \version 15
2882
2883 /// The number of columns to use for indentation.
2884 /// \code
2885 /// IndentWidth: 3
2886 ///
2887 /// void f() {
2888 /// someFunction();
2889 /// if (true, false) {
2890 /// f();
2891 /// }
2892 /// }
2893 /// \endcode
2894 /// \version 3.7
2895 unsigned IndentWidth;
2896
2897 /// Indent if a function definition or declaration is wrapped after the
2898 /// type.
2899 /// \code
2900 /// true:
2901 /// LoooooooooooooooooooooooooooooooooooooooongReturnType
2902 /// LoooooooooooooooooooooooooooooooongFunctionDeclaration();
2903 ///
2904 /// false:
2905 /// LoooooooooooooooooooooooooooooooooooooooongReturnType
2906 /// LoooooooooooooooooooooooooooooooongFunctionDeclaration();
2907 /// \endcode
2908 /// \version 3.7
2910
2911 /// Insert braces after control statements (``if``, ``else``, ``for``, ``do``,
2912 /// and ``while``) in C++ unless the control statements are inside macro
2913 /// definitions or the braces would enclose preprocessor directives.
2914 /// \warning
2915 /// Setting this option to ``true`` could lead to incorrect code formatting
2916 /// due to clang-format's lack of complete semantic information. As such,
2917 /// extra care should be taken to review code changes made by this option.
2918 /// \endwarning
2919 /// \code
2920 /// false: true:
2921 ///
2922 /// if (isa<FunctionDecl>(D)) vs. if (isa<FunctionDecl>(D)) {
2923 /// handleFunctionDecl(D); handleFunctionDecl(D);
2924 /// else if (isa<VarDecl>(D)) } else if (isa<VarDecl>(D)) {
2925 /// handleVarDecl(D); handleVarDecl(D);
2926 /// else } else {
2927 /// return; return;
2928 /// }
2929 ///
2930 /// while (i--) vs. while (i--) {
2931 /// for (auto *A : D.attrs()) for (auto *A : D.attrs()) {
2932 /// handleAttr(A); handleAttr(A);
2933 /// }
2934 /// }
2935 ///
2936 /// do vs. do {
2937 /// --i; --i;
2938 /// while (i); } while (i);
2939 /// \endcode
2940 /// \version 15
2942
2943 /// Insert a newline at end of file if missing.
2944 /// \version 16
2946
2947 /// The style of inserting trailing commas into container literals.
2948 enum TrailingCommaStyle : int8_t {
2949 /// Do not insert trailing commas.
2951 /// Insert trailing commas in container literals that were wrapped over
2952 /// multiple lines. Note that this is conceptually incompatible with
2953 /// bin-packing, because the trailing comma is used as an indicator
2954 /// that a container should be formatted one-per-line (i.e. not bin-packed).
2955 /// So inserting a trailing comma counteracts bin-packing.
2957 };
2958
2959 /// If set to ``TCS_Wrapped`` will insert trailing commas in container
2960 /// literals (arrays and objects) that wrap across multiple lines.
2961 /// It is currently only available for JavaScript
2962 /// and disabled by default ``TCS_None``.
2963 /// ``InsertTrailingCommas`` cannot be used together with ``BinPackArguments``
2964 /// as inserting the comma disables bin-packing.
2965 /// \code
2966 /// TSC_Wrapped:
2967 /// const someArray = [
2968 /// aaaaaaaaaaaaaaaaaaaaaaaaaa,
2969 /// aaaaaaaaaaaaaaaaaaaaaaaaaa,
2970 /// aaaaaaaaaaaaaaaaaaaaaaaaaa,
2971 /// // ^ inserted
2972 /// ]
2973 /// \endcode
2974 /// \version 11
2976
2977 /// Separator format of integer literals of different bases.
2978 ///
2979 /// If negative, remove separators. If ``0``, leave the literal as is. If
2980 /// positive, insert separators between digits starting from the rightmost
2981 /// digit.
2982 ///
2983 /// For example, the config below will leave separators in binary literals
2984 /// alone, insert separators in decimal literals to separate the digits into
2985 /// groups of 3, and remove separators in hexadecimal literals.
2986 /// \code
2987 /// IntegerLiteralSeparator:
2988 /// Binary: 0
2989 /// Decimal: 3
2990 /// Hex: -1
2991 /// \endcode
2992 ///
2993 /// You can also specify a minimum number of digits (``BinaryMinDigits``,
2994 /// ``DecimalMinDigits``, and ``HexMinDigits``) the integer literal must
2995 /// have in order for the separators to be inserted.
2997 /// Format separators in binary literals.
2998 /// \code{.text}
2999 /// /* -1: */ b = 0b100111101101;
3000 /// /* 0: */ b = 0b10011'11'0110'1;
3001 /// /* 3: */ b = 0b100'111'101'101;
3002 /// /* 4: */ b = 0b1001'1110'1101;
3003 /// \endcode
3004 int8_t Binary;
3005 /// Format separators in binary literals with a minimum number of digits.
3006 /// \code{.text}
3007 /// // Binary: 3
3008 /// // BinaryMinDigits: 7
3009 /// b1 = 0b101101;
3010 /// b2 = 0b1'101'101;
3011 /// \endcode
3013 /// Format separators in decimal literals.
3014 /// \code{.text}
3015 /// /* -1: */ d = 18446744073709550592ull;
3016 /// /* 0: */ d = 184467'440737'0'95505'92ull;
3017 /// /* 3: */ d = 18'446'744'073'709'550'592ull;
3018 /// \endcode
3019 int8_t Decimal;
3020 /// Format separators in decimal literals with a minimum number of digits.
3021 /// \code{.text}
3022 /// // Decimal: 3
3023 /// // DecimalMinDigits: 5
3024 /// d1 = 2023;
3025 /// d2 = 10'000;
3026 /// \endcode
3028 /// Format separators in hexadecimal literals.
3029 /// \code{.text}
3030 /// /* -1: */ h = 0xDEADBEEFDEADBEEFuz;
3031 /// /* 0: */ h = 0xDEAD'BEEF'DE'AD'BEE'Fuz;
3032 /// /* 2: */ h = 0xDE'AD'BE'EF'DE'AD'BE'EFuz;
3033 /// \endcode
3034 int8_t Hex;
3035 /// Format separators in hexadecimal literals with a minimum number of
3036 /// digits.
3037 /// \code{.text}
3038 /// // Hex: 2
3039 /// // HexMinDigits: 6
3040 /// h1 = 0xABCDE;
3041 /// h2 = 0xAB'CD'EF;
3042 /// \endcode
3045 return Binary == R.Binary && BinaryMinDigits == R.BinaryMinDigits &&
3047 Hex == R.Hex && HexMinDigits == R.HexMinDigits;
3048 }
3049 };
3050
3051 /// Format integer literal separators (``'`` for C++ and ``_`` for C#, Java,
3052 /// and JavaScript).
3053 /// \version 16
3055
3056 /// A vector of prefixes ordered by the desired groups for Java imports.
3057 ///
3058 /// One group's prefix can be a subset of another - the longest prefix is
3059 /// always matched. Within a group, the imports are ordered lexicographically.
3060 /// Static imports are grouped separately and follow the same group rules.
3061 /// By default, static imports are placed before non-static imports,
3062 /// but this behavior is changed by another option,
3063 /// ``SortJavaStaticImport``.
3064 ///
3065 /// In the .clang-format configuration file, this can be configured like
3066 /// in the following yaml example. This will result in imports being
3067 /// formatted as in the Java example below.
3068 /// \code{.yaml}
3069 /// JavaImportGroups: [com.example, com, org]
3070 /// \endcode
3071 ///
3072 /// \code{.java}
3073 /// import static com.example.function1;
3074 ///
3075 /// import static com.test.function2;
3076 ///
3077 /// import static org.example.function3;
3078 ///
3079 /// import com.example.ClassA;
3080 /// import com.example.Test;
3081 /// import com.example.a.ClassB;
3082 ///
3083 /// import com.test.ClassC;
3084 ///
3085 /// import org.example.ClassD;
3086 /// \endcode
3087 /// \version 8
3088 std::vector<std::string> JavaImportGroups;
3089
3090 /// Quotation styles for JavaScript strings. Does not affect template
3091 /// strings.
3092 enum JavaScriptQuoteStyle : int8_t {
3093 /// Leave string quotes as they are.
3094 /// \code{.js}
3095 /// string1 = "foo";
3096 /// string2 = 'bar';
3097 /// \endcode
3099 /// Always use single quotes.
3100 /// \code{.js}
3101 /// string1 = 'foo';
3102 /// string2 = 'bar';
3103 /// \endcode
3105 /// Always use double quotes.
3106 /// \code{.js}
3107 /// string1 = "foo";
3108 /// string2 = "bar";
3109 /// \endcode
3112
3113 /// The JavaScriptQuoteStyle to use for JavaScript strings.
3114 /// \version 3.9
3116
3117 // clang-format off
3118 /// Whether to wrap JavaScript import/export statements.
3119 /// \code{.js}
3120 /// true:
3121 /// import {
3122 /// VeryLongImportsAreAnnoying,
3123 /// VeryLongImportsAreAnnoying,
3124 /// VeryLongImportsAreAnnoying,
3125 /// } from "some/module.js"
3126 ///
3127 /// false:
3128 /// import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js"
3129 /// \endcode
3130 /// \version 3.9
3132 // clang-format on
3133
3134 /// Options regarding which empty lines are kept.
3135 ///
3136 /// For example, the config below will remove empty lines at start of the
3137 /// file, end of the file, and start of blocks.
3138 ///
3139 /// \code
3140 /// KeepEmptyLines:
3141 /// AtEndOfFile: false
3142 /// AtStartOfBlock: false
3143 /// AtStartOfFile: false
3144 /// \endcode
3146 /// Keep empty lines at end of file.
3148 /// Keep empty lines at start of a block.
3149 /// \code
3150 /// true: false:
3151 /// if (foo) { vs. if (foo) {
3152 /// bar();
3153 /// bar(); }
3154 /// }
3155 /// \endcode
3157 /// Keep empty lines at start of file.
3159 bool operator==(const KeepEmptyLinesStyle &R) const {
3160 return AtEndOfFile == R.AtEndOfFile &&
3163 }
3164 };
3165 /// Which empty lines are kept. See ``MaxEmptyLinesToKeep`` for how many
3166 /// consecutive empty lines are kept.
3167 /// \version 19
3169
3170 /// This option is deprecated. See ``AtEndOfFile`` of ``KeepEmptyLines``.
3171 /// \version 17
3172 // bool KeepEmptyLinesAtEOF;
3173
3174 /// This option is deprecated. See ``AtStartOfBlock`` of ``KeepEmptyLines``.
3175 /// \version 3.7
3176 // bool KeepEmptyLinesAtTheStartOfBlocks;
3177
3178 /// Indentation logic for lambda bodies.
3180 /// Align lambda body relative to the lambda signature. This is the default.
3181 /// \code
3182 /// someMethod(
3183 /// [](SomeReallyLongLambdaSignatureArgument foo) {
3184 /// return;
3185 /// });
3186 /// \endcode
3188 /// For statements within block scope, align lambda body relative to the
3189 /// indentation level of the outer scope the lambda signature resides in.
3190 /// \code
3191 /// someMethod(
3192 /// [](SomeReallyLongLambdaSignatureArgument foo) {
3193 /// return;
3194 /// });
3195 ///
3196 /// someMethod(someOtherMethod(
3197 /// [](SomeReallyLongLambdaSignatureArgument foo) {
3198 /// return;
3199 /// }));
3200 /// \endcode
3202 };
3203
3204 /// The indentation style of lambda bodies. ``Signature`` (the default)
3205 /// causes the lambda body to be indented one additional level relative to
3206 /// the indentation level of the signature. ``OuterScope`` forces the lambda
3207 /// body to be indented one additional level relative to the parent scope
3208 /// containing the lambda signature.
3209 /// \version 13
3211
3212 /// Supported languages.
3213 ///
3214 /// When stored in a configuration file, specifies the language, that the
3215 /// configuration targets. When passed to the ``reformat()`` function, enables
3216 /// syntax features specific to the language.
3217 enum LanguageKind : int8_t {
3218 /// Do not use.
3220 /// Should be used for C, C++.
3222 /// Should be used for C#.
3224 /// Should be used for Java.
3226 /// Should be used for JavaScript.
3228 /// Should be used for JSON.
3230 /// Should be used for Objective-C, Objective-C++.
3232 /// Should be used for Protocol Buffers
3233 /// (https://developers.google.com/protocol-buffers/).
3235 /// Should be used for TableGen code.
3237 /// Should be used for Protocol Buffer messages in text format
3238 /// (https://developers.google.com/protocol-buffers/).
3240 /// Should be used for Verilog and SystemVerilog.
3241 /// https://standards.ieee.org/ieee/1800/6700/
3242 /// https://sci-hub.st/10.1109/IEEESTD.2018.8299595
3245 bool isCpp() const { return Language == LK_Cpp || Language == LK_ObjC; }
3246 bool isCSharp() const { return Language == LK_CSharp; }
3247 bool isJson() const { return Language == LK_Json; }
3248 bool isJavaScript() const { return Language == LK_JavaScript; }
3249 bool isVerilog() const { return Language == LK_Verilog; }
3250 bool isProto() const {
3251 return Language == LK_Proto || Language == LK_TextProto;
3252 }
3253 bool isTableGen() const { return Language == LK_TableGen; }
3254
3255 /// Language, this format style is targeted at.
3256 /// \version 3.5
3258
3259 /// Line ending style.
3260 enum LineEndingStyle : int8_t {
3261 /// Use ``\n``.
3263 /// Use ``\r\n``.
3265 /// Use ``\n`` unless the input has more lines ending in ``\r\n``.
3267 /// Use ``\r\n`` unless the input has more lines ending in ``\n``.
3269 };
3270
3271 /// Line ending style (``\n`` or ``\r\n``) to use.
3272 /// \version 16
3274
3275 /// A regular expression matching macros that start a block.
3276 /// \code
3277 /// # With:
3278 /// MacroBlockBegin: "^NS_MAP_BEGIN|\
3279 /// NS_TABLE_HEAD$"
3280 /// MacroBlockEnd: "^\
3281 /// NS_MAP_END|\
3282 /// NS_TABLE_.*_END$"
3283 ///
3284 /// NS_MAP_BEGIN
3285 /// foo();
3286 /// NS_MAP_END
3287 ///
3288 /// NS_TABLE_HEAD
3289 /// bar();
3290 /// NS_TABLE_FOO_END
3291 ///
3292 /// # Without:
3293 /// NS_MAP_BEGIN
3294 /// foo();
3295 /// NS_MAP_END
3296 ///
3297 /// NS_TABLE_HEAD
3298 /// bar();
3299 /// NS_TABLE_FOO_END
3300 /// \endcode
3301 /// \version 3.7
3302 std::string MacroBlockBegin;
3303
3304 /// A regular expression matching macros that end a block.
3305 /// \version 3.7
3306 std::string MacroBlockEnd;
3307
3308 /// A list of macros of the form \c <definition>=<expansion> .
3309 ///
3310 /// Code will be parsed with macros expanded, in order to determine how to
3311 /// interpret and format the macro arguments.
3312 ///
3313 /// For example, the code:
3314 /// \code
3315 /// A(a*b);
3316 /// \endcode
3317 ///
3318 /// will usually be interpreted as a call to a function A, and the
3319 /// multiplication expression will be formatted as ``a * b``.
3320 ///
3321 /// If we specify the macro definition:
3322 /// \code{.yaml}
3323 /// Macros:
3324 /// - A(x)=x
3325 /// \endcode
3326 ///
3327 /// the code will now be parsed as a declaration of the variable b of type a*,
3328 /// and formatted as ``a* b`` (depending on pointer-binding rules).
3329 ///
3330 /// Features and restrictions:
3331 /// * Both function-like macros and object-like macros are supported.
3332 /// * Macro arguments must be used exactly once in the expansion.
3333 /// * No recursive expansion; macros referencing other macros will be
3334 /// ignored.
3335 /// * Overloading by arity is supported: for example, given the macro
3336 /// definitions A=x, A()=y, A(a)=a
3337 ///
3338 /// \code
3339 /// A; -> x;
3340 /// A(); -> y;
3341 /// A(z); -> z;
3342 /// A(a, b); // will not be expanded.
3343 /// \endcode
3344 ///
3345 /// \version 17
3346 std::vector<std::string> Macros;
3347
3348 /// The maximum number of consecutive empty lines to keep.
3349 /// \code
3350 /// MaxEmptyLinesToKeep: 1 vs. MaxEmptyLinesToKeep: 0
3351 /// int f() { int f() {
3352 /// int = 1; int i = 1;
3353 /// i = foo();
3354 /// i = foo(); return i;
3355 /// }
3356 /// return i;
3357 /// }
3358 /// \endcode
3359 /// \version 3.7
3361
3362 /// Different ways to indent namespace contents.
3364 /// Don't indent in namespaces.
3365 /// \code
3366 /// namespace out {
3367 /// int i;
3368 /// namespace in {
3369 /// int i;
3370 /// }
3371 /// }
3372 /// \endcode
3374 /// Indent only in inner namespaces (nested in other namespaces).
3375 /// \code
3376 /// namespace out {
3377 /// int i;
3378 /// namespace in {
3379 /// int i;
3380 /// }
3381 /// }
3382 /// \endcode
3384 /// Indent in all namespaces.
3385 /// \code
3386 /// namespace out {
3387 /// int i;
3388 /// namespace in {
3389 /// int i;
3390 /// }
3391 /// }
3392 /// \endcode
3393 NI_All
3395
3396 /// The indentation used for namespaces.
3397 /// \version 3.7
3399
3400 /// A vector of macros which are used to open namespace blocks.
3401 ///
3402 /// These are expected to be macros of the form:
3403 /// \code
3404 /// NAMESPACE(<namespace-name>, ...) {
3405 /// <namespace-content>
3406 /// }
3407 /// \endcode
3408 ///
3409 /// For example: TESTSUITE
3410 /// \version 9
3411 std::vector<std::string> NamespaceMacros;
3412
3413 /// Controls bin-packing Objective-C protocol conformance list
3414 /// items into as few lines as possible when they go over ``ColumnLimit``.
3415 ///
3416 /// If ``Auto`` (the default), delegates to the value in
3417 /// ``BinPackParameters``. If that is ``true``, bin-packs Objective-C
3418 /// protocol conformance list items into as few lines as possible
3419 /// whenever they go over ``ColumnLimit``.
3420 ///
3421 /// If ``Always``, always bin-packs Objective-C protocol conformance
3422 /// list items into as few lines as possible whenever they go over
3423 /// ``ColumnLimit``.
3424 ///
3425 /// If ``Never``, lays out Objective-C protocol conformance list items
3426 /// onto individual lines whenever they go over ``ColumnLimit``.
3427 ///
3428 /// \code{.objc}
3429 /// Always (or Auto, if BinPackParameters=true):
3430 /// @interface ccccccccccccc () <
3431 /// ccccccccccccc, ccccccccccccc,
3432 /// ccccccccccccc, ccccccccccccc> {
3433 /// }
3434 ///
3435 /// Never (or Auto, if BinPackParameters=false):
3436 /// @interface ddddddddddddd () <
3437 /// ddddddddddddd,
3438 /// ddddddddddddd,
3439 /// ddddddddddddd,
3440 /// ddddddddddddd> {
3441 /// }
3442 /// \endcode
3443 /// \version 7
3445
3446 /// The number of characters to use for indentation of ObjC blocks.
3447 /// \code{.objc}
3448 /// ObjCBlockIndentWidth: 4
3449 ///
3450 /// [operation setCompletionBlock:^{
3451 /// [self onOperationDone];
3452 /// }];
3453 /// \endcode
3454 /// \version 3.7
3456
3457 /// Break parameters list into lines when there is nested block
3458 /// parameters in a function call.
3459 /// \code
3460 /// false:
3461 /// - (void)_aMethod
3462 /// {
3463 /// [self.test1 t:self w:self callback:^(typeof(self) self, NSNumber
3464 /// *u, NSNumber *v) {
3465 /// u = c;
3466 /// }]
3467 /// }
3468 /// true:
3469 /// - (void)_aMethod
3470 /// {
3471 /// [self.test1 t:self
3472 /// w:self
3473 /// callback:^(typeof(self) self, NSNumber *u, NSNumber *v) {
3474 /// u = c;
3475 /// }]
3476 /// }
3477 /// \endcode
3478 /// \version 11
3480
3481 /// The order in which ObjC property attributes should appear.
3482 ///
3483 /// Attributes in code will be sorted in the order specified. Any attributes
3484 /// encountered that are not mentioned in this array will be sorted last, in
3485 /// stable order. Comments between attributes will leave the attributes
3486 /// untouched.
3487 /// \warning
3488 /// Using this option could lead to incorrect code formatting due to
3489 /// clang-format's lack of complete semantic information. As such, extra
3490 /// care should be taken to review code changes made by this option.
3491 /// \endwarning
3492 /// \code{.yaml}
3493 /// ObjCPropertyAttributeOrder: [
3494 /// class, direct,
3495 /// atomic, nonatomic,
3496 /// assign, retain, strong, copy, weak, unsafe_unretained,
3497 /// readonly, readwrite, getter, setter,
3498 /// nullable, nonnull, null_resettable, null_unspecified
3499 /// ]
3500 /// \endcode
3501 /// \version 18
3502 std::vector<std::string> ObjCPropertyAttributeOrder;
3503
3504 /// Add a space after ``@property`` in Objective-C, i.e. use
3505 /// ``@property (readonly)`` instead of ``@property(readonly)``.
3506 /// \version 3.7
3508
3509 /// Add a space in front of an Objective-C protocol list, i.e. use
3510 /// ``Foo <Protocol>`` instead of ``Foo<Protocol>``.
3511 /// \version 3.7
3513
3514 /// Different ways to try to fit all constructor initializers on a line.
3516 /// Always put each constructor initializer on its own line.
3517 /// \code
3518 /// Constructor()
3519 /// : a(),
3520 /// b()
3521 /// \endcode
3523 /// Bin-pack constructor initializers.
3524 /// \code
3525 /// Constructor()
3526 /// : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(),
3527 /// cccccccccccccccccccc()
3528 /// \endcode
3530 /// Put all constructor initializers on the current line if they fit.
3531 /// Otherwise, put each one on its own line.
3532 /// \code
3533 /// Constructor() : a(), b()
3534 ///
3535 /// Constructor()
3536 /// : aaaaaaaaaaaaaaaaaaaa(),
3537 /// bbbbbbbbbbbbbbbbbbbb(),
3538 /// ddddddddddddd()
3539 /// \endcode
3541 /// Same as ``PCIS_CurrentLine`` except that if all constructor initializers
3542 /// do not fit on the current line, try to fit them on the next line.
3543 /// \code
3544 /// Constructor() : a(), b()
3545 ///
3546 /// Constructor()
3547 /// : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), ddddddddddddd()
3548 ///
3549 /// Constructor()
3550 /// : aaaaaaaaaaaaaaaaaaaa(),
3551 /// bbbbbbbbbbbbbbbbbbbb(),
3552 /// cccccccccccccccccccc()
3553 /// \endcode
3555 /// Put all constructor initializers on the next line if they fit.
3556 /// Otherwise, put each one on its own line.
3557 /// \code
3558 /// Constructor()
3559 /// : a(), b()
3560 ///
3561 /// Constructor()
3562 /// : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), ddddddddddddd()
3563 ///
3564 /// Constructor()
3565 /// : aaaaaaaaaaaaaaaaaaaa(),
3566 /// bbbbbbbbbbbbbbbbbbbb(),
3567 /// cccccccccccccccccccc()
3568 /// \endcode
3570 };
3571
3572 /// The pack constructor initializers style to use.
3573 /// \version 14
3575
3576 /// The penalty for breaking around an assignment operator.
3577 /// \version 5
3579
3580 /// The penalty for breaking a function call after ``call(``.
3581 /// \version 3.7
3583
3584 /// The penalty for each line break introduced inside a comment.
3585 /// \version 3.7
3587
3588 /// The penalty for breaking before the first ``<<``.
3589 /// \version 3.7
3591
3592 /// The penalty for breaking after ``(``.
3593 /// \version 14
3595
3596 /// The penalty for breaking after ``::``.
3597 /// \version 18
3599
3600 /// The penalty for each line break introduced inside a string literal.
3601 /// \version 3.7
3603
3604 /// The penalty for breaking after template declaration.
3605 /// \version 7
3607
3608 /// The penalty for each character outside of the column limit.
3609 /// \version 3.7
3611
3612 /// Penalty for each character of whitespace indentation
3613 /// (counted relative to leading non-whitespace column).
3614 /// \version 12
3616
3617 /// Penalty for putting the return type of a function onto its own line.
3618 /// \version 3.7
3620
3621 /// The ``&``, ``&&`` and ``*`` alignment style.
3623 /// Align pointer to the left.
3624 /// \code
3625 /// int* a;
3626 /// \endcode
3628 /// Align pointer to the right.
3629 /// \code
3630 /// int *a;
3631 /// \endcode
3633 /// Align pointer in the middle.
3634 /// \code
3635 /// int * a;
3636 /// \endcode
3639
3640 /// Pointer and reference alignment style.
3641 /// \version 3.7
3643
3644 /// The number of columns to use for indentation of preprocessor statements.
3645 /// When set to -1 (default) ``IndentWidth`` is used also for preprocessor
3646 /// statements.
3647 /// \code
3648 /// PPIndentWidth: 1
3649 ///
3650 /// #ifdef __linux__
3651 /// # define FOO
3652 /// #else
3653 /// # define BAR
3654 /// #endif
3655 /// \endcode
3656 /// \version 13
3658
3659 /// Different specifiers and qualifiers alignment styles.
3661 /// Don't change specifiers/qualifiers to either Left or Right alignment
3662 /// (default).
3663 /// \code
3664 /// int const a;
3665 /// const int *a;
3666 /// \endcode
3668 /// Change specifiers/qualifiers to be left-aligned.
3669 /// \code
3670 /// const int a;
3671 /// const int *a;
3672 /// \endcode
3674 /// Change specifiers/qualifiers to be right-aligned.
3675 /// \code
3676 /// int const a;
3677 /// int const *a;
3678 /// \endcode
3680 /// Change specifiers/qualifiers to be aligned based on ``QualifierOrder``.
3681 /// With:
3682 /// \code{.yaml}
3683 /// QualifierOrder: [inline, static, type, const]
3684 /// \endcode
3685 ///
3686 /// \code
3687 ///
3688 /// int const a;
3689 /// int const *a;
3690 /// \endcode
3693
3694 /// Different ways to arrange specifiers and qualifiers (e.g. const/volatile).
3695 /// \warning
3696 /// Setting ``QualifierAlignment`` to something other than ``Leave``, COULD
3697 /// lead to incorrect code formatting due to incorrect decisions made due to
3698 /// clang-formats lack of complete semantic information.
3699 /// As such extra care should be taken to review code changes made by the use
3700 /// of this option.
3701 /// \endwarning
3702 /// \version 14
3704
3705 /// The order in which the qualifiers appear.
3706 /// Order is an array that can contain any of the following:
3707 ///
3708 /// * const
3709 /// * inline
3710 /// * static
3711 /// * friend
3712 /// * constexpr
3713 /// * volatile
3714 /// * restrict
3715 /// * type
3716 ///
3717 /// \note
3718 /// It **must** contain ``type``.
3719 /// \endnote
3720 ///
3721 /// Items to the left of ``type`` will be placed to the left of the type and
3722 /// aligned in the order supplied. Items to the right of ``type`` will be
3723 /// placed to the right of the type and aligned in the order supplied.
3724 ///
3725 /// \code{.yaml}
3726 /// QualifierOrder: [inline, static, type, const, volatile]
3727 /// \endcode
3728 /// \version 14
3729 std::vector<std::string> QualifierOrder;
3730
3731 /// See documentation of ``RawStringFormats``.
3733 /// The language of this raw string.
3735 /// A list of raw string delimiters that match this language.
3736 std::vector<std::string> Delimiters;
3737 /// A list of enclosing function names that match this language.
3738 std::vector<std::string> EnclosingFunctions;
3739 /// The canonical delimiter for this language.
3741 /// The style name on which this raw string format is based on.
3742 /// If not specified, the raw string format is based on the style that this
3743 /// format is based on.
3744 std::string BasedOnStyle;
3745 bool operator==(const RawStringFormat &Other) const {
3746 return Language == Other.Language && Delimiters == Other.Delimiters &&
3747 EnclosingFunctions == Other.EnclosingFunctions &&
3748 CanonicalDelimiter == Other.CanonicalDelimiter &&
3749 BasedOnStyle == Other.BasedOnStyle;
3750 }
3751 };
3752
3753 /// Defines hints for detecting supported languages code blocks in raw
3754 /// strings.
3755 ///
3756 /// A raw string with a matching delimiter or a matching enclosing function
3757 /// name will be reformatted assuming the specified language based on the
3758 /// style for that language defined in the .clang-format file. If no style has
3759 /// been defined in the .clang-format file for the specific language, a
3760 /// predefined style given by ``BasedOnStyle`` is used. If ``BasedOnStyle`` is
3761 /// not found, the formatting is based on ``LLVM`` style. A matching delimiter
3762 /// takes precedence over a matching enclosing function name for determining
3763 /// the language of the raw string contents.
3764 ///
3765 /// If a canonical delimiter is specified, occurrences of other delimiters for
3766 /// the same language will be updated to the canonical if possible.
3767 ///
3768 /// There should be at most one specification per language and each delimiter
3769 /// and enclosing function should not occur in multiple specifications.
3770 ///
3771 /// To configure this in the .clang-format file, use:
3772 /// \code{.yaml}
3773 /// RawStringFormats:
3774 /// - Language: TextProto
3775 /// Delimiters:
3776 /// - pb
3777 /// - proto
3778 /// EnclosingFunctions:
3779 /// - PARSE_TEXT_PROTO
3780 /// BasedOnStyle: google
3781 /// - Language: Cpp
3782 /// Delimiters:
3783 /// - cc
3784 /// - cpp
3785 /// BasedOnStyle: LLVM
3786 /// CanonicalDelimiter: cc
3787 /// \endcode
3788 /// \version 6
3789 std::vector<RawStringFormat> RawStringFormats;
3790
3791 /// \brief The ``&`` and ``&&`` alignment style.
3793 /// Align reference like ``PointerAlignment``.
3795 /// Align reference to the left.
3796 /// \code
3797 /// int& a;
3798 /// \endcode
3800 /// Align reference to the right.
3801 /// \code
3802 /// int &a;
3803 /// \endcode
3805 /// Align reference in the middle.
3806 /// \code
3807 /// int & a;
3808 /// \endcode
3811
3812 /// \brief Reference alignment style (overrides ``PointerAlignment`` for
3813 /// references).
3814 /// \version 13
3816
3817 // clang-format off
3818 /// If ``true``, clang-format will attempt to re-flow comments. That is it
3819 /// will touch a comment and *reflow* long comments into new lines, trying to
3820 /// obey the ``ColumnLimit``.
3821 /// \code
3822 /// false:
3823 /// // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
3824 /// /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */
3825 ///
3826 /// true:
3827 /// // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
3828 /// // information
3829 /// /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
3830 /// * information */
3831 /// \endcode
3832 /// \version 3.8
3834 // clang-format on
3835
3836 /// Remove optional braces of control statements (``if``, ``else``, ``for``,
3837 /// and ``while``) in C++ according to the LLVM coding style.
3838 /// \warning
3839 /// This option will be renamed and expanded to support other styles.
3840 /// \endwarning
3841 /// \warning
3842 /// Setting this option to ``true`` could lead to incorrect code formatting
3843 /// due to clang-format's lack of complete semantic information. As such,
3844 /// extra care should be taken to review code changes made by this option.
3845 /// \endwarning
3846 /// \code
3847 /// false: true:
3848 ///
3849 /// if (isa<FunctionDecl>(D)) { vs. if (isa<FunctionDecl>(D))
3850 /// handleFunctionDecl(D); handleFunctionDecl(D);
3851 /// } else if (isa<VarDecl>(D)) { else if (isa<VarDecl>(D))
3852 /// handleVarDecl(D); handleVarDecl(D);
3853 /// }
3854 ///
3855 /// if (isa<VarDecl>(D)) { vs. if (isa<VarDecl>(D)) {
3856 /// for (auto *A : D.attrs()) { for (auto *A : D.attrs())
3857 /// if (shouldProcessAttr(A)) { if (shouldProcessAttr(A))
3858 /// handleAttr(A); handleAttr(A);
3859 /// } }
3860 /// }
3861 /// }
3862 ///
3863 /// if (isa<FunctionDecl>(D)) { vs. if (isa<FunctionDecl>(D))
3864 /// for (auto *A : D.attrs()) { for (auto *A : D.attrs())
3865 /// handleAttr(A); handleAttr(A);
3866 /// }
3867 /// }
3868 ///
3869 /// if (auto *D = (T)(D)) { vs. if (auto *D = (T)(D)) {
3870 /// if (shouldProcess(D)) { if (shouldProcess(D))
3871 /// handleVarDecl(D); handleVarDecl(D);
3872 /// } else { else
3873 /// markAsIgnored(D); markAsIgnored(D);
3874 /// } }
3875 /// }
3876 ///
3877 /// if (a) { vs. if (a)
3878 /// b(); b();
3879 /// } else { else if (c)
3880 /// if (c) { d();
3881 /// d(); else
3882 /// } else { e();
3883 /// e();
3884 /// }
3885 /// }
3886 /// \endcode
3887 /// \version 14
3889
3890 /// Types of redundant parentheses to remove.
3892 /// Do not remove parentheses.
3893 /// \code
3894 /// class __declspec((dllimport)) X {};
3895 /// co_return (((0)));
3896 /// return ((a + b) - ((c + d)));
3897 /// \endcode
3899 /// Replace multiple parentheses with single parentheses.
3900 /// \code
3901 /// class __declspec(dllimport) X {};
3902 /// co_return (0);
3903 /// return ((a + b) - (c + d));
3904 /// \endcode
3906 /// Also remove parentheses enclosing the expression in a
3907 /// ``return``/``co_return`` statement.
3908 /// \code
3909 /// class __declspec(dllimport) X {};
3910 /// co_return 0;
3911 /// return (a + b) - (c + d);
3912 /// \endcode
3914 };
3915
3916 /// Remove redundant parentheses.
3917 /// \warning
3918 /// Setting this option to any value other than ``Leave`` could lead to
3919 /// incorrect code formatting due to clang-format's lack of complete semantic
3920 /// information. As such, extra care should be taken to review code changes
3921 /// made by this option.
3922 /// \endwarning
3923 /// \version 17
3925
3926 /// Remove semicolons after the closing braces of functions and
3927 /// constructors/destructors.
3928 /// \warning
3929 /// Setting this option to ``true`` could lead to incorrect code formatting
3930 /// due to clang-format's lack of complete semantic information. As such,
3931 /// extra care should be taken to review code changes made by this option.
3932 /// \endwarning
3933 /// \code
3934 /// false: true:
3935 ///
3936 /// int max(int a, int b) { int max(int a, int b) {
3937 /// return a > b ? a : b; return a > b ? a : b;
3938 /// }; }
3939 ///
3940 /// \endcode
3941 /// \version 16
3943
3944 /// \brief The possible positions for the requires clause. The
3945 /// ``IndentRequires`` option is only used if the ``requires`` is put on the
3946 /// start of a line.
3948 /// Always put the ``requires`` clause on its own line (possibly followed by
3949 /// a semicolon).
3950 /// \code
3951 /// template <typename T>
3952 /// requires C<T>
3953 /// struct Foo {...
3954 ///
3955 /// template <typename T>
3956 /// void bar(T t)
3957 /// requires C<T>;
3958 ///
3959 /// template <typename T>
3960 /// requires C<T>
3961 /// void bar(T t) {...
3962 ///
3963 /// template <typename T>
3964 /// void baz(T t)
3965 /// requires C<T>
3966 /// {...
3967 /// \endcode
3969 /// As with ``OwnLine``, except, unless otherwise prohibited, place a
3970 /// following open brace (of a function definition) to follow on the same
3971 /// line.
3972 /// \code
3973 /// void bar(T t)
3974 /// requires C<T> {
3975 /// return;
3976 /// }
3977 ///
3978 /// void bar(T t)
3979 /// requires C<T> {}
3980 ///
3981 /// template <typename T>
3982 /// requires C<T>
3983 /// void baz(T t) {
3984 /// ...
3985 /// \endcode
3987 /// Try to put the clause together with the preceding part of a declaration.
3988 /// For class templates: stick to the template declaration.
3989 /// For function templates: stick to the template declaration.
3990 /// For function declaration followed by a requires clause: stick to the
3991 /// parameter list.
3992 /// \code
3993 /// template <typename T> requires C<T>
3994 /// struct Foo {...
3995 ///
3996 /// template <typename T> requires C<T>
3997 /// void bar(T t) {...
3998 ///
3999 /// template <typename T>
4000 /// void baz(T t) requires C<T>
4001 /// {...
4002 /// \endcode
4004 /// Try to put the ``requires`` clause together with the class or function
4005 /// declaration.
4006 /// \code
4007 /// template <typename T>
4008 /// requires C<T> struct Foo {...
4009 ///
4010 /// template <typename T>
4011 /// requires C<T> void bar(T t) {...
4012 ///
4013 /// template <typename T>
4014 /// void baz(T t)
4015 /// requires C<T> {...
4016 /// \endcode
4018 /// Try to put everything in the same line if possible. Otherwise normal
4019 /// line breaking rules take over.
4020 /// \code
4021 /// // Fitting:
4022 /// template <typename T> requires C<T> struct Foo {...
4023 ///
4024 /// template <typename T> requires C<T> void bar(T t) {...
4025 ///
4026 /// template <typename T> void bar(T t) requires C<T> {...
4027 ///
4028 /// // Not fitting, one possible example:
4029 /// template <typename LongName>
4030 /// requires C<LongName>
4031 /// struct Foo {...
4032 ///
4033 /// template <typename LongName>
4034 /// requires C<LongName>
4035 /// void bar(LongName ln) {
4036 ///
4037 /// template <typename LongName>
4038 /// void bar(LongName ln)
4039 /// requires C<LongName> {
4040 /// \endcode
4042 };
4043
4044 /// \brief The position of the ``requires`` clause.
4045 /// \version 15
4047
4048 /// Indentation logic for requires expression bodies.
4050 /// Align requires expression body relative to the indentation level of the
4051 /// outer scope the requires expression resides in.
4052 /// This is the default.
4053 /// \code
4054 /// template <typename T>
4055 /// concept C = requires(T t) {
4056 /// ...
4057 /// }
4058 /// \endcode
4060 /// Align requires expression body relative to the ``requires`` keyword.
4061 /// \code
4062 /// template <typename T>
4063 /// concept C = requires(T t) {
4064 /// ...
4065 /// }
4066 /// \endcode
4068 };
4069
4070 /// The indentation used for requires expression bodies.
4071 /// \version 16
4073
4074 /// \brief The style if definition blocks should be separated.
4076 /// Leave definition blocks as they are.
4078 /// Insert an empty line between definition blocks.
4080 /// Remove any empty line between definition blocks.
4081 SDS_Never
4083
4084 /// Specifies the use of empty lines to separate definition blocks, including
4085 /// classes, structs, enums, and functions.
4086 /// \code
4087 /// Never v.s. Always
4088 /// #include <cstring> #include <cstring>
4089 /// struct Foo {
4090 /// int a, b, c; struct Foo {
4091 /// }; int a, b, c;
4092 /// namespace Ns { };
4093 /// class Bar {
4094 /// public: namespace Ns {
4095 /// struct Foobar { class Bar {
4096 /// int a; public:
4097 /// int b; struct Foobar {
4098 /// }; int a;
4099 /// private: int b;
4100 /// int t; };
4101 /// int method1() {
4102 /// // ... private:
4103 /// } int t;
4104 /// enum List {
4105 /// ITEM1, int method1() {
4106 /// ITEM2 // ...
4107 /// }; }
4108 /// template<typename T>
4109 /// int method2(T x) { enum List {
4110 /// // ... ITEM1,
4111 /// } ITEM2
4112 /// int i, j, k; };
4113 /// int method3(int par) {
4114 /// // ... template<typename T>
4115 /// } int method2(T x) {
4116 /// }; // ...
4117 /// class C {}; }
4118 /// }
4119 /// int i, j, k;
4120 ///
4121 /// int method3(int par) {
4122 /// // ...
4123 /// }
4124 /// };
4125 ///
4126 /// class C {};
4127 /// }
4128 /// \endcode
4129 /// \version 14
4131
4132 /// The maximal number of unwrapped lines that a short namespace spans.
4133 /// Defaults to 1.
4134 ///
4135 /// This determines the maximum length of short namespaces by counting
4136 /// unwrapped lines (i.e. containing neither opening nor closing
4137 /// namespace brace) and makes ``FixNamespaceComments`` omit adding
4138 /// end comments for those.
4139 /// \code
4140 /// ShortNamespaceLines: 1 vs. ShortNamespaceLines: 0
4141 /// namespace a { namespace a {
4142 /// int foo; int foo;
4143 /// } } // namespace a
4144 ///
4145 /// ShortNamespaceLines: 1 vs. ShortNamespaceLines: 0
4146 /// namespace b { namespace b {
4147 /// int foo; int foo;
4148 /// int bar; int bar;
4149 /// } // namespace b } // namespace b
4150 /// \endcode
4151 /// \version 13
4153
4154 /// Do not format macro definition body.
4155 /// \version 18
4157
4158 /// Include sorting options.
4159 enum SortIncludesOptions : int8_t {
4160 /// Includes are never sorted.
4161 /// \code
4162 /// #include "B/A.h"
4163 /// #include "A/B.h"
4164 /// #include "a/b.h"
4165 /// #include "A/b.h"
4166 /// #include "B/a.h"
4167 /// \endcode
4169 /// Includes are sorted in an ASCIIbetical or case sensitive fashion.
4170 /// \code
4171 /// #include "A/B.h"
4172 /// #include "A/b.h"
4173 /// #include "B/A.h"
4174 /// #include "B/a.h"
4175 /// #include "a/b.h"
4176 /// \endcode
4178 /// Includes are sorted in an alphabetical or case insensitive fashion.
4179 /// \code
4180 /// #include "A/B.h"
4181 /// #include "A/b.h"
4182 /// #include "a/b.h"
4183 /// #include "B/A.h"
4184 /// #include "B/a.h"
4185 /// \endcode
4187 };
4188
4189 /// Controls if and how clang-format will sort ``#includes``.
4190 /// \version 3.8
4192
4193 /// Position for Java Static imports.
4195 /// Static imports are placed before non-static imports.
4196 /// \code{.java}
4197 /// import static org.example.function1;
4198 ///
4199 /// import org.example.ClassA;
4200 /// \endcode
4202 /// Static imports are placed after non-static imports.
4203 /// \code{.java}
4204 /// import org.example.ClassA;
4205 ///
4206 /// import static org.example.function1;
4207 /// \endcode
4209 };
4210
4211 /// When sorting Java imports, by default static imports are placed before
4212 /// non-static imports. If ``JavaStaticImportAfterImport`` is ``After``,
4213 /// static imports are placed after non-static imports.
4214 /// \version 12
4216
4217 /// Using declaration sorting options.
4219 /// Using declarations are never sorted.
4220 /// \code
4221 /// using std::chrono::duration_cast;
4222 /// using std::move;
4223 /// using boost::regex;
4224 /// using boost::regex_constants::icase;
4225 /// using std::string;
4226 /// \endcode
4228 /// Using declarations are sorted in the order defined as follows:
4229 /// Split the strings by ``::`` and discard any initial empty strings. Sort
4230 /// the lists of names lexicographically, and within those groups, names are
4231 /// in case-insensitive lexicographic order.
4232 /// \code
4233 /// using boost::regex;
4234 /// using boost::regex_constants::icase;
4235 /// using std::chrono::duration_cast;
4236 /// using std::move;
4237 /// using std::string;
4238 /// \endcode
4240 /// Using declarations are sorted in the order defined as follows:
4241 /// Split the strings by ``::`` and discard any initial empty strings. The
4242 /// last element of each list is a non-namespace name; all others are
4243 /// namespace names. Sort the lists of names lexicographically, where the
4244 /// sort order of individual names is that all non-namespace names come
4245 /// before all namespace names, and within those groups, names are in
4246 /// case-insensitive lexicographic order.
4247 /// \code
4248 /// using boost::regex;
4249 /// using boost::regex_constants::icase;
4250 /// using std::move;
4251 /// using std::string;
4252 /// using std::chrono::duration_cast;
4253 /// \endcode
4255 };
4256
4257 /// Controls if and how clang-format will sort using declarations.
4258 /// \version 5
4260
4261 /// If ``true``, a space is inserted after C style casts.
4262 /// \code
4263 /// true: false:
4264 /// (int) i; vs. (int)i;
4265 /// \endcode
4266 /// \version 3.5
4268
4269 /// If ``true``, a space is inserted after the logical not operator (``!``).
4270 /// \code
4271 /// true: false:
4272 /// ! someExpression(); vs. !someExpression();
4273 /// \endcode
4274 /// \version 9
4276
4277 /// If \c true, a space will be inserted after the ``template`` keyword.
4278 /// \code
4279 /// true: false:
4280 /// template <int> void foo(); vs. template<int> void foo();
4281 /// \endcode
4282 /// \version 4
4284
4285 /// Different ways to put a space before opening parentheses.
4287 /// Don't ensure spaces around pointer qualifiers and use PointerAlignment
4288 /// instead.
4289 /// \code
4290 /// PointerAlignment: Left PointerAlignment: Right
4291 /// void* const* x = NULL; vs. void *const *x = NULL;
4292 /// \endcode
4294 /// Ensure that there is a space before pointer qualifiers.
4295 /// \code
4296 /// PointerAlignment: Left PointerAlignment: Right
4297 /// void* const* x = NULL; vs. void * const *x = NULL;
4298 /// \endcode
4300 /// Ensure that there is a space after pointer qualifiers.
4301 /// \code
4302 /// PointerAlignment: Left PointerAlignment: Right
4303 /// void* const * x = NULL; vs. void *const *x = NULL;
4304 /// \endcode
4306 /// Ensure that there is a space both before and after pointer qualifiers.
4307 /// \code
4308 /// PointerAlignment: Left PointerAlignment: Right
4309 /// void* const * x = NULL; vs. void * const *x = NULL;
4310 /// \endcode
4312 };
4313
4314 /// Defines in which cases to put a space before or after pointer qualifiers
4315 /// \version 12
4317
4318 /// If ``false``, spaces will be removed before assignment operators.
4319 /// \code
4320 /// true: false:
4321 /// int a = 5; vs. int a= 5;
4322 /// a += 42; a+= 42;
4323 /// \endcode
4324 /// \version 3.7
4326
4327 /// If ``false``, spaces will be removed before case colon.
4328 /// \code
4329 /// true: false
4330 /// switch (x) { vs. switch (x) {
4331 /// case 1 : break; case 1: break;
4332 /// } }
4333 /// \endcode
4334 /// \version 12
4336
4337 /// If ``true``, a space will be inserted before a C++11 braced list
4338 /// used to initialize an object (after the preceding identifier or type).
4339 /// \code
4340 /// true: false:
4341 /// Foo foo { bar }; vs. Foo foo{ bar };
4342 /// Foo {}; Foo{};
4343 /// vector<int> { 1, 2, 3 }; vector<int>{ 1, 2, 3 };
4344 /// new int[3] { 1, 2, 3 }; new int[3]{ 1, 2, 3 };
4345 /// \endcode
4346 /// \version 7
4348
4349 /// If ``false``, spaces will be removed before constructor initializer
4350 /// colon.
4351 /// \code
4352 /// true: false:
4353 /// Foo::Foo() : a(a) {} Foo::Foo(): a(a) {}
4354 /// \endcode
4355 /// \version 7
4357
4358 /// If ``false``, spaces will be removed before inheritance colon.
4359 /// \code
4360 /// true: false:
4361 /// class Foo : Bar {} vs. class Foo: Bar {}
4362 /// \endcode
4363 /// \version 7
4365
4366 /// If ``true``, a space will be added before a JSON colon. For other
4367 /// languages, e.g. JavaScript, use ``SpacesInContainerLiterals`` instead.
4368 /// \code
4369 /// true: false:
4370 /// { {
4371 /// "key" : "value" vs. "key": "value"
4372 /// } }
4373 /// \endcode
4374 /// \version 17
4376
4377 /// Different ways to put a space before opening parentheses.
4379 /// This is **deprecated** and replaced by ``Custom`` below, with all
4380 /// ``SpaceBeforeParensOptions`` but ``AfterPlacementOperator`` set to
4381 /// ``false``.
4383 /// Put a space before opening parentheses only after control statement
4384 /// keywords (``for/if/while...``).
4385 /// \code
4386 /// void f() {
4387 /// if (true) {
4388 /// f();
4389 /// }
4390 /// }
4391 /// \endcode
4393 /// Same as ``SBPO_ControlStatements`` except this option doesn't apply to
4394 /// ForEach and If macros. This is useful in projects where ForEach/If
4395 /// macros are treated as function calls instead of control statements.
4396 /// ``SBPO_ControlStatementsExceptForEachMacros`` remains an alias for
4397 /// backward compatibility.
4398 /// \code
4399 /// void f() {
4400 /// Q_FOREACH(...) {
4401 /// f();
4402 /// }
4403 /// }
4404 /// \endcode
4406 /// Put a space before opening parentheses only if the parentheses are not
4407 /// empty.
4408 /// \code
4409 /// void() {
4410 /// if (true) {
4411 /// f();
4412 /// g (x, y, z);
4413 /// }
4414 /// }
4415 /// \endcode
4417 /// Always put a space before opening parentheses, except when it's
4418 /// prohibited by the syntax rules (in function-like macro definitions) or
4419 /// when determined by other style rules (after unary operators, opening
4420 /// parentheses, etc.)
4421 /// \code
4422 /// void f () {
4423 /// if (true) {
4424 /// f ();
4425 /// }
4426 /// }
4427 /// \endcode
4429 /// Configure each individual space before parentheses in
4430 /// ``SpaceBeforeParensOptions``.
4432 };
4433
4434 /// Defines in which cases to put a space before opening parentheses.
4435 /// \version 3.5
4437
4438 /// Precise control over the spacing before parentheses.
4439 /// \code
4440 /// # Should be declared this way:
4441 /// SpaceBeforeParens: Custom
4442 /// SpaceBeforeParensOptions:
4443 /// AfterControlStatements: true
4444 /// AfterFunctionDefinitionName: true
4445 /// \endcode
4447 /// If ``true``, put space between control statement keywords
4448 /// (for/if/while...) and opening parentheses.
4449 /// \code
4450 /// true: false:
4451 /// if (...) {} vs. if(...) {}
4452 /// \endcode
4454 /// If ``true``, put space between foreach macros and opening parentheses.
4455 /// \code
4456 /// true: false:
4457 /// FOREACH (...) vs. FOREACH(...)
4458 /// <loop-body> <loop-body>
4459 /// \endcode
4461 /// If ``true``, put a space between function declaration name and opening
4462 /// parentheses.
4463 /// \code
4464 /// true: false:
4465 /// void f (); vs. void f();
4466 /// \endcode
4468 /// If ``true``, put a space between function definition name and opening
4469 /// parentheses.
4470 /// \code
4471 /// true: false:
4472 /// void f () {} vs. void f() {}
4473 /// \endcode
4475 /// If ``true``, put space between if macros and opening parentheses.
4476 /// \code
4477 /// true: false:
4478 /// IF (...) vs. IF(...)
4479 /// <conditional-body> <conditional-body>
4480 /// \endcode
4482 /// If ``true``, put a space between operator overloading and opening
4483 /// parentheses.
4484 /// \code
4485 /// true: false:
4486 /// void operator++ (int a); vs. void operator++(int a);
4487 /// object.operator++ (10); object.operator++(10);
4488 /// \endcode
4490 /// If ``true``, put a space between operator ``new``/``delete`` and opening
4491 /// parenthesis.
4492 /// \code
4493 /// true: false:
4494 /// new (buf) T; vs. new(buf) T;
4495 /// delete (buf) T; delete(buf) T;
4496 /// \endcode
4498 /// If ``true``, put space between requires keyword in a requires clause and
4499 /// opening parentheses, if there is one.
4500 /// \code
4501 /// true: false:
4502 /// template<typename T> vs. template<typename T>
4503 /// requires (A<T> && B<T>) requires(A<T> && B<T>)
4504 /// ... ...
4505 /// \endcode
4507 /// If ``true``, put space between requires keyword in a requires expression
4508 /// and opening parentheses.
4509 /// \code
4510 /// true: false:
4511 /// template<typename T> vs. template<typename T>
4512 /// concept C = requires (T t) { concept C = requires(T t) {
4513 /// ... ...
4514 /// } }
4515 /// \endcode
4517 /// If ``true``, put a space before opening parentheses only if the
4518 /// parentheses are not empty.
4519 /// \code
4520 /// true: false:
4521 /// void f (int a); vs. void f();
4522 /// f (a); f();
4523 /// \endcode
4525
4533
4535 return AfterControlStatements == Other.AfterControlStatements &&
4536 AfterForeachMacros == Other.AfterForeachMacros &&
4538 Other.AfterFunctionDeclarationName &&
4539 AfterFunctionDefinitionName == Other.AfterFunctionDefinitionName &&
4540 AfterIfMacros == Other.AfterIfMacros &&
4541 AfterOverloadedOperator == Other.AfterOverloadedOperator &&
4542 AfterPlacementOperator == Other.AfterPlacementOperator &&
4543 AfterRequiresInClause == Other.AfterRequiresInClause &&
4544 AfterRequiresInExpression == Other.AfterRequiresInExpression &&
4545 BeforeNonEmptyParentheses == Other.BeforeNonEmptyParentheses;
4546 }
4547 };
4548
4549 /// Control of individual space before parentheses.
4550 ///
4551 /// If ``SpaceBeforeParens`` is set to ``Custom``, use this to specify
4552 /// how each individual space before parentheses case should be handled.
4553 /// Otherwise, this is ignored.
4554 /// \code{.yaml}
4555 /// # Example of usage:
4556 /// SpaceBeforeParens: Custom
4557 /// SpaceBeforeParensOptions:
4558 /// AfterControlStatements: true
4559 /// AfterFunctionDefinitionName: true
4560 /// \endcode
4561 /// \version 14
4563
4564 /// If ``true``, spaces will be before ``[``.
4565 /// Lambdas will not be affected. Only the first ``[`` will get a space added.
4566 /// \code
4567 /// true: false:
4568 /// int a [5]; vs. int a[5];
4569 /// int a [5][5]; vs. int a[5][5];
4570 /// \endcode
4571 /// \version 10
4573
4574 /// If ``false``, spaces will be removed before range-based for loop
4575 /// colon.
4576 /// \code
4577 /// true: false:
4578 /// for (auto v : values) {} vs. for(auto v: values) {}
4579 /// \endcode
4580 /// \version 7
4582
4583 /// If ``true``, spaces will be inserted into ``{}``.
4584 /// \code
4585 /// true: false:
4586 /// void f() { } vs. void f() {}
4587 /// while (true) { } while (true) {}
4588 /// \endcode
4589 /// \version 10
4591
4592 /// If ``true``, spaces may be inserted into ``()``.
4593 /// This option is **deprecated**. See ``InEmptyParentheses`` of
4594 /// ``SpacesInParensOptions``.
4595 /// \version 3.7
4596 // bool SpaceInEmptyParentheses;
4597
4598 /// The number of spaces before trailing line comments
4599 /// (``//`` - comments).
4600 ///
4601 /// This does not affect trailing block comments (``/*`` - comments) as those
4602 /// commonly have different usage patterns and a number of special cases. In
4603 /// the case of Verilog, it doesn't affect a comment right after the opening
4604 /// parenthesis in the port or parameter list in a module header, because it
4605 /// is probably for the port on the following line instead of the parenthesis
4606 /// it follows.
4607 /// \code
4608 /// SpacesBeforeTrailingComments: 3
4609 /// void f() {
4610 /// if (true) { // foo1
4611 /// f(); // bar
4612 /// } // foo
4613 /// }
4614 /// \endcode
4615 /// \version 3.7
4617
4618 /// Styles for adding spacing after ``<`` and before ``>``
4619 /// in template argument lists.
4620 enum SpacesInAnglesStyle : int8_t {
4621 /// Remove spaces after ``<`` and before ``>``.
4622 /// \code
4623 /// static_cast<int>(arg);
4624 /// std::function<void(int)> fct;
4625 /// \endcode
4627 /// Add spaces after ``<`` and before ``>``.
4628 /// \code
4629 /// static_cast< int >(arg);
4630 /// std::function< void(int) > fct;
4631 /// \endcode
4633 /// Keep a single space after ``<`` and before ``>`` if any spaces were
4634 /// present. Option ``Standard: Cpp03`` takes precedence.
4637 /// The SpacesInAnglesStyle to use for template argument lists.
4638 /// \version 3.4
4640
4641 /// If ``true``, spaces will be inserted around if/for/switch/while
4642 /// conditions.
4643 /// This option is **deprecated**. See ``InConditionalStatements`` of
4644 /// ``SpacesInParensOptions``.
4645 /// \version 10
4646 // bool SpacesInConditionalStatement;
4647
4648 /// If ``true``, spaces are inserted inside container literals (e.g. ObjC and
4649 /// Javascript array and dict literals). For JSON, use
4650 /// ``SpaceBeforeJsonColon`` instead.
4651 /// \code{.js}
4652 /// true: false:
4653 /// var arr = [ 1, 2, 3 ]; vs. var arr = [1, 2, 3];
4654 /// f({a : 1, b : 2, c : 3}); f({a: 1, b: 2, c: 3});
4655 /// \endcode
4656 /// \version 3.7
4658
4659 /// If ``true``, spaces may be inserted into C style casts.
4660 /// This option is **deprecated**. See ``InCStyleCasts`` of
4661 /// ``SpacesInParensOptions``.
4662 /// \version 3.7
4663 // bool SpacesInCStyleCastParentheses;
4664
4665 /// Control of spaces within a single line comment.
4667 /// The minimum number of spaces at the start of the comment.
4668 unsigned Minimum;
4669 /// The maximum number of spaces at the start of the comment.
4670 unsigned Maximum;
4671 };
4672
4673 /// How many spaces are allowed at the start of a line comment. To disable the
4674 /// maximum set it to ``-1``, apart from that the maximum takes precedence
4675 /// over the minimum.
4676 /// \code
4677 /// Minimum = 1
4678 /// Maximum = -1
4679 /// // One space is forced
4680 ///
4681 /// // but more spaces are possible
4682 ///
4683 /// Minimum = 0
4684 /// Maximum = 0
4685 /// //Forces to start every comment directly after the slashes
4686 /// \endcode
4687 ///
4688 /// Note that in line comment sections the relative indent of the subsequent
4689 /// lines is kept, that means the following:
4690 /// \code
4691 /// before: after:
4692 /// Minimum: 1
4693 /// //if (b) { // if (b) {
4694 /// // return true; // return true;
4695 /// //} // }
4696 ///
4697 /// Maximum: 0
4698 /// /// List: ///List:
4699 /// /// - Foo /// - Foo
4700 /// /// - Bar /// - Bar
4701 /// \endcode
4702 ///
4703 /// This option has only effect if ``ReflowComments`` is set to ``true``.
4704 /// \version 13
4706
4707 /// Different ways to put a space before opening and closing parentheses.
4708 enum SpacesInParensStyle : int8_t {
4709 /// Never put a space in parentheses.
4710 /// \code
4711 /// void f() {
4712 /// if(true) {
4713 /// f();
4714 /// }
4715 /// }
4716 /// \endcode
4718 /// Configure each individual space in parentheses in
4719 /// `SpacesInParensOptions`.
4721 };
4722
4723 /// If ``true``, spaces will be inserted after ``(`` and before ``)``.
4724 /// This option is **deprecated**. The previous behavior is preserved by using
4725 /// ``SpacesInParens`` with ``Custom`` and by setting all
4726 /// ``SpacesInParensOptions`` to ``true`` except for ``InCStyleCasts`` and
4727 /// ``InEmptyParentheses``.
4728 /// \version 3.7
4729 // bool SpacesInParentheses;
4730
4731 /// Defines in which cases spaces will be inserted after ``(`` and before
4732 /// ``)``.
4733 /// \version 17
4735
4736 /// Precise control over the spacing in parentheses.
4737 /// \code
4738 /// # Should be declared this way:
4739 /// SpacesInParens: Custom
4740 /// SpacesInParensOptions:
4741 /// ExceptDoubleParentheses: false
4742 /// InConditionalStatements: true
4743 /// Other: true
4744 /// \endcode
4746 /// Override any of the following options to prevent addition of space
4747 /// when both opening and closing parentheses use multiple parentheses.
4748 /// \code
4749 /// true:
4750 /// __attribute__(( noreturn ))
4751 /// __decltype__(( x ))
4752 /// if (( a = b ))
4753 /// \endcode
4754 /// false:
4755 /// Uses the applicable option.
4757 /// Put a space in parentheses only inside conditional statements
4758 /// (``for/if/while/switch...``).
4759 /// \code
4760 /// true: false:
4761 /// if ( a ) { ... } vs. if (a) { ... }
4762 /// while ( i < 5 ) { ... } while (i < 5) { ... }
4763 /// \endcode
4765 /// Put a space in C style casts.
4766 /// \code
4767 /// true: false:
4768 /// x = ( int32 )y vs. x = (int32)y
4769 /// y = (( int (*)(int) )foo)(x); y = ((int (*)(int))foo)(x);
4770 /// \endcode
4772 /// Insert a space in empty parentheses, i.e. ``()``.
4773 /// \code
4774 /// true: false:
4775 /// void f( ) { vs. void f() {
4776 /// int x[] = {foo( ), bar( )}; int x[] = {foo(), bar()};
4777 /// if (true) { if (true) {
4778 /// f( ); f();
4779 /// } }
4780 /// } }
4781 /// \endcode
4783 /// Put a space in parentheses not covered by preceding options.
4784 /// \code
4785 /// true: false:
4786 /// t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete;
4787 /// \endcode
4788 bool Other;
4789
4793
4796 bool InEmptyParentheses, bool Other)
4800 Other(Other) {}
4801
4802 bool operator==(const SpacesInParensCustom &R) const {
4807 }
4808 bool operator!=(const SpacesInParensCustom &R) const {
4809 return !(*this == R);
4810 }
4811 };
4812
4813 /// Control of individual spaces in parentheses.
4814 ///
4815 /// If ``SpacesInParens`` is set to ``Custom``, use this to specify
4816 /// how each individual space in parentheses case should be handled.
4817 /// Otherwise, this is ignored.
4818 /// \code{.yaml}
4819 /// # Example of usage:
4820 /// SpacesInParens: Custom
4821 /// SpacesInParensOptions:
4822 /// ExceptDoubleParentheses: false
4823 /// InConditionalStatements: true
4824 /// InEmptyParentheses: true
4825 /// \endcode
4826 /// \version 17
4828
4829 /// If ``true``, spaces will be inserted after ``[`` and before ``]``.
4830 /// Lambdas without arguments or unspecified size array declarations will not
4831 /// be affected.
4832 /// \code
4833 /// true: false:
4834 /// int a[ 5 ]; vs. int a[5];
4835 /// std::unique_ptr<int[]> foo() {} // Won't be affected
4836 /// \endcode
4837 /// \version 3.7
4839
4840 /// Supported language standards for parsing and formatting C++ constructs.
4841 /// \code
4842 /// Latest: vector<set<int>>
4843 /// c++03 vs. vector<set<int> >
4844 /// \endcode
4845 ///
4846 /// The correct way to spell a specific language version is e.g. ``c++11``.
4847 /// The historical aliases ``Cpp03`` and ``Cpp11`` are deprecated.
4848 enum LanguageStandard : int8_t {
4849 /// Parse and format as C++03.
4850 /// ``Cpp03`` is a deprecated alias for ``c++03``
4851 LS_Cpp03, // c++03
4852 /// Parse and format as C++11.
4853 LS_Cpp11, // c++11
4854 /// Parse and format as C++14.
4855 LS_Cpp14, // c++14
4856 /// Parse and format as C++17.
4857 LS_Cpp17, // c++17
4858 /// Parse and format as C++20.
4859 LS_Cpp20, // c++20
4860 /// Parse and format using the latest supported language version.
4861 /// ``Cpp11`` is a deprecated alias for ``Latest``
4863 /// Automatic detection based on the input.
4865 };
4866
4867 /// Parse and format C++ constructs compatible with this standard.
4868 /// \code
4869 /// c++03: latest:
4870 /// vector<set<int> > x; vs. vector<set<int>> x;
4871 /// \endcode
4872 /// \version 3.7
4874
4875 /// Macros which are ignored in front of a statement, as if they were an
4876 /// attribute. So that they are not parsed as identifier, for example for Qts
4877 /// emit.
4878 /// \code
4879 /// AlignConsecutiveDeclarations: true
4880 /// StatementAttributeLikeMacros: []
4881 /// unsigned char data = 'x';
4882 /// emit signal(data); // This is parsed as variable declaration.
4883 ///
4884 /// AlignConsecutiveDeclarations: true
4885 /// StatementAttributeLikeMacros: [emit]
4886 /// unsigned char data = 'x';
4887 /// emit signal(data); // Now it's fine again.
4888 /// \endcode
4889 /// \version 12
4890 std::vector<std::string> StatementAttributeLikeMacros;
4891
4892 /// A vector of macros that should be interpreted as complete
4893 /// statements.
4894 ///
4895 /// Typical macros are expressions, and require a semi-colon to be
4896 /// added; sometimes this is not the case, and this allows to make
4897 /// clang-format aware of such cases.
4898 ///
4899 /// For example: Q_UNUSED
4900 /// \version 8
4901 std::vector<std::string> StatementMacros;
4902
4903 /// Works only when TableGenBreakInsideDAGArg is not DontBreak.
4904 /// The string list needs to consist of identifiers in TableGen.
4905 /// If any identifier is specified, this limits the line breaks by
4906 /// TableGenBreakInsideDAGArg option only on DAGArg values beginning with
4907 /// the specified identifiers.
4908 ///
4909 /// For example the configuration,
4910 /// \code{.yaml}
4911 /// TableGenBreakInsideDAGArg: BreakAll
4912 /// TableGenBreakingDAGArgOperators: [ins, outs]
4913 /// \endcode
4914 ///
4915 /// makes the line break only occurs inside DAGArgs beginning with the
4916 /// specified identifiers ``ins`` and ``outs``.
4917 ///
4918 /// \code
4919 /// let DAGArgIns = (ins
4920 /// i32:$src1,
4921 /// i32:$src2
4922 /// );
4923 /// let DAGArgOtherID = (other i32:$other1, i32:$other2);
4924 /// let DAGArgBang = (!cast<SomeType>("Some") i32:$src1, i32:$src2)
4925 /// \endcode
4926 /// \version 19
4927 std::vector<std::string> TableGenBreakingDAGArgOperators;
4928
4929 /// Different ways to control the format inside TableGen DAGArg.
4930 enum DAGArgStyle : int8_t {
4931 /// Never break inside DAGArg.
4932 /// \code
4933 /// let DAGArgIns = (ins i32:$src1, i32:$src2);
4934 /// \endcode
4936 /// Break inside DAGArg after each list element but for the last.
4937 /// This aligns to the first element.
4938 /// \code
4939 /// let DAGArgIns = (ins i32:$src1,
4940 /// i32:$src2);
4941 /// \endcode
4943 /// Break inside DAGArg after the operator and the all elements.
4944 /// \code
4945 /// let DAGArgIns = (ins
4946 /// i32:$src1,
4947 /// i32:$src2
4948 /// );
4949 /// \endcode
4951 };
4952
4953 /// The styles of the line break inside the DAGArg in TableGen.
4954 /// \version 19
4956
4957 /// The number of columns used for tab stops.
4958 /// \version 3.7
4959 unsigned TabWidth;
4960
4961 /// A vector of non-keyword identifiers that should be interpreted as type
4962 /// names.
4963 ///
4964 /// A ``*``, ``&``, or ``&&`` between a type name and another non-keyword
4965 /// identifier is annotated as a pointer or reference token instead of a
4966 /// binary operator.
4967 ///
4968 /// \version 17
4969 std::vector<std::string> TypeNames;
4970
4971 /// \brief A vector of macros that should be interpreted as type declarations
4972 /// instead of as function calls.
4973 ///
4974 /// These are expected to be macros of the form:
4975 /// \code
4976 /// STACK_OF(...)
4977 /// \endcode
4978 ///
4979 /// In the .clang-format configuration file, this can be configured like:
4980 /// \code{.yaml}
4981 /// TypenameMacros: [STACK_OF, LIST]
4982 /// \endcode
4983 ///
4984 /// For example: OpenSSL STACK_OF, BSD LIST_ENTRY.
4985 /// \version 9
4986 std::vector<std::string> TypenameMacros;
4987
4988 /// This option is **deprecated**. See ``LF`` and ``CRLF`` of ``LineEnding``.
4989 /// \version 10
4990 // bool UseCRLF;
4991
4992 /// Different ways to use tab in formatting.
4993 enum UseTabStyle : int8_t {
4994 /// Never use tab.
4996 /// Use tabs only for indentation.
4998 /// Fill all leading whitespace with tabs, and use spaces for alignment that
4999 /// appears within a line (e.g. consecutive assignments and declarations).
5001 /// Use tabs for line continuation and indentation, and spaces for
5002 /// alignment.
5004 /// Use tabs whenever we need to fill whitespace that spans at least from
5005 /// one tab stop to the next one.
5006 UT_Always
5008
5009 /// The way to use tab characters in the resulting file.
5010 /// \version 3.7
5012
5013 /// For Verilog, put each port on its own line in module instantiations.
5014 /// \code
5015 /// true:
5016 /// ffnand ff1(.q(),
5017 /// .qbar(out1),
5018 /// .clear(in1),
5019 /// .preset(in2));
5020 ///
5021 /// false:
5022 /// ffnand ff1(.q(), .qbar(out1), .clear(in1), .preset(in2));
5023 /// \endcode
5024 /// \version 17
5026
5027 /// A vector of macros which are whitespace-sensitive and should not
5028 /// be touched.
5029 ///
5030 /// These are expected to be macros of the form:
5031 /// \code
5032 /// STRINGIZE(...)
5033 /// \endcode
5034 ///
5035 /// In the .clang-format configuration file, this can be configured like:
5036 /// \code{.yaml}
5037 /// WhitespaceSensitiveMacros: [STRINGIZE, PP_STRINGIZE]
5038 /// \endcode
5039 ///
5040 /// For example: BOOST_PP_STRINGIZE
5041 /// \version 11
5042 std::vector<std::string> WhitespaceSensitiveMacros;
5043
5044 bool operator==(const FormatStyle &R) const {
5093 BreakArrays == R.BreakArrays &&
5134 IndentWidth == R.IndentWidth &&
5211 Standard == R.Standard &&
5217 TabWidth == R.TabWidth && TypeNames == R.TypeNames &&
5222 }
5223
5224 std::optional<FormatStyle> GetLanguageStyle(LanguageKind Language) const;
5225
5226 // Stores per-language styles. A FormatStyle instance inside has an empty
5227 // StyleSet. A FormatStyle instance returned by the Get method has its
5228 // StyleSet set to a copy of the originating StyleSet, effectively keeping the
5229 // internal representation of that StyleSet alive.
5230 //
5231 // The memory management and ownership reminds of a birds nest: chicks
5232 // leaving the nest take photos of the nest with them.
5234 typedef std::map<FormatStyle::LanguageKind, FormatStyle> MapType;
5235
5236 std::optional<FormatStyle> Get(FormatStyle::LanguageKind Language) const;
5237
5238 // Adds \p Style to this FormatStyleSet. Style must not have an associated
5239 // FormatStyleSet.
5240 // Style.Language should be different than LK_None. If this FormatStyleSet
5241 // already contains an entry for Style.Language, that gets replaced with the
5242 // passed Style.
5243 void Add(FormatStyle Style);
5244
5245 // Clears this FormatStyleSet.
5246 void Clear();
5247
5248 private:
5249 std::shared_ptr<MapType> Styles;
5250 };
5251
5253 const FormatStyle &MainStyle,
5254 const std::vector<FormatStyle> &ConfigurationStyles);
5255
5256private:
5257 FormatStyleSet StyleSet;
5258
5259 friend std::error_code
5260 parseConfiguration(llvm::MemoryBufferRef Config, FormatStyle *Style,
5261 bool AllowUnknownOptions,
5262 llvm::SourceMgr::DiagHandlerTy DiagHandler,
5263 void *DiagHandlerCtxt);
5264};
5265
5266/// Returns a format style complying with the LLVM coding standards:
5267/// http://llvm.org/docs/CodingStandards.html.
5270
5271/// Returns a format style complying with one of Google's style guides:
5272/// http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml.
5273/// http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml.
5274/// https://developers.google.com/protocol-buffers/docs/style.
5276
5277/// Returns a format style complying with Chromium's style guide:
5278/// http://www.chromium.org/developers/coding-style.
5280
5281/// Returns a format style complying with Mozilla's style guide:
5282/// https://firefox-source-docs.mozilla.org/code-quality/coding-style/index.html.
5284
5285/// Returns a format style complying with Webkit's style guide:
5286/// http://www.webkit.org/coding/coding-style.html
5288
5289/// Returns a format style complying with GNU Coding Standards:
5290/// http://www.gnu.org/prep/standards/standards.html
5292
5293/// Returns a format style complying with Microsoft style guide:
5294/// https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017
5296
5298
5299/// Returns style indicating formatting should be not applied at all.
5301
5302/// Gets a predefined style for the specified language by name.
5303///
5304/// Currently supported names: LLVM, Google, Chromium, Mozilla. Names are
5305/// compared case-insensitively.
5306///
5307/// Returns ``true`` if the Style has been set.
5309 FormatStyle *Style);
5310
5311/// Parse configuration from YAML-formatted text.
5312///
5313/// Style->Language is used to get the base style, if the ``BasedOnStyle``
5314/// option is present.
5315///
5316/// The FormatStyleSet of Style is reset.
5317///
5318/// When ``BasedOnStyle`` is not present, options not present in the YAML
5319/// document, are retained in \p Style.
5320///
5321/// If AllowUnknownOptions is true, no errors are emitted if unknown
5322/// format options are occurred.
5323///
5324/// If set all diagnostics are emitted through the DiagHandler.
5325std::error_code
5326parseConfiguration(llvm::MemoryBufferRef Config, FormatStyle *Style,
5327 bool AllowUnknownOptions = false,
5328 llvm::SourceMgr::DiagHandlerTy DiagHandler = nullptr,
5329 void *DiagHandlerCtx = nullptr);
5330
5331/// Like above but accepts an unnamed buffer.
5332inline std::error_code parseConfiguration(StringRef Config, FormatStyle *Style,
5333 bool AllowUnknownOptions = false) {
5334 return parseConfiguration(llvm::MemoryBufferRef(Config, "YAML"), Style,
5335 AllowUnknownOptions);
5336}
5337
5338/// Gets configuration in a YAML string.
5339std::string configurationAsText(const FormatStyle &Style);
5340
5341/// Returns the replacements necessary to sort all ``#include`` blocks
5342/// that are affected by ``Ranges``.
5343tooling::Replacements sortIncludes(const FormatStyle &Style, StringRef Code,
5345 StringRef FileName,
5346 unsigned *Cursor = nullptr);
5347
5348/// Returns the replacements corresponding to applying and formatting
5349/// \p Replaces on success; otheriwse, return an llvm::Error carrying
5350/// llvm::StringError.
5352formatReplacements(StringRef Code, const tooling::Replacements &Replaces,
5353 const FormatStyle &Style);
5354
5355/// Returns the replacements corresponding to applying \p Replaces and
5356/// cleaning up the code after that on success; otherwise, return an llvm::Error
5357/// carrying llvm::StringError.
5358/// This also supports inserting/deleting C++ #include directives:
5359/// - If a replacement has offset UINT_MAX, length 0, and a replacement text
5360/// that is an #include directive, this will insert the #include into the
5361/// correct block in the \p Code.
5362/// - If a replacement has offset UINT_MAX, length 1, and a replacement text
5363/// that is the name of the header to be removed, the header will be removed
5364/// from \p Code if it exists.
5365/// The include manipulation is done via ``tooling::HeaderInclude``, see its
5366/// documentation for more details on how include insertion points are found and
5367/// what edits are produced.
5369cleanupAroundReplacements(StringRef Code, const tooling::Replacements &Replaces,
5370 const FormatStyle &Style);
5371
5372/// Represents the status of a formatting attempt.
5374 /// A value of ``false`` means that any of the affected ranges were not
5375 /// formatted due to a non-recoverable syntax error.
5376 bool FormatComplete = true;
5377
5378 /// If ``FormatComplete`` is false, ``Line`` records a one-based
5379 /// original line number at which a syntax error might have occurred. This is
5380 /// based on a best-effort analysis and could be imprecise.
5381 unsigned Line = 0;
5382};
5383
5384/// Reformats the given \p Ranges in \p Code.
5385///
5386/// Each range is extended on either end to its next bigger logic unit, i.e.
5387/// everything that might influence its formatting or might be influenced by its
5388/// formatting.
5389///
5390/// Returns the ``Replacements`` necessary to make all \p Ranges comply with
5391/// \p Style.
5392///
5393/// If ``Status`` is non-null, its value will be populated with the status of
5394/// this formatting attempt. See \c FormattingAttemptStatus.
5395tooling::Replacements reformat(const FormatStyle &Style, StringRef Code,
5397 StringRef FileName = "<stdin>",
5398 FormattingAttemptStatus *Status = nullptr);
5399
5400/// Same as above, except if ``IncompleteFormat`` is non-null, its value
5401/// will be set to true if any of the affected ranges were not formatted due to
5402/// a non-recoverable syntax error.
5403tooling::Replacements reformat(const FormatStyle &Style, StringRef Code,
5405 StringRef FileName, bool *IncompleteFormat);
5406
5407/// Clean up any erroneous/redundant code in the given \p Ranges in \p
5408/// Code.
5409///
5410/// Returns the ``Replacements`` that clean up all \p Ranges in \p Code.
5411tooling::Replacements cleanup(const FormatStyle &Style, StringRef Code,
5413 StringRef FileName = "<stdin>");
5414
5415/// Fix namespace end comments in the given \p Ranges in \p Code.
5416///
5417/// Returns the ``Replacements`` that fix the namespace comments in all
5418/// \p Ranges in \p Code.
5420 StringRef Code,
5422 StringRef FileName = "<stdin>");
5423
5424/// Inserts or removes empty lines separating definition blocks including
5425/// classes, structs, functions, namespaces, and enums in the given \p Ranges in
5426/// \p Code.
5427///
5428/// Returns the ``Replacements`` that inserts or removes empty lines separating
5429/// definition blocks in all \p Ranges in \p Code.
5431 StringRef Code,
5433 StringRef FileName = "<stdin>");
5434
5435/// Sort consecutive using declarations in the given \p Ranges in
5436/// \p Code.
5437///
5438/// Returns the ``Replacements`` that sort the using declarations in all
5439/// \p Ranges in \p Code.
5441 StringRef Code,
5443 StringRef FileName = "<stdin>");
5444
5445/// Returns the ``LangOpts`` that the formatter expects you to set.
5446///
5447/// \param Style determines specific settings for lexing mode.
5449
5450/// Description to be used for help text for a ``llvm::cl`` option for
5451/// specifying format style. The description is closely related to the operation
5452/// of ``getStyle()``.
5453extern const char *StyleOptionHelpDescription;
5454
5455/// The suggested format style to use by default. This allows tools using
5456/// ``getStyle`` to have a consistent default style.
5457/// Different builds can modify the value to the preferred styles.
5458extern const char *DefaultFormatStyle;
5459
5460/// The suggested predefined style to use as the fallback style in ``getStyle``.
5461/// Different builds can modify the value to the preferred styles.
5462extern const char *DefaultFallbackStyle;
5463
5464/// Construct a FormatStyle based on ``StyleName``.
5465///
5466/// ``StyleName`` can take several forms:
5467/// * "{<key>: <value>, ...}" - Set specic style parameters.
5468/// * "<style name>" - One of the style names supported by
5469/// getPredefinedStyle().
5470/// * "file" - Load style configuration from a file called ``.clang-format``
5471/// located in one of the parent directories of ``FileName`` or the current
5472/// directory if ``FileName`` is empty.
5473/// * "file:<format_file_path>" to explicitly specify the configuration file to
5474/// use.
5475///
5476/// \param[in] StyleName Style name to interpret according to the description
5477/// above.
5478/// \param[in] FileName Path to start search for .clang-format if ``StyleName``
5479/// == "file".
5480/// \param[in] FallbackStyle The name of a predefined style used to fallback to
5481/// in case \p StyleName is "file" and no file can be found.
5482/// \param[in] Code The actual code to be formatted. Used to determine the
5483/// language if the filename isn't sufficient.
5484/// \param[in] FS The underlying file system, in which the file resides. By
5485/// default, the file system is the real file system.
5486/// \param[in] AllowUnknownOptions If true, unknown format options only
5487/// emit a warning. If false, errors are emitted on unknown format
5488/// options.
5489///
5490/// \returns FormatStyle as specified by ``StyleName``. If ``StyleName`` is
5491/// "file" and no file is found, returns ``FallbackStyle``. If no style could be
5492/// determined, returns an Error.
5494getStyle(StringRef StyleName, StringRef FileName, StringRef FallbackStyle,
5495 StringRef Code = "", llvm::vfs::FileSystem *FS = nullptr,
5496 bool AllowUnknownOptions = false,
5497 llvm::SourceMgr::DiagHandlerTy DiagHandler = nullptr);
5498
5499// Guesses the language from the ``FileName`` and ``Code`` to be formatted.
5500// Defaults to FormatStyle::LK_Cpp.
5501FormatStyle::LanguageKind guessLanguage(StringRef FileName, StringRef Code);
5502
5503// Returns a string representation of ``Language``.
5505 switch (Language) {
5507 return "C++";
5509 return "CSharp";
5511 return "Objective-C";
5513 return "Java";
5515 return "JavaScript";
5517 return "Json";
5519 return "Proto";
5521 return "TableGen";
5523 return "TextProto";
5525 return "Verilog";
5526 default:
5527 return "Unknown";
5528 }
5529}
5530
5531bool isClangFormatOn(StringRef Comment);
5532bool isClangFormatOff(StringRef Comment);
5533
5534} // end namespace format
5535} // end namespace clang
5536
5537template <>
5538struct std::is_error_code_enum<clang::format::ParseError> : std::true_type {};
5539
5540#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:476
const char * name() const noexcept override
Definition: Format.cpp:1266
std::string message(int EV) const override
Definition: Format.cpp:1270
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:3902
const char * DefaultFallbackStyle
The suggested predefined style to use as the fallback style in getStyle.
Definition: Format.cpp:3977
FormatStyle getWebKitStyle()
Returns a format style complying with Webkit's style guide: http://www.webkit.org/coding/coding-style...
Definition: Format.cpp:1873
std::error_code make_error_code(ParseError e)
Definition: Format.cpp:1257
FormatStyle getClangFormatStyle()
Definition: Format.cpp:1940
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:1424
FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language)
Returns a format style complying with one of Google's style guides: http://google-styleguide....
Definition: Format.cpp:1645
std::string configurationAsText(const FormatStyle &Style)
Gets configuration in a YAML string.
Definition: Format.cpp:2088
FormatStyle getMicrosoftStyle(FormatStyle::LanguageKind Language)
Returns a format style complying with Microsoft style guide: https://docs.microsoft....
Definition: Format.cpp:1911
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:2022
const std::error_category & getParseCategory()
Definition: Format.cpp:1253
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:3853
FormatStyle::LanguageKind guessLanguage(StringRef FileName, StringRef Code)
Definition: Format.cpp:3956
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:3994
const char * DefaultFormatStyle
The suggested format style to use by default.
Definition: Format.cpp:3975
FormatStyle getGNUStyle()
Returns a format style complying with GNU Coding Standards: http://www.gnu.org/prep/standards/standar...
Definition: Format.cpp:1897
bool isClangFormatOff(StringRef Comment)
Definition: Format.cpp:4177
LangOptions getFormattingLangOpts(const FormatStyle &Style=getLLVMStyle())
Returns the LangOpts that the formatter expects you to set.
Definition: Format.cpp:3873
FormatStyle getMozillaStyle()
Returns a format style complying with Mozilla's style guide: https://firefox-source-docs....
Definition: Format.cpp:1847
bool getPredefinedStyle(StringRef Name, FormatStyle::LanguageKind Language, FormatStyle *Style)
Gets a predefined style for the specified language by name.
Definition: Format.cpp:1961
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:3617
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:3820
bool isClangFormatOn(StringRef Comment)
Definition: Format.cpp:4173
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:3863
FormatStyle getChromiumStyle(FormatStyle::LanguageKind Language)
Returns a format style complying with Chromium's style guide: http://www.chromium....
Definition: Format.cpp:1787
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:3831
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:3507
FormatStyle getNoStyle()
Returns style indicating formatting should be not applied at all.
Definition: Format.cpp:1953
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:3466
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:5504
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:5234
std::optional< FormatStyle > Get(FormatStyle::LanguageKind Language) const
Definition: Format.cpp:2104
Separator format of integer literals of different bases.
Definition: Format.h:2996
int8_t BinaryMinDigits
Format separators in binary literals with a minimum number of digits.
Definition: Format.h:3012
bool operator==(const IntegerLiteralSeparatorStyle &R) const
Definition: Format.h:3044
int8_t Binary
Format separators in binary literals.
Definition: Format.h:3004
int8_t DecimalMinDigits
Format separators in decimal literals with a minimum number of digits.
Definition: Format.h:3027
int8_t Decimal
Format separators in decimal literals.
Definition: Format.h:3019
int8_t HexMinDigits
Format separators in hexadecimal literals with a minimum number of digits.
Definition: Format.h:3043
int8_t Hex
Format separators in hexadecimal literals.
Definition: Format.h:3034
Options regarding which empty lines are kept.
Definition: Format.h:3145
bool AtStartOfFile
Keep empty lines at start of file.
Definition: Format.h:3158
bool AtEndOfFile
Keep empty lines at end of file.
Definition: Format.h:3147
bool operator==(const KeepEmptyLinesStyle &R) const
Definition: Format.h:3159
bool AtStartOfBlock
Keep empty lines at start of a block.
Definition: Format.h:3156
See documentation of RawStringFormats.
Definition: Format.h:3732
std::string CanonicalDelimiter
The canonical delimiter for this language.
Definition: Format.h:3740
LanguageKind Language
The language of this raw string.
Definition: Format.h:3734
std::string BasedOnStyle
The style name on which this raw string format is based on.
Definition: Format.h:3744
std::vector< std::string > EnclosingFunctions
A list of enclosing function names that match this language.
Definition: Format.h:3738
bool operator==(const RawStringFormat &Other) const
Definition: Format.h:3745
std::vector< std::string > Delimiters
A list of raw string delimiters that match this language.
Definition: Format.h:3736
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:4446
bool AfterControlStatements
If true, put space between control statement keywords (for/if/while...) and opening parentheses.
Definition: Format.h:4453
bool AfterOverloadedOperator
If true, put a space between operator overloading and opening parentheses.
Definition: Format.h:4489
bool AfterRequiresInExpression
If true, put space between requires keyword in a requires expression and opening parentheses.
Definition: Format.h:4516
bool AfterFunctionDeclarationName
If true, put a space between function declaration name and opening parentheses.
Definition: Format.h:4467
bool AfterRequiresInClause
If true, put space between requires keyword in a requires clause and opening parentheses,...
Definition: Format.h:4506
bool AfterForeachMacros
If true, put space between foreach macros and opening parentheses.
Definition: Format.h:4460
bool AfterFunctionDefinitionName
If true, put a space between function definition name and opening parentheses.
Definition: Format.h:4474
bool BeforeNonEmptyParentheses
If true, put a space before opening parentheses only if the parentheses are not empty.
Definition: Format.h:4524
bool operator==(const SpaceBeforeParensCustom &Other) const
Definition: Format.h:4534
bool AfterIfMacros
If true, put space between if macros and opening parentheses.
Definition: Format.h:4481
bool AfterPlacementOperator
If true, put a space between operator new/delete and opening parenthesis.
Definition: Format.h:4497
If true, spaces may be inserted into C style casts.
Definition: Format.h:4666
unsigned Maximum
The maximum number of spaces at the start of the comment.
Definition: Format.h:4670
unsigned Minimum
The minimum number of spaces at the start of the comment.
Definition: Format.h:4668
Precise control over the spacing in parentheses.
Definition: Format.h:4745
bool operator==(const SpacesInParensCustom &R) const
Definition: Format.h:4802
bool ExceptDoubleParentheses
Override any of the following options to prevent addition of space when both opening and closing pare...
Definition: Format.h:4756
bool Other
Put a space in parentheses not covered by preceding options.
Definition: Format.h:4788
bool InEmptyParentheses
Insert a space in empty parentheses, i.e.
Definition: Format.h:4782
bool InCStyleCasts
Put a space in C style casts.
Definition: Format.h:4771
bool operator!=(const SpacesInParensCustom &R) const
Definition: Format.h:4808
bool InConditionalStatements
Put a space in parentheses only inside conditional statements (for/if/while/switch....
Definition: Format.h:4764
SpacesInParensCustom(bool ExceptDoubleParentheses, bool InConditionalStatements, bool InCStyleCasts, bool InEmptyParentheses, bool Other)
Definition: Format.h:4794
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:4993
@ UT_AlignWithSpaces
Use tabs for line continuation and indentation, and spaces for alignment.
Definition: Format.h:5003
@ UT_ForContinuationAndIndentation
Fill all leading whitespace with tabs, and use spaces for alignment that appears within a line (e....
Definition: Format.h:5000
@ UT_ForIndentation
Use tabs only for indentation.
Definition: Format.h:4997
@ 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:5006
@ UT_Never
Never use tab.
Definition: Format.h:4995
bool SpaceBeforeInheritanceColon
If false, spaces will be removed before inheritance colon.
Definition: Format.h:4364
unsigned ContinuationIndentWidth
Indent width for line continuations.
Definition: Format.h:2471
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:4873
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:3253
LanguageKind
Supported languages.
Definition: Format.h:3217
@ LK_CSharp
Should be used for C#.
Definition: Format.h:3223
@ LK_None
Do not use.
Definition: Format.h:3219
@ LK_Java
Should be used for Java.
Definition: Format.h:3225
@ LK_Cpp
Should be used for C, C++.
Definition: Format.h:3221
@ LK_JavaScript
Should be used for JavaScript.
Definition: Format.h:3227
@ LK_ObjC
Should be used for Objective-C, Objective-C++.
Definition: Format.h:3231
@ LK_Verilog
Should be used for Verilog and SystemVerilog.
Definition: Format.h:3243
@ LK_TableGen
Should be used for TableGen code.
Definition: Format.h:3236
@ LK_Proto
Should be used for Protocol Buffers (https://developers.google.com/protocol-buffers/).
Definition: Format.h:3234
@ LK_Json
Should be used for JSON.
Definition: Format.h:3229
@ LK_TextProto
Should be used for Protocol Buffer messages in text format (https://developers.google....
Definition: Format.h:3239
bool Cpp11BracedListStyle
If true, format braced lists as best suited for C++11 braced lists.
Definition: Format.h:2494
SortIncludesOptions SortIncludes
Controls if and how clang-format will sort #includes.
Definition: Format.h:4191
BreakInheritanceListStyle BreakInheritanceList
The inheritance list style to use.
Definition: Format.h:2422
unsigned IndentWidth
The number of columns to use for indentation.
Definition: Format.h:2895
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:4075
@ SDS_Never
Remove any empty line between definition blocks.
Definition: Format.h:4081
@ SDS_Always
Insert an empty line between definition blocks.
Definition: Format.h:4079
@ SDS_Leave
Leave definition blocks as they are.
Definition: Format.h:4077
bool IndentRequiresClause
Indent the requires clause in a template.
Definition: Format.h:2881
SpacesInAnglesStyle SpacesInAngles
The SpacesInAnglesStyle to use for template argument lists.
Definition: Format.h:4639
bool IndentCaseLabels
Indent case labels one level from the switch statement.
Definition: Format.h:2766
std::vector< RawStringFormat > RawStringFormats
Defines hints for detecting supported languages code blocks in raw strings.
Definition: Format.h:3789
SortJavaStaticImportOptions
Position for Java Static imports.
Definition: Format.h:4194
@ SJSIO_Before
Static imports are placed before non-static imports.
Definition: Format.h:4201
@ SJSIO_After
Static imports are placed after non-static imports.
Definition: Format.h:4208
PPDirectiveIndentStyle IndentPPDirectives
The preprocessor directive indenting style to use.
Definition: Format.h:2858
bool RemoveSemicolon
Remove semicolons after the closing braces of functions and constructors/destructors.
Definition: Format.h:3942
std::vector< std::string > Macros
A list of macros of the form <definition>=<expansion> .
Definition: Format.h:3346
bool SpaceBeforeJsonColon
If true, a space will be added before a JSON colon.
Definition: Format.h:4375
TrailingCommaStyle
The style of inserting trailing commas into container literals.
Definition: Format.h:2948
@ TCS_Wrapped
Insert trailing commas in container literals that were wrapped over multiple lines.
Definition: Format.h:2956
@ TCS_None
Do not insert trailing commas.
Definition: Format.h:2950
unsigned PenaltyBreakBeforeFirstCallParameter
The penalty for breaking a function call after call(.
Definition: Format.h:3582
bool SpaceBeforeCtorInitializerColon
If false, spaces will be removed before constructor initializer colon.
Definition: Format.h:4356
BinaryOperatorStyle BreakBeforeBinaryOperators
The way to wrap binary operators.
Definition: Format.h:1729
SortIncludesOptions
Include sorting options.
Definition: Format.h:4159
@ SI_Never
Includes are never sorted.
Definition: Format.h:4168
@ SI_CaseSensitive
Includes are sorted in an ASCIIbetical or case sensitive fashion.
Definition: Format.h:4177
@ SI_CaseInsensitive
Includes are sorted in an alphabetical or case insensitive fashion.
Definition: Format.h:4186
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:2565
@ ELBAMS_LogicalBlock
Add empty line only when access modifier starts a new logical block.
Definition: Format.h:2600
@ ELBAMS_Never
Remove all empty lines before access modifiers.
Definition: Format.h:2580
@ ELBAMS_Always
Always add empty line before access modifiers unless access modifier is at the start of struct or cla...
Definition: Format.h:2620
@ ELBAMS_Leave
Keep existing empty lines before access modifiers.
Definition: Format.h:2582
unsigned SpacesBeforeTrailingComments
If true, spaces may be inserted into ().
Definition: Format.h:4616
BreakConstructorInitializersStyle
Different ways to break initializers.
Definition: Format.h:2270
@ BCIS_AfterColon
Break constructor initializers after the colon and commas.
Definition: Format.h:2292
@ BCIS_BeforeColon
Break constructor initializers before the colon and after the commas.
Definition: Format.h:2277
@ BCIS_BeforeComma
Break constructor initializers before the colon and commas, and align the commas with the colon.
Definition: Format.h:2285
IndentExternBlockStyle
Indents extern blocks.
Definition: Format.h:2786
@ IEBS_AfterExternBlock
Backwards compatible with AfterExternBlock's indenting.
Definition: Format.h:2804
@ IEBS_Indent
Indents extern blocks.
Definition: Format.h:2818
@ IEBS_NoIndent
Does not indent extern blocks.
Definition: Format.h:2811
bool IndentCaseBlocks
Indent case label blocks one level from the case label.
Definition: Format.h:2747
bool InsertBraces
Insert braces after control statements (if, else, for, do, and while) in C++ unless the control state...
Definition: Format.h:2941
BreakBeforeConceptDeclarationsStyle BreakBeforeConceptDeclarations
The concept declaration style to use.
Definition: Format.h:2188
BreakTemplateDeclarationsStyle BreakTemplateDeclarations
The template declaration breaking style to use.
Definition: Format.h:2426
bool DerivePointerAlignment
This option is deprecated.
Definition: Format.h:2507
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:3260
@ LE_DeriveLF
Use \n unless the input has more lines ending in \r\n.
Definition: Format.h:3266
@ LE_DeriveCRLF
Use \r\n unless the input has more lines ending in \n.
Definition: Format.h:3268
bool SpacesInSquareBrackets
If true, spaces will be inserted after [ and before ].
Definition: Format.h:4838
bool IndentWrappedFunctionNames
Indent if a function definition or declaration is wrapped after the type.
Definition: Format.h:2909
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:2656
bool ObjCSpaceBeforeProtocolList
Add a space in front of an Objective-C protocol list, i.e.
Definition: Format.h:3512
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:3924
std::string MacroBlockBegin
A regular expression matching macros that start a block.
Definition: Format.h:3302
bool SpaceInEmptyBlock
If true, spaces will be inserted into {}.
Definition: Format.h:4590
LanguageKind Language
Language, this format style is targeted at.
Definition: Format.h:3257
SpacesInParensStyle
Different ways to put a space before opening and closing parentheses.
Definition: Format.h:4708
@ SIPO_Custom
Configure each individual space in parentheses in SpacesInParensOptions.
Definition: Format.h:4720
@ SIPO_Never
Never put a space in parentheses.
Definition: Format.h:4717
bool RemoveBracesLLVM
Remove optional braces of control statements (if, else, for, and while) in C++ according to the LLVM ...
Definition: Format.h:3888
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:5025
unsigned TabWidth
The number of columns used for tab stops.
Definition: Format.h:4959
PPDirectiveIndentStyle
Options for indenting preprocessor directives.
Definition: Format.h:2826
@ PPDIS_BeforeHash
Indents directives before the hash.
Definition: Format.h:2853
@ PPDIS_None
Does not indent any directives.
Definition: Format.h:2835
@ PPDIS_AfterHash
Indents directives after the hash.
Definition: Format.h:2844
LambdaBodyIndentationKind
This option is deprecated.
Definition: Format.h:3179
@ LBI_OuterScope
For statements within block scope, align lambda body relative to the indentation level of the outer s...
Definition: Format.h:3201
@ LBI_Signature
Align lambda body relative to the lambda signature.
Definition: Format.h:3187
std::vector< std::string > JavaImportGroups
A vector of prefixes ordered by the desired groups for Java imports.
Definition: Format.h:3088
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:3590
std::vector< std::string > StatementAttributeLikeMacros
Macros which are ignored in front of a statement, as if they were an attribute.
Definition: Format.h:4890
unsigned ObjCBlockIndentWidth
The number of characters to use for indentation of ObjC blocks.
Definition: Format.h:3455
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:3729
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:2129
std::vector< std::string > IfMacros
A vector of macros that should be interpreted as conditionals instead of as function calls.
Definition: Format.h:2697
NamespaceIndentationKind NamespaceIndentation
The indentation used for namespaces.
Definition: Format.h:3398
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:2321
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:3502
bool ExperimentalAutoDetectBinPacking
If true, clang-format detects whether function calls and definitions are formatted with one parameter...
Definition: Format.h:2640
bool ObjCBreakBeforeNestedBlockParam
Break parameters list into lines when there is nested block parameters in a function call.
Definition: Format.h:3479
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:3594
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:2022
SpacesInParensStyle SpacesInParens
If true, spaces will be inserted after ( and before ).
Definition: Format.h:4734
SpacesInParensCustom SpacesInParensOptions
Control of individual spaces in parentheses.
Definition: Format.h:4827
std::vector< std::string > ForEachMacros
A vector of macros that should be interpreted as foreach loops instead of as function calls.
Definition: Format.h:2674
ReferenceAlignmentStyle ReferenceAlignment
Reference alignment style (overrides PointerAlignment for references).
Definition: Format.h:3815
BreakBinaryOperationsStyle BreakBinaryOperations
The break constructor initializers style to use.
Definition: Format.h:2267
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:2975
unsigned PenaltyBreakTemplateDeclaration
The penalty for breaking after template declaration.
Definition: Format.h:3606
SpaceBeforeParensCustom SpaceBeforeParensOptions
Control of individual space before parentheses.
Definition: Format.h:4562
BreakConstructorInitializersStyle BreakConstructorInitializers
The break constructor initializers style to use.
Definition: Format.h:2297
bool BreakStringLiterals
Allow breaking string literals when formatting.
Definition: Format.h:2364
bool SpaceAfterLogicalNot
If true, a space is inserted after the logical not operator (!).
Definition: Format.h:4275
SpaceBeforeParensStyle
Different ways to put a space before opening parentheses.
Definition: Format.h:4378
@ SBPO_Never
This is deprecated and replaced by Custom below, with all SpaceBeforeParensOptions but AfterPlacement...
Definition: Format.h:4382
@ SBPO_Custom
Configure each individual space before parentheses in SpaceBeforeParensOptions.
Definition: Format.h:4431
@ SBPO_NonEmptyParentheses
Put a space before opening parentheses only if the parentheses are not empty.
Definition: Format.h:4416
@ SBPO_ControlStatementsExceptControlMacros
Same as SBPO_ControlStatements except this option doesn't apply to ForEach and If macros.
Definition: Format.h:4405
@ SBPO_ControlStatements
Put a space before opening parentheses only after control statement keywords (for/if/while....
Definition: Format.h:4392
@ SBPO_Always
Always put a space before opening parentheses, except when it's prohibited by the syntax rules (in fu...
Definition: Format.h:4428
PackConstructorInitializersStyle
Different ways to try to fit all constructor initializers on a line.
Definition: Format.h:3515
@ PCIS_NextLineOnly
Put all constructor initializers on the next line if they fit.
Definition: Format.h:3569
@ PCIS_Never
Always put each constructor initializer on its own line.
Definition: Format.h:3522
@ PCIS_CurrentLine
Put all constructor initializers on the current line if they fit.
Definition: Format.h:3540
@ PCIS_BinPack
Bin-pack constructor initializers.
Definition: Format.h:3529
@ PCIS_NextLine
Same as PCIS_CurrentLine except that if all constructor initializers do not fit on the current line,...
Definition: Format.h:3554
std::vector< std::string > TypeNames
A vector of non-keyword identifiers that should be interpreted as type names.
Definition: Format.h:4969
bool ObjCSpaceAfterProperty
Add a space after @property in Objective-C, i.e.
Definition: Format.h:3507
BraceBreakingStyle BreakBeforeBraces
The brace breaking style to use.
Definition: Format.h:2164
BreakInheritanceListStyle
Different ways to break inheritance list.
Definition: Format.h:2385
@ BILS_AfterColon
Break inheritance list after the colon and commas.
Definition: Format.h:2410
@ BILS_AfterComma
Break inheritance list only after the commas.
Definition: Format.h:2417
@ BILS_BeforeColon
Break inheritance list before the colon and after the commas.
Definition: Format.h:2393
@ BILS_BeforeComma
Break inheritance list before the colon and commas, and align the commas with the colon.
Definition: Format.h:2402
bool isCSharp() const
Definition: Format.h:3246
unsigned PenaltyExcessCharacter
The penalty for each character outside of the column limit.
Definition: Format.h:3610
std::vector< std::string > WhitespaceSensitiveMacros
A vector of macros which are whitespace-sensitive and should not be touched.
Definition: Format.h:5042
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:4930
@ DAS_BreakElements
Break inside DAGArg after each list element but for the last.
Definition: Format.h:4942
@ DAS_DontBreak
Never break inside DAGArg.
Definition: Format.h:4935
@ DAS_BreakAll
Break inside DAGArg after the operator and the all elements.
Definition: Format.h:4950
unsigned ConstructorInitializerIndentWidth
This option is deprecated.
Definition: Format.h:2460
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:2450
RequiresClausePositionStyle
The possible positions for the requires clause.
Definition: Format.h:3947
@ RCPS_OwnLineWithBrace
As with OwnLine, except, unless otherwise prohibited, place a following open brace (of a function def...
Definition: Format.h:3986
@ RCPS_OwnLine
Always put the requires clause on its own line (possibly followed by a semicolon).
Definition: Format.h:3968
@ RCPS_WithPreceding
Try to put the clause together with the preceding part of a declaration.
Definition: Format.h:4003
@ RCPS_SingleLine
Try to put everything in the same line if possible.
Definition: Format.h:4041
@ RCPS_WithFollowing
Try to put the requires clause together with the class or function declaration.
Definition: Format.h:4017
bool operator==(const FormatStyle &R) const
Definition: Format.h:5044
LanguageStandard
Supported language standards for parsing and formatting C++ constructs.
Definition: Format.h:4848
@ LS_Cpp17
Parse and format as C++17.
Definition: Format.h:4857
@ LS_Latest
Parse and format using the latest supported language version.
Definition: Format.h:4862
@ LS_Cpp11
Parse and format as C++11.
Definition: Format.h:4853
@ LS_Auto
Automatic detection based on the input.
Definition: Format.h:4864
@ LS_Cpp03
Parse and format as C++03.
Definition: Format.h:4851
@ LS_Cpp14
Parse and format as C++14.
Definition: Format.h:4855
@ LS_Cpp20
Parse and format as C++20.
Definition: Format.h:4859
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:4046
JavaScriptQuoteStyle
Quotation styles for JavaScript strings.
Definition: Format.h:3092
@ JSQS_Double
Always use double quotes.
Definition: Format.h:3110
@ JSQS_Single
Always use single quotes.
Definition: Format.h:3104
@ JSQS_Leave
Leave string quotes as they are.
Definition: Format.h:3098
bool SpaceAfterCStyleCast
If true, a space is inserted after C style casts.
Definition: Format.h:4267
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:3657
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:3054
SpaceAroundPointerQualifiersStyle SpaceAroundPointerQualifiers
Defines in which cases to put a space before or after pointer qualifiers.
Definition: Format.h:4316
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:4325
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:3598
unsigned PenaltyReturnTypeOnItsOwnLine
Penalty for putting the return type of a function onto its own line.
Definition: Format.h:3619
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:3642
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:2311
RequiresExpressionIndentationKind
Indentation logic for requires expression bodies.
Definition: Format.h:4049
@ REI_Keyword
Align requires expression body relative to the requires keyword.
Definition: Format.h:4067
@ REI_OuterScope
Align requires expression body relative to the indentation level of the outer scope the requires expr...
Definition: Format.h:4059
PackConstructorInitializersStyle PackConstructorInitializers
The pack constructor initializers style to use.
Definition: Format.h:3574
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:3168
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:3250
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:3833
unsigned MaxEmptyLinesToKeep
The maximum number of consecutive empty lines to keep.
Definition: Format.h:3360
bool SpaceBeforeSquareBrackets
If true, spaces will be before [.
Definition: Format.h:4572
BinPackStyle ObjCBinPackProtocolList
Controls bin-packing Objective-C protocol conformance list items into as few lines as possible when t...
Definition: Format.h:3444
bool isVerilog() const
Definition: Format.h:3249
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:4705
std::string CommentPragmas
A regular expression that describes comments with special meaning, which should not be split into lin...
Definition: Format.h:2382
bool isJavaScript() const
Definition: Format.h:3248
DAGArgStyle TableGenBreakInsideDAGArg
The styles of the line break inside the DAGArg in TableGen.
Definition: Format.h:4955
JavaScriptQuoteStyle JavaScriptQuotes
The JavaScriptQuoteStyle to use for JavaScript strings.
Definition: Format.h:3115
bool SpacesInContainerLiterals
If true, spaces will be inserted around if/for/switch/while conditions.
Definition: Format.h:4657
SortJavaStaticImportOptions SortJavaStaticImport
When sorting Java imports, by default static imports are placed before non-static imports.
Definition: Format.h:4215
SpaceAroundPointerQualifiersStyle
Different ways to put a space before opening parentheses.
Definition: Format.h:4286
@ SAPQ_After
Ensure that there is a space after pointer qualifiers.
Definition: Format.h:4305
@ SAPQ_Default
Don't ensure spaces around pointer qualifiers and use PointerAlignment instead.
Definition: Format.h:4293
@ SAPQ_Both
Ensure that there is a space both before and after pointer qualifiers.
Definition: Format.h:4311
@ SAPQ_Before
Ensure that there is a space before pointer qualifiers.
Definition: Format.h:4299
bool SpaceBeforeRangeBasedForLoopColon
If false, spaces will be removed before range-based for loop colon.
Definition: Format.h:4581
bool DisableFormat
Disables formatting completely.
Definition: Format.h:2511
EmptyLineAfterAccessModifierStyle
Different styles for empty line after access modifiers.
Definition: Format.h:2516
@ ELAAMS_Always
Always add empty line after access modifiers if there are none.
Definition: Format.h:2555
@ ELAAMS_Never
Remove all empty lines after access modifiers.
Definition: Format.h:2531
@ ELAAMS_Leave
Keep existing empty lines after access modifiers.
Definition: Format.h:2534
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:3411
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:3210
QualifierAlignmentStyle QualifierAlignment
Different ways to arrange specifiers and qualifiers (e.g.
Definition: Format.h:3703
BreakBinaryOperationsStyle
Different ways to break binary operations.
Definition: Format.h:2235
@ BBO_OnePerLine
Binary operations will either be all on the same line, or each operation will have one line each.
Definition: Format.h:2252
@ BBO_Never
Don't break binary operations.
Definition: Format.h:2241
@ BBO_RespectPrecedence
Binary operations of a particular precedence that exceed the column limit will have one line each.
Definition: Format.h:2262
bool IndentGotoLabels
Indent goto labels.
Definition: Format.h:2783
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:4901
SpacesInAnglesStyle
Styles for adding spacing after < and before > in template argument lists.
Definition: Format.h:4620
@ SIAS_Never
Remove spaces after < and before >.
Definition: Format.h:4626
@ SIAS_Always
Add spaces after < and before >.
Definition: Format.h:4632
@ SIAS_Leave
Keep a single space after < and before > if any spaces were present.
Definition: Format.h:4635
SortUsingDeclarationsOptions
Using declaration sorting options.
Definition: Format.h:4218
@ SUD_LexicographicNumeric
Using declarations are sorted in the order defined as follows: Split the strings by :: and discard an...
Definition: Format.h:4254
@ SUD_Lexicographic
Using declarations are sorted in the order defined as follows: Split the strings by :: and discard an...
Definition: Format.h:4239
@ SUD_Never
Using declarations are never sorted.
Definition: Format.h:4227
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:3891
@ RPS_Leave
Do not remove parentheses.
Definition: Format.h:3898
@ RPS_ReturnStatement
Also remove parentheses enclosing the expression in a return/co_return statement.
Definition: Format.h:3913
@ RPS_MultipleParentheses
Replace multiple parentheses with single parentheses.
Definition: Format.h:3905
std::vector< std::string > TableGenBreakingDAGArgOperators
Works only when TableGenBreakInsideDAGArg is not DontBreak.
Definition: Format.h:4927
EmptyLineBeforeAccessModifierStyle EmptyLineBeforeAccessModifier
Defines in which cases to put empty line before access modifiers.
Definition: Format.h:2625
bool SpaceBeforeCaseColon
If false, spaces will be removed before case colon.
Definition: Format.h:4335
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:3131
bool SkipMacroDefinitionBody
Do not format macro definition body.
Definition: Format.h:4156
unsigned PenaltyBreakAssignment
The penalty for breaking around an assignment operator.
Definition: Format.h:3578
PointerAlignmentStyle
The &, && and * alignment style.
Definition: Format.h:3622
@ PAS_Left
Align pointer to the left.
Definition: Format.h:3627
@ PAS_Middle
Align pointer in the middle.
Definition: Format.h:3637
@ PAS_Right
Align pointer to the right.
Definition: Format.h:3632
unsigned PenaltyBreakString
The penalty for each line break introduced inside a string literal.
Definition: Format.h:3602
RequiresExpressionIndentationKind RequiresExpressionIndentation
The indentation used for requires expression bodies.
Definition: Format.h:4072
bool SpaceAfterTemplateKeyword
If true, a space will be inserted after the template keyword.
Definition: Format.h:4283
unsigned PenaltyIndentedWhitespace
Penalty for each character of whitespace indentation (counted relative to leading non-whitespace colu...
Definition: Format.h:3615
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:3363
@ NI_None
Don't indent in namespaces.
Definition: Format.h:3373
@ NI_All
Indent in all namespaces.
Definition: Format.h:3393
@ NI_Inner
Indent only in inner namespaces (nested in other namespaces).
Definition: Format.h:3383
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:3306
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:3586
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:3792
@ RAS_Right
Align reference to the right.
Definition: Format.h:3804
@ RAS_Left
Align reference to the left.
Definition: Format.h:3799
@ RAS_Pointer
Align reference like PointerAlignment.
Definition: Format.h:3794
@ RAS_Middle
Align reference in the middle.
Definition: Format.h:3809
EmptyLineAfterAccessModifierStyle EmptyLineAfterAccessModifier
Defines when to put an empty line after access modifiers.
Definition: Format.h:2562
bool IndentAccessModifiers
Specify whether access modifiers should have their own indentation level.
Definition: Format.h:2724
bool InsertNewlineAtEOF
Insert a newline at end of file if missing.
Definition: Format.h:2945
SpaceBeforeParensStyle SpaceBeforeParens
Defines in which cases to put a space before opening parentheses.
Definition: Format.h:4436
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:4347
UseTabStyle UseTab
The way to use tab characters in the resulting file.
Definition: Format.h:5011
QualifierAlignmentStyle
Different specifiers and qualifiers alignment styles.
Definition: Format.h:3660
@ QAS_Right
Change specifiers/qualifiers to be right-aligned.
Definition: Format.h:3679
@ QAS_Custom
Change specifiers/qualifiers to be aligned based on QualifierOrder.
Definition: Format.h:3691
@ QAS_Left
Change specifiers/qualifiers to be left-aligned.
Definition: Format.h:3673
@ QAS_Leave
Don't change specifiers/qualifiers to either Left or Right alignment (default).
Definition: Format.h:3667
std::vector< std::string > TypenameMacros
A vector of macros that should be interpreted as type declarations instead of as function calls.
Definition: Format.h:4986
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:3273
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:4152
SortUsingDeclarationsOptions SortUsingDeclarations
Controls if and how clang-format will sort using declarations.
Definition: Format.h:4259
IndentExternBlockStyle IndentExternBlock
IndentExternBlockStyle is the type of indenting of extern blocks.
Definition: Format.h:2823
SeparateDefinitionStyle SeparateDefinitionBlocks
Specifies the use of empty lines to separate definition blocks, including classes,...
Definition: Format.h:4130
tooling::IncludeStyle IncludeStyle
Definition: Format.h:2676
unsigned ColumnLimit
The column limit.
Definition: Format.h:2372
Represents the status of a formatting attempt.
Definition: Format.h:5373
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:5376
unsigned Line
If FormatComplete is false, Line records a one-based original line number at which a syntax error mig...
Definition: Format.h:5381
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