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``, or ``WithFollowing``.
2862 ///
2863 /// In clang-format 12, 13 and 14 it was named ``IndentRequires``.
2864 /// \code
2865 /// true:
2866 /// template <typename It>
2867 /// requires Iterator<It>
2868 /// void sort(It begin, It end) {
2869 /// //....
2870 /// }
2871 ///
2872 /// false:
2873 /// template <typename It>
2874 /// requires Iterator<It>
2875 /// void sort(It begin, It end) {
2876 /// //....
2877 /// }
2878 /// \endcode
2879 /// \version 15
2881
2882 /// The number of columns to use for indentation.
2883 /// \code
2884 /// IndentWidth: 3
2885 ///
2886 /// void f() {
2887 /// someFunction();
2888 /// if (true, false) {
2889 /// f();
2890 /// }
2891 /// }
2892 /// \endcode
2893 /// \version 3.7
2894 unsigned IndentWidth;
2895
2896 /// Indent if a function definition or declaration is wrapped after the
2897 /// type.
2898 /// \code
2899 /// true:
2900 /// LoooooooooooooooooooooooooooooooooooooooongReturnType
2901 /// LoooooooooooooooooooooooooooooooongFunctionDeclaration();
2902 ///
2903 /// false:
2904 /// LoooooooooooooooooooooooooooooooooooooooongReturnType
2905 /// LoooooooooooooooooooooooooooooooongFunctionDeclaration();
2906 /// \endcode
2907 /// \version 3.7
2909
2910 /// Insert braces after control statements (``if``, ``else``, ``for``, ``do``,
2911 /// and ``while``) in C++ unless the control statements are inside macro
2912 /// definitions or the braces would enclose preprocessor directives.
2913 /// \warning
2914 /// Setting this option to ``true`` could lead to incorrect code formatting
2915 /// due to clang-format's lack of complete semantic information. As such,
2916 /// extra care should be taken to review code changes made by this option.
2917 /// \endwarning
2918 /// \code
2919 /// false: true:
2920 ///
2921 /// if (isa<FunctionDecl>(D)) vs. if (isa<FunctionDecl>(D)) {
2922 /// handleFunctionDecl(D); handleFunctionDecl(D);
2923 /// else if (isa<VarDecl>(D)) } else if (isa<VarDecl>(D)) {
2924 /// handleVarDecl(D); handleVarDecl(D);
2925 /// else } else {
2926 /// return; return;
2927 /// }
2928 ///
2929 /// while (i--) vs. while (i--) {
2930 /// for (auto *A : D.attrs()) for (auto *A : D.attrs()) {
2931 /// handleAttr(A); handleAttr(A);
2932 /// }
2933 /// }
2934 ///
2935 /// do vs. do {
2936 /// --i; --i;
2937 /// while (i); } while (i);
2938 /// \endcode
2939 /// \version 15
2941
2942 /// Insert a newline at end of file if missing.
2943 /// \version 16
2945
2946 /// The style of inserting trailing commas into container literals.
2947 enum TrailingCommaStyle : int8_t {
2948 /// Do not insert trailing commas.
2950 /// Insert trailing commas in container literals that were wrapped over
2951 /// multiple lines. Note that this is conceptually incompatible with
2952 /// bin-packing, because the trailing comma is used as an indicator
2953 /// that a container should be formatted one-per-line (i.e. not bin-packed).
2954 /// So inserting a trailing comma counteracts bin-packing.
2956 };
2957
2958 /// If set to ``TCS_Wrapped`` will insert trailing commas in container
2959 /// literals (arrays and objects) that wrap across multiple lines.
2960 /// It is currently only available for JavaScript
2961 /// and disabled by default ``TCS_None``.
2962 /// ``InsertTrailingCommas`` cannot be used together with ``BinPackArguments``
2963 /// as inserting the comma disables bin-packing.
2964 /// \code
2965 /// TSC_Wrapped:
2966 /// const someArray = [
2967 /// aaaaaaaaaaaaaaaaaaaaaaaaaa,
2968 /// aaaaaaaaaaaaaaaaaaaaaaaaaa,
2969 /// aaaaaaaaaaaaaaaaaaaaaaaaaa,
2970 /// // ^ inserted
2971 /// ]
2972 /// \endcode
2973 /// \version 11
2975
2976 /// Separator format of integer literals of different bases.
2977 ///
2978 /// If negative, remove separators. If ``0``, leave the literal as is. If
2979 /// positive, insert separators between digits starting from the rightmost
2980 /// digit.
2981 ///
2982 /// For example, the config below will leave separators in binary literals
2983 /// alone, insert separators in decimal literals to separate the digits into
2984 /// groups of 3, and remove separators in hexadecimal literals.
2985 /// \code
2986 /// IntegerLiteralSeparator:
2987 /// Binary: 0
2988 /// Decimal: 3
2989 /// Hex: -1
2990 /// \endcode
2991 ///
2992 /// You can also specify a minimum number of digits (``BinaryMinDigits``,
2993 /// ``DecimalMinDigits``, and ``HexMinDigits``) the integer literal must
2994 /// have in order for the separators to be inserted.
2996 /// Format separators in binary literals.
2997 /// \code{.text}
2998 /// /* -1: */ b = 0b100111101101;
2999 /// /* 0: */ b = 0b10011'11'0110'1;
3000 /// /* 3: */ b = 0b100'111'101'101;
3001 /// /* 4: */ b = 0b1001'1110'1101;
3002 /// \endcode
3003 int8_t Binary;
3004 /// Format separators in binary literals with a minimum number of digits.
3005 /// \code{.text}
3006 /// // Binary: 3
3007 /// // BinaryMinDigits: 7
3008 /// b1 = 0b101101;
3009 /// b2 = 0b1'101'101;
3010 /// \endcode
3012 /// Format separators in decimal literals.
3013 /// \code{.text}
3014 /// /* -1: */ d = 18446744073709550592ull;
3015 /// /* 0: */ d = 184467'440737'0'95505'92ull;
3016 /// /* 3: */ d = 18'446'744'073'709'550'592ull;
3017 /// \endcode
3018 int8_t Decimal;
3019 /// Format separators in decimal literals with a minimum number of digits.
3020 /// \code{.text}
3021 /// // Decimal: 3
3022 /// // DecimalMinDigits: 5
3023 /// d1 = 2023;
3024 /// d2 = 10'000;
3025 /// \endcode
3027 /// Format separators in hexadecimal literals.
3028 /// \code{.text}
3029 /// /* -1: */ h = 0xDEADBEEFDEADBEEFuz;
3030 /// /* 0: */ h = 0xDEAD'BEEF'DE'AD'BEE'Fuz;
3031 /// /* 2: */ h = 0xDE'AD'BE'EF'DE'AD'BE'EFuz;
3032 /// \endcode
3033 int8_t Hex;
3034 /// Format separators in hexadecimal literals with a minimum number of
3035 /// digits.
3036 /// \code{.text}
3037 /// // Hex: 2
3038 /// // HexMinDigits: 6
3039 /// h1 = 0xABCDE;
3040 /// h2 = 0xAB'CD'EF;
3041 /// \endcode
3044 return Binary == R.Binary && BinaryMinDigits == R.BinaryMinDigits &&
3046 Hex == R.Hex && HexMinDigits == R.HexMinDigits;
3047 }
3048 };
3049
3050 /// Format integer literal separators (``'`` for C++ and ``_`` for C#, Java,
3051 /// and JavaScript).
3052 /// \version 16
3054
3055 /// A vector of prefixes ordered by the desired groups for Java imports.
3056 ///
3057 /// One group's prefix can be a subset of another - the longest prefix is
3058 /// always matched. Within a group, the imports are ordered lexicographically.
3059 /// Static imports are grouped separately and follow the same group rules.
3060 /// By default, static imports are placed before non-static imports,
3061 /// but this behavior is changed by another option,
3062 /// ``SortJavaStaticImport``.
3063 ///
3064 /// In the .clang-format configuration file, this can be configured like
3065 /// in the following yaml example. This will result in imports being
3066 /// formatted as in the Java example below.
3067 /// \code{.yaml}
3068 /// JavaImportGroups: [com.example, com, org]
3069 /// \endcode
3070 ///
3071 /// \code{.java}
3072 /// import static com.example.function1;
3073 ///
3074 /// import static com.test.function2;
3075 ///
3076 /// import static org.example.function3;
3077 ///
3078 /// import com.example.ClassA;
3079 /// import com.example.Test;
3080 /// import com.example.a.ClassB;
3081 ///
3082 /// import com.test.ClassC;
3083 ///
3084 /// import org.example.ClassD;
3085 /// \endcode
3086 /// \version 8
3087 std::vector<std::string> JavaImportGroups;
3088
3089 /// Quotation styles for JavaScript strings. Does not affect template
3090 /// strings.
3091 enum JavaScriptQuoteStyle : int8_t {
3092 /// Leave string quotes as they are.
3093 /// \code{.js}
3094 /// string1 = "foo";
3095 /// string2 = 'bar';
3096 /// \endcode
3098 /// Always use single quotes.
3099 /// \code{.js}
3100 /// string1 = 'foo';
3101 /// string2 = 'bar';
3102 /// \endcode
3104 /// Always use double quotes.
3105 /// \code{.js}
3106 /// string1 = "foo";
3107 /// string2 = "bar";
3108 /// \endcode
3111
3112 /// The JavaScriptQuoteStyle to use for JavaScript strings.
3113 /// \version 3.9
3115
3116 // clang-format off
3117 /// Whether to wrap JavaScript import/export statements.
3118 /// \code{.js}
3119 /// true:
3120 /// import {
3121 /// VeryLongImportsAreAnnoying,
3122 /// VeryLongImportsAreAnnoying,
3123 /// VeryLongImportsAreAnnoying,
3124 /// } from "some/module.js"
3125 ///
3126 /// false:
3127 /// import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js"
3128 /// \endcode
3129 /// \version 3.9
3131 // clang-format on
3132
3133 /// Options regarding which empty lines are kept.
3134 ///
3135 /// For example, the config below will remove empty lines at start of the
3136 /// file, end of the file, and start of blocks.
3137 ///
3138 /// \code
3139 /// KeepEmptyLines:
3140 /// AtEndOfFile: false
3141 /// AtStartOfBlock: false
3142 /// AtStartOfFile: false
3143 /// \endcode
3145 /// Keep empty lines at end of file.
3147 /// Keep empty lines at start of a block.
3148 /// \code
3149 /// true: false:
3150 /// if (foo) { vs. if (foo) {
3151 /// bar();
3152 /// bar(); }
3153 /// }
3154 /// \endcode
3156 /// Keep empty lines at start of file.
3158 bool operator==(const KeepEmptyLinesStyle &R) const {
3159 return AtEndOfFile == R.AtEndOfFile &&
3162 }
3163 };
3164 /// Which empty lines are kept. See ``MaxEmptyLinesToKeep`` for how many
3165 /// consecutive empty lines are kept.
3166 /// \version 19
3168
3169 /// This option is deprecated. See ``AtEndOfFile`` of ``KeepEmptyLines``.
3170 /// \version 17
3171 // bool KeepEmptyLinesAtEOF;
3172
3173 /// This option is deprecated. See ``AtStartOfBlock`` of ``KeepEmptyLines``.
3174 /// \version 3.7
3175 // bool KeepEmptyLinesAtTheStartOfBlocks;
3176
3177 /// Indentation logic for lambda bodies.
3179 /// Align lambda body relative to the lambda signature. This is the default.
3180 /// \code
3181 /// someMethod(
3182 /// [](SomeReallyLongLambdaSignatureArgument foo) {
3183 /// return;
3184 /// });
3185 /// \endcode
3187 /// For statements within block scope, align lambda body relative to the
3188 /// indentation level of the outer scope the lambda signature resides in.
3189 /// \code
3190 /// someMethod(
3191 /// [](SomeReallyLongLambdaSignatureArgument foo) {
3192 /// return;
3193 /// });
3194 ///
3195 /// someMethod(someOtherMethod(
3196 /// [](SomeReallyLongLambdaSignatureArgument foo) {
3197 /// return;
3198 /// }));
3199 /// \endcode
3201 };
3202
3203 /// The indentation style of lambda bodies. ``Signature`` (the default)
3204 /// causes the lambda body to be indented one additional level relative to
3205 /// the indentation level of the signature. ``OuterScope`` forces the lambda
3206 /// body to be indented one additional level relative to the parent scope
3207 /// containing the lambda signature.
3208 /// \version 13
3210
3211 /// Supported languages.
3212 ///
3213 /// When stored in a configuration file, specifies the language, that the
3214 /// configuration targets. When passed to the ``reformat()`` function, enables
3215 /// syntax features specific to the language.
3216 enum LanguageKind : int8_t {
3217 /// Do not use.
3219 /// Should be used for C, C++.
3221 /// Should be used for C#.
3223 /// Should be used for Java.
3225 /// Should be used for JavaScript.
3227 /// Should be used for JSON.
3229 /// Should be used for Objective-C, Objective-C++.
3231 /// Should be used for Protocol Buffers
3232 /// (https://developers.google.com/protocol-buffers/).
3234 /// Should be used for TableGen code.
3236 /// Should be used for Protocol Buffer messages in text format
3237 /// (https://developers.google.com/protocol-buffers/).
3239 /// Should be used for Verilog and SystemVerilog.
3240 /// https://standards.ieee.org/ieee/1800/6700/
3241 /// https://sci-hub.st/10.1109/IEEESTD.2018.8299595
3244 bool isCpp() const { return Language == LK_Cpp || Language == LK_ObjC; }
3245 bool isCSharp() const { return Language == LK_CSharp; }
3246 bool isJson() const { return Language == LK_Json; }
3247 bool isJavaScript() const { return Language == LK_JavaScript; }
3248 bool isVerilog() const { return Language == LK_Verilog; }
3249 bool isProto() const {
3250 return Language == LK_Proto || Language == LK_TextProto;
3251 }
3252 bool isTableGen() const { return Language == LK_TableGen; }
3253
3254 /// Language, this format style is targeted at.
3255 /// \version 3.5
3257
3258 /// Line ending style.
3259 enum LineEndingStyle : int8_t {
3260 /// Use ``\n``.
3262 /// Use ``\r\n``.
3264 /// Use ``\n`` unless the input has more lines ending in ``\r\n``.
3266 /// Use ``\r\n`` unless the input has more lines ending in ``\n``.
3268 };
3269
3270 /// Line ending style (``\n`` or ``\r\n``) to use.
3271 /// \version 16
3273
3274 /// A regular expression matching macros that start a block.
3275 /// \code
3276 /// # With:
3277 /// MacroBlockBegin: "^NS_MAP_BEGIN|\
3278 /// NS_TABLE_HEAD$"
3279 /// MacroBlockEnd: "^\
3280 /// NS_MAP_END|\
3281 /// NS_TABLE_.*_END$"
3282 ///
3283 /// NS_MAP_BEGIN
3284 /// foo();
3285 /// NS_MAP_END
3286 ///
3287 /// NS_TABLE_HEAD
3288 /// bar();
3289 /// NS_TABLE_FOO_END
3290 ///
3291 /// # Without:
3292 /// NS_MAP_BEGIN
3293 /// foo();
3294 /// NS_MAP_END
3295 ///
3296 /// NS_TABLE_HEAD
3297 /// bar();
3298 /// NS_TABLE_FOO_END
3299 /// \endcode
3300 /// \version 3.7
3301 std::string MacroBlockBegin;
3302
3303 /// A regular expression matching macros that end a block.
3304 /// \version 3.7
3305 std::string MacroBlockEnd;
3306
3307 /// A list of macros of the form \c <definition>=<expansion> .
3308 ///
3309 /// Code will be parsed with macros expanded, in order to determine how to
3310 /// interpret and format the macro arguments.
3311 ///
3312 /// For example, the code:
3313 /// \code
3314 /// A(a*b);
3315 /// \endcode
3316 ///
3317 /// will usually be interpreted as a call to a function A, and the
3318 /// multiplication expression will be formatted as ``a * b``.
3319 ///
3320 /// If we specify the macro definition:
3321 /// \code{.yaml}
3322 /// Macros:
3323 /// - A(x)=x
3324 /// \endcode
3325 ///
3326 /// the code will now be parsed as a declaration of the variable b of type a*,
3327 /// and formatted as ``a* b`` (depending on pointer-binding rules).
3328 ///
3329 /// Features and restrictions:
3330 /// * Both function-like macros and object-like macros are supported.
3331 /// * Macro arguments must be used exactly once in the expansion.
3332 /// * No recursive expansion; macros referencing other macros will be
3333 /// ignored.
3334 /// * Overloading by arity is supported: for example, given the macro
3335 /// definitions A=x, A()=y, A(a)=a
3336 ///
3337 /// \code
3338 /// A; -> x;
3339 /// A(); -> y;
3340 /// A(z); -> z;
3341 /// A(a, b); // will not be expanded.
3342 /// \endcode
3343 ///
3344 /// \version 17
3345 std::vector<std::string> Macros;
3346
3347 /// The maximum number of consecutive empty lines to keep.
3348 /// \code
3349 /// MaxEmptyLinesToKeep: 1 vs. MaxEmptyLinesToKeep: 0
3350 /// int f() { int f() {
3351 /// int = 1; int i = 1;
3352 /// i = foo();
3353 /// i = foo(); return i;
3354 /// }
3355 /// return i;
3356 /// }
3357 /// \endcode
3358 /// \version 3.7
3360
3361 /// Different ways to indent namespace contents.
3363 /// Don't indent in namespaces.
3364 /// \code
3365 /// namespace out {
3366 /// int i;
3367 /// namespace in {
3368 /// int i;
3369 /// }
3370 /// }
3371 /// \endcode
3373 /// Indent only in inner namespaces (nested in other namespaces).
3374 /// \code
3375 /// namespace out {
3376 /// int i;
3377 /// namespace in {
3378 /// int i;
3379 /// }
3380 /// }
3381 /// \endcode
3383 /// Indent in all namespaces.
3384 /// \code
3385 /// namespace out {
3386 /// int i;
3387 /// namespace in {
3388 /// int i;
3389 /// }
3390 /// }
3391 /// \endcode
3392 NI_All
3394
3395 /// The indentation used for namespaces.
3396 /// \version 3.7
3398
3399 /// A vector of macros which are used to open namespace blocks.
3400 ///
3401 /// These are expected to be macros of the form:
3402 /// \code
3403 /// NAMESPACE(<namespace-name>, ...) {
3404 /// <namespace-content>
3405 /// }
3406 /// \endcode
3407 ///
3408 /// For example: TESTSUITE
3409 /// \version 9
3410 std::vector<std::string> NamespaceMacros;
3411
3412 /// Controls bin-packing Objective-C protocol conformance list
3413 /// items into as few lines as possible when they go over ``ColumnLimit``.
3414 ///
3415 /// If ``Auto`` (the default), delegates to the value in
3416 /// ``BinPackParameters``. If that is ``true``, bin-packs Objective-C
3417 /// protocol conformance list items into as few lines as possible
3418 /// whenever they go over ``ColumnLimit``.
3419 ///
3420 /// If ``Always``, always bin-packs Objective-C protocol conformance
3421 /// list items into as few lines as possible whenever they go over
3422 /// ``ColumnLimit``.
3423 ///
3424 /// If ``Never``, lays out Objective-C protocol conformance list items
3425 /// onto individual lines whenever they go over ``ColumnLimit``.
3426 ///
3427 /// \code{.objc}
3428 /// Always (or Auto, if BinPackParameters=true):
3429 /// @interface ccccccccccccc () <
3430 /// ccccccccccccc, ccccccccccccc,
3431 /// ccccccccccccc, ccccccccccccc> {
3432 /// }
3433 ///
3434 /// Never (or Auto, if BinPackParameters=false):
3435 /// @interface ddddddddddddd () <
3436 /// ddddddddddddd,
3437 /// ddddddddddddd,
3438 /// ddddddddddddd,
3439 /// ddddddddddddd> {
3440 /// }
3441 /// \endcode
3442 /// \version 7
3444
3445 /// The number of characters to use for indentation of ObjC blocks.
3446 /// \code{.objc}
3447 /// ObjCBlockIndentWidth: 4
3448 ///
3449 /// [operation setCompletionBlock:^{
3450 /// [self onOperationDone];
3451 /// }];
3452 /// \endcode
3453 /// \version 3.7
3455
3456 /// Break parameters list into lines when there is nested block
3457 /// parameters in a function call.
3458 /// \code
3459 /// false:
3460 /// - (void)_aMethod
3461 /// {
3462 /// [self.test1 t:self w:self callback:^(typeof(self) self, NSNumber
3463 /// *u, NSNumber *v) {
3464 /// u = c;
3465 /// }]
3466 /// }
3467 /// true:
3468 /// - (void)_aMethod
3469 /// {
3470 /// [self.test1 t:self
3471 /// w:self
3472 /// callback:^(typeof(self) self, NSNumber *u, NSNumber *v) {
3473 /// u = c;
3474 /// }]
3475 /// }
3476 /// \endcode
3477 /// \version 11
3479
3480 /// The order in which ObjC property attributes should appear.
3481 ///
3482 /// Attributes in code will be sorted in the order specified. Any attributes
3483 /// encountered that are not mentioned in this array will be sorted last, in
3484 /// stable order. Comments between attributes will leave the attributes
3485 /// untouched.
3486 /// \warning
3487 /// Using this option could lead to incorrect code formatting due to
3488 /// clang-format's lack of complete semantic information. As such, extra
3489 /// care should be taken to review code changes made by this option.
3490 /// \endwarning
3491 /// \code{.yaml}
3492 /// ObjCPropertyAttributeOrder: [
3493 /// class, direct,
3494 /// atomic, nonatomic,
3495 /// assign, retain, strong, copy, weak, unsafe_unretained,
3496 /// readonly, readwrite, getter, setter,
3497 /// nullable, nonnull, null_resettable, null_unspecified
3498 /// ]
3499 /// \endcode
3500 /// \version 18
3501 std::vector<std::string> ObjCPropertyAttributeOrder;
3502
3503 /// Add a space after ``@property`` in Objective-C, i.e. use
3504 /// ``@property (readonly)`` instead of ``@property(readonly)``.
3505 /// \version 3.7
3507
3508 /// Add a space in front of an Objective-C protocol list, i.e. use
3509 /// ``Foo <Protocol>`` instead of ``Foo<Protocol>``.
3510 /// \version 3.7
3512
3513 /// Different ways to try to fit all constructor initializers on a line.
3515 /// Always put each constructor initializer on its own line.
3516 /// \code
3517 /// Constructor()
3518 /// : a(),
3519 /// b()
3520 /// \endcode
3522 /// Bin-pack constructor initializers.
3523 /// \code
3524 /// Constructor()
3525 /// : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(),
3526 /// cccccccccccccccccccc()
3527 /// \endcode
3529 /// Put all constructor initializers on the current line if they fit.
3530 /// Otherwise, put each one on its own line.
3531 /// \code
3532 /// Constructor() : a(), b()
3533 ///
3534 /// Constructor()
3535 /// : aaaaaaaaaaaaaaaaaaaa(),
3536 /// bbbbbbbbbbbbbbbbbbbb(),
3537 /// ddddddddddddd()
3538 /// \endcode
3540 /// Same as ``PCIS_CurrentLine`` except that if all constructor initializers
3541 /// do not fit on the current line, try to fit them on the next line.
3542 /// \code
3543 /// Constructor() : a(), b()
3544 ///
3545 /// Constructor()
3546 /// : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), ddddddddddddd()
3547 ///
3548 /// Constructor()
3549 /// : aaaaaaaaaaaaaaaaaaaa(),
3550 /// bbbbbbbbbbbbbbbbbbbb(),
3551 /// cccccccccccccccccccc()
3552 /// \endcode
3554 /// Put all constructor initializers on the next line if they fit.
3555 /// Otherwise, put each one on its own line.
3556 /// \code
3557 /// Constructor()
3558 /// : a(), b()
3559 ///
3560 /// Constructor()
3561 /// : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), ddddddddddddd()
3562 ///
3563 /// Constructor()
3564 /// : aaaaaaaaaaaaaaaaaaaa(),
3565 /// bbbbbbbbbbbbbbbbbbbb(),
3566 /// cccccccccccccccccccc()
3567 /// \endcode
3569 };
3570
3571 /// The pack constructor initializers style to use.
3572 /// \version 14
3574
3575 /// The penalty for breaking around an assignment operator.
3576 /// \version 5
3578
3579 /// The penalty for breaking a function call after ``call(``.
3580 /// \version 3.7
3582
3583 /// The penalty for each line break introduced inside a comment.
3584 /// \version 3.7
3586
3587 /// The penalty for breaking before the first ``<<``.
3588 /// \version 3.7
3590
3591 /// The penalty for breaking after ``(``.
3592 /// \version 14
3594
3595 /// The penalty for breaking after ``::``.
3596 /// \version 18
3598
3599 /// The penalty for each line break introduced inside a string literal.
3600 /// \version 3.7
3602
3603 /// The penalty for breaking after template declaration.
3604 /// \version 7
3606
3607 /// The penalty for each character outside of the column limit.
3608 /// \version 3.7
3610
3611 /// Penalty for each character of whitespace indentation
3612 /// (counted relative to leading non-whitespace column).
3613 /// \version 12
3615
3616 /// Penalty for putting the return type of a function onto its own line.
3617 /// \version 3.7
3619
3620 /// The ``&``, ``&&`` and ``*`` alignment style.
3622 /// Align pointer to the left.
3623 /// \code
3624 /// int* a;
3625 /// \endcode
3627 /// Align pointer to the right.
3628 /// \code
3629 /// int *a;
3630 /// \endcode
3632 /// Align pointer in the middle.
3633 /// \code
3634 /// int * a;
3635 /// \endcode
3638
3639 /// Pointer and reference alignment style.
3640 /// \version 3.7
3642
3643 /// The number of columns to use for indentation of preprocessor statements.
3644 /// When set to -1 (default) ``IndentWidth`` is used also for preprocessor
3645 /// statements.
3646 /// \code
3647 /// PPIndentWidth: 1
3648 ///
3649 /// #ifdef __linux__
3650 /// # define FOO
3651 /// #else
3652 /// # define BAR
3653 /// #endif
3654 /// \endcode
3655 /// \version 13
3657
3658 /// Different specifiers and qualifiers alignment styles.
3660 /// Don't change specifiers/qualifiers to either Left or Right alignment
3661 /// (default).
3662 /// \code
3663 /// int const a;
3664 /// const int *a;
3665 /// \endcode
3667 /// Change specifiers/qualifiers to be left-aligned.
3668 /// \code
3669 /// const int a;
3670 /// const int *a;
3671 /// \endcode
3673 /// Change specifiers/qualifiers to be right-aligned.
3674 /// \code
3675 /// int const a;
3676 /// int const *a;
3677 /// \endcode
3679 /// Change specifiers/qualifiers to be aligned based on ``QualifierOrder``.
3680 /// With:
3681 /// \code{.yaml}
3682 /// QualifierOrder: [inline, static, type, const]
3683 /// \endcode
3684 ///
3685 /// \code
3686 ///
3687 /// int const a;
3688 /// int const *a;
3689 /// \endcode
3692
3693 /// Different ways to arrange specifiers and qualifiers (e.g. const/volatile).
3694 /// \warning
3695 /// Setting ``QualifierAlignment`` to something other than ``Leave``, COULD
3696 /// lead to incorrect code formatting due to incorrect decisions made due to
3697 /// clang-formats lack of complete semantic information.
3698 /// As such extra care should be taken to review code changes made by the use
3699 /// of this option.
3700 /// \endwarning
3701 /// \version 14
3703
3704 /// The order in which the qualifiers appear.
3705 /// Order is an array that can contain any of the following:
3706 ///
3707 /// * const
3708 /// * inline
3709 /// * static
3710 /// * friend
3711 /// * constexpr
3712 /// * volatile
3713 /// * restrict
3714 /// * type
3715 ///
3716 /// \note
3717 /// It **must** contain ``type``.
3718 /// \endnote
3719 ///
3720 /// Items to the left of ``type`` will be placed to the left of the type and
3721 /// aligned in the order supplied. Items to the right of ``type`` will be
3722 /// placed to the right of the type and aligned in the order supplied.
3723 ///
3724 /// \code{.yaml}
3725 /// QualifierOrder: [inline, static, type, const, volatile]
3726 /// \endcode
3727 /// \version 14
3728 std::vector<std::string> QualifierOrder;
3729
3730 /// See documentation of ``RawStringFormats``.
3732 /// The language of this raw string.
3734 /// A list of raw string delimiters that match this language.
3735 std::vector<std::string> Delimiters;
3736 /// A list of enclosing function names that match this language.
3737 std::vector<std::string> EnclosingFunctions;
3738 /// The canonical delimiter for this language.
3740 /// The style name on which this raw string format is based on.
3741 /// If not specified, the raw string format is based on the style that this
3742 /// format is based on.
3743 std::string BasedOnStyle;
3744 bool operator==(const RawStringFormat &Other) const {
3745 return Language == Other.Language && Delimiters == Other.Delimiters &&
3746 EnclosingFunctions == Other.EnclosingFunctions &&
3747 CanonicalDelimiter == Other.CanonicalDelimiter &&
3748 BasedOnStyle == Other.BasedOnStyle;
3749 }
3750 };
3751
3752 /// Defines hints for detecting supported languages code blocks in raw
3753 /// strings.
3754 ///
3755 /// A raw string with a matching delimiter or a matching enclosing function
3756 /// name will be reformatted assuming the specified language based on the
3757 /// style for that language defined in the .clang-format file. If no style has
3758 /// been defined in the .clang-format file for the specific language, a
3759 /// predefined style given by ``BasedOnStyle`` is used. If ``BasedOnStyle`` is
3760 /// not found, the formatting is based on ``LLVM`` style. A matching delimiter
3761 /// takes precedence over a matching enclosing function name for determining
3762 /// the language of the raw string contents.
3763 ///
3764 /// If a canonical delimiter is specified, occurrences of other delimiters for
3765 /// the same language will be updated to the canonical if possible.
3766 ///
3767 /// There should be at most one specification per language and each delimiter
3768 /// and enclosing function should not occur in multiple specifications.
3769 ///
3770 /// To configure this in the .clang-format file, use:
3771 /// \code{.yaml}
3772 /// RawStringFormats:
3773 /// - Language: TextProto
3774 /// Delimiters:
3775 /// - pb
3776 /// - proto
3777 /// EnclosingFunctions:
3778 /// - PARSE_TEXT_PROTO
3779 /// BasedOnStyle: google
3780 /// - Language: Cpp
3781 /// Delimiters:
3782 /// - cc
3783 /// - cpp
3784 /// BasedOnStyle: LLVM
3785 /// CanonicalDelimiter: cc
3786 /// \endcode
3787 /// \version 6
3788 std::vector<RawStringFormat> RawStringFormats;
3789
3790 /// \brief The ``&`` and ``&&`` alignment style.
3792 /// Align reference like ``PointerAlignment``.
3794 /// Align reference to the left.
3795 /// \code
3796 /// int& a;
3797 /// \endcode
3799 /// Align reference to the right.
3800 /// \code
3801 /// int &a;
3802 /// \endcode
3804 /// Align reference in the middle.
3805 /// \code
3806 /// int & a;
3807 /// \endcode
3810
3811 /// \brief Reference alignment style (overrides ``PointerAlignment`` for
3812 /// references).
3813 /// \version 13
3815
3816 // clang-format off
3817 /// If ``true``, clang-format will attempt to re-flow comments. That is it
3818 /// will touch a comment and *reflow* long comments into new lines, trying to
3819 /// obey the ``ColumnLimit``.
3820 /// \code
3821 /// false:
3822 /// // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
3823 /// /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */
3824 ///
3825 /// true:
3826 /// // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
3827 /// // information
3828 /// /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
3829 /// * information */
3830 /// \endcode
3831 /// \version 3.8
3833 // clang-format on
3834
3835 /// Remove optional braces of control statements (``if``, ``else``, ``for``,
3836 /// and ``while``) in C++ according to the LLVM coding style.
3837 /// \warning
3838 /// This option will be renamed and expanded to support other styles.
3839 /// \endwarning
3840 /// \warning
3841 /// Setting this option to ``true`` could lead to incorrect code formatting
3842 /// due to clang-format's lack of complete semantic information. As such,
3843 /// extra care should be taken to review code changes made by this option.
3844 /// \endwarning
3845 /// \code
3846 /// false: true:
3847 ///
3848 /// if (isa<FunctionDecl>(D)) { vs. if (isa<FunctionDecl>(D))
3849 /// handleFunctionDecl(D); handleFunctionDecl(D);
3850 /// } else if (isa<VarDecl>(D)) { else if (isa<VarDecl>(D))
3851 /// handleVarDecl(D); handleVarDecl(D);
3852 /// }
3853 ///
3854 /// if (isa<VarDecl>(D)) { vs. if (isa<VarDecl>(D)) {
3855 /// for (auto *A : D.attrs()) { for (auto *A : D.attrs())
3856 /// if (shouldProcessAttr(A)) { if (shouldProcessAttr(A))
3857 /// handleAttr(A); handleAttr(A);
3858 /// } }
3859 /// }
3860 /// }
3861 ///
3862 /// if (isa<FunctionDecl>(D)) { vs. if (isa<FunctionDecl>(D))
3863 /// for (auto *A : D.attrs()) { for (auto *A : D.attrs())
3864 /// handleAttr(A); handleAttr(A);
3865 /// }
3866 /// }
3867 ///
3868 /// if (auto *D = (T)(D)) { vs. if (auto *D = (T)(D)) {
3869 /// if (shouldProcess(D)) { if (shouldProcess(D))
3870 /// handleVarDecl(D); handleVarDecl(D);
3871 /// } else { else
3872 /// markAsIgnored(D); markAsIgnored(D);
3873 /// } }
3874 /// }
3875 ///
3876 /// if (a) { vs. if (a)
3877 /// b(); b();
3878 /// } else { else if (c)
3879 /// if (c) { d();
3880 /// d(); else
3881 /// } else { e();
3882 /// e();
3883 /// }
3884 /// }
3885 /// \endcode
3886 /// \version 14
3888
3889 /// Types of redundant parentheses to remove.
3891 /// Do not remove parentheses.
3892 /// \code
3893 /// class __declspec((dllimport)) X {};
3894 /// co_return (((0)));
3895 /// return ((a + b) - ((c + d)));
3896 /// \endcode
3898 /// Replace multiple parentheses with single parentheses.
3899 /// \code
3900 /// class __declspec(dllimport) X {};
3901 /// co_return (0);
3902 /// return ((a + b) - (c + d));
3903 /// \endcode
3905 /// Also remove parentheses enclosing the expression in a
3906 /// ``return``/``co_return`` statement.
3907 /// \code
3908 /// class __declspec(dllimport) X {};
3909 /// co_return 0;
3910 /// return (a + b) - (c + d);
3911 /// \endcode
3913 };
3914
3915 /// Remove redundant parentheses.
3916 /// \warning
3917 /// Setting this option to any value other than ``Leave`` could lead to
3918 /// incorrect code formatting due to clang-format's lack of complete semantic
3919 /// information. As such, extra care should be taken to review code changes
3920 /// made by this option.
3921 /// \endwarning
3922 /// \version 17
3924
3925 /// Remove semicolons after the closing braces of functions and
3926 /// constructors/destructors.
3927 /// \warning
3928 /// Setting this option to ``true`` could lead to incorrect code formatting
3929 /// due to clang-format's lack of complete semantic information. As such,
3930 /// extra care should be taken to review code changes made by this option.
3931 /// \endwarning
3932 /// \code
3933 /// false: true:
3934 ///
3935 /// int max(int a, int b) { int max(int a, int b) {
3936 /// return a > b ? a : b; return a > b ? a : b;
3937 /// }; }
3938 ///
3939 /// \endcode
3940 /// \version 16
3942
3943 /// \brief The possible positions for the requires clause. The
3944 /// ``IndentRequires`` option is only used if the ``requires`` is put on the
3945 /// start of a line.
3947 /// Always put the ``requires`` clause on its own line.
3948 /// \code
3949 /// template <typename T>
3950 /// requires C<T>
3951 /// struct Foo {...
3952 ///
3953 /// template <typename T>
3954 /// requires C<T>
3955 /// void bar(T t) {...
3956 ///
3957 /// template <typename T>
3958 /// void baz(T t)
3959 /// requires C<T>
3960 /// {...
3961 /// \endcode
3963 /// Try to put the clause together with the preceding part of a declaration.
3964 /// For class templates: stick to the template declaration.
3965 /// For function templates: stick to the template declaration.
3966 /// For function declaration followed by a requires clause: stick to the
3967 /// parameter list.
3968 /// \code
3969 /// template <typename T> requires C<T>
3970 /// struct Foo {...
3971 ///
3972 /// template <typename T> requires C<T>
3973 /// void bar(T t) {...
3974 ///
3975 /// template <typename T>
3976 /// void baz(T t) requires C<T>
3977 /// {...
3978 /// \endcode
3980 /// Try to put the ``requires`` clause together with the class or function
3981 /// declaration.
3982 /// \code
3983 /// template <typename T>
3984 /// requires C<T> struct Foo {...
3985 ///
3986 /// template <typename T>
3987 /// requires C<T> void bar(T t) {...
3988 ///
3989 /// template <typename T>
3990 /// void baz(T t)
3991 /// requires C<T> {...
3992 /// \endcode
3994 /// Try to put everything in the same line if possible. Otherwise normal
3995 /// line breaking rules take over.
3996 /// \code
3997 /// // Fitting:
3998 /// template <typename T> requires C<T> struct Foo {...
3999 ///
4000 /// template <typename T> requires C<T> void bar(T t) {...
4001 ///
4002 /// template <typename T> void bar(T t) requires C<T> {...
4003 ///
4004 /// // Not fitting, one possible example:
4005 /// template <typename LongName>
4006 /// requires C<LongName>
4007 /// struct Foo {...
4008 ///
4009 /// template <typename LongName>
4010 /// requires C<LongName>
4011 /// void bar(LongName ln) {
4012 ///
4013 /// template <typename LongName>
4014 /// void bar(LongName ln)
4015 /// requires C<LongName> {
4016 /// \endcode
4018 };
4019
4020 /// \brief The position of the ``requires`` clause.
4021 /// \version 15
4023
4024 /// Indentation logic for requires expression bodies.
4026 /// Align requires expression body relative to the indentation level of the
4027 /// outer scope the requires expression resides in.
4028 /// This is the default.
4029 /// \code
4030 /// template <typename T>
4031 /// concept C = requires(T t) {
4032 /// ...
4033 /// }
4034 /// \endcode
4036 /// Align requires expression body relative to the ``requires`` keyword.
4037 /// \code
4038 /// template <typename T>
4039 /// concept C = requires(T t) {
4040 /// ...
4041 /// }
4042 /// \endcode
4044 };
4045
4046 /// The indentation used for requires expression bodies.
4047 /// \version 16
4049
4050 /// \brief The style if definition blocks should be separated.
4052 /// Leave definition blocks as they are.
4054 /// Insert an empty line between definition blocks.
4056 /// Remove any empty line between definition blocks.
4057 SDS_Never
4059
4060 /// Specifies the use of empty lines to separate definition blocks, including
4061 /// classes, structs, enums, and functions.
4062 /// \code
4063 /// Never v.s. Always
4064 /// #include <cstring> #include <cstring>
4065 /// struct Foo {
4066 /// int a, b, c; struct Foo {
4067 /// }; int a, b, c;
4068 /// namespace Ns { };
4069 /// class Bar {
4070 /// public: namespace Ns {
4071 /// struct Foobar { class Bar {
4072 /// int a; public:
4073 /// int b; struct Foobar {
4074 /// }; int a;
4075 /// private: int b;
4076 /// int t; };
4077 /// int method1() {
4078 /// // ... private:
4079 /// } int t;
4080 /// enum List {
4081 /// ITEM1, int method1() {
4082 /// ITEM2 // ...
4083 /// }; }
4084 /// template<typename T>
4085 /// int method2(T x) { enum List {
4086 /// // ... ITEM1,
4087 /// } ITEM2
4088 /// int i, j, k; };
4089 /// int method3(int par) {
4090 /// // ... template<typename T>
4091 /// } int method2(T x) {
4092 /// }; // ...
4093 /// class C {}; }
4094 /// }
4095 /// int i, j, k;
4096 ///
4097 /// int method3(int par) {
4098 /// // ...
4099 /// }
4100 /// };
4101 ///
4102 /// class C {};
4103 /// }
4104 /// \endcode
4105 /// \version 14
4107
4108 /// The maximal number of unwrapped lines that a short namespace spans.
4109 /// Defaults to 1.
4110 ///
4111 /// This determines the maximum length of short namespaces by counting
4112 /// unwrapped lines (i.e. containing neither opening nor closing
4113 /// namespace brace) and makes ``FixNamespaceComments`` omit adding
4114 /// end comments for those.
4115 /// \code
4116 /// ShortNamespaceLines: 1 vs. ShortNamespaceLines: 0
4117 /// namespace a { namespace a {
4118 /// int foo; int foo;
4119 /// } } // namespace a
4120 ///
4121 /// ShortNamespaceLines: 1 vs. ShortNamespaceLines: 0
4122 /// namespace b { namespace b {
4123 /// int foo; int foo;
4124 /// int bar; int bar;
4125 /// } // namespace b } // namespace b
4126 /// \endcode
4127 /// \version 13
4129
4130 /// Do not format macro definition body.
4131 /// \version 18
4133
4134 /// Include sorting options.
4135 enum SortIncludesOptions : int8_t {
4136 /// Includes are never sorted.
4137 /// \code
4138 /// #include "B/A.h"
4139 /// #include "A/B.h"
4140 /// #include "a/b.h"
4141 /// #include "A/b.h"
4142 /// #include "B/a.h"
4143 /// \endcode
4145 /// Includes are sorted in an ASCIIbetical or case sensitive fashion.
4146 /// \code
4147 /// #include "A/B.h"
4148 /// #include "A/b.h"
4149 /// #include "B/A.h"
4150 /// #include "B/a.h"
4151 /// #include "a/b.h"
4152 /// \endcode
4154 /// Includes are sorted in an alphabetical or case insensitive fashion.
4155 /// \code
4156 /// #include "A/B.h"
4157 /// #include "A/b.h"
4158 /// #include "a/b.h"
4159 /// #include "B/A.h"
4160 /// #include "B/a.h"
4161 /// \endcode
4163 };
4164
4165 /// Controls if and how clang-format will sort ``#includes``.
4166 /// \version 3.8
4168
4169 /// Position for Java Static imports.
4171 /// Static imports are placed before non-static imports.
4172 /// \code{.java}
4173 /// import static org.example.function1;
4174 ///
4175 /// import org.example.ClassA;
4176 /// \endcode
4178 /// Static imports are placed after non-static imports.
4179 /// \code{.java}
4180 /// import org.example.ClassA;
4181 ///
4182 /// import static org.example.function1;
4183 /// \endcode
4185 };
4186
4187 /// When sorting Java imports, by default static imports are placed before
4188 /// non-static imports. If ``JavaStaticImportAfterImport`` is ``After``,
4189 /// static imports are placed after non-static imports.
4190 /// \version 12
4192
4193 /// Using declaration sorting options.
4195 /// Using declarations are never sorted.
4196 /// \code
4197 /// using std::chrono::duration_cast;
4198 /// using std::move;
4199 /// using boost::regex;
4200 /// using boost::regex_constants::icase;
4201 /// using std::string;
4202 /// \endcode
4204 /// Using declarations are sorted in the order defined as follows:
4205 /// Split the strings by ``::`` and discard any initial empty strings. Sort
4206 /// the lists of names lexicographically, and within those groups, names are
4207 /// in case-insensitive lexicographic order.
4208 /// \code
4209 /// using boost::regex;
4210 /// using boost::regex_constants::icase;
4211 /// using std::chrono::duration_cast;
4212 /// using std::move;
4213 /// using std::string;
4214 /// \endcode
4216 /// Using declarations are sorted in the order defined as follows:
4217 /// Split the strings by ``::`` and discard any initial empty strings. The
4218 /// last element of each list is a non-namespace name; all others are
4219 /// namespace names. Sort the lists of names lexicographically, where the
4220 /// sort order of individual names is that all non-namespace names come
4221 /// before all namespace names, and within those groups, names are in
4222 /// case-insensitive lexicographic order.
4223 /// \code
4224 /// using boost::regex;
4225 /// using boost::regex_constants::icase;
4226 /// using std::move;
4227 /// using std::string;
4228 /// using std::chrono::duration_cast;
4229 /// \endcode
4231 };
4232
4233 /// Controls if and how clang-format will sort using declarations.
4234 /// \version 5
4236
4237 /// If ``true``, a space is inserted after C style casts.
4238 /// \code
4239 /// true: false:
4240 /// (int) i; vs. (int)i;
4241 /// \endcode
4242 /// \version 3.5
4244
4245 /// If ``true``, a space is inserted after the logical not operator (``!``).
4246 /// \code
4247 /// true: false:
4248 /// ! someExpression(); vs. !someExpression();
4249 /// \endcode
4250 /// \version 9
4252
4253 /// If \c true, a space will be inserted after the ``template`` keyword.
4254 /// \code
4255 /// true: false:
4256 /// template <int> void foo(); vs. template<int> void foo();
4257 /// \endcode
4258 /// \version 4
4260
4261 /// Different ways to put a space before opening parentheses.
4263 /// Don't ensure spaces around pointer qualifiers and use PointerAlignment
4264 /// instead.
4265 /// \code
4266 /// PointerAlignment: Left PointerAlignment: Right
4267 /// void* const* x = NULL; vs. void *const *x = NULL;
4268 /// \endcode
4270 /// Ensure that there is a space before pointer qualifiers.
4271 /// \code
4272 /// PointerAlignment: Left PointerAlignment: Right
4273 /// void* const* x = NULL; vs. void * const *x = NULL;
4274 /// \endcode
4276 /// Ensure that there is a space after pointer qualifiers.
4277 /// \code
4278 /// PointerAlignment: Left PointerAlignment: Right
4279 /// void* const * x = NULL; vs. void *const *x = NULL;
4280 /// \endcode
4282 /// Ensure that there is a space both before and after pointer qualifiers.
4283 /// \code
4284 /// PointerAlignment: Left PointerAlignment: Right
4285 /// void* const * x = NULL; vs. void * const *x = NULL;
4286 /// \endcode
4288 };
4289
4290 /// Defines in which cases to put a space before or after pointer qualifiers
4291 /// \version 12
4293
4294 /// If ``false``, spaces will be removed before assignment operators.
4295 /// \code
4296 /// true: false:
4297 /// int a = 5; vs. int a= 5;
4298 /// a += 42; a+= 42;
4299 /// \endcode
4300 /// \version 3.7
4302
4303 /// If ``false``, spaces will be removed before case colon.
4304 /// \code
4305 /// true: false
4306 /// switch (x) { vs. switch (x) {
4307 /// case 1 : break; case 1: break;
4308 /// } }
4309 /// \endcode
4310 /// \version 12
4312
4313 /// If ``true``, a space will be inserted before a C++11 braced list
4314 /// used to initialize an object (after the preceding identifier or type).
4315 /// \code
4316 /// true: false:
4317 /// Foo foo { bar }; vs. Foo foo{ bar };
4318 /// Foo {}; Foo{};
4319 /// vector<int> { 1, 2, 3 }; vector<int>{ 1, 2, 3 };
4320 /// new int[3] { 1, 2, 3 }; new int[3]{ 1, 2, 3 };
4321 /// \endcode
4322 /// \version 7
4324
4325 /// If ``false``, spaces will be removed before constructor initializer
4326 /// colon.
4327 /// \code
4328 /// true: false:
4329 /// Foo::Foo() : a(a) {} Foo::Foo(): a(a) {}
4330 /// \endcode
4331 /// \version 7
4333
4334 /// If ``false``, spaces will be removed before inheritance colon.
4335 /// \code
4336 /// true: false:
4337 /// class Foo : Bar {} vs. class Foo: Bar {}
4338 /// \endcode
4339 /// \version 7
4341
4342 /// If ``true``, a space will be added before a JSON colon. For other
4343 /// languages, e.g. JavaScript, use ``SpacesInContainerLiterals`` instead.
4344 /// \code
4345 /// true: false:
4346 /// { {
4347 /// "key" : "value" vs. "key": "value"
4348 /// } }
4349 /// \endcode
4350 /// \version 17
4352
4353 /// Different ways to put a space before opening parentheses.
4355 /// This is **deprecated** and replaced by ``Custom`` below, with all
4356 /// ``SpaceBeforeParensOptions`` but ``AfterPlacementOperator`` set to
4357 /// ``false``.
4359 /// Put a space before opening parentheses only after control statement
4360 /// keywords (``for/if/while...``).
4361 /// \code
4362 /// void f() {
4363 /// if (true) {
4364 /// f();
4365 /// }
4366 /// }
4367 /// \endcode
4369 /// Same as ``SBPO_ControlStatements`` except this option doesn't apply to
4370 /// ForEach and If macros. This is useful in projects where ForEach/If
4371 /// macros are treated as function calls instead of control statements.
4372 /// ``SBPO_ControlStatementsExceptForEachMacros`` remains an alias for
4373 /// backward compatibility.
4374 /// \code
4375 /// void f() {
4376 /// Q_FOREACH(...) {
4377 /// f();
4378 /// }
4379 /// }
4380 /// \endcode
4382 /// Put a space before opening parentheses only if the parentheses are not
4383 /// empty.
4384 /// \code
4385 /// void() {
4386 /// if (true) {
4387 /// f();
4388 /// g (x, y, z);
4389 /// }
4390 /// }
4391 /// \endcode
4393 /// Always put a space before opening parentheses, except when it's
4394 /// prohibited by the syntax rules (in function-like macro definitions) or
4395 /// when determined by other style rules (after unary operators, opening
4396 /// parentheses, etc.)
4397 /// \code
4398 /// void f () {
4399 /// if (true) {
4400 /// f ();
4401 /// }
4402 /// }
4403 /// \endcode
4405 /// Configure each individual space before parentheses in
4406 /// ``SpaceBeforeParensOptions``.
4408 };
4409
4410 /// Defines in which cases to put a space before opening parentheses.
4411 /// \version 3.5
4413
4414 /// Precise control over the spacing before parentheses.
4415 /// \code
4416 /// # Should be declared this way:
4417 /// SpaceBeforeParens: Custom
4418 /// SpaceBeforeParensOptions:
4419 /// AfterControlStatements: true
4420 /// AfterFunctionDefinitionName: true
4421 /// \endcode
4423 /// If ``true``, put space between control statement keywords
4424 /// (for/if/while...) and opening parentheses.
4425 /// \code
4426 /// true: false:
4427 /// if (...) {} vs. if(...) {}
4428 /// \endcode
4430 /// If ``true``, put space between foreach macros and opening parentheses.
4431 /// \code
4432 /// true: false:
4433 /// FOREACH (...) vs. FOREACH(...)
4434 /// <loop-body> <loop-body>
4435 /// \endcode
4437 /// If ``true``, put a space between function declaration name and opening
4438 /// parentheses.
4439 /// \code
4440 /// true: false:
4441 /// void f (); vs. void f();
4442 /// \endcode
4444 /// If ``true``, put a space between function definition name and opening
4445 /// parentheses.
4446 /// \code
4447 /// true: false:
4448 /// void f () {} vs. void f() {}
4449 /// \endcode
4451 /// If ``true``, put space between if macros and opening parentheses.
4452 /// \code
4453 /// true: false:
4454 /// IF (...) vs. IF(...)
4455 /// <conditional-body> <conditional-body>
4456 /// \endcode
4458 /// If ``true``, put a space between operator overloading and opening
4459 /// parentheses.
4460 /// \code
4461 /// true: false:
4462 /// void operator++ (int a); vs. void operator++(int a);
4463 /// object.operator++ (10); object.operator++(10);
4464 /// \endcode
4466 /// If ``true``, put a space between operator ``new``/``delete`` and opening
4467 /// parenthesis.
4468 /// \code
4469 /// true: false:
4470 /// new (buf) T; vs. new(buf) T;
4471 /// delete (buf) T; delete(buf) T;
4472 /// \endcode
4474 /// If ``true``, put space between requires keyword in a requires clause and
4475 /// opening parentheses, if there is one.
4476 /// \code
4477 /// true: false:
4478 /// template<typename T> vs. template<typename T>
4479 /// requires (A<T> && B<T>) requires(A<T> && B<T>)
4480 /// ... ...
4481 /// \endcode
4483 /// If ``true``, put space between requires keyword in a requires expression
4484 /// and opening parentheses.
4485 /// \code
4486 /// true: false:
4487 /// template<typename T> vs. template<typename T>
4488 /// concept C = requires (T t) { concept C = requires(T t) {
4489 /// ... ...
4490 /// } }
4491 /// \endcode
4493 /// If ``true``, put a space before opening parentheses only if the
4494 /// parentheses are not empty.
4495 /// \code
4496 /// true: false:
4497 /// void f (int a); vs. void f();
4498 /// f (a); f();
4499 /// \endcode
4501
4509
4511 return AfterControlStatements == Other.AfterControlStatements &&
4512 AfterForeachMacros == Other.AfterForeachMacros &&
4514 Other.AfterFunctionDeclarationName &&
4515 AfterFunctionDefinitionName == Other.AfterFunctionDefinitionName &&
4516 AfterIfMacros == Other.AfterIfMacros &&
4517 AfterOverloadedOperator == Other.AfterOverloadedOperator &&
4518 AfterPlacementOperator == Other.AfterPlacementOperator &&
4519 AfterRequiresInClause == Other.AfterRequiresInClause &&
4520 AfterRequiresInExpression == Other.AfterRequiresInExpression &&
4521 BeforeNonEmptyParentheses == Other.BeforeNonEmptyParentheses;
4522 }
4523 };
4524
4525 /// Control of individual space before parentheses.
4526 ///
4527 /// If ``SpaceBeforeParens`` is set to ``Custom``, use this to specify
4528 /// how each individual space before parentheses case should be handled.
4529 /// Otherwise, this is ignored.
4530 /// \code{.yaml}
4531 /// # Example of usage:
4532 /// SpaceBeforeParens: Custom
4533 /// SpaceBeforeParensOptions:
4534 /// AfterControlStatements: true
4535 /// AfterFunctionDefinitionName: true
4536 /// \endcode
4537 /// \version 14
4539
4540 /// If ``true``, spaces will be before ``[``.
4541 /// Lambdas will not be affected. Only the first ``[`` will get a space added.
4542 /// \code
4543 /// true: false:
4544 /// int a [5]; vs. int a[5];
4545 /// int a [5][5]; vs. int a[5][5];
4546 /// \endcode
4547 /// \version 10
4549
4550 /// If ``false``, spaces will be removed before range-based for loop
4551 /// colon.
4552 /// \code
4553 /// true: false:
4554 /// for (auto v : values) {} vs. for(auto v: values) {}
4555 /// \endcode
4556 /// \version 7
4558
4559 /// If ``true``, spaces will be inserted into ``{}``.
4560 /// \code
4561 /// true: false:
4562 /// void f() { } vs. void f() {}
4563 /// while (true) { } while (true) {}
4564 /// \endcode
4565 /// \version 10
4567
4568 /// If ``true``, spaces may be inserted into ``()``.
4569 /// This option is **deprecated**. See ``InEmptyParentheses`` of
4570 /// ``SpacesInParensOptions``.
4571 /// \version 3.7
4572 // bool SpaceInEmptyParentheses;
4573
4574 /// The number of spaces before trailing line comments
4575 /// (``//`` - comments).
4576 ///
4577 /// This does not affect trailing block comments (``/*`` - comments) as those
4578 /// commonly have different usage patterns and a number of special cases. In
4579 /// the case of Verilog, it doesn't affect a comment right after the opening
4580 /// parenthesis in the port or parameter list in a module header, because it
4581 /// is probably for the port on the following line instead of the parenthesis
4582 /// it follows.
4583 /// \code
4584 /// SpacesBeforeTrailingComments: 3
4585 /// void f() {
4586 /// if (true) { // foo1
4587 /// f(); // bar
4588 /// } // foo
4589 /// }
4590 /// \endcode
4591 /// \version 3.7
4593
4594 /// Styles for adding spacing after ``<`` and before ``>``
4595 /// in template argument lists.
4596 enum SpacesInAnglesStyle : int8_t {
4597 /// Remove spaces after ``<`` and before ``>``.
4598 /// \code
4599 /// static_cast<int>(arg);
4600 /// std::function<void(int)> fct;
4601 /// \endcode
4603 /// Add spaces after ``<`` and before ``>``.
4604 /// \code
4605 /// static_cast< int >(arg);
4606 /// std::function< void(int) > fct;
4607 /// \endcode
4609 /// Keep a single space after ``<`` and before ``>`` if any spaces were
4610 /// present. Option ``Standard: Cpp03`` takes precedence.
4613 /// The SpacesInAnglesStyle to use for template argument lists.
4614 /// \version 3.4
4616
4617 /// If ``true``, spaces will be inserted around if/for/switch/while
4618 /// conditions.
4619 /// This option is **deprecated**. See ``InConditionalStatements`` of
4620 /// ``SpacesInParensOptions``.
4621 /// \version 10
4622 // bool SpacesInConditionalStatement;
4623
4624 /// If ``true``, spaces are inserted inside container literals (e.g. ObjC and
4625 /// Javascript array and dict literals). For JSON, use
4626 /// ``SpaceBeforeJsonColon`` instead.
4627 /// \code{.js}
4628 /// true: false:
4629 /// var arr = [ 1, 2, 3 ]; vs. var arr = [1, 2, 3];
4630 /// f({a : 1, b : 2, c : 3}); f({a: 1, b: 2, c: 3});
4631 /// \endcode
4632 /// \version 3.7
4634
4635 /// If ``true``, spaces may be inserted into C style casts.
4636 /// This option is **deprecated**. See ``InCStyleCasts`` of
4637 /// ``SpacesInParensOptions``.
4638 /// \version 3.7
4639 // bool SpacesInCStyleCastParentheses;
4640
4641 /// Control of spaces within a single line comment.
4643 /// The minimum number of spaces at the start of the comment.
4644 unsigned Minimum;
4645 /// The maximum number of spaces at the start of the comment.
4646 unsigned Maximum;
4647 };
4648
4649 /// How many spaces are allowed at the start of a line comment. To disable the
4650 /// maximum set it to ``-1``, apart from that the maximum takes precedence
4651 /// over the minimum.
4652 /// \code
4653 /// Minimum = 1
4654 /// Maximum = -1
4655 /// // One space is forced
4656 ///
4657 /// // but more spaces are possible
4658 ///
4659 /// Minimum = 0
4660 /// Maximum = 0
4661 /// //Forces to start every comment directly after the slashes
4662 /// \endcode
4663 ///
4664 /// Note that in line comment sections the relative indent of the subsequent
4665 /// lines is kept, that means the following:
4666 /// \code
4667 /// before: after:
4668 /// Minimum: 1
4669 /// //if (b) { // if (b) {
4670 /// // return true; // return true;
4671 /// //} // }
4672 ///
4673 /// Maximum: 0
4674 /// /// List: ///List:
4675 /// /// - Foo /// - Foo
4676 /// /// - Bar /// - Bar
4677 /// \endcode
4678 ///
4679 /// This option has only effect if ``ReflowComments`` is set to ``true``.
4680 /// \version 13
4682
4683 /// Different ways to put a space before opening and closing parentheses.
4684 enum SpacesInParensStyle : int8_t {
4685 /// Never put a space in parentheses.
4686 /// \code
4687 /// void f() {
4688 /// if(true) {
4689 /// f();
4690 /// }
4691 /// }
4692 /// \endcode
4694 /// Configure each individual space in parentheses in
4695 /// `SpacesInParensOptions`.
4697 };
4698
4699 /// If ``true``, spaces will be inserted after ``(`` and before ``)``.
4700 /// This option is **deprecated**. The previous behavior is preserved by using
4701 /// ``SpacesInParens`` with ``Custom`` and by setting all
4702 /// ``SpacesInParensOptions`` to ``true`` except for ``InCStyleCasts`` and
4703 /// ``InEmptyParentheses``.
4704 /// \version 3.7
4705 // bool SpacesInParentheses;
4706
4707 /// Defines in which cases spaces will be inserted after ``(`` and before
4708 /// ``)``.
4709 /// \version 17
4711
4712 /// Precise control over the spacing in parentheses.
4713 /// \code
4714 /// # Should be declared this way:
4715 /// SpacesInParens: Custom
4716 /// SpacesInParensOptions:
4717 /// ExceptDoubleParentheses: false
4718 /// InConditionalStatements: true
4719 /// Other: true
4720 /// \endcode
4722 /// Override any of the following options to prevent addition of space
4723 /// when both opening and closing parentheses use multiple parentheses.
4724 /// \code
4725 /// true:
4726 /// __attribute__(( noreturn ))
4727 /// __decltype__(( x ))
4728 /// if (( a = b ))
4729 /// \endcode
4730 /// false:
4731 /// Uses the applicable option.
4733 /// Put a space in parentheses only inside conditional statements
4734 /// (``for/if/while/switch...``).
4735 /// \code
4736 /// true: false:
4737 /// if ( a ) { ... } vs. if (a) { ... }
4738 /// while ( i < 5 ) { ... } while (i < 5) { ... }
4739 /// \endcode
4741 /// Put a space in C style casts.
4742 /// \code
4743 /// true: false:
4744 /// x = ( int32 )y vs. x = (int32)y
4745 /// y = (( int (*)(int) )foo)(x); y = ((int (*)(int))foo)(x);
4746 /// \endcode
4748 /// Insert a space in empty parentheses, i.e. ``()``.
4749 /// \code
4750 /// true: false:
4751 /// void f( ) { vs. void f() {
4752 /// int x[] = {foo( ), bar( )}; int x[] = {foo(), bar()};
4753 /// if (true) { if (true) {
4754 /// f( ); f();
4755 /// } }
4756 /// } }
4757 /// \endcode
4759 /// Put a space in parentheses not covered by preceding options.
4760 /// \code
4761 /// true: false:
4762 /// t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete;
4763 /// \endcode
4764 bool Other;
4765
4769
4772 bool InEmptyParentheses, bool Other)
4776 Other(Other) {}
4777
4778 bool operator==(const SpacesInParensCustom &R) const {
4783 }
4784 bool operator!=(const SpacesInParensCustom &R) const {
4785 return !(*this == R);
4786 }
4787 };
4788
4789 /// Control of individual spaces in parentheses.
4790 ///
4791 /// If ``SpacesInParens`` is set to ``Custom``, use this to specify
4792 /// how each individual space in parentheses case should be handled.
4793 /// Otherwise, this is ignored.
4794 /// \code{.yaml}
4795 /// # Example of usage:
4796 /// SpacesInParens: Custom
4797 /// SpacesInParensOptions:
4798 /// ExceptDoubleParentheses: false
4799 /// InConditionalStatements: true
4800 /// InEmptyParentheses: true
4801 /// \endcode
4802 /// \version 17
4804
4805 /// If ``true``, spaces will be inserted after ``[`` and before ``]``.
4806 /// Lambdas without arguments or unspecified size array declarations will not
4807 /// be affected.
4808 /// \code
4809 /// true: false:
4810 /// int a[ 5 ]; vs. int a[5];
4811 /// std::unique_ptr<int[]> foo() {} // Won't be affected
4812 /// \endcode
4813 /// \version 3.7
4815
4816 /// Supported language standards for parsing and formatting C++ constructs.
4817 /// \code
4818 /// Latest: vector<set<int>>
4819 /// c++03 vs. vector<set<int> >
4820 /// \endcode
4821 ///
4822 /// The correct way to spell a specific language version is e.g. ``c++11``.
4823 /// The historical aliases ``Cpp03`` and ``Cpp11`` are deprecated.
4824 enum LanguageStandard : int8_t {
4825 /// Parse and format as C++03.
4826 /// ``Cpp03`` is a deprecated alias for ``c++03``
4827 LS_Cpp03, // c++03
4828 /// Parse and format as C++11.
4829 LS_Cpp11, // c++11
4830 /// Parse and format as C++14.
4831 LS_Cpp14, // c++14
4832 /// Parse and format as C++17.
4833 LS_Cpp17, // c++17
4834 /// Parse and format as C++20.
4835 LS_Cpp20, // c++20
4836 /// Parse and format using the latest supported language version.
4837 /// ``Cpp11`` is a deprecated alias for ``Latest``
4839 /// Automatic detection based on the input.
4841 };
4842
4843 /// Parse and format C++ constructs compatible with this standard.
4844 /// \code
4845 /// c++03: latest:
4846 /// vector<set<int> > x; vs. vector<set<int>> x;
4847 /// \endcode
4848 /// \version 3.7
4850
4851 /// Macros which are ignored in front of a statement, as if they were an
4852 /// attribute. So that they are not parsed as identifier, for example for Qts
4853 /// emit.
4854 /// \code
4855 /// AlignConsecutiveDeclarations: true
4856 /// StatementAttributeLikeMacros: []
4857 /// unsigned char data = 'x';
4858 /// emit signal(data); // This is parsed as variable declaration.
4859 ///
4860 /// AlignConsecutiveDeclarations: true
4861 /// StatementAttributeLikeMacros: [emit]
4862 /// unsigned char data = 'x';
4863 /// emit signal(data); // Now it's fine again.
4864 /// \endcode
4865 /// \version 12
4866 std::vector<std::string> StatementAttributeLikeMacros;
4867
4868 /// A vector of macros that should be interpreted as complete
4869 /// statements.
4870 ///
4871 /// Typical macros are expressions, and require a semi-colon to be
4872 /// added; sometimes this is not the case, and this allows to make
4873 /// clang-format aware of such cases.
4874 ///
4875 /// For example: Q_UNUSED
4876 /// \version 8
4877 std::vector<std::string> StatementMacros;
4878
4879 /// Works only when TableGenBreakInsideDAGArg is not DontBreak.
4880 /// The string list needs to consist of identifiers in TableGen.
4881 /// If any identifier is specified, this limits the line breaks by
4882 /// TableGenBreakInsideDAGArg option only on DAGArg values beginning with
4883 /// the specified identifiers.
4884 ///
4885 /// For example the configuration,
4886 /// \code{.yaml}
4887 /// TableGenBreakInsideDAGArg: BreakAll
4888 /// TableGenBreakingDAGArgOperators: [ins, outs]
4889 /// \endcode
4890 ///
4891 /// makes the line break only occurs inside DAGArgs beginning with the
4892 /// specified identifiers ``ins`` and ``outs``.
4893 ///
4894 /// \code
4895 /// let DAGArgIns = (ins
4896 /// i32:$src1,
4897 /// i32:$src2
4898 /// );
4899 /// let DAGArgOtherID = (other i32:$other1, i32:$other2);
4900 /// let DAGArgBang = (!cast<SomeType>("Some") i32:$src1, i32:$src2)
4901 /// \endcode
4902 /// \version 19
4903 std::vector<std::string> TableGenBreakingDAGArgOperators;
4904
4905 /// Different ways to control the format inside TableGen DAGArg.
4906 enum DAGArgStyle : int8_t {
4907 /// Never break inside DAGArg.
4908 /// \code
4909 /// let DAGArgIns = (ins i32:$src1, i32:$src2);
4910 /// \endcode
4912 /// Break inside DAGArg after each list element but for the last.
4913 /// This aligns to the first element.
4914 /// \code
4915 /// let DAGArgIns = (ins i32:$src1,
4916 /// i32:$src2);
4917 /// \endcode
4919 /// Break inside DAGArg after the operator and the all elements.
4920 /// \code
4921 /// let DAGArgIns = (ins
4922 /// i32:$src1,
4923 /// i32:$src2
4924 /// );
4925 /// \endcode
4927 };
4928
4929 /// The styles of the line break inside the DAGArg in TableGen.
4930 /// \version 19
4932
4933 /// The number of columns used for tab stops.
4934 /// \version 3.7
4935 unsigned TabWidth;
4936
4937 /// A vector of non-keyword identifiers that should be interpreted as type
4938 /// names.
4939 ///
4940 /// A ``*``, ``&``, or ``&&`` between a type name and another non-keyword
4941 /// identifier is annotated as a pointer or reference token instead of a
4942 /// binary operator.
4943 ///
4944 /// \version 17
4945 std::vector<std::string> TypeNames;
4946
4947 /// \brief A vector of macros that should be interpreted as type declarations
4948 /// instead of as function calls.
4949 ///
4950 /// These are expected to be macros of the form:
4951 /// \code
4952 /// STACK_OF(...)
4953 /// \endcode
4954 ///
4955 /// In the .clang-format configuration file, this can be configured like:
4956 /// \code{.yaml}
4957 /// TypenameMacros: [STACK_OF, LIST]
4958 /// \endcode
4959 ///
4960 /// For example: OpenSSL STACK_OF, BSD LIST_ENTRY.
4961 /// \version 9
4962 std::vector<std::string> TypenameMacros;
4963
4964 /// This option is **deprecated**. See ``LF`` and ``CRLF`` of ``LineEnding``.
4965 /// \version 10
4966 // bool UseCRLF;
4967
4968 /// Different ways to use tab in formatting.
4969 enum UseTabStyle : int8_t {
4970 /// Never use tab.
4972 /// Use tabs only for indentation.
4974 /// Fill all leading whitespace with tabs, and use spaces for alignment that
4975 /// appears within a line (e.g. consecutive assignments and declarations).
4977 /// Use tabs for line continuation and indentation, and spaces for
4978 /// alignment.
4980 /// Use tabs whenever we need to fill whitespace that spans at least from
4981 /// one tab stop to the next one.
4982 UT_Always
4984
4985 /// The way to use tab characters in the resulting file.
4986 /// \version 3.7
4988
4989 /// For Verilog, put each port on its own line in module instantiations.
4990 /// \code
4991 /// true:
4992 /// ffnand ff1(.q(),
4993 /// .qbar(out1),
4994 /// .clear(in1),
4995 /// .preset(in2));
4996 ///
4997 /// false:
4998 /// ffnand ff1(.q(), .qbar(out1), .clear(in1), .preset(in2));
4999 /// \endcode
5000 /// \version 17
5002
5003 /// A vector of macros which are whitespace-sensitive and should not
5004 /// be touched.
5005 ///
5006 /// These are expected to be macros of the form:
5007 /// \code
5008 /// STRINGIZE(...)
5009 /// \endcode
5010 ///
5011 /// In the .clang-format configuration file, this can be configured like:
5012 /// \code{.yaml}
5013 /// WhitespaceSensitiveMacros: [STRINGIZE, PP_STRINGIZE]
5014 /// \endcode
5015 ///
5016 /// For example: BOOST_PP_STRINGIZE
5017 /// \version 11
5018 std::vector<std::string> WhitespaceSensitiveMacros;
5019
5020 bool operator==(const FormatStyle &R) const {
5069 BreakArrays == R.BreakArrays &&
5110 IndentWidth == R.IndentWidth &&
5187 Standard == R.Standard &&
5193 TabWidth == R.TabWidth && TypeNames == R.TypeNames &&
5198 }
5199
5200 std::optional<FormatStyle> GetLanguageStyle(LanguageKind Language) const;
5201
5202 // Stores per-language styles. A FormatStyle instance inside has an empty
5203 // StyleSet. A FormatStyle instance returned by the Get method has its
5204 // StyleSet set to a copy of the originating StyleSet, effectively keeping the
5205 // internal representation of that StyleSet alive.
5206 //
5207 // The memory management and ownership reminds of a birds nest: chicks
5208 // leaving the nest take photos of the nest with them.
5210 typedef std::map<FormatStyle::LanguageKind, FormatStyle> MapType;
5211
5212 std::optional<FormatStyle> Get(FormatStyle::LanguageKind Language) const;
5213
5214 // Adds \p Style to this FormatStyleSet. Style must not have an associated
5215 // FormatStyleSet.
5216 // Style.Language should be different than LK_None. If this FormatStyleSet
5217 // already contains an entry for Style.Language, that gets replaced with the
5218 // passed Style.
5219 void Add(FormatStyle Style);
5220
5221 // Clears this FormatStyleSet.
5222 void Clear();
5223
5224 private:
5225 std::shared_ptr<MapType> Styles;
5226 };
5227
5229 const FormatStyle &MainStyle,
5230 const std::vector<FormatStyle> &ConfigurationStyles);
5231
5232private:
5233 FormatStyleSet StyleSet;
5234
5235 friend std::error_code
5236 parseConfiguration(llvm::MemoryBufferRef Config, FormatStyle *Style,
5237 bool AllowUnknownOptions,
5238 llvm::SourceMgr::DiagHandlerTy DiagHandler,
5239 void *DiagHandlerCtxt);
5240};
5241
5242/// Returns a format style complying with the LLVM coding standards:
5243/// http://llvm.org/docs/CodingStandards.html.
5246
5247/// Returns a format style complying with one of Google's style guides:
5248/// http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml.
5249/// http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml.
5250/// https://developers.google.com/protocol-buffers/docs/style.
5252
5253/// Returns a format style complying with Chromium's style guide:
5254/// http://www.chromium.org/developers/coding-style.
5256
5257/// Returns a format style complying with Mozilla's style guide:
5258/// https://firefox-source-docs.mozilla.org/code-quality/coding-style/index.html.
5260
5261/// Returns a format style complying with Webkit's style guide:
5262/// http://www.webkit.org/coding/coding-style.html
5264
5265/// Returns a format style complying with GNU Coding Standards:
5266/// http://www.gnu.org/prep/standards/standards.html
5268
5269/// Returns a format style complying with Microsoft style guide:
5270/// https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017
5272
5274
5275/// Returns style indicating formatting should be not applied at all.
5277
5278/// Gets a predefined style for the specified language by name.
5279///
5280/// Currently supported names: LLVM, Google, Chromium, Mozilla. Names are
5281/// compared case-insensitively.
5282///
5283/// Returns ``true`` if the Style has been set.
5285 FormatStyle *Style);
5286
5287/// Parse configuration from YAML-formatted text.
5288///
5289/// Style->Language is used to get the base style, if the ``BasedOnStyle``
5290/// option is present.
5291///
5292/// The FormatStyleSet of Style is reset.
5293///
5294/// When ``BasedOnStyle`` is not present, options not present in the YAML
5295/// document, are retained in \p Style.
5296///
5297/// If AllowUnknownOptions is true, no errors are emitted if unknown
5298/// format options are occurred.
5299///
5300/// If set all diagnostics are emitted through the DiagHandler.
5301std::error_code
5302parseConfiguration(llvm::MemoryBufferRef Config, FormatStyle *Style,
5303 bool AllowUnknownOptions = false,
5304 llvm::SourceMgr::DiagHandlerTy DiagHandler = nullptr,
5305 void *DiagHandlerCtx = nullptr);
5306
5307/// Like above but accepts an unnamed buffer.
5308inline std::error_code parseConfiguration(StringRef Config, FormatStyle *Style,
5309 bool AllowUnknownOptions = false) {
5310 return parseConfiguration(llvm::MemoryBufferRef(Config, "YAML"), Style,
5311 AllowUnknownOptions);
5312}
5313
5314/// Gets configuration in a YAML string.
5315std::string configurationAsText(const FormatStyle &Style);
5316
5317/// Returns the replacements necessary to sort all ``#include`` blocks
5318/// that are affected by ``Ranges``.
5319tooling::Replacements sortIncludes(const FormatStyle &Style, StringRef Code,
5321 StringRef FileName,
5322 unsigned *Cursor = nullptr);
5323
5324/// Returns the replacements corresponding to applying and formatting
5325/// \p Replaces on success; otheriwse, return an llvm::Error carrying
5326/// llvm::StringError.
5328formatReplacements(StringRef Code, const tooling::Replacements &Replaces,
5329 const FormatStyle &Style);
5330
5331/// Returns the replacements corresponding to applying \p Replaces and
5332/// cleaning up the code after that on success; otherwise, return an llvm::Error
5333/// carrying llvm::StringError.
5334/// This also supports inserting/deleting C++ #include directives:
5335/// - If a replacement has offset UINT_MAX, length 0, and a replacement text
5336/// that is an #include directive, this will insert the #include into the
5337/// correct block in the \p Code.
5338/// - If a replacement has offset UINT_MAX, length 1, and a replacement text
5339/// that is the name of the header to be removed, the header will be removed
5340/// from \p Code if it exists.
5341/// The include manipulation is done via ``tooling::HeaderInclude``, see its
5342/// documentation for more details on how include insertion points are found and
5343/// what edits are produced.
5345cleanupAroundReplacements(StringRef Code, const tooling::Replacements &Replaces,
5346 const FormatStyle &Style);
5347
5348/// Represents the status of a formatting attempt.
5350 /// A value of ``false`` means that any of the affected ranges were not
5351 /// formatted due to a non-recoverable syntax error.
5352 bool FormatComplete = true;
5353
5354 /// If ``FormatComplete`` is false, ``Line`` records a one-based
5355 /// original line number at which a syntax error might have occurred. This is
5356 /// based on a best-effort analysis and could be imprecise.
5357 unsigned Line = 0;
5358};
5359
5360/// Reformats the given \p Ranges in \p Code.
5361///
5362/// Each range is extended on either end to its next bigger logic unit, i.e.
5363/// everything that might influence its formatting or might be influenced by its
5364/// formatting.
5365///
5366/// Returns the ``Replacements`` necessary to make all \p Ranges comply with
5367/// \p Style.
5368///
5369/// If ``Status`` is non-null, its value will be populated with the status of
5370/// this formatting attempt. See \c FormattingAttemptStatus.
5371tooling::Replacements reformat(const FormatStyle &Style, StringRef Code,
5373 StringRef FileName = "<stdin>",
5374 FormattingAttemptStatus *Status = nullptr);
5375
5376/// Same as above, except if ``IncompleteFormat`` is non-null, its value
5377/// will be set to true if any of the affected ranges were not formatted due to
5378/// a non-recoverable syntax error.
5379tooling::Replacements reformat(const FormatStyle &Style, StringRef Code,
5381 StringRef FileName, bool *IncompleteFormat);
5382
5383/// Clean up any erroneous/redundant code in the given \p Ranges in \p
5384/// Code.
5385///
5386/// Returns the ``Replacements`` that clean up all \p Ranges in \p Code.
5387tooling::Replacements cleanup(const FormatStyle &Style, StringRef Code,
5389 StringRef FileName = "<stdin>");
5390
5391/// Fix namespace end comments in the given \p Ranges in \p Code.
5392///
5393/// Returns the ``Replacements`` that fix the namespace comments in all
5394/// \p Ranges in \p Code.
5396 StringRef Code,
5398 StringRef FileName = "<stdin>");
5399
5400/// Inserts or removes empty lines separating definition blocks including
5401/// classes, structs, functions, namespaces, and enums in the given \p Ranges in
5402/// \p Code.
5403///
5404/// Returns the ``Replacements`` that inserts or removes empty lines separating
5405/// definition blocks in all \p Ranges in \p Code.
5407 StringRef Code,
5409 StringRef FileName = "<stdin>");
5410
5411/// Sort consecutive using declarations in the given \p Ranges in
5412/// \p Code.
5413///
5414/// Returns the ``Replacements`` that sort the using declarations in all
5415/// \p Ranges in \p Code.
5417 StringRef Code,
5419 StringRef FileName = "<stdin>");
5420
5421/// Returns the ``LangOpts`` that the formatter expects you to set.
5422///
5423/// \param Style determines specific settings for lexing mode.
5425
5426/// Description to be used for help text for a ``llvm::cl`` option for
5427/// specifying format style. The description is closely related to the operation
5428/// of ``getStyle()``.
5429extern const char *StyleOptionHelpDescription;
5430
5431/// The suggested format style to use by default. This allows tools using
5432/// ``getStyle`` to have a consistent default style.
5433/// Different builds can modify the value to the preferred styles.
5434extern const char *DefaultFormatStyle;
5435
5436/// The suggested predefined style to use as the fallback style in ``getStyle``.
5437/// Different builds can modify the value to the preferred styles.
5438extern const char *DefaultFallbackStyle;
5439
5440/// Construct a FormatStyle based on ``StyleName``.
5441///
5442/// ``StyleName`` can take several forms:
5443/// * "{<key>: <value>, ...}" - Set specic style parameters.
5444/// * "<style name>" - One of the style names supported by
5445/// getPredefinedStyle().
5446/// * "file" - Load style configuration from a file called ``.clang-format``
5447/// located in one of the parent directories of ``FileName`` or the current
5448/// directory if ``FileName`` is empty.
5449/// * "file:<format_file_path>" to explicitly specify the configuration file to
5450/// use.
5451///
5452/// \param[in] StyleName Style name to interpret according to the description
5453/// above.
5454/// \param[in] FileName Path to start search for .clang-format if ``StyleName``
5455/// == "file".
5456/// \param[in] FallbackStyle The name of a predefined style used to fallback to
5457/// in case \p StyleName is "file" and no file can be found.
5458/// \param[in] Code The actual code to be formatted. Used to determine the
5459/// language if the filename isn't sufficient.
5460/// \param[in] FS The underlying file system, in which the file resides. By
5461/// default, the file system is the real file system.
5462/// \param[in] AllowUnknownOptions If true, unknown format options only
5463/// emit a warning. If false, errors are emitted on unknown format
5464/// options.