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