clang 22.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 /// If a function call or braced initializer list doesn't fit on a line, allow
655 /// putting all arguments onto the next line, even if ``BinPackArguments`` is
656 /// ``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 imply ``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 /// If ``BinPackLongBracedList`` is ``true`` it overrides
1216 /// ``BinPackArguments`` if there are 20 or more items in a braced
1217 /// initializer list.
1218 /// \code
1219 /// BinPackLongBracedList: false vs. BinPackLongBracedList: true
1220 /// vector<int> x{ vector<int> x{1, 2, ...,
1221 /// 20, 21};
1222 /// 1,
1223 /// 2,
1224 /// ...,
1225 /// 20,
1226 /// 21};
1227 /// \endcode
1228 /// \version 21
1230
1231 /// Different way to try to fit all parameters on a line.
1233 /// Bin-pack parameters.
1234 /// \code
1235 /// void f(int a, int bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
1236 /// int ccccccccccccccccccccccccccccccccccccccccccc);
1237 /// \endcode
1239 /// Put all parameters on the current line if they fit.
1240 /// Otherwise, put each one on its own line.
1241 /// \code
1242 /// void f(int a, int b, int c);
1243 ///
1244 /// void f(int a,
1245 /// int b,
1246 /// int ccccccccccccccccccccccccccccccccccccc);
1247 /// \endcode
1249 /// Always put each parameter on its own line.
1250 /// \code
1251 /// void f(int a,
1252 /// int b,
1253 /// int c);
1254 /// \endcode
1256 };
1257
1258 /// The bin pack parameters style to use.
1259 /// \version 3.7
1261
1262 /// Styles for adding spacing around ``:`` in bitfield definitions.
1264 /// Add one space on each side of the ``:``
1265 /// \code
1266 /// unsigned bf : 2;
1267 /// \endcode
1269 /// Add no space around the ``:`` (except when needed for
1270 /// ``AlignConsecutiveBitFields``).
1271 /// \code
1272 /// unsigned bf:2;
1273 /// \endcode
1275 /// Add space before the ``:`` only
1276 /// \code
1277 /// unsigned bf :2;
1278 /// \endcode
1280 /// Add space after the ``:`` only (space may be added before if
1281 /// needed for ``AlignConsecutiveBitFields``).
1282 /// \code
1283 /// unsigned bf: 2;
1284 /// \endcode
1287 /// The BitFieldColonSpacingStyle to use for bitfields.
1288 /// \version 12
1290
1291 /// The number of columns to use to indent the contents of braced init lists.
1292 /// If unset or negative, ``ContinuationIndentWidth`` is used.
1293 /// \code
1294 /// AlignAfterOpenBracket: AlwaysBreak
1295 /// BracedInitializerIndentWidth: 2
1296 ///
1297 /// void f() {
1298 /// SomeClass c{
1299 /// "foo",
1300 /// "bar",
1301 /// "baz",
1302 /// };
1303 /// auto s = SomeStruct{
1304 /// .foo = "foo",
1305 /// .bar = "bar",
1306 /// .baz = "baz",
1307 /// };
1308 /// SomeArrayT a[3] = {
1309 /// {
1310 /// foo,
1311 /// bar,
1312 /// },
1313 /// {
1314 /// foo,
1315 /// bar,
1316 /// },
1317 /// SomeArrayT{},
1318 /// };
1319 /// }
1320 /// \endcode
1321 /// \version 17
1323
1324 /// Different ways to wrap braces after control statements.
1326 /// Never wrap braces after a control statement.
1327 /// \code
1328 /// if (foo()) {
1329 /// } else {
1330 /// }
1331 /// for (int i = 0; i < 10; ++i) {
1332 /// }
1333 /// \endcode
1335 /// Only wrap braces after a multi-line control statement.
1336 /// \code
1337 /// if (foo && bar &&
1338 /// baz)
1339 /// {
1340 /// quux();
1341 /// }
1342 /// while (foo || bar) {
1343 /// }
1344 /// \endcode
1346 /// Always wrap braces after a control statement.
1347 /// \code
1348 /// if (foo())
1349 /// {
1350 /// } else
1351 /// {}
1352 /// for (int i = 0; i < 10; ++i)
1353 /// {}
1354 /// \endcode
1357
1358 /// Precise control over the wrapping of braces.
1359 /// \code
1360 /// # Should be declared this way:
1361 /// BreakBeforeBraces: Custom
1362 /// BraceWrapping:
1363 /// AfterClass: true
1364 /// \endcode
1366 /// Wrap case labels.
1367 /// \code
1368 /// false: true:
1369 /// switch (foo) { vs. switch (foo) {
1370 /// case 1: { case 1:
1371 /// bar(); {
1372 /// break; bar();
1373 /// } break;
1374 /// default: { }
1375 /// plop(); default:
1376 /// } {
1377 /// } plop();
1378 /// }
1379 /// }
1380 /// \endcode
1382 /// Wrap class definitions.
1383 /// \code
1384 /// true:
1385 /// class foo
1386 /// {};
1387 ///
1388 /// false:
1389 /// class foo {};
1390 /// \endcode
1392
1393 /// Wrap control statements (``if``/``for``/``while``/``switch``/..).
1395 /// Wrap enum definitions.
1396 /// \code
1397 /// true:
1398 /// enum X : int
1399 /// {
1400 /// B
1401 /// };
1402 ///
1403 /// false:
1404 /// enum X : int { B };
1405 /// \endcode
1407 /// Wrap function definitions.
1408 /// \code
1409 /// true:
1410 /// void foo()
1411 /// {
1412 /// bar();
1413 /// bar2();
1414 /// }
1415 ///
1416 /// false:
1417 /// void foo() {
1418 /// bar();
1419 /// bar2();
1420 /// }
1421 /// \endcode
1423 /// Wrap namespace definitions.
1424 /// \code
1425 /// true:
1426 /// namespace
1427 /// {
1428 /// int foo();
1429 /// int bar();
1430 /// }
1431 ///
1432 /// false:
1433 /// namespace {
1434 /// int foo();
1435 /// int bar();
1436 /// }
1437 /// \endcode
1439 /// Wrap ObjC definitions (interfaces, implementations...).
1440 /// \note
1441 /// @autoreleasepool and @synchronized blocks are wrapped
1442 /// according to ``AfterControlStatement`` flag.
1443 /// \endnote
1445 /// Wrap struct definitions.
1446 /// \code
1447 /// true:
1448 /// struct foo
1449 /// {
1450 /// int x;
1451 /// };
1452 ///
1453 /// false:
1454 /// struct foo {
1455 /// int x;
1456 /// };
1457 /// \endcode
1459 /// Wrap union definitions.
1460 /// \code
1461 /// true:
1462 /// union foo
1463 /// {
1464 /// int x;
1465 /// }
1466 ///
1467 /// false:
1468 /// union foo {
1469 /// int x;
1470 /// }
1471 /// \endcode
1473 /// Wrap extern blocks.
1474 /// \code
1475 /// true:
1476 /// extern "C"
1477 /// {
1478 /// int foo();
1479 /// }
1480 ///
1481 /// false:
1482 /// extern "C" {
1483 /// int foo();
1484 /// }
1485 /// \endcode
1486 bool AfterExternBlock; // Partially superseded by IndentExternBlock
1487 /// Wrap before ``catch``.
1488 /// \code
1489 /// true:
1490 /// try {
1491 /// foo();
1492 /// }
1493 /// catch () {
1494 /// }
1495 ///
1496 /// false:
1497 /// try {
1498 /// foo();
1499 /// } catch () {
1500 /// }
1501 /// \endcode
1503 /// Wrap before ``else``.
1504 /// \code
1505 /// true:
1506 /// if (foo()) {
1507 /// }
1508 /// else {
1509 /// }
1510 ///
1511 /// false:
1512 /// if (foo()) {
1513 /// } else {
1514 /// }
1515 /// \endcode
1517 /// Wrap lambda block.
1518 /// \code
1519 /// true:
1520 /// connect(
1521 /// []()
1522 /// {
1523 /// foo();
1524 /// bar();
1525 /// });
1526 ///
1527 /// false:
1528 /// connect([]() {
1529 /// foo();
1530 /// bar();
1531 /// });
1532 /// \endcode
1534 /// Wrap before ``while``.
1535 /// \code
1536 /// true:
1537 /// do {
1538 /// foo();
1539 /// }
1540 /// while (1);
1541 ///
1542 /// false:
1543 /// do {
1544 /// foo();
1545 /// } while (1);
1546 /// \endcode
1548 /// Indent the wrapped braces themselves.
1550 /// If ``false``, empty function body can be put on a single line.
1551 /// This option is used only if the opening brace of the function has
1552 /// already been wrapped, i.e. the ``AfterFunction`` brace wrapping mode is
1553 /// set, and the function could/should not be put on a single line (as per
1554 /// ``AllowShortFunctionsOnASingleLine`` and constructor formatting
1555 /// options).
1556 /// \code
1557 /// false: true:
1558 /// int f() vs. int f()
1559 /// {} {
1560 /// }
1561 /// \endcode
1562 ///
1564 /// If ``false``, empty record (e.g. class, struct or union) body
1565 /// can be put on a single line. This option is used only if the opening
1566 /// brace of the record has already been wrapped, i.e. the ``AfterClass``
1567 /// (for classes) brace wrapping mode is set.
1568 /// \code
1569 /// false: true:
1570 /// class Foo vs. class Foo
1571 /// {} {
1572 /// }
1573 /// \endcode
1574 ///
1576 /// If ``false``, empty namespace body can be put on a single line.
1577 /// This option is used only if the opening brace of the namespace has
1578 /// already been wrapped, i.e. the ``AfterNamespace`` brace wrapping mode is
1579 /// set.
1580 /// \code
1581 /// false: true:
1582 /// namespace Foo vs. namespace Foo
1583 /// {} {
1584 /// }
1585 /// \endcode
1586 ///
1588 };
1589
1590 /// Control of individual brace wrapping cases.
1591 ///
1592 /// If ``BreakBeforeBraces`` is set to ``Custom``, use this to specify how
1593 /// each individual brace case should be handled. Otherwise, this is ignored.
1594 /// \code{.yaml}
1595 /// # Example of usage:
1596 /// BreakBeforeBraces: Custom
1597 /// BraceWrapping:
1598 /// AfterEnum: true
1599 /// AfterStruct: false
1600 /// SplitEmptyFunction: false
1601 /// \endcode
1602 /// \version 3.8
1604
1605 /// Break between adjacent string literals.
1606 /// \code
1607 /// true:
1608 /// return "Code"
1609 /// "\0\52\26\55\55\0"
1610 /// "x013"
1611 /// "\02\xBA";
1612 /// false:
1613 /// return "Code" "\0\52\26\55\55\0" "x013" "\02\xBA";
1614 /// \endcode
1615 /// \version 18
1617
1618 /// Different ways to break after attributes.
1620 /// Always break after attributes.
1621 /// \code
1622 /// [[maybe_unused]]
1623 /// const int i;
1624 /// [[gnu::const]] [[maybe_unused]]
1625 /// int j;
1626 ///
1627 /// [[nodiscard]]
1628 /// inline int f();
1629 /// [[gnu::const]] [[nodiscard]]
1630 /// int g();
1631 ///
1632 /// [[likely]]
1633 /// if (a)
1634 /// f();
1635 /// else
1636 /// g();
1637 ///
1638 /// switch (b) {
1639 /// [[unlikely]]
1640 /// case 1:
1641 /// ++b;
1642 /// break;
1643 /// [[likely]]
1644 /// default:
1645 /// return;
1646 /// }
1647 /// \endcode
1649 /// Leave the line breaking after attributes as is.
1650 /// \code
1651 /// [[maybe_unused]] const int i;
1652 /// [[gnu::const]] [[maybe_unused]]
1653 /// int j;
1654 ///
1655 /// [[nodiscard]] inline int f();
1656 /// [[gnu::const]] [[nodiscard]]
1657 /// int g();
1658 ///
1659 /// [[likely]] if (a)
1660 /// f();
1661 /// else
1662 /// g();
1663 ///
1664 /// switch (b) {
1665 /// [[unlikely]] case 1:
1666 /// ++b;
1667 /// break;
1668 /// [[likely]]
1669 /// default:
1670 /// return;
1671 /// }
1672 /// \endcode
1674 /// Never break after attributes.
1675 /// \code
1676 /// [[maybe_unused]] const int i;
1677 /// [[gnu::const]] [[maybe_unused]] int j;
1678 ///
1679 /// [[nodiscard]] inline int f();
1680 /// [[gnu::const]] [[nodiscard]] int g();
1681 ///
1682 /// [[likely]] if (a)
1683 /// f();
1684 /// else
1685 /// g();
1686 ///
1687 /// switch (b) {
1688 /// [[unlikely]] case 1:
1689 /// ++b;
1690 /// break;
1691 /// [[likely]] default:
1692 /// return;
1693 /// }
1694 /// \endcode
1696 };
1697
1698 /// Break after a group of C++11 attributes before variable or function
1699 /// (including constructor/destructor) declaration/definition names or before
1700 /// control statements, i.e. ``if``, ``switch`` (including ``case`` and
1701 /// ``default`` labels), ``for``, and ``while`` statements.
1702 /// \version 16
1704
1705 /// The function declaration return type breaking style to use.
1706 /// \version 19
1708
1709 /// If ``true``, clang-format will always break after a Json array ``[``
1710 /// otherwise it will scan until the closing ``]`` to determine if it should
1711 /// add newlines between elements (prettier compatible).
1712 ///
1713 /// \note
1714 /// This is currently only for formatting JSON.
1715 /// \endnote
1716 /// \code
1717 /// true: false:
1718 /// [ vs. [1, 2, 3, 4]
1719 /// 1,
1720 /// 2,
1721 /// 3,
1722 /// 4
1723 /// ]
1724 /// \endcode
1725 /// \version 16
1727
1728 /// The style of wrapping parameters on the same line (bin-packed) or
1729 /// on one line each.
1730 enum BinPackStyle : int8_t {
1731 /// Automatically determine parameter bin-packing behavior.
1733 /// Always bin-pack parameters.
1735 /// Never bin-pack parameters.
1737 };
1738
1739 /// The style of breaking before or after binary operators.
1740 enum BinaryOperatorStyle : int8_t {
1741 /// Break after operators.
1742 /// \code
1743 /// LooooooooooongType loooooooooooooooooooooongVariable =
1744 /// someLooooooooooooooooongFunction();
1745 ///
1746 /// bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
1747 /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ==
1748 /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
1749 /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa >
1750 /// ccccccccccccccccccccccccccccccccccccccccc;
1751 /// \endcode
1753 /// Break before operators that aren't assignments.
1754 /// \code
1755 /// LooooooooooongType loooooooooooooooooooooongVariable =
1756 /// someLooooooooooooooooongFunction();
1757 ///
1758 /// bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1759 /// + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1760 /// == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1761 /// && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1762 /// > ccccccccccccccccccccccccccccccccccccccccc;
1763 /// \endcode
1765 /// Break before operators.
1766 /// \code
1767 /// LooooooooooongType loooooooooooooooooooooongVariable
1768 /// = someLooooooooooooooooongFunction();
1769 ///
1770 /// bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1771 /// + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1772 /// == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1773 /// && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1774 /// > ccccccccccccccccccccccccccccccccccccccccc;
1775 /// \endcode
1777 };
1778
1779 /// The way to wrap binary operators.
1780 /// \version 3.6
1782
1783 /// Different ways to attach braces to their surrounding context.
1784 enum BraceBreakingStyle : int8_t {
1785 /// Always attach braces to surrounding context.
1786 /// \code
1787 /// namespace N {
1788 /// enum E {
1789 /// E1,
1790 /// E2,
1791 /// };
1792 ///
1793 /// class C {
1794 /// public:
1795 /// C();
1796 /// };
1797 ///
1798 /// bool baz(int i) {
1799 /// try {
1800 /// do {
1801 /// switch (i) {
1802 /// case 1: {
1803 /// foobar();
1804 /// break;
1805 /// }
1806 /// default: {
1807 /// break;
1808 /// }
1809 /// }
1810 /// } while (--i);
1811 /// return true;
1812 /// } catch (...) {
1813 /// handleError();
1814 /// return false;
1815 /// }
1816 /// }
1817 ///
1818 /// void foo(bool b) {
1819 /// if (b) {
1820 /// baz(2);
1821 /// } else {
1822 /// baz(5);
1823 /// }
1824 /// }
1825 ///
1826 /// void bar() { foo(true); }
1827 /// } // namespace N
1828 /// \endcode
1830 /// Like ``Attach``, but break before braces on function, namespace and
1831 /// class definitions.
1832 /// \code
1833 /// namespace N
1834 /// {
1835 /// enum E {
1836 /// E1,
1837 /// E2,
1838 /// };
1839 ///
1840 /// class C
1841 /// {
1842 /// public:
1843 /// C();
1844 /// };
1845 ///
1846 /// bool baz(int i)
1847 /// {
1848 /// try {
1849 /// do {
1850 /// switch (i) {
1851 /// case 1: {
1852 /// foobar();
1853 /// break;
1854 /// }
1855 /// default: {
1856 /// break;
1857 /// }
1858 /// }
1859 /// } while (--i);
1860 /// return true;
1861 /// } catch (...) {
1862 /// handleError();
1863 /// return false;
1864 /// }
1865 /// }
1866 ///
1867 /// void foo(bool b)
1868 /// {
1869 /// if (b) {
1870 /// baz(2);
1871 /// } else {
1872 /// baz(5);
1873 /// }
1874 /// }
1875 ///
1876 /// void bar() { foo(true); }
1877 /// } // namespace N
1878 /// \endcode
1880 /// Like ``Attach``, but break before braces on enum, function, and record
1881 /// definitions.
1882 /// \code
1883 /// namespace N {
1884 /// enum E
1885 /// {
1886 /// E1,
1887 /// E2,
1888 /// };
1889 ///
1890 /// class C
1891 /// {
1892 /// public:
1893 /// C();
1894 /// };
1895 ///
1896 /// bool baz(int i)
1897 /// {
1898 /// try {
1899 /// do {
1900 /// switch (i) {
1901 /// case 1: {
1902 /// foobar();
1903 /// break;
1904 /// }
1905 /// default: {
1906 /// break;
1907 /// }
1908 /// }
1909 /// } while (--i);
1910 /// return true;
1911 /// } catch (...) {
1912 /// handleError();
1913 /// return false;
1914 /// }
1915 /// }
1916 ///
1917 /// void foo(bool b)
1918 /// {
1919 /// if (b) {
1920 /// baz(2);
1921 /// } else {
1922 /// baz(5);
1923 /// }
1924 /// }
1925 ///
1926 /// void bar() { foo(true); }
1927 /// } // namespace N
1928 /// \endcode
1930 /// Like ``Attach``, but break before function definitions, ``catch``, and
1931 /// ``else``.
1932 /// \code
1933 /// namespace N {
1934 /// enum E {
1935 /// E1,
1936 /// E2,
1937 /// };
1938 ///
1939 /// class C {
1940 /// public:
1941 /// C();
1942 /// };
1943 ///
1944 /// bool baz(int i)
1945 /// {
1946 /// try {
1947 /// do {
1948 /// switch (i) {
1949 /// case 1: {
1950 /// foobar();
1951 /// break;
1952 /// }
1953 /// default: {
1954 /// break;
1955 /// }
1956 /// }
1957 /// } while (--i);
1958 /// return true;
1959 /// }
1960 /// catch (...) {
1961 /// handleError();
1962 /// return false;
1963 /// }
1964 /// }
1965 ///
1966 /// void foo(bool b)
1967 /// {
1968 /// if (b) {
1969 /// baz(2);
1970 /// }
1971 /// else {
1972 /// baz(5);
1973 /// }
1974 /// }
1975 ///
1976 /// void bar() { foo(true); }
1977 /// } // namespace N
1978 /// \endcode
1980 /// Always break before braces.
1981 /// \code
1982 /// namespace N
1983 /// {
1984 /// enum E
1985 /// {
1986 /// E1,
1987 /// E2,
1988 /// };
1989 ///
1990 /// class C
1991 /// {
1992 /// public:
1993 /// C();
1994 /// };
1995 ///
1996 /// bool baz(int i)
1997 /// {
1998 /// try
1999 /// {
2000 /// do
2001 /// {
2002 /// switch (i)
2003 /// {
2004 /// case 1:
2005 /// {
2006 /// foobar();
2007 /// break;
2008 /// }
2009 /// default:
2010 /// {
2011 /// break;
2012 /// }
2013 /// }
2014 /// } while (--i);
2015 /// return true;
2016 /// }
2017 /// catch (...)
2018 /// {
2019 /// handleError();
2020 /// return false;
2021 /// }
2022 /// }
2023 ///
2024 /// void foo(bool b)
2025 /// {
2026 /// if (b)
2027 /// {
2028 /// baz(2);
2029 /// }
2030 /// else
2031 /// {
2032 /// baz(5);
2033 /// }
2034 /// }
2035 ///
2036 /// void bar() { foo(true); }
2037 /// } // namespace N
2038 /// \endcode
2040 /// Like ``Allman`` but always indent braces and line up code with braces.
2041 /// \code
2042 /// namespace N
2043 /// {
2044 /// enum E
2045 /// {
2046 /// E1,
2047 /// E2,
2048 /// };
2049 ///
2050 /// class C
2051 /// {
2052 /// public:
2053 /// C();
2054 /// };
2055 ///
2056 /// bool baz(int i)
2057 /// {
2058 /// try
2059 /// {
2060 /// do
2061 /// {
2062 /// switch (i)
2063 /// {
2064 /// case 1:
2065 /// {
2066 /// foobar();
2067 /// break;
2068 /// }
2069 /// default:
2070 /// {
2071 /// break;
2072 /// }
2073 /// }
2074 /// } while (--i);
2075 /// return true;
2076 /// }
2077 /// catch (...)
2078 /// {
2079 /// handleError();
2080 /// return false;
2081 /// }
2082 /// }
2083 ///
2084 /// void foo(bool b)
2085 /// {
2086 /// if (b)
2087 /// {
2088 /// baz(2);
2089 /// }
2090 /// else
2091 /// {
2092 /// baz(5);
2093 /// }
2094 /// }
2095 ///
2096 /// void bar() { foo(true); }
2097 /// } // namespace N
2098 /// \endcode
2100 /// Always break before braces and add an extra level of indentation to
2101 /// braces of control statements, not to those of class, function
2102 /// or other definitions.
2103 /// \code
2104 /// namespace N
2105 /// {
2106 /// enum E
2107 /// {
2108 /// E1,
2109 /// E2,
2110 /// };
2111 ///
2112 /// class C
2113 /// {
2114 /// public:
2115 /// C();
2116 /// };
2117 ///
2118 /// bool baz(int i)
2119 /// {
2120 /// try
2121 /// {
2122 /// do
2123 /// {
2124 /// switch (i)
2125 /// {
2126 /// case 1:
2127 /// {
2128 /// foobar();
2129 /// break;
2130 /// }
2131 /// default:
2132 /// {
2133 /// break;
2134 /// }
2135 /// }
2136 /// }
2137 /// while (--i);
2138 /// return true;
2139 /// }
2140 /// catch (...)
2141 /// {
2142 /// handleError();
2143 /// return false;
2144 /// }
2145 /// }
2146 ///
2147 /// void foo(bool b)
2148 /// {
2149 /// if (b)
2150 /// {
2151 /// baz(2);
2152 /// }
2153 /// else
2154 /// {
2155 /// baz(5);
2156 /// }
2157 /// }
2158 ///
2159 /// void bar() { foo(true); }
2160 /// } // namespace N
2161 /// \endcode
2163 /// Like ``Attach``, but break before functions.
2164 /// \code
2165 /// namespace N {
2166 /// enum E {
2167 /// E1,
2168 /// E2,
2169 /// };
2170 ///
2171 /// class C {
2172 /// public:
2173 /// C();
2174 /// };
2175 ///
2176 /// bool baz(int i)
2177 /// {
2178 /// try {
2179 /// do {
2180 /// switch (i) {
2181 /// case 1: {
2182 /// foobar();
2183 /// break;
2184 /// }
2185 /// default: {
2186 /// break;
2187 /// }
2188 /// }
2189 /// } while (--i);
2190 /// return true;
2191 /// } catch (...) {
2192 /// handleError();
2193 /// return false;
2194 /// }
2195 /// }
2196 ///
2197 /// void foo(bool b)
2198 /// {
2199 /// if (b) {
2200 /// baz(2);
2201 /// } else {
2202 /// baz(5);
2203 /// }
2204 /// }
2205 ///
2206 /// void bar() { foo(true); }
2207 /// } // namespace N
2208 /// \endcode
2210 /// Configure each individual brace in ``BraceWrapping``.
2211 BS_Custom
2213
2214 /// The brace breaking style to use.
2215 /// \version 3.7
2217
2218 /// Different ways to break before concept declarations.
2220 /// Keep the template declaration line together with ``concept``.
2221 /// \code
2222 /// template <typename T> concept C = ...;
2223 /// \endcode
2225 /// Breaking between template declaration and ``concept`` is allowed. The
2226 /// actual behavior depends on the content and line breaking rules and
2227 /// penalties.
2229 /// Always break before ``concept``, putting it in the line after the
2230 /// template declaration.
2231 /// \code
2232 /// template <typename T>
2233 /// concept C = ...;
2234 /// \endcode
2236 };
2237
2238 /// The concept declaration style to use.
2239 /// \version 12
2241
2242 /// Different ways to break ASM parameters.
2244 /// No break before inline ASM colon.
2245 /// \code
2246 /// asm volatile("string", : : val);
2247 /// \endcode
2249 /// Break before inline ASM colon if the line length is longer than column
2250 /// limit.
2251 /// \code
2252 /// asm volatile("string", : : val);
2253 /// asm("cmoveq %1, %2, %[result]"
2254 /// : [result] "=r"(result)
2255 /// : "r"(test), "r"(new), "[result]"(old));
2256 /// \endcode
2258 /// Always break before inline ASM colon.
2259 /// \code
2260 /// asm volatile("string",
2261 /// :
2262 /// : val);
2263 /// \endcode
2265 };
2266
2267 /// The inline ASM colon style to use.
2268 /// \version 16
2270
2271 /// If ``true``, break before a template closing bracket (``>``) when there is
2272 /// a line break after the matching opening bracket (``<``).
2273 /// \code
2274 /// true:
2275 /// template <typename Foo, typename Bar>
2276 ///
2277 /// template <typename Foo,
2278 /// typename Bar>
2279 ///
2280 /// template <
2281 /// typename Foo,
2282 /// typename Bar
2283 /// >
2284 ///
2285 /// false:
2286 /// template <typename Foo, typename Bar>
2287 ///
2288 /// template <typename Foo,
2289 /// typename Bar>
2290 ///
2291 /// template <
2292 /// typename Foo,
2293 /// typename Bar>
2294 /// \endcode
2295 /// \version 21
2297
2298 /// If ``true``, ternary operators will be placed after line breaks.
2299 /// \code
2300 /// true:
2301 /// veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription
2302 /// ? firstValue
2303 /// : SecondValueVeryVeryVeryVeryLong;
2304 ///
2305 /// false:
2306 /// veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ?
2307 /// firstValue :
2308 /// SecondValueVeryVeryVeryVeryLong;
2309 /// \endcode
2310 /// \version 3.7
2312
2313 /// Different ways to break binary operations.
2315 /// Don't break binary operations
2316 /// \code
2317 /// aaa + bbbb * ccccc - ddddd +
2318 /// eeeeeeeeeeeeeeee;
2319 /// \endcode
2321
2322 /// Binary operations will either be all on the same line, or each operation
2323 /// will have one line each.
2324 /// \code
2325 /// aaa +
2326 /// bbbb *
2327 /// ccccc -
2328 /// ddddd +
2329 /// eeeeeeeeeeeeeeee;
2330 /// \endcode
2332
2333 /// Binary operations of a particular precedence that exceed the column
2334 /// limit will have one line each.
2335 /// \code
2336 /// aaa +
2337 /// bbbb * ccccc -
2338 /// ddddd +
2339 /// eeeeeeeeeeeeeeee;
2340 /// \endcode
2343
2344 /// The break binary operations style to use.
2345 /// \version 20
2347
2348 /// Different ways to break initializers.
2350 /// Break constructor initializers before the colon and after the commas.
2351 /// \code
2352 /// Constructor()
2353 /// : initializer1(),
2354 /// initializer2()
2355 /// \endcode
2357 /// Break constructor initializers before the colon and commas, and align
2358 /// the commas with the colon.
2359 /// \code
2360 /// Constructor()
2361 /// : initializer1()
2362 /// , initializer2()
2363 /// \endcode
2365 /// Break constructor initializers after the colon and commas.
2366 /// \code
2367 /// Constructor() :
2368 /// initializer1(),
2369 /// initializer2()
2370 /// \endcode
2373
2374 /// The break constructor initializers style to use.
2375 /// \version 5
2377
2378 /// If ``true``, clang-format will always break before function definition
2379 /// parameters.
2380 /// \code
2381 /// true:
2382 /// void functionDefinition(
2383 /// int A, int B) {}
2384 ///
2385 /// false:
2386 /// void functionDefinition(int A, int B) {}
2387 ///
2388 /// \endcode
2389 /// \version 19
2391
2392 /// Break after each annotation on a field in Java files.
2393 /// \code{.java}
2394 /// true: false:
2395 /// @Partial vs. @Partial @Mock DataLoad loader;
2396 /// @Mock
2397 /// DataLoad loader;
2398 /// \endcode
2399 /// \version 3.8
2401
2402 /// Allow breaking string literals when formatting.
2403 ///
2404 /// In C, C++, and Objective-C:
2405 /// \code
2406 /// true:
2407 /// const char* x = "veryVeryVeryVeryVeryVe"
2408 /// "ryVeryVeryVeryVeryVery"
2409 /// "VeryLongString";
2410 ///
2411 /// false:
2412 /// const char* x =
2413 /// "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
2414 /// \endcode
2415 ///
2416 /// In C# and Java:
2417 /// \code
2418 /// true:
2419 /// string x = "veryVeryVeryVeryVeryVe" +
2420 /// "ryVeryVeryVeryVeryVery" +
2421 /// "VeryLongString";
2422 ///
2423 /// false:
2424 /// string x =
2425 /// "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
2426 /// \endcode
2427 ///
2428 /// C# interpolated strings are not broken.
2429 ///
2430 /// In Verilog:
2431 /// \code
2432 /// true:
2433 /// string x = {"veryVeryVeryVeryVeryVe",
2434 /// "ryVeryVeryVeryVeryVery",
2435 /// "VeryLongString"};
2436 ///
2437 /// false:
2438 /// string x =
2439 /// "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
2440 /// \endcode
2441 ///
2442 /// \version 3.9
2444
2445 /// The column limit.
2446 ///
2447 /// A column limit of ``0`` means that there is no column limit. In this case,
2448 /// clang-format will respect the input's line breaking decisions within
2449 /// statements unless they contradict other rules.
2450 /// \version 3.7
2451 unsigned ColumnLimit;
2452
2453 /// A regular expression that describes comments with special meaning,
2454 /// which should not be split into lines or otherwise changed.
2455 /// \code
2456 /// // CommentPragmas: '^ FOOBAR pragma:'
2457 /// // Will leave the following line unaffected
2458 /// #include <vector> // FOOBAR pragma: keep
2459 /// \endcode
2460 /// \version 3.7
2461 std::string CommentPragmas;
2462
2463 /// Different ways to break inheritance list.
2465 /// Break inheritance list before the colon and after the commas.
2466 /// \code
2467 /// class Foo
2468 /// : Base1,
2469 /// Base2
2470 /// {};
2471 /// \endcode
2473 /// Break inheritance list before the colon and commas, and align
2474 /// the commas with the colon.
2475 /// \code
2476 /// class Foo
2477 /// : Base1
2478 /// , Base2
2479 /// {};
2480 /// \endcode
2482 /// Break inheritance list after the colon and commas.
2483 /// \code
2484 /// class Foo :
2485 /// Base1,
2486 /// Base2
2487 /// {};
2488 /// \endcode
2490 /// Break inheritance list only after the commas.
2491 /// \code
2492 /// class Foo : Base1,
2493 /// Base2
2494 /// {};
2495 /// \endcode
2497 };
2498
2499 /// The inheritance list style to use.
2500 /// \version 7
2502
2503 /// The template declaration breaking style to use.
2504 /// \version 19
2506
2507 /// If ``true``, consecutive namespace declarations will be on the same
2508 /// line. If ``false``, each namespace is declared on a new line.
2509 /// \code
2510 /// true:
2511 /// namespace Foo { namespace Bar {
2512 /// }}
2513 ///
2514 /// false:
2515 /// namespace Foo {
2516 /// namespace Bar {
2517 /// }
2518 /// }
2519 /// \endcode
2520 ///
2521 /// If it does not fit on a single line, the overflowing namespaces get
2522 /// wrapped:
2523 /// \code
2524 /// namespace Foo { namespace Bar {
2525 /// namespace Extra {
2526 /// }}}
2527 /// \endcode
2528 /// \version 5
2530
2531 /// This option is **deprecated**. See ``CurrentLine`` of
2532 /// ``PackConstructorInitializers``.
2533 /// \version 3.7
2534 // bool ConstructorInitializerAllOnOneLineOrOnePerLine;
2535
2536 /// The number of characters to use for indentation of constructor
2537 /// initializer lists as well as inheritance lists.
2538 /// \version 3.7
2540
2541 /// Indent width for line continuations.
2542 /// \code
2543 /// ContinuationIndentWidth: 2
2544 ///
2545 /// int i = // VeryVeryVeryVeryVeryLongComment
2546 /// longFunction( // Again a long comment
2547 /// arg);
2548 /// \endcode
2549 /// \version 3.7
2551
2552 /// If ``true``, format braced lists as best suited for C++11 braced
2553 /// lists.
2554 ///
2555 /// Important differences:
2556 ///
2557 /// * No spaces inside the braced list.
2558 /// * No line break before the closing brace.
2559 /// * Indentation with the continuation indent, not with the block indent.
2560 ///
2561 /// Fundamentally, C++11 braced lists are formatted exactly like function
2562 /// calls would be formatted in their place. If the braced list follows a name
2563 /// (e.g. a type or variable name), clang-format formats as if the ``{}`` were
2564 /// the parentheses of a function call with that name. If there is no name,
2565 /// a zero-length name is assumed.
2566 /// \code
2567 /// true: false:
2568 /// vector<int> x{1, 2, 3, 4}; vs. vector<int> x{ 1, 2, 3, 4 };
2569 /// vector<T> x{{}, {}, {}, {}}; vector<T> x{ {}, {}, {}, {} };
2570 /// f(MyMap[{composite, key}]); f(MyMap[{ composite, key }]);
2571 /// new int[3]{1, 2, 3}; new int[3]{ 1, 2, 3 };
2572 /// \endcode
2573 /// \version 3.4
2575
2576 /// This option is **deprecated**. See ``DeriveLF`` and ``DeriveCRLF`` of
2577 /// ``LineEnding``.
2578 /// \version 10
2579 // bool DeriveLineEnding;
2580
2581 /// If ``true``, analyze the formatted file for the most common
2582 /// alignment of ``&`` and ``*``.
2583 /// Pointer and reference alignment styles are going to be updated according
2584 /// to the preferences found in the file.
2585 /// ``PointerAlignment`` is then used only as fallback.
2586 /// \version 3.7
2588
2589 /// Disables formatting completely.
2590 /// \version 3.7
2592
2593 /// Different styles for empty line after access modifiers.
2594 /// ``EmptyLineBeforeAccessModifier`` configuration handles the number of
2595 /// empty lines between two access modifiers.
2597 /// Remove all empty lines after access modifiers.
2598 /// \code
2599 /// struct foo {
2600 /// private:
2601 /// int i;
2602 /// protected:
2603 /// int j;
2604 /// /* comment */
2605 /// public:
2606 /// foo() {}
2607 /// private:
2608 /// protected:
2609 /// };
2610 /// \endcode
2612 /// Keep existing empty lines after access modifiers.
2613 /// MaxEmptyLinesToKeep is applied instead.
2615 /// Always add empty line after access modifiers if there are none.
2616 /// MaxEmptyLinesToKeep is applied also.
2617 /// \code
2618 /// struct foo {
2619 /// private:
2620 ///
2621 /// int i;
2622 /// protected:
2623 ///
2624 /// int j;
2625 /// /* comment */
2626 /// public:
2627 ///
2628 /// foo() {}
2629 /// private:
2630 ///
2631 /// protected:
2632 ///
2633 /// };
2634 /// \endcode
2636 };
2637
2638 /// Defines when to put an empty line after access modifiers.
2639 /// ``EmptyLineBeforeAccessModifier`` configuration handles the number of
2640 /// empty lines between two access modifiers.
2641 /// \version 13
2643
2644 /// Different styles for empty line before access modifiers.
2646 /// Remove all empty lines before access modifiers.
2647 /// \code
2648 /// struct foo {
2649 /// private:
2650 /// int i;
2651 /// protected:
2652 /// int j;
2653 /// /* comment */
2654 /// public:
2655 /// foo() {}
2656 /// private:
2657 /// protected:
2658 /// };
2659 /// \endcode
2661 /// Keep existing empty lines before access modifiers.
2663 /// Add empty line only when access modifier starts a new logical block.
2664 /// Logical block is a group of one or more member fields or functions.
2665 /// \code
2666 /// struct foo {
2667 /// private:
2668 /// int i;
2669 ///
2670 /// protected:
2671 /// int j;
2672 /// /* comment */
2673 /// public:
2674 /// foo() {}
2675 ///
2676 /// private:
2677 /// protected:
2678 /// };
2679 /// \endcode
2681 /// Always add empty line before access modifiers unless access modifier
2682 /// is at the start of struct or class definition.
2683 /// \code
2684 /// struct foo {
2685 /// private:
2686 /// int i;
2687 ///
2688 /// protected:
2689 /// int j;
2690 /// /* comment */
2691 ///
2692 /// public:
2693 /// foo() {}
2694 ///
2695 /// private:
2696 ///
2697 /// protected:
2698 /// };
2699 /// \endcode
2701 };
2702
2703 /// Defines in which cases to put empty line before access modifiers.
2704 /// \version 12
2706
2707 /// Styles for ``enum`` trailing commas.
2709 /// Don't insert or remove trailing commas.
2710 /// \code
2711 /// enum { a, b, c, };
2712 /// enum Color { red, green, blue };
2713 /// \endcode
2715 /// Insert trailing commas.
2716 /// \code
2717 /// enum { a, b, c, };
2718 /// enum Color { red, green, blue, };
2719 /// \endcode
2721 /// Remove trailing commas.
2722 /// \code
2723 /// enum { a, b, c };
2724 /// enum Color { red, green, blue };
2725 /// \endcode
2727 };
2728
2729 /// Insert a comma (if missing) or remove the comma at the end of an ``enum``
2730 /// enumerator list.
2731 /// \warning
2732 /// Setting this option to any value other than ``Leave`` could lead to
2733 /// incorrect code formatting due to clang-format's lack of complete semantic
2734 /// information. As such, extra care should be taken to review code changes
2735 /// made by this option.
2736 /// \endwarning
2737 /// \version 21
2739
2740 /// If ``true``, clang-format detects whether function calls and
2741 /// definitions are formatted with one parameter per line.
2742 ///
2743 /// Each call can be bin-packed, one-per-line or inconclusive. If it is
2744 /// inconclusive, e.g. completely on one line, but a decision needs to be
2745 /// made, clang-format analyzes whether there are other bin-packed cases in
2746 /// the input file and act accordingly.
2747 ///
2748 /// \note
2749 /// This is an experimental flag, that might go away or be renamed. Do
2750 /// not use this in config files, etc. Use at your own risk.
2751 /// \endnote
2752 /// \version 3.7
2754
2755 /// If ``true``, clang-format adds missing namespace end comments for
2756 /// namespaces and fixes invalid existing ones. This doesn't affect short
2757 /// namespaces, which are controlled by ``ShortNamespaceLines``.
2758 /// \code
2759 /// true: false:
2760 /// namespace longNamespace { vs. namespace longNamespace {
2761 /// void foo(); void foo();
2762 /// void bar(); void bar();
2763 /// } // namespace a }
2764 /// namespace shortNamespace { namespace shortNamespace {
2765 /// void baz(); void baz();
2766 /// } }
2767 /// \endcode
2768 /// \version 5
2770
2771 /// A vector of macros that should be interpreted as foreach loops
2772 /// instead of as function calls.
2773 ///
2774 /// These are expected to be macros of the form:
2775 /// \code
2776 /// FOREACH(<variable-declaration>, ...)
2777 /// <loop-body>
2778 /// \endcode
2779 ///
2780 /// In the .clang-format configuration file, this can be configured like:
2781 /// \code{.yaml}
2782 /// ForEachMacros: [RANGES_FOR, FOREACH]
2783 /// \endcode
2784 ///
2785 /// For example: BOOST_FOREACH.
2786 /// \version 3.7
2787 std::vector<std::string> ForEachMacros;
2788
2790
2791 /// A vector of macros that should be interpreted as conditionals
2792 /// instead of as function calls.
2793 ///
2794 /// These are expected to be macros of the form:
2795 /// \code
2796 /// IF(...)
2797 /// <conditional-body>
2798 /// else IF(...)
2799 /// <conditional-body>
2800 /// \endcode
2801 ///
2802 /// In the .clang-format configuration file, this can be configured like:
2803 /// \code{.yaml}
2804 /// IfMacros: [IF]
2805 /// \endcode
2806 ///
2807 /// For example: `KJ_IF_MAYBE
2808 /// <https://github.com/capnproto/capnproto/blob/master/kjdoc/tour.md#maybes>`_
2809 /// \version 13
2810 std::vector<std::string> IfMacros;
2811
2812 /// Specify whether access modifiers should have their own indentation level.
2813 ///
2814 /// When ``false``, access modifiers are indented (or outdented) relative to
2815 /// the record members, respecting the ``AccessModifierOffset``. Record
2816 /// members are indented one level below the record.
2817 /// When ``true``, access modifiers get their own indentation level. As a
2818 /// consequence, record members are always indented 2 levels below the record,
2819 /// regardless of the access modifier presence. Value of the
2820 /// ``AccessModifierOffset`` is ignored.
2821 /// \code
2822 /// false: true:
2823 /// class C { vs. class C {
2824 /// class D { class D {
2825 /// void bar(); void bar();
2826 /// protected: protected:
2827 /// D(); D();
2828 /// }; };
2829 /// public: public:
2830 /// C(); C();
2831 /// }; };
2832 /// void foo() { void foo() {
2833 /// return 1; return 1;
2834 /// } }
2835 /// \endcode
2836 /// \version 13
2838
2839 /// Indent case label blocks one level from the case label.
2840 ///
2841 /// When ``false``, the block following the case label uses the same
2842 /// indentation level as for the case label, treating the case label the same
2843 /// as an if-statement.
2844 /// When ``true``, the block gets indented as a scope block.
2845 /// \code
2846 /// false: true:
2847 /// switch (fool) { vs. switch (fool) {
2848 /// case 1: { case 1:
2849 /// bar(); {
2850 /// } break; bar();
2851 /// default: { }
2852 /// plop(); break;
2853 /// } default:
2854 /// } {
2855 /// plop();
2856 /// }
2857 /// }
2858 /// \endcode
2859 /// \version 11
2861
2862 /// Indent case labels one level from the switch statement.
2863 ///
2864 /// When ``false``, use the same indentation level as for the switch
2865 /// statement. Switch statement body is always indented one level more than
2866 /// case labels (except the first block following the case label, which
2867 /// itself indents the code - unless IndentCaseBlocks is enabled).
2868 /// \code
2869 /// false: true:
2870 /// switch (fool) { vs. switch (fool) {
2871 /// case 1: case 1:
2872 /// bar(); bar();
2873 /// break; break;
2874 /// default: default:
2875 /// plop(); plop();
2876 /// } }
2877 /// \endcode
2878 /// \version 3.3
2880
2881 /// If ``true``, clang-format will indent the body of an ``export { ... }``
2882 /// block. This doesn't affect the formatting of anything else related to
2883 /// exported declarations.
2884 /// \code
2885 /// true: false:
2886 /// export { vs. export {
2887 /// void foo(); void foo();
2888 /// void bar(); void bar();
2889 /// } }
2890 /// \endcode
2891 /// \version 20
2893
2894 /// Indents extern blocks
2896 /// Backwards compatible with AfterExternBlock's indenting.
2897 /// \code
2898 /// IndentExternBlock: AfterExternBlock
2899 /// BraceWrapping.AfterExternBlock: true
2900 /// extern "C"
2901 /// {
2902 /// void foo();
2903 /// }
2904 /// \endcode
2905 ///
2906 /// \code
2907 /// IndentExternBlock: AfterExternBlock
2908 /// BraceWrapping.AfterExternBlock: false
2909 /// extern "C" {
2910 /// void foo();
2911 /// }
2912 /// \endcode
2914 /// Does not indent extern blocks.
2915 /// \code
2916 /// extern "C" {
2917 /// void foo();
2918 /// }
2919 /// \endcode
2921 /// Indents extern blocks.
2922 /// \code
2923 /// extern "C" {
2924 /// void foo();
2925 /// }
2926 /// \endcode
2928 };
2929
2930 /// IndentExternBlockStyle is the type of indenting of extern blocks.
2931 /// \version 11
2933
2934 /// Indent goto labels.
2935 ///
2936 /// When ``false``, goto labels are flushed left.
2937 /// \code
2938 /// true: false:
2939 /// int f() { vs. int f() {
2940 /// if (foo()) { if (foo()) {
2941 /// label1: label1:
2942 /// bar(); bar();
2943 /// } }
2944 /// label2: label2:
2945 /// return 1; return 1;
2946 /// } }
2947 /// \endcode
2948 /// \version 10
2950
2951 /// Options for indenting preprocessor directives.
2953 /// Does not indent any directives.
2954 /// \code
2955 /// #if FOO
2956 /// #if BAR
2957 /// #include <foo>
2958 /// #endif
2959 /// #endif
2960 /// \endcode
2962 /// Indents directives after the hash.
2963 /// \code
2964 /// #if FOO
2965 /// # if BAR
2966 /// # include <foo>
2967 /// # endif
2968 /// #endif
2969 /// \endcode
2971 /// Indents directives before the hash.
2972 /// \code
2973 /// #if FOO
2974 /// #if BAR
2975 /// #include <foo>
2976 /// #endif
2977 /// #endif
2978 /// \endcode
2981
2982 /// The preprocessor directive indenting style to use.
2983 /// \version 6
2985
2986 /// Indent the requires clause in a template. This only applies when
2987 /// ``RequiresClausePosition`` is ``OwnLine``, ``OwnLineWithBrace``,
2988 /// or ``WithFollowing``.
2989 ///
2990 /// In clang-format 12, 13 and 14 it was named ``IndentRequires``.
2991 /// \code
2992 /// true:
2993 /// template <typename It>
2994 /// requires Iterator<It>
2995 /// void sort(It begin, It end) {
2996 /// //....
2997 /// }
2998 ///
2999 /// false:
3000 /// template <typename It>
3001 /// requires Iterator<It>
3002 /// void sort(It begin, It end) {
3003 /// //....
3004 /// }
3005 /// \endcode
3006 /// \version 15
3008
3009 /// The number of columns to use for indentation.
3010 /// \code
3011 /// IndentWidth: 3
3012 ///
3013 /// void f() {
3014 /// someFunction();
3015 /// if (true, false) {
3016 /// f();
3017 /// }
3018 /// }
3019 /// \endcode
3020 /// \version 3.7
3021 unsigned IndentWidth;
3022
3023 /// Indent if a function definition or declaration is wrapped after the
3024 /// type.
3025 /// \code
3026 /// true:
3027 /// LoooooooooooooooooooooooooooooooooooooooongReturnType
3028 /// LoooooooooooooooooooooooooooooooongFunctionDeclaration();
3029 ///
3030 /// false:
3031 /// LoooooooooooooooooooooooooooooooooooooooongReturnType
3032 /// LoooooooooooooooooooooooooooooooongFunctionDeclaration();
3033 /// \endcode
3034 /// \version 3.7
3036
3037 /// Insert braces after control statements (``if``, ``else``, ``for``, ``do``,
3038 /// and ``while``) in C++ unless the control statements are inside macro
3039 /// definitions or the braces would enclose preprocessor directives.
3040 /// \warning
3041 /// Setting this option to ``true`` could lead to incorrect code formatting
3042 /// due to clang-format's lack of complete semantic information. As such,
3043 /// extra care should be taken to review code changes made by this option.
3044 /// \endwarning
3045 /// \code
3046 /// false: true:
3047 ///
3048 /// if (isa<FunctionDecl>(D)) vs. if (isa<FunctionDecl>(D)) {
3049 /// handleFunctionDecl(D); handleFunctionDecl(D);
3050 /// else if (isa<VarDecl>(D)) } else if (isa<VarDecl>(D)) {
3051 /// handleVarDecl(D); handleVarDecl(D);
3052 /// else } else {
3053 /// return; return;
3054 /// }
3055 ///
3056 /// while (i--) vs. while (i--) {
3057 /// for (auto *A : D.attrs()) for (auto *A : D.attrs()) {
3058 /// handleAttr(A); handleAttr(A);
3059 /// }
3060 /// }
3061 ///
3062 /// do vs. do {
3063 /// --i; --i;
3064 /// while (i); } while (i);
3065 /// \endcode
3066 /// \version 15
3068
3069 /// Insert a newline at end of file if missing.
3070 /// \version 16
3072
3073 /// The style of inserting trailing commas into container literals.
3074 enum TrailingCommaStyle : int8_t {
3075 /// Do not insert trailing commas.
3077 /// Insert trailing commas in container literals that were wrapped over
3078 /// multiple lines. Note that this is conceptually incompatible with
3079 /// bin-packing, because the trailing comma is used as an indicator
3080 /// that a container should be formatted one-per-line (i.e. not bin-packed).
3081 /// So inserting a trailing comma counteracts bin-packing.
3083 };
3084
3085 /// If set to ``TCS_Wrapped`` will insert trailing commas in container
3086 /// literals (arrays and objects) that wrap across multiple lines.
3087 /// It is currently only available for JavaScript
3088 /// and disabled by default ``TCS_None``.
3089 /// ``InsertTrailingCommas`` cannot be used together with ``BinPackArguments``
3090 /// as inserting the comma disables bin-packing.
3091 /// \code
3092 /// TSC_Wrapped:
3093 /// const someArray = [
3094 /// aaaaaaaaaaaaaaaaaaaaaaaaaa,
3095 /// aaaaaaaaaaaaaaaaaaaaaaaaaa,
3096 /// aaaaaaaaaaaaaaaaaaaaaaaaaa,
3097 /// // ^ inserted
3098 /// ]
3099 /// \endcode
3100 /// \version 11
3102
3103 /// Separator format of integer literals of different bases.
3104 ///
3105 /// If negative, remove separators. If ``0``, leave the literal as is. If
3106 /// positive, insert separators between digits starting from the rightmost
3107 /// digit.
3108 ///
3109 /// For example, the config below will leave separators in binary literals
3110 /// alone, insert separators in decimal literals to separate the digits into
3111 /// groups of 3, and remove separators in hexadecimal literals.
3112 /// \code
3113 /// IntegerLiteralSeparator:
3114 /// Binary: 0
3115 /// Decimal: 3
3116 /// Hex: -1
3117 /// \endcode
3118 ///
3119 /// You can also specify a minimum number of digits (``BinaryMinDigits``,
3120 /// ``DecimalMinDigits``, and ``HexMinDigits``) the integer literal must
3121 /// have in order for the separators to be inserted.
3123 /// Format separators in binary literals.
3124 /// \code{.text}
3125 /// /* -1: */ b = 0b100111101101;
3126 /// /* 0: */ b = 0b10011'11'0110'1;
3127 /// /* 3: */ b = 0b100'111'101'101;
3128 /// /* 4: */ b = 0b1001'1110'1101;
3129 /// \endcode
3130 int8_t Binary;
3131 /// Format separators in binary literals with a minimum number of digits.
3132 /// \code{.text}
3133 /// // Binary: 3
3134 /// // BinaryMinDigits: 7
3135 /// b1 = 0b101101;
3136 /// b2 = 0b1'101'101;
3137 /// \endcode
3139 /// Format separators in decimal literals.
3140 /// \code{.text}
3141 /// /* -1: */ d = 18446744073709550592ull;
3142 /// /* 0: */ d = 184467'440737'0'95505'92ull;
3143 /// /* 3: */ d = 18'446'744'073'709'550'592ull;
3144 /// \endcode
3145 int8_t Decimal;
3146 /// Format separators in decimal literals with a minimum number of digits.
3147 /// \code{.text}
3148 /// // Decimal: 3
3149 /// // DecimalMinDigits: 5
3150 /// d1 = 2023;
3151 /// d2 = 10'000;
3152 /// \endcode
3154 /// Format separators in hexadecimal literals.
3155 /// \code{.text}
3156 /// /* -1: */ h = 0xDEADBEEFDEADBEEFuz;
3157 /// /* 0: */ h = 0xDEAD'BEEF'DE'AD'BEE'Fuz;
3158 /// /* 2: */ h = 0xDE'AD'BE'EF'DE'AD'BE'EFuz;
3159 /// \endcode
3160 int8_t Hex;
3161 /// Format separators in hexadecimal literals with a minimum number of
3162 /// digits.
3163 /// \code{.text}
3164 /// // Hex: 2
3165 /// // HexMinDigits: 6
3166 /// h1 = 0xABCDE;
3167 /// h2 = 0xAB'CD'EF;
3168 /// \endcode
3171 return Binary == R.Binary && BinaryMinDigits == R.BinaryMinDigits &&
3173 Hex == R.Hex && HexMinDigits == R.HexMinDigits;
3174 }
3175 };
3176
3177 /// Format integer literal separators (``'`` for C++ and ``_`` for C#, Java,
3178 /// and JavaScript).
3179 /// \version 16
3181
3182 /// A vector of prefixes ordered by the desired groups for Java imports.
3183 ///
3184 /// One group's prefix can be a subset of another - the longest prefix is
3185 /// always matched. Within a group, the imports are ordered lexicographically.
3186 /// Static imports are grouped separately and follow the same group rules.
3187 /// By default, static imports are placed before non-static imports,
3188 /// but this behavior is changed by another option,
3189 /// ``SortJavaStaticImport``.
3190 ///
3191 /// In the .clang-format configuration file, this can be configured like
3192 /// in the following yaml example. This will result in imports being
3193 /// formatted as in the Java example below.
3194 /// \code{.yaml}
3195 /// JavaImportGroups: [com.example, com, org]
3196 /// \endcode
3197 ///
3198 /// \code{.java}
3199 /// import static com.example.function1;
3200 ///
3201 /// import static com.test.function2;
3202 ///
3203 /// import static org.example.function3;
3204 ///
3205 /// import com.example.ClassA;
3206 /// import com.example.Test;
3207 /// import com.example.a.ClassB;
3208 ///
3209 /// import com.test.ClassC;
3210 ///
3211 /// import org.example.ClassD;
3212 /// \endcode
3213 /// \version 8
3214 std::vector<std::string> JavaImportGroups;
3215
3216 /// Quotation styles for JavaScript strings. Does not affect template
3217 /// strings.
3218 enum JavaScriptQuoteStyle : int8_t {
3219 /// Leave string quotes as they are.
3220 /// \code{.js}
3221 /// string1 = "foo";
3222 /// string2 = 'bar';
3223 /// \endcode
3225 /// Always use single quotes.
3226 /// \code{.js}
3227 /// string1 = 'foo';
3228 /// string2 = 'bar';
3229 /// \endcode
3231 /// Always use double quotes.
3232 /// \code{.js}
3233 /// string1 = "foo";
3234 /// string2 = "bar";
3235 /// \endcode
3238
3239 /// The JavaScriptQuoteStyle to use for JavaScript strings.
3240 /// \version 3.9
3242
3243 // clang-format off
3244 /// Whether to wrap JavaScript import/export statements.
3245 /// \code{.js}
3246 /// true:
3247 /// import {
3248 /// VeryLongImportsAreAnnoying,
3249 /// VeryLongImportsAreAnnoying,
3250 /// VeryLongImportsAreAnnoying,
3251 /// } from "some/module.js"
3252 ///
3253 /// false:
3254 /// import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js"
3255 /// \endcode
3256 /// \version 3.9
3258 // clang-format on
3259
3260 /// Options regarding which empty lines are kept.
3261 ///
3262 /// For example, the config below will remove empty lines at start of the
3263 /// file, end of the file, and start of blocks.
3264 ///
3265 /// \code
3266 /// KeepEmptyLines:
3267 /// AtEndOfFile: false
3268 /// AtStartOfBlock: false
3269 /// AtStartOfFile: false
3270 /// \endcode
3272 /// Keep empty lines at end of file.
3274 /// Keep empty lines at start of a block.
3275 /// \code
3276 /// true: false:
3277 /// if (foo) { vs. if (foo) {
3278 /// bar();
3279 /// bar(); }
3280 /// }
3281 /// \endcode
3283 /// Keep empty lines at start of file.
3285 bool operator==(const KeepEmptyLinesStyle &R) const {
3286 return AtEndOfFile == R.AtEndOfFile &&
3289 }
3290 };
3291 /// Which empty lines are kept. See ``MaxEmptyLinesToKeep`` for how many
3292 /// consecutive empty lines are kept.
3293 /// \version 19
3295
3296 /// This option is **deprecated**. See ``AtEndOfFile`` of ``KeepEmptyLines``.
3297 /// \version 17
3298 // bool KeepEmptyLinesAtEOF;
3299
3300 /// This option is **deprecated**. See ``AtStartOfBlock`` of
3301 /// ``KeepEmptyLines``.
3302 /// \version 3.7
3303 // bool KeepEmptyLinesAtTheStartOfBlocks;
3304
3305 /// Keep the form feed character if it's immediately preceded and followed by
3306 /// a newline. Multiple form feeds and newlines within a whitespace range are
3307 /// replaced with a single newline and form feed followed by the remaining
3308 /// newlines.
3309 /// \version 20
3311
3312 /// Indentation logic for lambda bodies.
3314 /// Align lambda body relative to the lambda signature. This is the default.
3315 /// \code
3316 /// someMethod(
3317 /// [](SomeReallyLongLambdaSignatureArgument foo) {
3318 /// return;
3319 /// });
3320 /// \endcode
3322 /// For statements within block scope, align lambda body relative to the
3323 /// indentation level of the outer scope the lambda signature resides in.
3324 /// \code
3325 /// someMethod(
3326 /// [](SomeReallyLongLambdaSignatureArgument foo) {
3327 /// return;
3328 /// });
3329 ///
3330 /// someMethod(someOtherMethod(
3331 /// [](SomeReallyLongLambdaSignatureArgument foo) {
3332 /// return;
3333 /// }));
3334 /// \endcode
3336 };
3337
3338 /// The indentation style of lambda bodies. ``Signature`` (the default)
3339 /// causes the lambda body to be indented one additional level relative to
3340 /// the indentation level of the signature. ``OuterScope`` forces the lambda
3341 /// body to be indented one additional level relative to the parent scope
3342 /// containing the lambda signature.
3343 /// \version 13
3345
3346 /// Supported languages.
3347 ///
3348 /// When stored in a configuration file, specifies the language, that the
3349 /// configuration targets. When passed to the ``reformat()`` function, enables
3350 /// syntax features specific to the language.
3351 enum LanguageKind : int8_t {
3352 /// Do not use.
3354 /// Should be used for C.
3356 /// Should be used for C++.
3358 /// Should be used for C#.
3360 /// Should be used for Java.
3362 /// Should be used for JavaScript.
3364 /// Should be used for JSON.
3366 /// Should be used for Objective-C, Objective-C++.
3368 /// Should be used for Protocol Buffers
3369 /// (https://developers.google.com/protocol-buffers/).
3371 /// Should be used for TableGen code.
3373 /// Should be used for Protocol Buffer messages in text format
3374 /// (https://developers.google.com/protocol-buffers/).
3376 /// Should be used for Verilog and SystemVerilog.
3377 /// https://standards.ieee.org/ieee/1800/6700/
3378 /// https://sci-hub.st/10.1109/IEEESTD.2018.8299595
3381 bool isCpp() const {
3382 return Language == LK_Cpp || Language == LK_C || Language == LK_ObjC;
3383 }
3384 bool isCSharp() const { return Language == LK_CSharp; }
3385 bool isJson() const { return Language == LK_Json; }
3386 bool isJava() const { return Language == LK_Java; }
3387 bool isJavaScript() const { return Language == LK_JavaScript; }
3388 bool isVerilog() const { return Language == LK_Verilog; }
3389 bool isTextProto() const { return Language == LK_TextProto; }
3390 bool isProto() const { return Language == LK_Proto || isTextProto(); }
3391 bool isTableGen() const { return Language == LK_TableGen; }
3392
3393 /// The language that this format style targets.
3394 /// \note
3395 /// You can specify the language (``C``, ``Cpp``, or ``ObjC``) for ``.h``
3396 /// files by adding a ``// clang-format Language:`` line before the first
3397 /// non-comment (and non-empty) line, e.g. ``// clang-format Language: Cpp``.
3398 /// \endnote
3399 /// \version 3.5
3401
3402 /// Line ending style.
3403 enum LineEndingStyle : int8_t {
3404 /// Use ``\n``.
3406 /// Use ``\r\n``.
3408 /// Use ``\n`` unless the input has more lines ending in ``\r\n``.
3410 /// Use ``\r\n`` unless the input has more lines ending in ``\n``.
3412 };
3413
3414 /// Line ending style (``\n`` or ``\r\n``) to use.
3415 /// \version 16
3417
3418 /// A regular expression matching macros that start a block.
3419 /// \code
3420 /// # With:
3421 /// MacroBlockBegin: "^NS_MAP_BEGIN|\
3422 /// NS_TABLE_HEAD$"
3423 /// MacroBlockEnd: "^\
3424 /// NS_MAP_END|\
3425 /// NS_TABLE_.*_END$"
3426 ///
3427 /// NS_MAP_BEGIN
3428 /// foo();
3429 /// NS_MAP_END
3430 ///
3431 /// NS_TABLE_HEAD
3432 /// bar();
3433 /// NS_TABLE_FOO_END
3434 ///
3435 /// # Without:
3436 /// NS_MAP_BEGIN
3437 /// foo();
3438 /// NS_MAP_END
3439 ///
3440 /// NS_TABLE_HEAD
3441 /// bar();
3442 /// NS_TABLE_FOO_END
3443 /// \endcode
3444 /// \version 3.7
3445 std::string MacroBlockBegin;
3446
3447 /// A regular expression matching macros that end a block.
3448 /// \version 3.7
3449 std::string MacroBlockEnd;
3450
3451 /// A list of macros of the form \c <definition>=<expansion> .
3452 ///
3453 /// Code will be parsed with macros expanded, in order to determine how to
3454 /// interpret and format the macro arguments.
3455 ///
3456 /// For example, the code:
3457 /// \code
3458 /// A(a*b);
3459 /// \endcode
3460 ///
3461 /// will usually be interpreted as a call to a function A, and the
3462 /// multiplication expression will be formatted as ``a * b``.
3463 ///
3464 /// If we specify the macro definition:
3465 /// \code{.yaml}
3466 /// Macros:
3467 /// - A(x)=x
3468 /// \endcode
3469 ///
3470 /// the code will now be parsed as a declaration of the variable b of type a*,
3471 /// and formatted as ``a* b`` (depending on pointer-binding rules).
3472 ///
3473 /// Features and restrictions:
3474 /// * Both function-like macros and object-like macros are supported.
3475 /// * Macro arguments must be used exactly once in the expansion.
3476 /// * No recursive expansion; macros referencing other macros will be
3477 /// ignored.
3478 /// * Overloading by arity is supported: for example, given the macro
3479 /// definitions A=x, A()=y, A(a)=a
3480 ///
3481 /// \code
3482 /// A; -> x;
3483 /// A(); -> y;
3484 /// A(z); -> z;
3485 /// A(a, b); // will not be expanded.
3486 /// \endcode
3487 ///
3488 /// \version 17
3489 std::vector<std::string> Macros;
3490
3491 /// A vector of function-like macros whose invocations should be skipped by
3492 /// ``RemoveParentheses``.
3493 /// \version 21
3494 std::vector<std::string> MacrosSkippedByRemoveParentheses;
3495
3496 /// The maximum number of consecutive empty lines to keep.
3497 /// \code
3498 /// MaxEmptyLinesToKeep: 1 vs. MaxEmptyLinesToKeep: 0
3499 /// int f() { int f() {
3500 /// int = 1; int i = 1;
3501 /// i = foo();
3502 /// i = foo(); return i;
3503 /// }
3504 /// return i;
3505 /// }
3506 /// \endcode
3507 /// \version 3.7
3509
3510 /// Different ways to indent namespace contents.
3512 /// Don't indent in namespaces.
3513 /// \code
3514 /// namespace out {
3515 /// int i;
3516 /// namespace in {
3517 /// int i;
3518 /// }
3519 /// }
3520 /// \endcode
3522 /// Indent only in inner namespaces (nested in other namespaces).
3523 /// \code
3524 /// namespace out {
3525 /// int i;
3526 /// namespace in {
3527 /// int i;
3528 /// }
3529 /// }
3530 /// \endcode
3532 /// Indent in all namespaces.
3533 /// \code
3534 /// namespace out {
3535 /// int i;
3536 /// namespace in {
3537 /// int i;
3538 /// }
3539 /// }
3540 /// \endcode
3541 NI_All
3543
3544 /// The indentation used for namespaces.
3545 /// \version 3.7
3547
3548 /// A vector of macros which are used to open namespace blocks.
3549 ///
3550 /// These are expected to be macros of the form:
3551 /// \code
3552 /// NAMESPACE(<namespace-name>, ...) {
3553 /// <namespace-content>
3554 /// }
3555 /// \endcode
3556 ///
3557 /// For example: TESTSUITE
3558 /// \version 9
3559 std::vector<std::string> NamespaceMacros;
3560
3561 /// Controls bin-packing Objective-C protocol conformance list
3562 /// items into as few lines as possible when they go over ``ColumnLimit``.
3563 ///
3564 /// If ``Auto`` (the default), delegates to the value in
3565 /// ``BinPackParameters``. If that is ``BinPack``, bin-packs Objective-C
3566 /// protocol conformance list items into as few lines as possible
3567 /// whenever they go over ``ColumnLimit``.
3568 ///
3569 /// If ``Always``, always bin-packs Objective-C protocol conformance
3570 /// list items into as few lines as possible whenever they go over
3571 /// ``ColumnLimit``.
3572 ///
3573 /// If ``Never``, lays out Objective-C protocol conformance list items
3574 /// onto individual lines whenever they go over ``ColumnLimit``.
3575 ///
3576 /// \code{.objc}
3577 /// Always (or Auto, if BinPackParameters==BinPack):
3578 /// @interface ccccccccccccc () <
3579 /// ccccccccccccc, ccccccccccccc,
3580 /// ccccccccccccc, ccccccccccccc> {
3581 /// }
3582 ///
3583 /// Never (or Auto, if BinPackParameters!=BinPack):
3584 /// @interface ddddddddddddd () <
3585 /// ddddddddddddd,
3586 /// ddddddddddddd,
3587 /// ddddddddddddd,
3588 /// ddddddddddddd> {
3589 /// }
3590 /// \endcode
3591 /// \version 7
3593
3594 /// The number of characters to use for indentation of ObjC blocks.
3595 /// \code{.objc}
3596 /// ObjCBlockIndentWidth: 4
3597 ///
3598 /// [operation setCompletionBlock:^{
3599 /// [self onOperationDone];
3600 /// }];
3601 /// \endcode
3602 /// \version 3.7
3604
3605 /// Break parameters list into lines when there is nested block
3606 /// parameters in a function call.
3607 /// \code
3608 /// false:
3609 /// - (void)_aMethod
3610 /// {
3611 /// [self.test1 t:self w:self callback:^(typeof(self) self, NSNumber
3612 /// *u, NSNumber *v) {
3613 /// u = c;
3614 /// }]
3615 /// }
3616 /// true:
3617 /// - (void)_aMethod
3618 /// {
3619 /// [self.test1 t:self
3620 /// w:self
3621 /// callback:^(typeof(self) self, NSNumber *u, NSNumber *v) {
3622 /// u = c;
3623 /// }]
3624 /// }
3625 /// \endcode
3626 /// \version 11
3628
3629 /// The order in which ObjC property attributes should appear.
3630 ///
3631 /// Attributes in code will be sorted in the order specified. Any attributes
3632 /// encountered that are not mentioned in this array will be sorted last, in
3633 /// stable order. Comments between attributes will leave the attributes
3634 /// untouched.
3635 /// \warning
3636 /// Using this option could lead to incorrect code formatting due to
3637 /// clang-format's lack of complete semantic information. As such, extra
3638 /// care should be taken to review code changes made by this option.
3639 /// \endwarning
3640 /// \code{.yaml}
3641 /// ObjCPropertyAttributeOrder: [
3642 /// class, direct,
3643 /// atomic, nonatomic,
3644 /// assign, retain, strong, copy, weak, unsafe_unretained,
3645 /// readonly, readwrite, getter, setter,
3646 /// nullable, nonnull, null_resettable, null_unspecified
3647 /// ]
3648 /// \endcode
3649 /// \version 18
3650 std::vector<std::string> ObjCPropertyAttributeOrder;
3651
3652 /// Add a space after ``@property`` in Objective-C, i.e. use
3653 /// ``@property (readonly)`` instead of ``@property(readonly)``.
3654 /// \version 3.7
3656
3657 /// Add a space in front of an Objective-C protocol list, i.e. use
3658 /// ``Foo <Protocol>`` instead of ``Foo<Protocol>``.
3659 /// \version 3.7
3661
3662 /// A regular expression that describes markers for turning formatting off for
3663 /// one line. If it matches a comment that is the only token of a line,
3664 /// clang-format skips the comment and the next line. Otherwise, clang-format
3665 /// skips lines containing a matched token.
3666 /// \code
3667 /// // OneLineFormatOffRegex: ^(// NOLINT|logger$)
3668 /// // results in the output below:
3669 /// int a;
3670 /// int b ; // NOLINT
3671 /// int c;
3672 /// // NOLINTNEXTLINE
3673 /// int d ;
3674 /// int e;
3675 /// s = "// NOLINT";
3676 /// logger() ;
3677 /// logger2();
3678 /// my_logger();
3679 /// \endcode
3680 /// \version 21
3682
3683 /// Different ways to try to fit all constructor initializers on a line.
3685 /// Always put each constructor initializer on its own line.
3686 /// \code
3687 /// Constructor()
3688 /// : a(),
3689 /// b()
3690 /// \endcode
3692 /// Bin-pack constructor initializers.
3693 /// \code
3694 /// Constructor()
3695 /// : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(),
3696 /// cccccccccccccccccccc()
3697 /// \endcode
3699 /// Put all constructor initializers on the current line if they fit.
3700 /// Otherwise, put each one on its own line.
3701 /// \code
3702 /// Constructor() : a(), b()
3703 ///
3704 /// Constructor()
3705 /// : aaaaaaaaaaaaaaaaaaaa(),
3706 /// bbbbbbbbbbbbbbbbbbbb(),
3707 /// ddddddddddddd()
3708 /// \endcode
3710 /// Same as ``PCIS_CurrentLine`` except that if all constructor initializers
3711 /// do not fit on the current line, try to fit them on the next line.
3712 /// \code
3713 /// Constructor() : a(), b()
3714 ///
3715 /// Constructor()
3716 /// : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), ddddddddddddd()
3717 ///
3718 /// Constructor()
3719 /// : aaaaaaaaaaaaaaaaaaaa(),
3720 /// bbbbbbbbbbbbbbbbbbbb(),
3721 /// cccccccccccccccccccc()
3722 /// \endcode
3724 /// Put all constructor initializers on the next line if they fit.
3725 /// Otherwise, put each one on its own line.
3726 /// \code
3727 /// Constructor()
3728 /// : a(), b()
3729 ///
3730 /// Constructor()
3731 /// : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), ddddddddddddd()
3732 ///
3733 /// Constructor()
3734 /// : aaaaaaaaaaaaaaaaaaaa(),
3735 /// bbbbbbbbbbbbbbbbbbbb(),
3736 /// cccccccccccccccccccc()
3737 /// \endcode
3739 };
3740
3741 /// The pack constructor initializers style to use.
3742 /// \version 14
3744
3745 /// The penalty for breaking around an assignment operator.
3746 /// \version 5
3748
3749 /// The penalty for breaking a function call after ``call(``.
3750 /// \version 3.7
3752
3753 /// The penalty for breaking before a member access operator (``.``, ``->``).
3754 /// \version 20
3756
3757 /// The penalty for each line break introduced inside a comment.
3758 /// \version 3.7
3760
3761 /// The penalty for breaking before the first ``<<``.
3762 /// \version 3.7
3764
3765 /// The penalty for breaking after ``(``.
3766 /// \version 14
3768
3769 /// The penalty for breaking after ``::``.
3770 /// \version 18
3772
3773 /// The penalty for each line break introduced inside a string literal.
3774 /// \version 3.7
3776
3777 /// The penalty for breaking after template declaration.
3778 /// \version 7
3780
3781 /// The penalty for each character outside of the column limit.
3782 /// \version 3.7
3784
3785 /// Penalty for each character of whitespace indentation
3786 /// (counted relative to leading non-whitespace column).
3787 /// \version 12
3789
3790 /// Penalty for putting the return type of a function onto its own line.
3791 /// \version 3.7
3793
3794 /// The ``&``, ``&&`` and ``*`` alignment style.
3796 /// Align pointer to the left.
3797 /// \code
3798 /// int* a;
3799 /// \endcode
3801 /// Align pointer to the right.
3802 /// \code
3803 /// int *a;
3804 /// \endcode
3806 /// Align pointer in the middle.
3807 /// \code
3808 /// int * a;
3809 /// \endcode
3812
3813 /// Pointer and reference alignment style.
3814 /// \version 3.7
3816
3817 /// The number of columns to use for indentation of preprocessor statements.
3818 /// When set to -1 (default) ``IndentWidth`` is used also for preprocessor
3819 /// statements.
3820 /// \code
3821 /// PPIndentWidth: 1
3822 ///
3823 /// #ifdef __linux__
3824 /// # define FOO
3825 /// #else
3826 /// # define BAR
3827 /// #endif
3828 /// \endcode
3829 /// \version 13
3831
3832 /// Different specifiers and qualifiers alignment styles.
3834 /// Don't change specifiers/qualifiers to either Left or Right alignment
3835 /// (default).
3836 /// \code
3837 /// int const a;
3838 /// const int *a;
3839 /// \endcode
3841 /// Change specifiers/qualifiers to be left-aligned.
3842 /// \code
3843 /// const int a;
3844 /// const int *a;
3845 /// \endcode
3847 /// Change specifiers/qualifiers to be right-aligned.
3848 /// \code
3849 /// int const a;
3850 /// int const *a;
3851 /// \endcode
3853 /// Change specifiers/qualifiers to be aligned based on ``QualifierOrder``.
3854 /// With:
3855 /// \code{.yaml}
3856 /// QualifierOrder: [inline, static, type, const]
3857 /// \endcode
3858 ///
3859 /// \code
3860 ///
3861 /// int const a;
3862 /// int const *a;
3863 /// \endcode
3866
3867 /// Different ways to arrange specifiers and qualifiers (e.g. const/volatile).
3868 /// \warning
3869 /// Setting ``QualifierAlignment`` to something other than ``Leave``, COULD
3870 /// lead to incorrect code formatting due to incorrect decisions made due to
3871 /// clang-formats lack of complete semantic information.
3872 /// As such extra care should be taken to review code changes made by the use
3873 /// of this option.
3874 /// \endwarning
3875 /// \version 14
3877
3878 /// The order in which the qualifiers appear.
3879 /// The order is an array that can contain any of the following:
3880 ///
3881 /// * ``const``
3882 /// * ``inline``
3883 /// * ``static``
3884 /// * ``friend``
3885 /// * ``constexpr``
3886 /// * ``volatile``
3887 /// * ``restrict``
3888 /// * ``type``
3889 ///
3890 /// \note
3891 /// It must contain ``type``.
3892 /// \endnote
3893 ///
3894 /// Items to the left of ``type`` will be placed to the left of the type and
3895 /// aligned in the order supplied. Items to the right of ``type`` will be
3896 /// placed to the right of the type and aligned in the order supplied.
3897 ///
3898 /// \code{.yaml}
3899 /// QualifierOrder: [inline, static, type, const, volatile]
3900 /// \endcode
3901 /// \version 14
3902 std::vector<std::string> QualifierOrder;
3903
3904 /// See documentation of ``RawStringFormats``.
3906 /// The language of this raw string.
3908 /// A list of raw string delimiters that match this language.
3909 std::vector<std::string> Delimiters;
3910 /// A list of enclosing function names that match this language.
3911 std::vector<std::string> EnclosingFunctions;
3912 /// The canonical delimiter for this language.
3914 /// The style name on which this raw string format is based on.
3915 /// If not specified, the raw string format is based on the style that this
3916 /// format is based on.
3917 std::string BasedOnStyle;
3918 bool operator==(const RawStringFormat &Other) const {
3919 return Language == Other.Language && Delimiters == Other.Delimiters &&
3920 EnclosingFunctions == Other.EnclosingFunctions &&
3921 CanonicalDelimiter == Other.CanonicalDelimiter &&
3922 BasedOnStyle == Other.BasedOnStyle;
3923 }
3924 };
3925
3926 /// Defines hints for detecting supported languages code blocks in raw
3927 /// strings.
3928 ///
3929 /// A raw string with a matching delimiter or a matching enclosing function
3930 /// name will be reformatted assuming the specified language based on the
3931 /// style for that language defined in the .clang-format file. If no style has
3932 /// been defined in the .clang-format file for the specific language, a
3933 /// predefined style given by ``BasedOnStyle`` is used. If ``BasedOnStyle`` is
3934 /// not found, the formatting is based on ``LLVM`` style. A matching delimiter
3935 /// takes precedence over a matching enclosing function name for determining
3936 /// the language of the raw string contents.
3937 ///
3938 /// If a canonical delimiter is specified, occurrences of other delimiters for
3939 /// the same language will be updated to the canonical if possible.
3940 ///
3941 /// There should be at most one specification per language and each delimiter
3942 /// and enclosing function should not occur in multiple specifications.
3943 ///
3944 /// To configure this in the .clang-format file, use:
3945 /// \code{.yaml}
3946 /// RawStringFormats:
3947 /// - Language: TextProto
3948 /// Delimiters:
3949 /// - pb
3950 /// - proto
3951 /// EnclosingFunctions:
3952 /// - PARSE_TEXT_PROTO
3953 /// BasedOnStyle: google
3954 /// - Language: Cpp
3955 /// Delimiters:
3956 /// - cc
3957 /// - cpp
3958 /// BasedOnStyle: LLVM
3959 /// CanonicalDelimiter: cc
3960 /// \endcode
3961 /// \version 6
3962 std::vector<RawStringFormat> RawStringFormats;
3963
3964 /// The ``&`` and ``&&`` alignment style.
3966 /// Align reference like ``PointerAlignment``.
3968 /// Align reference to the left.
3969 /// \code
3970 /// int& a;
3971 /// \endcode
3973 /// Align reference to the right.
3974 /// \code
3975 /// int &a;
3976 /// \endcode
3978 /// Align reference in the middle.
3979 /// \code
3980 /// int & a;
3981 /// \endcode
3984
3985 /// Reference alignment style (overrides ``PointerAlignment`` for references).
3986 /// \version 13
3988
3989 // clang-format off
3990 /// Types of comment reflow style.
3991 enum ReflowCommentsStyle : int8_t {
3992 /// Leave comments untouched.
3993 /// \code
3994 /// // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
3995 /// /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */
3996 /// /* third veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
3997 /// * and a misaligned second line */
3998 /// \endcode
4000 /// Only apply indentation rules, moving comments left or right, without
4001 /// changing formatting inside the comments.
4002 /// \code
4003 /// // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
4004 /// /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */
4005 /// /* third veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
4006 /// * and a misaligned second line */
4007 /// \endcode
4009 /// Apply indentation rules and reflow long comments into new lines, trying
4010 /// to obey the ``ColumnLimit``.
4011 /// \code
4012 /// // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
4013 /// // information
4014 /// /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
4015 /// * information */
4016 /// /* third veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
4017 /// * information and a misaligned second line */
4018 /// \endcode
4021 // clang-format on
4022
4023 /// Comment reformatting style.
4024 /// \version 3.8
4026
4027 /// Remove optional braces of control statements (``if``, ``else``, ``for``,
4028 /// and ``while``) in C++ according to the LLVM coding style.
4029 /// \warning
4030 /// This option will be renamed and expanded to support other styles.
4031 /// \endwarning
4032 /// \warning
4033 /// Setting this option to ``true`` could lead to incorrect code formatting
4034 /// due to clang-format's lack of complete semantic information. As such,
4035 /// extra care should be taken to review code changes made by this option.
4036 /// \endwarning
4037 /// \code
4038 /// false: true:
4039 ///
4040 /// if (isa<FunctionDecl>(D)) { vs. if (isa<FunctionDecl>(D))
4041 /// handleFunctionDecl(D); handleFunctionDecl(D);
4042 /// } else if (isa<VarDecl>(D)) { else if (isa<VarDecl>(D))
4043 /// handleVarDecl(D); handleVarDecl(D);
4044 /// }
4045 ///
4046 /// if (isa<VarDecl>(D)) { vs. if (isa<VarDecl>(D)) {
4047 /// for (auto *A : D.attrs()) { for (auto *A : D.attrs())
4048 /// if (shouldProcessAttr(A)) { if (shouldProcessAttr(A))
4049 /// handleAttr(A); handleAttr(A);
4050 /// } }
4051 /// }
4052 /// }
4053 ///
4054 /// if (isa<FunctionDecl>(D)) { vs. if (isa<FunctionDecl>(D))
4055 /// for (auto *A : D.attrs()) { for (auto *A : D.attrs())
4056 /// handleAttr(A); handleAttr(A);
4057 /// }
4058 /// }
4059 ///
4060 /// if (auto *D = (T)(D)) { vs. if (auto *D = (T)(D)) {
4061 /// if (shouldProcess(D)) { if (shouldProcess(D))
4062 /// handleVarDecl(D); handleVarDecl(D);
4063 /// } else { else
4064 /// markAsIgnored(D); markAsIgnored(D);
4065 /// } }
4066 /// }
4067 ///
4068 /// if (a) { vs. if (a)
4069 /// b(); b();
4070 /// } else { else if (c)
4071 /// if (c) { d();
4072 /// d(); else
4073 /// } else { e();
4074 /// e();
4075 /// }
4076 /// }
4077 /// \endcode
4078 /// \version 14
4080
4081 /// Remove empty lines within unwrapped lines.
4082 /// \code
4083 /// false: true:
4084 ///
4085 /// int c vs. int c = a + b;
4086 ///
4087 /// = a + b;
4088 ///
4089 /// enum : unsigned vs. enum : unsigned {
4090 /// AA = 0,
4091 /// { BB
4092 /// AA = 0, } myEnum;
4093 /// BB
4094 /// } myEnum;
4095 ///
4096 /// while ( vs. while (true) {
4097 /// }
4098 /// true) {
4099 /// }
4100 /// \endcode
4101 /// \version 20
4103
4104 /// Types of redundant parentheses to remove.
4106 /// Do not remove parentheses.
4107 /// \code
4108 /// class __declspec((dllimport)) X {};
4109 /// co_return (((0)));
4110 /// return ((a + b) - ((c + d)));
4111 /// \endcode
4113 /// Replace multiple parentheses with single parentheses.
4114 /// \code
4115 /// class __declspec(dllimport) X {};
4116 /// co_return (0);
4117 /// return ((a + b) - (c + d));
4118 /// \endcode
4120 /// Also remove parentheses enclosing the expression in a
4121 /// ``return``/``co_return`` statement.
4122 /// \code
4123 /// class __declspec(dllimport) X {};
4124 /// co_return 0;
4125 /// return (a + b) - (c + d);
4126 /// \endcode
4128 };
4129
4130 /// Remove redundant parentheses.
4131 /// \warning
4132 /// Setting this option to any value other than ``Leave`` could lead to
4133 /// incorrect code formatting due to clang-format's lack of complete semantic
4134 /// information. As such, extra care should be taken to review code changes
4135 /// made by this option.
4136 /// \endwarning
4137 /// \version 17
4139
4140 /// Remove semicolons after the closing braces of functions and
4141 /// constructors/destructors.
4142 /// \warning
4143 /// Setting this option to ``true`` could lead to incorrect code formatting
4144 /// due to clang-format's lack of complete semantic information. As such,
4145 /// extra care should be taken to review code changes made by this option.
4146 /// \endwarning
4147 /// \code
4148 /// false: true:
4149 ///
4150 /// int max(int a, int b) { int max(int a, int b) {
4151 /// return a > b ? a : b; return a > b ? a : b;
4152 /// }; }
4153 ///
4154 /// \endcode
4155 /// \version 16
4157
4158 /// The possible positions for the requires clause. The ``IndentRequires``
4159 /// option is only used if the ``requires`` is put on the start of a line.
4161 /// Always put the ``requires`` clause on its own line (possibly followed by
4162 /// a semicolon).
4163 /// \code
4164 /// template <typename T>
4165 /// requires C<T>
4166 /// struct Foo {...
4167 ///
4168 /// template <typename T>
4169 /// void bar(T t)
4170 /// requires C<T>;
4171 ///
4172 /// template <typename T>
4173 /// requires C<T>
4174 /// void bar(T t) {...
4175 ///
4176 /// template <typename T>
4177 /// void baz(T t)
4178 /// requires C<T>
4179 /// {...
4180 /// \endcode
4182 /// As with ``OwnLine``, except, unless otherwise prohibited, place a
4183 /// following open brace (of a function definition) to follow on the same
4184 /// line.
4185 /// \code
4186 /// void bar(T t)
4187 /// requires C<T> {
4188 /// return;
4189 /// }
4190 ///
4191 /// void bar(T t)
4192 /// requires C<T> {}
4193 ///
4194 /// template <typename T>
4195 /// requires C<T>
4196 /// void baz(T t) {
4197 /// ...
4198 /// \endcode
4200 /// Try to put the clause together with the preceding part of a declaration.
4201 /// For class templates: stick to the template declaration.
4202 /// For function templates: stick to the template declaration.
4203 /// For function declaration followed by a requires clause: stick to the
4204 /// parameter list.
4205 /// \code
4206 /// template <typename T> requires C<T>
4207 /// struct Foo {...
4208 ///
4209 /// template <typename T> requires C<T>
4210 /// void bar(T t) {...
4211 ///
4212 /// template <typename T>
4213 /// void baz(T t) requires C<T>
4214 /// {...
4215 /// \endcode
4217 /// Try to put the ``requires`` clause together with the class or function
4218 /// declaration.
4219 /// \code
4220 /// template <typename T>
4221 /// requires C<T> struct Foo {...
4222 ///
4223 /// template <typename T>
4224 /// requires C<T> void bar(T t) {...
4225 ///
4226 /// template <typename T>
4227 /// void baz(T t)
4228 /// requires C<T> {...
4229 /// \endcode
4231 /// Try to put everything in the same line if possible. Otherwise normal
4232 /// line breaking rules take over.
4233 /// \code
4234 /// // Fitting:
4235 /// template <typename T> requires C<T> struct Foo {...
4236 ///
4237 /// template <typename T> requires C<T> void bar(T t) {...
4238 ///
4239 /// template <typename T> void bar(T t) requires C<T> {...
4240 ///
4241 /// // Not fitting, one possible example:
4242 /// template <typename LongName>
4243 /// requires C<LongName>
4244 /// struct Foo {...
4245 ///
4246 /// template <typename LongName>
4247 /// requires C<LongName>
4248 /// void bar(LongName ln) {
4249 ///
4250 /// template <typename LongName>
4251 /// void bar(LongName ln)
4252 /// requires C<LongName> {
4253 /// \endcode
4255 };
4256
4257 /// The position of the ``requires`` clause.
4258 /// \version 15
4260
4261 /// Indentation logic for requires expression bodies.
4263 /// Align requires expression body relative to the indentation level of the
4264 /// outer scope the requires expression resides in.
4265 /// This is the default.
4266 /// \code
4267 /// template <typename T>
4268 /// concept C = requires(T t) {
4269 /// ...
4270 /// }
4271 /// \endcode
4273 /// Align requires expression body relative to the ``requires`` keyword.
4274 /// \code
4275 /// template <typename T>
4276 /// concept C = requires(T t) {
4277 /// ...
4278 /// }
4279 /// \endcode
4281 };
4282
4283 /// The indentation used for requires expression bodies.
4284 /// \version 16
4286
4287 /// The style if definition blocks should be separated.
4289 /// Leave definition blocks as they are.
4291 /// Insert an empty line between definition blocks.
4293 /// Remove any empty line between definition blocks.
4294 SDS_Never
4296
4297 /// Specifies the use of empty lines to separate definition blocks, including
4298 /// classes, structs, enums, and functions.
4299 /// \code
4300 /// Never v.s. Always
4301 /// #include <cstring> #include <cstring>
4302 /// struct Foo {
4303 /// int a, b, c; struct Foo {
4304 /// }; int a, b, c;
4305 /// namespace Ns { };
4306 /// class Bar {
4307 /// public: namespace Ns {
4308 /// struct Foobar { class Bar {
4309 /// int a; public:
4310 /// int b; struct Foobar {
4311 /// }; int a;
4312 /// private: int b;
4313 /// int t; };
4314 /// int method1() {
4315 /// // ... private:
4316 /// } int t;
4317 /// enum List {
4318 /// ITEM1, int method1() {
4319 /// ITEM2 // ...
4320 /// }; }
4321 /// template<typename T>
4322 /// int method2(T x) { enum List {
4323 /// // ... ITEM1,
4324 /// } ITEM2
4325 /// int i, j, k; };
4326 /// int method3(int par) {
4327 /// // ... template<typename T>
4328 /// } int method2(T x) {
4329 /// }; // ...
4330 /// class C {}; }
4331 /// }
4332 /// int i, j, k;
4333 ///
4334 /// int method3(int par) {
4335 /// // ...
4336 /// }
4337 /// };
4338 ///
4339 /// class C {};
4340 /// }
4341 /// \endcode
4342 /// \version 14
4344
4345 /// The maximal number of unwrapped lines that a short namespace spans.
4346 /// Defaults to 1.
4347 ///
4348 /// This determines the maximum length of short namespaces by counting
4349 /// unwrapped lines (i.e. containing neither opening nor closing
4350 /// namespace brace) and makes ``FixNamespaceComments`` omit adding
4351 /// end comments for those.
4352 /// \code
4353 /// ShortNamespaceLines: 1 vs. ShortNamespaceLines: 0
4354 /// namespace a { namespace a {
4355 /// int foo; int foo;
4356 /// } } // namespace a
4357 ///
4358 /// ShortNamespaceLines: 1 vs. ShortNamespaceLines: 0
4359 /// namespace b { namespace b {
4360 /// int foo; int foo;
4361 /// int bar; int bar;
4362 /// } // namespace b } // namespace b
4363 /// \endcode
4364 /// \version 13
4366
4367 /// Do not format macro definition body.
4368 /// \version 18
4370
4371 /// Includes sorting options.
4373 /// If ``true``, includes are sorted based on the other suboptions below.
4374 /// (``Never`` is deprecated by ``Enabled: false``.)
4376 /// Whether or not includes are sorted in a case-insensitive fashion.
4377 /// (``CaseSensitive`` and ``CaseInsensitive`` are deprecated by
4378 /// ``IgnoreCase: false`` and ``IgnoreCase: true``, respectively.)
4379 /// \code
4380 /// true: false:
4381 /// #include "A/B.h" vs. #include "A/B.h"
4382 /// #include "A/b.h" #include "A/b.h"
4383 /// #include "a/b.h" #include "B/A.h"
4384 /// #include "B/A.h" #include "B/a.h"
4385 /// #include "B/a.h" #include "a/b.h"
4386 /// \endcode
4388 /// When sorting includes in each block, only take file extensions into
4389 /// account if two includes compare equal otherwise.
4390 /// \code
4391 /// true: false:
4392 /// # include "A.h" vs. # include "A-util.h"
4393 /// # include "A.inc" # include "A.h"
4394 /// # include "A-util.h" # include "A.inc"
4395 /// \endcode
4397 bool operator==(const SortIncludesOptions &R) const {
4398 return Enabled == R.Enabled && IgnoreCase == R.IgnoreCase &&
4400 }
4401 bool operator!=(const SortIncludesOptions &R) const {
4402 return !(*this == R);
4403 }
4404 };
4405
4406 /// Controls if and how clang-format will sort ``#includes``.
4407 /// \version 3.8
4409
4410 /// Position for Java Static imports.
4412 /// Static imports are placed before non-static imports.
4413 /// \code{.java}
4414 /// import static org.example.function1;
4415 ///
4416 /// import org.example.ClassA;
4417 /// \endcode
4419 /// Static imports are placed after non-static imports.
4420 /// \code{.java}
4421 /// import org.example.ClassA;
4422 ///
4423 /// import static org.example.function1;
4424 /// \endcode
4426 };
4427
4428 /// When sorting Java imports, by default static imports are placed before
4429 /// non-static imports. If ``JavaStaticImportAfterImport`` is ``After``,
4430 /// static imports are placed after non-static imports.
4431 /// \version 12
4433
4434 /// Using declaration sorting options.
4436 /// Using declarations are never sorted.
4437 /// \code
4438 /// using std::chrono::duration_cast;
4439 /// using std::move;
4440 /// using boost::regex;
4441 /// using boost::regex_constants::icase;
4442 /// using std::string;
4443 /// \endcode
4445 /// Using declarations are sorted in the order defined as follows:
4446 /// Split the strings by ``::`` and discard any initial empty strings. Sort
4447 /// the lists of names lexicographically, and within those groups, names are
4448 /// in case-insensitive lexicographic order.
4449 /// \code
4450 /// using boost::regex;
4451 /// using boost::regex_constants::icase;
4452 /// using std::chrono::duration_cast;
4453 /// using std::move;
4454 /// using std::string;
4455 /// \endcode
4457 /// Using declarations are sorted in the order defined as follows:
4458 /// Split the strings by ``::`` and discard any initial empty strings. The
4459 /// last element of each list is a non-namespace name; all others are
4460 /// namespace names. Sort the lists of names lexicographically, where the
4461 /// sort order of individual names is that all non-namespace names come
4462 /// before all namespace names, and within those groups, names are in
4463 /// case-insensitive lexicographic order.
4464 /// \code
4465 /// using boost::regex;
4466 /// using boost::regex_constants::icase;
4467 /// using std::move;
4468 /// using std::string;
4469 /// using std::chrono::duration_cast;
4470 /// \endcode
4472 };
4473
4474 /// Controls if and how clang-format will sort using declarations.
4475 /// \version 5
4477
4478 /// If ``true``, a space is inserted after C style casts.
4479 /// \code
4480 /// true: false:
4481 /// (int) i; vs. (int)i;
4482 /// \endcode
4483 /// \version 3.5
4485
4486 /// If ``true``, a space is inserted after the logical not operator (``!``).
4487 /// \code
4488 /// true: false:
4489 /// ! someExpression(); vs. !someExpression();
4490 /// \endcode
4491 /// \version 9
4493
4494 /// If ``true``, a space will be inserted after the ``operator`` keyword.
4495 /// \code
4496 /// true: false:
4497 /// bool operator ==(int a); vs. bool operator==(int a);
4498 /// \endcode
4499 /// \version 21
4501
4502 /// If \c true, a space will be inserted after the ``template`` keyword.
4503 /// \code
4504 /// true: false:
4505 /// template <int> void foo(); vs. template<int> void foo();
4506 /// \endcode
4507 /// \version 4
4509
4510 /// Different ways to put a space before opening parentheses.
4512 /// Don't ensure spaces around pointer qualifiers and use PointerAlignment
4513 /// instead.
4514 /// \code
4515 /// PointerAlignment: Left PointerAlignment: Right
4516 /// void* const* x = NULL; vs. void *const *x = NULL;
4517 /// \endcode
4519 /// Ensure that there is a space before pointer qualifiers.
4520 /// \code
4521 /// PointerAlignment: Left PointerAlignment: Right
4522 /// void* const* x = NULL; vs. void * const *x = NULL;
4523 /// \endcode
4525 /// Ensure that there is a space after pointer qualifiers.
4526 /// \code
4527 /// PointerAlignment: Left PointerAlignment: Right
4528 /// void* const * x = NULL; vs. void *const *x = NULL;
4529 /// \endcode
4531 /// Ensure that there is a space both before and after pointer qualifiers.
4532 /// \code
4533 /// PointerAlignment: Left PointerAlignment: Right
4534 /// void* const * x = NULL; vs. void * const *x = NULL;
4535 /// \endcode
4537 };
4538
4539 /// Defines in which cases to put a space before or after pointer qualifiers
4540 /// \version 12
4542
4543 /// If ``false``, spaces will be removed before assignment operators.
4544 /// \code
4545 /// true: false:
4546 /// int a = 5; vs. int a= 5;
4547 /// a += 42; a+= 42;
4548 /// \endcode
4549 /// \version 3.7
4551
4552 /// If ``false``, spaces will be removed before case colon.
4553 /// \code
4554 /// true: false
4555 /// switch (x) { vs. switch (x) {
4556 /// case 1 : break; case 1: break;
4557 /// } }
4558 /// \endcode
4559 /// \version 12
4561
4562 /// If ``true``, a space will be inserted before a C++11 braced list
4563 /// used to initialize an object (after the preceding identifier or type).
4564 /// \code
4565 /// true: false:
4566 /// Foo foo { bar }; vs. Foo foo{ bar };
4567 /// Foo {}; Foo{};
4568 /// vector<int> { 1, 2, 3 }; vector<int>{ 1, 2, 3 };
4569 /// new int[3] { 1, 2, 3 }; new int[3]{ 1, 2, 3 };
4570 /// \endcode
4571 /// \version 7
4573
4574 /// If ``false``, spaces will be removed before constructor initializer
4575 /// colon.
4576 /// \code
4577 /// true: false:
4578 /// Foo::Foo() : a(a) {} Foo::Foo(): a(a) {}
4579 /// \endcode
4580 /// \version 7
4582
4583 /// If ``false``, spaces will be removed before inheritance colon.
4584 /// \code
4585 /// true: false:
4586 /// class Foo : Bar {} vs. class Foo: Bar {}
4587 /// \endcode
4588 /// \version 7
4590
4591 /// If ``true``, a space will be added before a JSON colon. For other
4592 /// languages, e.g. JavaScript, use ``SpacesInContainerLiterals`` instead.
4593 /// \code
4594 /// true: false:
4595 /// { {
4596 /// "key" : "value" vs. "key": "value"
4597 /// } }
4598 /// \endcode
4599 /// \version 17
4601
4602 /// Different ways to put a space before opening parentheses.
4604 /// This is **deprecated** and replaced by ``Custom`` below, with all
4605 /// ``SpaceBeforeParensOptions`` but ``AfterPlacementOperator`` set to
4606 /// ``false``.
4608 /// Put a space before opening parentheses only after control statement
4609 /// keywords (``for/if/while...``).
4610 /// \code
4611 /// void f() {
4612 /// if (true) {
4613 /// f();
4614 /// }
4615 /// }
4616 /// \endcode
4618 /// Same as ``SBPO_ControlStatements`` except this option doesn't apply to
4619 /// ForEach and If macros. This is useful in projects where ForEach/If
4620 /// macros are treated as function calls instead of control statements.
4621 /// ``SBPO_ControlStatementsExceptForEachMacros`` remains an alias for
4622 /// backward compatibility.
4623 /// \code
4624 /// void f() {
4625 /// Q_FOREACH(...) {
4626 /// f();
4627 /// }
4628 /// }
4629 /// \endcode
4631 /// Put a space before opening parentheses only if the parentheses are not
4632 /// empty.
4633 /// \code
4634 /// void() {
4635 /// if (true) {
4636 /// f();
4637 /// g (x, y, z);
4638 /// }
4639 /// }
4640 /// \endcode
4642 /// Always put a space before opening parentheses, except when it's
4643 /// prohibited by the syntax rules (in function-like macro definitions) or
4644 /// when determined by other style rules (after unary operators, opening
4645 /// parentheses, etc.)
4646 /// \code
4647 /// void f () {
4648 /// if (true) {
4649 /// f ();
4650 /// }
4651 /// }
4652 /// \endcode
4654 /// Configure each individual space before parentheses in
4655 /// ``SpaceBeforeParensOptions``.
4657 };
4658
4659 /// Defines in which cases to put a space before opening parentheses.
4660 /// \version 3.5
4662
4663 /// Precise control over the spacing before parentheses.
4664 /// \code
4665 /// # Should be declared this way:
4666 /// SpaceBeforeParens: Custom
4667 /// SpaceBeforeParensOptions:
4668 /// AfterControlStatements: true
4669 /// AfterFunctionDefinitionName: true
4670 /// \endcode
4672 /// If ``true``, put space between control statement keywords
4673 /// (for/if/while...) and opening parentheses.
4674 /// \code
4675 /// true: false:
4676 /// if (...) {} vs. if(...) {}
4677 /// \endcode
4679 /// If ``true``, put space between foreach macros and opening parentheses.
4680 /// \code
4681 /// true: false:
4682 /// FOREACH (...) vs. FOREACH(...)
4683 /// <loop-body> <loop-body>
4684 /// \endcode
4686 /// If ``true``, put a space between function declaration name and opening
4687 /// parentheses.
4688 /// \code
4689 /// true: false:
4690 /// void f (); vs. void f();
4691 /// \endcode
4693 /// If ``true``, put a space between function definition name and opening
4694 /// parentheses.
4695 /// \code
4696 /// true: false:
4697 /// void f () {} vs. void f() {}
4698 /// \endcode
4700 /// If ``true``, put space between if macros and opening parentheses.
4701 /// \code
4702 /// true: false:
4703 /// IF (...) vs. IF(...)
4704 /// <conditional-body> <conditional-body>
4705 /// \endcode
4707 /// If ``true``, put a space between alternative operator ``not`` and the
4708 /// opening parenthesis.
4709 /// \code
4710 /// true: false:
4711 /// return not (a || b); vs. return not(a || b);
4712 /// \endcode
4714 /// If ``true``, put a space between operator overloading and opening
4715 /// parentheses.
4716 /// \code
4717 /// true: false:
4718 /// void operator++ (int a); vs. void operator++(int a);
4719 /// object.operator++ (10); object.operator++(10);
4720 /// \endcode
4722 /// If ``true``, put a space between operator ``new``/``delete`` and opening
4723 /// parenthesis.
4724 /// \code
4725 /// true: false:
4726 /// new (buf) T; vs. new(buf) T;
4727 /// delete (buf) T; delete(buf) T;
4728 /// \endcode
4730 /// If ``true``, put space between requires keyword in a requires clause and
4731 /// opening parentheses, if there is one.
4732 /// \code
4733 /// true: false:
4734 /// template<typename T> vs. template<typename T>
4735 /// requires (A<T> && B<T>) requires(A<T> && B<T>)
4736 /// ... ...
4737 /// \endcode
4739 /// If ``true``, put space between requires keyword in a requires expression
4740 /// and opening parentheses.
4741 /// \code
4742 /// true: false:
4743 /// template<typename T> vs. template<typename T>
4744 /// concept C = requires (T t) { concept C = requires(T t) {
4745 /// ... ...
4746 /// } }
4747 /// \endcode
4749 /// If ``true``, put a space before opening parentheses only if the
4750 /// parentheses are not empty.
4751 /// \code
4752 /// true: false:
4753 /// void f (int a); vs. void f();
4754 /// f (a); f();
4755 /// \endcode
4757
4765
4767 return AfterControlStatements == Other.AfterControlStatements &&
4768 AfterForeachMacros == Other.AfterForeachMacros &&
4770 Other.AfterFunctionDeclarationName &&
4771 AfterFunctionDefinitionName == Other.AfterFunctionDefinitionName &&
4772 AfterIfMacros == Other.AfterIfMacros &&
4773 AfterNot == Other.AfterNot &&
4774 AfterOverloadedOperator == Other.AfterOverloadedOperator &&
4775 AfterPlacementOperator == Other.AfterPlacementOperator &&
4776 AfterRequiresInClause == Other.AfterRequiresInClause &&
4777 AfterRequiresInExpression == Other.AfterRequiresInExpression &&
4778 BeforeNonEmptyParentheses == Other.BeforeNonEmptyParentheses;
4779 }
4780 };
4781
4782 /// Control of individual space before parentheses.
4783 ///
4784 /// If ``SpaceBeforeParens`` is set to ``Custom``, use this to specify
4785 /// how each individual space before parentheses case should be handled.
4786 /// Otherwise, this is ignored.
4787 /// \code{.yaml}
4788 /// # Example of usage:
4789 /// SpaceBeforeParens: Custom
4790 /// SpaceBeforeParensOptions:
4791 /// AfterControlStatements: true
4792 /// AfterFunctionDefinitionName: true
4793 /// \endcode
4794 /// \version 14
4796
4797 /// If ``true``, spaces will be before ``[``.
4798 /// Lambdas will not be affected. Only the first ``[`` will get a space added.
4799 /// \code
4800 /// true: false:
4801 /// int a [5]; vs. int a[5];
4802 /// int a [5][5]; vs. int a[5][5];
4803 /// \endcode
4804 /// \version 10
4806
4807 /// If ``false``, spaces will be removed before range-based for loop
4808 /// colon.
4809 /// \code
4810 /// true: false:
4811 /// for (auto v : values) {} vs. for(auto v: values) {}
4812 /// \endcode
4813 /// \version 7
4815
4816 /// This option is **deprecated**. See ``Block`` of ``SpaceInEmptyBraces``.
4817 /// \version 10
4818 // bool SpaceInEmptyBlock;
4819
4820 /// Style of when to insert a space in empty braces.
4822 /// Always insert a space in empty braces.
4823 /// \code
4824 /// void f() { }
4825 /// class Unit { };
4826 /// auto a = [] { };
4827 /// int x{ };
4828 /// \endcode
4830 /// Only insert a space in empty blocks.
4831 /// \code
4832 /// void f() { }
4833 /// class Unit { };
4834 /// auto a = [] { };
4835 /// int x{};
4836 /// \endcode
4838 /// Never insert a space in empty braces.
4839 /// \code
4840 /// void f() {}
4841 /// class Unit {};
4842 /// auto a = [] {};
4843 /// int x{};
4844 /// \endcode
4847
4848 /// Specifies when to insert a space in empty braces.
4849 /// \note
4850 /// This option doesn't apply to initializer braces if
4851 /// ``Cpp11BracedListStyle`` is set to ``true``.
4852 /// \endnote
4853 /// \version 22
4855
4856 /// If ``true``, spaces may be inserted into ``()``.
4857 /// This option is **deprecated**. See ``InEmptyParentheses`` of
4858 /// ``SpacesInParensOptions``.
4859 /// \version 3.7
4860 // bool SpaceInEmptyParentheses;
4861
4862 /// The number of spaces before trailing line comments
4863 /// (``//`` - comments).
4864 ///
4865 /// This does not affect trailing block comments (``/*`` - comments) as those
4866 /// commonly have different usage patterns and a number of special cases. In
4867 /// the case of Verilog, it doesn't affect a comment right after the opening
4868 /// parenthesis in the port or parameter list in a module header, because it
4869 /// is probably for the port on the following line instead of the parenthesis
4870 /// it follows.
4871 /// \code
4872 /// SpacesBeforeTrailingComments: 3
4873 /// void f() {
4874 /// if (true) { // foo1
4875 /// f(); // bar
4876 /// } // foo
4877 /// }
4878 /// \endcode
4879 /// \version 3.7
4881
4882 /// Styles for adding spacing after ``<`` and before ``>``
4883 /// in template argument lists.
4884 enum SpacesInAnglesStyle : int8_t {
4885 /// Remove spaces after ``<`` and before ``>``.
4886 /// \code
4887 /// static_cast<int>(arg);
4888 /// std::function<void(int)> fct;
4889 /// \endcode
4891 /// Add spaces after ``<`` and before ``>``.
4892 /// \code
4893 /// static_cast< int >(arg);
4894 /// std::function< void(int) > fct;
4895 /// \endcode
4897 /// Keep a single space after ``<`` and before ``>`` if any spaces were
4898 /// present. Option ``Standard: Cpp03`` takes precedence.
4901 /// The SpacesInAnglesStyle to use for template argument lists.
4902 /// \version 3.4
4904
4905 /// If ``true``, spaces will be inserted around if/for/switch/while
4906 /// conditions.
4907 /// This option is **deprecated**. See ``InConditionalStatements`` of
4908 /// ``SpacesInParensOptions``.
4909 /// \version 10
4910 // bool SpacesInConditionalStatement;
4911
4912 /// If ``true``, spaces are inserted inside container literals (e.g. ObjC and
4913 /// Javascript array and dict literals). For JSON, use
4914 /// ``SpaceBeforeJsonColon`` instead.
4915 /// \code{.js}
4916 /// true: false:
4917 /// var arr = [ 1, 2, 3 ]; vs. var arr = [1, 2, 3];
4918 /// f({a : 1, b : 2, c : 3}); f({a: 1, b: 2, c: 3});
4919 /// \endcode
4920 /// \version 3.7
4922
4923 /// If ``true``, spaces may be inserted into C style casts.
4924 /// This option is **deprecated**. See ``InCStyleCasts`` of
4925 /// ``SpacesInParensOptions``.
4926 /// \version 3.7
4927 // bool SpacesInCStyleCastParentheses;
4928
4929 /// Control of spaces within a single line comment.
4931 /// The minimum number of spaces at the start of the comment.
4932 unsigned Minimum;
4933 /// The maximum number of spaces at the start of the comment.
4934 unsigned Maximum;
4935 };
4936
4937 /// How many spaces are allowed at the start of a line comment. To disable the
4938 /// maximum set it to ``-1``, apart from that the maximum takes precedence
4939 /// over the minimum.
4940 /// \code
4941 /// Minimum = 1
4942 /// Maximum = -1
4943 /// // One space is forced
4944 ///
4945 /// // but more spaces are possible
4946 ///
4947 /// Minimum = 0
4948 /// Maximum = 0
4949 /// //Forces to start every comment directly after the slashes
4950 /// \endcode
4951 ///
4952 /// Note that in line comment sections the relative indent of the subsequent
4953 /// lines is kept, that means the following:
4954 /// \code
4955 /// before: after:
4956 /// Minimum: 1
4957 /// //if (b) { // if (b) {
4958 /// // return true; // return true;
4959 /// //} // }
4960 ///
4961 /// Maximum: 0
4962 /// /// List: ///List:
4963 /// /// - Foo /// - Foo
4964 /// /// - Bar /// - Bar
4965 /// \endcode
4966 ///
4967 /// This option has only effect if ``ReflowComments`` is set to ``true``.
4968 /// \version 13
4970
4971 /// Different ways to put a space before opening and closing parentheses.
4972 enum SpacesInParensStyle : int8_t {
4973 /// Never put a space in parentheses.
4974 /// \code
4975 /// void f() {
4976 /// if(true) {
4977 /// f();
4978 /// }
4979 /// }
4980 /// \endcode
4982 /// Configure each individual space in parentheses in
4983 /// `SpacesInParensOptions`.
4985 };
4986
4987 /// If ``true``, spaces will be inserted after ``(`` and before ``)``.
4988 /// This option is **deprecated**. The previous behavior is preserved by using
4989 /// ``SpacesInParens`` with ``Custom`` and by setting all
4990 /// ``SpacesInParensOptions`` to ``true`` except for ``InCStyleCasts`` and
4991 /// ``InEmptyParentheses``.
4992 /// \version 3.7
4993 // bool SpacesInParentheses;
4994
4995 /// Defines in which cases spaces will be inserted after ``(`` and before
4996 /// ``)``.
4997 /// \version 17
4999
5000 /// Precise control over the spacing in parentheses.
5001 /// \code
5002 /// # Should be declared this way:
5003 /// SpacesInParens: Custom
5004 /// SpacesInParensOptions:
5005 /// ExceptDoubleParentheses: false
5006 /// InConditionalStatements: true
5007 /// Other: true
5008 /// \endcode
5010 /// Override any of the following options to prevent addition of space
5011 /// when both opening and closing parentheses use multiple parentheses.
5012 /// \code
5013 /// true:
5014 /// __attribute__(( noreturn ))
5015 /// __decltype__(( x ))
5016 /// if (( a = b ))
5017 /// \endcode
5018 /// false:
5019 /// Uses the applicable option.
5021 /// Put a space in parentheses only inside conditional statements
5022 /// (``for/if/while/switch...``).
5023 /// \code
5024 /// true: false:
5025 /// if ( a ) { ... } vs. if (a) { ... }
5026 /// while ( i < 5 ) { ... } while (i < 5) { ... }
5027 /// \endcode
5029 /// Put a space in C style casts.
5030 /// \code
5031 /// true: false:
5032 /// x = ( int32 )y vs. x = (int32)y
5033 /// y = (( int (*)(int) )foo)(x); y = ((int (*)(int))foo)(x);
5034 /// \endcode
5036 /// Insert a space in empty parentheses, i.e. ``()``.
5037 /// \code
5038 /// true: false:
5039 /// void f( ) { vs. void f() {
5040 /// int x[] = {foo( ), bar( )}; int x[] = {foo(), bar()};
5041 /// if (true) { if (true) {
5042 /// f( ); f();
5043 /// } }
5044 /// } }
5045 /// \endcode
5047 /// Put a space in parentheses not covered by preceding options.
5048 /// \code
5049 /// true: false:
5050 /// t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete;
5051 /// \endcode
5052 bool Other;
5053
5057
5060 bool InEmptyParentheses, bool Other)
5064 Other(Other) {}
5065
5066 bool operator==(const SpacesInParensCustom &R) const {
5071 }
5072 bool operator!=(const SpacesInParensCustom &R) const {
5073 return !(*this == R);
5074 }
5075 };
5076
5077 /// Control of individual spaces in parentheses.
5078 ///
5079 /// If ``SpacesInParens`` is set to ``Custom``, use this to specify
5080 /// how each individual space in parentheses case should be handled.
5081 /// Otherwise, this is ignored.
5082 /// \code{.yaml}
5083 /// # Example of usage:
5084 /// SpacesInParens: Custom
5085 /// SpacesInParensOptions:
5086 /// ExceptDoubleParentheses: false
5087 /// InConditionalStatements: true
5088 /// InEmptyParentheses: true
5089 /// \endcode
5090 /// \version 17
5092
5093 /// If ``true``, spaces will be inserted after ``[`` and before ``]``.
5094 /// Lambdas without arguments or unspecified size array declarations will not
5095 /// be affected.
5096 /// \code
5097 /// true: false:
5098 /// int a[ 5 ]; vs. int a[5];
5099 /// std::unique_ptr<int[]> foo() {} // Won't be affected
5100 /// \endcode
5101 /// \version 3.7
5103
5104 /// Supported language standards for parsing and formatting C++ constructs.
5105 /// \code
5106 /// Latest: vector<set<int>>
5107 /// c++03 vs. vector<set<int> >
5108 /// \endcode
5109 ///
5110 /// The correct way to spell a specific language version is e.g. ``c++11``.
5111 /// The historical aliases ``Cpp03`` and ``Cpp11`` are deprecated.
5112 enum LanguageStandard : int8_t {
5113 /// Parse and format as C++03.
5114 /// ``Cpp03`` is a deprecated alias for ``c++03``
5115 LS_Cpp03, // c++03
5116 /// Parse and format as C++11.
5117 LS_Cpp11, // c++11
5118 /// Parse and format as C++14.
5119 LS_Cpp14, // c++14
5120 /// Parse and format as C++17.
5121 LS_Cpp17, // c++17
5122 /// Parse and format as C++20.
5123 LS_Cpp20, // c++20
5124 /// Parse and format using the latest supported language version.
5125 /// ``Cpp11`` is a deprecated alias for ``Latest``
5127 /// Automatic detection based on the input.
5129 };
5130
5131 /// Parse and format C++ constructs compatible with this standard.
5132 /// \code
5133 /// c++03: latest:
5134 /// vector<set<int> > x; vs. vector<set<int>> x;
5135 /// \endcode
5136 /// \version 3.7
5138
5139 /// Macros which are ignored in front of a statement, as if they were an
5140 /// attribute. So that they are not parsed as identifier, for example for Qts
5141 /// emit.
5142 /// \code
5143 /// AlignConsecutiveDeclarations: true
5144 /// StatementAttributeLikeMacros: []
5145 /// unsigned char data = 'x';
5146 /// emit signal(data); // This is parsed as variable declaration.
5147 ///
5148 /// AlignConsecutiveDeclarations: true
5149 /// StatementAttributeLikeMacros: [emit]
5150 /// unsigned char data = 'x';
5151 /// emit signal(data); // Now it's fine again.
5152 /// \endcode
5153 /// \version 12
5154 std::vector<std::string> StatementAttributeLikeMacros;
5155
5156 /// A vector of macros that should be interpreted as complete statements.
5157 ///
5158 /// Typical macros are expressions and require a semicolon to be added.
5159 /// Sometimes this is not the case, and this allows to make clang-format aware
5160 /// of such cases.
5161 ///
5162 /// For example: Q_UNUSED
5163 /// \version 8
5164 std::vector<std::string> StatementMacros;
5165
5166 /// Works only when TableGenBreakInsideDAGArg is not DontBreak.
5167 /// The string list needs to consist of identifiers in TableGen.
5168 /// If any identifier is specified, this limits the line breaks by
5169 /// TableGenBreakInsideDAGArg option only on DAGArg values beginning with
5170 /// the specified identifiers.
5171 ///
5172 /// For example the configuration,
5173 /// \code{.yaml}
5174 /// TableGenBreakInsideDAGArg: BreakAll
5175 /// TableGenBreakingDAGArgOperators: [ins, outs]
5176 /// \endcode
5177 ///
5178 /// makes the line break only occurs inside DAGArgs beginning with the
5179 /// specified identifiers ``ins`` and ``outs``.
5180 ///
5181 /// \code
5182 /// let DAGArgIns = (ins
5183 /// i32:$src1,
5184 /// i32:$src2
5185 /// );
5186 /// let DAGArgOtherID = (other i32:$other1, i32:$other2);
5187 /// let DAGArgBang = (!cast<SomeType>("Some") i32:$src1, i32:$src2)
5188 /// \endcode
5189 /// \version 19
5190 std::vector<std::string> TableGenBreakingDAGArgOperators;
5191
5192 /// Different ways to control the format inside TableGen DAGArg.
5193 enum DAGArgStyle : int8_t {
5194 /// Never break inside DAGArg.
5195 /// \code
5196 /// let DAGArgIns = (ins i32:$src1, i32:$src2);
5197 /// \endcode
5199 /// Break inside DAGArg after each list element but for the last.
5200 /// This aligns to the first element.
5201 /// \code
5202 /// let DAGArgIns = (ins i32:$src1,
5203 /// i32:$src2);
5204 /// \endcode
5206 /// Break inside DAGArg after the operator and the all elements.
5207 /// \code
5208 /// let DAGArgIns = (ins
5209 /// i32:$src1,
5210 /// i32:$src2
5211 /// );
5212 /// \endcode
5214 };
5215
5216 /// The styles of the line break inside the DAGArg in TableGen.
5217 /// \version 19
5219
5220 /// The number of columns used for tab stops.
5221 /// \version 3.7
5222 unsigned TabWidth;
5223
5224 /// A vector of non-keyword identifiers that should be interpreted as template
5225 /// names.
5226 ///
5227 /// A ``<`` after a template name is annotated as a template opener instead of
5228 /// a binary operator.
5229 ///
5230 /// \version 20
5231 std::vector<std::string> TemplateNames;
5232
5233 /// A vector of non-keyword identifiers that should be interpreted as type
5234 /// names.
5235 ///
5236 /// A ``*``, ``&``, or ``&&`` between a type name and another non-keyword
5237 /// identifier is annotated as a pointer or reference token instead of a
5238 /// binary operator.
5239 ///
5240 /// \version 17
5241 std::vector<std::string> TypeNames;
5242
5243 /// A vector of macros that should be interpreted as type declarations instead
5244 /// of as function calls.
5245 ///
5246 /// These are expected to be macros of the form:
5247 /// \code
5248 /// STACK_OF(...)
5249 /// \endcode
5250 ///
5251 /// In the .clang-format configuration file, this can be configured like:
5252 /// \code{.yaml}
5253 /// TypenameMacros: [STACK_OF, LIST]
5254 /// \endcode
5255 ///
5256 /// For example: OpenSSL STACK_OF, BSD LIST_ENTRY.
5257 /// \version 9
5258 std::vector<std::string> TypenameMacros;
5259
5260 /// This option is **deprecated**. See ``LF`` and ``CRLF`` of ``LineEnding``.
5261 /// \version 10
5262 // bool UseCRLF;
5263
5264 /// Different ways to use tab in formatting.
5265 enum UseTabStyle : int8_t {
5266 /// Never use tab.
5268 /// Use tabs only for indentation.
5270 /// Fill all leading whitespace with tabs, and use spaces for alignment that
5271 /// appears within a line (e.g. consecutive assignments and declarations).
5273 /// Use tabs for line continuation and indentation, and spaces for
5274 /// alignment.
5276 /// Use tabs whenever we need to fill whitespace that spans at least from
5277 /// one tab stop to the next one.
5278 UT_Always
5280
5281 /// The way to use tab characters in the resulting file.
5282 /// \version 3.7
5284
5285 /// A vector of non-keyword identifiers that should be interpreted as variable
5286 /// template names.
5287 ///
5288 /// A ``)`` after a variable template instantiation is **not** annotated as
5289 /// the closing parenthesis of C-style cast operator.
5290 ///
5291 /// \version 20
5292 std::vector<std::string> VariableTemplates;
5293
5294 /// For Verilog, put each port on its own line in module instantiations.
5295 /// \code
5296 /// true:
5297 /// ffnand ff1(.q(),
5298 /// .qbar(out1),
5299 /// .clear(in1),
5300 /// .preset(in2));
5301 ///
5302 /// false:
5303 /// ffnand ff1(.q(), .qbar(out1), .clear(in1), .preset(in2));
5304 /// \endcode
5305 /// \version 17
5307
5308 /// A vector of macros which are whitespace-sensitive and should not
5309 /// be touched.
5310 ///
5311 /// These are expected to be macros of the form:
5312 /// \code
5313 /// STRINGIZE(...)
5314 /// \endcode
5315 ///
5316 /// In the .clang-format configuration file, this can be configured like:
5317 /// \code{.yaml}
5318 /// WhitespaceSensitiveMacros: [STRINGIZE, PP_STRINGIZE]
5319 /// \endcode
5320 ///
5321 /// For example: BOOST_PP_STRINGIZE
5322 /// \version 11
5323 std::vector<std::string> WhitespaceSensitiveMacros;
5324
5325 /// Different styles for wrapping namespace body with empty lines.
5327 /// Remove all empty lines at the beginning and the end of namespace body.
5328 /// \code
5329 /// namespace N1 {
5330 /// namespace N2 {
5331 /// function();
5332 /// }
5333 /// }
5334 /// \endcode
5336 /// Always have at least one empty line at the beginning and the end of
5337 /// namespace body except that the number of empty lines between consecutive
5338 /// nested namespace definitions is not increased.
5339 /// \code
5340 /// namespace N1 {
5341 /// namespace N2 {
5342 ///
5343 /// function();
5344 ///
5345 /// }
5346 /// }
5347 /// \endcode
5349 /// Keep existing newlines at the beginning and the end of namespace body.
5350 /// ``MaxEmptyLinesToKeep`` still applies.
5353
5354 /// Wrap namespace body with empty lines.
5355 /// \version 20
5357
5358 bool operator==(const FormatStyle &R) const {
5410 BreakArrays == R.BreakArrays &&
5454 IndentWidth == R.IndentWidth &&
5539 Standard == R.Standard &&
5552 }
5553
5554 std::optional<FormatStyle> GetLanguageStyle(LanguageKind Language) const;
5555
5556 // Stores per-language styles. A FormatStyle instance inside has an empty
5557 // StyleSet. A FormatStyle instance returned by the Get method has its
5558 // StyleSet set to a copy of the originating StyleSet, effectively keeping the
5559 // internal representation of that StyleSet alive.
5560 //
5561 // The memory management and ownership reminds of a birds nest: chicks
5562 // leaving the nest take photos of the nest with them.
5564 typedef std::map<LanguageKind, FormatStyle> MapType;
5565
5566 std::optional<FormatStyle> Get(LanguageKind Language) const;
5567
5568 // Adds \p Style to this FormatStyleSet. Style must not have an associated
5569 // FormatStyleSet.
5570 // Style.Language should be different than LK_None. If this FormatStyleSet
5571 // already contains an entry for Style.Language, that gets replaced with the
5572 // passed Style.
5573 void Add(FormatStyle Style);
5574
5575 // Clears this FormatStyleSet.
5576 void Clear();
5577
5578 private:
5579 std::shared_ptr<MapType> Styles;
5580 };
5581
5583 const FormatStyle &MainStyle,
5584 const std::vector<FormatStyle> &ConfigurationStyles);
5585
5586private:
5587 FormatStyleSet StyleSet;
5588
5589 friend std::error_code
5590 parseConfiguration(llvm::MemoryBufferRef Config, FormatStyle *Style,
5591 bool AllowUnknownOptions,
5592 llvm::SourceMgr::DiagHandlerTy DiagHandler,
5593 void *DiagHandlerCtxt, bool IsDotHFile);
5594};
5595
5596/// Returns a format style complying with the LLVM coding standards:
5597/// http://llvm.org/docs/CodingStandards.html.
5600
5601/// Returns a format style complying with one of Google's style guides:
5602/// http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml.
5603/// http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml.
5604/// https://developers.google.com/protocol-buffers/docs/style.
5606
5607/// Returns a format style complying with Chromium's style guide:
5608/// http://www.chromium.org/developers/coding-style.
5610
5611/// Returns a format style complying with Mozilla's style guide:
5612/// https://firefox-source-docs.mozilla.org/code-quality/coding-style/index.html.
5614
5615/// Returns a format style complying with Webkit's style guide:
5616/// http://www.webkit.org/coding/coding-style.html
5618
5619/// Returns a format style complying with GNU Coding Standards:
5620/// http://www.gnu.org/prep/standards/standards.html
5622
5623/// Returns a format style complying with Microsoft style guide:
5624/// https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017
5626
5628
5629/// Returns style indicating formatting should be not applied at all.
5631
5632/// Gets a predefined style for the specified language by name.
5633///
5634/// Currently supported names: LLVM, Google, Chromium, Mozilla. Names are
5635/// compared case-insensitively.
5636///
5637/// Returns ``true`` if the Style has been set.
5639 FormatStyle *Style);
5640
5641/// Parse configuration from YAML-formatted text.
5642///
5643/// Style->Language is used to get the base style, if the ``BasedOnStyle``
5644/// option is present.
5645///
5646/// The FormatStyleSet of Style is reset.
5647///
5648/// When ``BasedOnStyle`` is not present, options not present in the YAML
5649/// document, are retained in \p Style.
5650///
5651/// If AllowUnknownOptions is true, no errors are emitted if unknown
5652/// format options are occurred.
5653///
5654/// If set all diagnostics are emitted through the DiagHandler.
5655std::error_code
5656parseConfiguration(llvm::MemoryBufferRef Config, FormatStyle *Style,
5657 bool AllowUnknownOptions = false,
5658 llvm::SourceMgr::DiagHandlerTy DiagHandler = nullptr,
5659 void *DiagHandlerCtx = nullptr, bool IsDotHFile = false);
5660
5661/// Like above but accepts an unnamed buffer.
5662inline std::error_code parseConfiguration(StringRef Config, FormatStyle *Style,
5663 bool AllowUnknownOptions = false,
5664 bool IsDotHFile = false) {
5665 return parseConfiguration(llvm::MemoryBufferRef(Config, "YAML"), Style,
5666 AllowUnknownOptions, /*DiagHandler=*/nullptr,
5667 /*DiagHandlerCtx=*/nullptr, IsDotHFile);
5668}
5669
5670/// Gets configuration in a YAML string.
5671std::string configurationAsText(const FormatStyle &Style);
5672
5673/// Returns the replacements necessary to sort all ``#include`` blocks
5674/// that are affected by ``Ranges``.
5675tooling::Replacements sortIncludes(const FormatStyle &Style, StringRef Code,
5677 StringRef FileName,
5678 unsigned *Cursor = nullptr);
5679
5680/// Returns the replacements corresponding to applying and formatting
5681/// \p Replaces on success; otheriwse, return an llvm::Error carrying
5682/// llvm::StringError.
5684formatReplacements(StringRef Code, const tooling::Replacements &Replaces,
5685 const FormatStyle &Style);
5686
5687/// Returns the replacements corresponding to applying \p Replaces and
5688/// cleaning up the code after that on success; otherwise, return an llvm::Error
5689/// carrying llvm::StringError.
5690/// This also supports inserting/deleting C++ #include directives:
5691/// * If a replacement has offset UINT_MAX, length 0, and a replacement text
5692/// that is an #include directive, this will insert the #include into the
5693/// correct block in the \p Code.
5694/// * If a replacement has offset UINT_MAX, length 1, and a replacement text
5695/// that is the name of the header to be removed, the header will be removed
5696/// from \p Code if it exists.
5697/// The include manipulation is done via ``tooling::HeaderInclude``, see its
5698/// documentation for more details on how include insertion points are found and
5699/// what edits are produced.
5701cleanupAroundReplacements(StringRef Code, const tooling::Replacements &Replaces,
5702 const FormatStyle &Style);
5703
5704/// Represents the status of a formatting attempt.
5706 /// A value of ``false`` means that any of the affected ranges were not
5707 /// formatted due to a non-recoverable syntax error.
5708 bool FormatComplete = true;
5709
5710 /// If ``FormatComplete`` is false, ``Line`` records a one-based
5711 /// original line number at which a syntax error might have occurred. This is
5712 /// based on a best-effort analysis and could be imprecise.
5713 unsigned Line = 0;
5714};
5715
5716/// Reformats the given \p Ranges in \p Code.
5717///
5718/// Each range is extended on either end to its next bigger logic unit, i.e.
5719/// everything that might influence its formatting or might be influenced by its
5720/// formatting.
5721///
5722/// Returns the ``Replacements`` necessary to make all \p Ranges comply with
5723/// \p Style.
5724///
5725/// If ``Status`` is non-null, its value will be populated with the status of
5726/// this formatting attempt. See \c FormattingAttemptStatus.
5727tooling::Replacements reformat(const FormatStyle &Style, StringRef Code,
5729 StringRef FileName = "<stdin>",
5730 FormattingAttemptStatus *Status = nullptr);
5731
5732/// Same as above, except if ``IncompleteFormat`` is non-null, its value
5733/// will be set to true if any of the affected ranges were not formatted due to
5734/// a non-recoverable syntax error.
5735tooling::Replacements reformat(const FormatStyle &Style, StringRef Code,
5737 StringRef FileName, bool *IncompleteFormat);
5738
5739/// Clean up any erroneous/redundant code in the given \p Ranges in \p
5740/// Code.
5741///
5742/// Returns the ``Replacements`` that clean up all \p Ranges in \p Code.
5743tooling::Replacements cleanup(const FormatStyle &Style, StringRef Code,
5745 StringRef FileName = "<stdin>");
5746
5747/// Fix namespace end comments in the given \p Ranges in \p Code.
5748///
5749/// Returns the ``Replacements`` that fix the namespace comments in all
5750/// \p Ranges in \p Code.
5752 StringRef Code,
5754 StringRef FileName = "<stdin>");
5755
5756/// Inserts or removes empty lines separating definition blocks including
5757/// classes, structs, functions, namespaces, and enums in the given \p Ranges in
5758/// \p Code.
5759///
5760/// Returns the ``Replacements`` that inserts or removes empty lines separating
5761/// definition blocks in all \p Ranges in \p Code.
5763 StringRef Code,
5765 StringRef FileName = "<stdin>");
5766
5767/// Sort consecutive using declarations in the given \p Ranges in
5768/// \p Code.
5769///
5770/// Returns the ``Replacements`` that sort the using declarations in all
5771/// \p Ranges in \p Code.
5773 StringRef Code,
5775 StringRef FileName = "<stdin>");
5776
5777/// Returns the ``LangOpts`` that the formatter expects you to set.
5778///
5779/// \param Style determines specific settings for lexing mode.
5781
5782/// Description to be used for help text for a ``llvm::cl`` option for
5783/// specifying format style. The description is closely related to the operation
5784/// of ``getStyle()``.
5785extern const char *StyleOptionHelpDescription;
5786
5787/// The suggested format style to use by default. This allows tools using
5788/// ``getStyle`` to have a consistent default style.
5789/// Different builds can modify the value to the preferred styles.
5790extern const char *DefaultFormatStyle;
5791
5792/// The suggested predefined style to use as the fallback style in ``getStyle``.
5793/// Different builds can modify the value to the preferred styles.
5794extern const char *DefaultFallbackStyle;
5795
5796/// Construct a FormatStyle based on ``StyleName``.
5797///
5798/// ``StyleName`` can take several forms:
5799/// * "{<key>: <value>, ...}" - Set specic style parameters.
5800/// * "<style name>" - One of the style names supported by getPredefinedStyle().
5801/// * "file" - Load style configuration from a file called ``.clang-format``
5802/// located in one of the parent directories of ``FileName`` or the current
5803/// directory if ``FileName`` is empty.
5804/// * "file:<format_file_path>" to explicitly specify the configuration file to
5805/// use.
5806///
5807/// \param[in] StyleName Style name to interpret according to the description
5808/// above.
5809/// \param[in] FileName Path to start search for .clang-format if ``StyleName``
5810/// == "file".
5811/// \param[in] FallbackStyle The name of a predefined style used to fallback to
5812/// in case \p StyleName is "file" and no file can be found.
5813/// \param[in] Code The actual code to be formatted. Used to determine the
5814/// language if the filename isn't sufficient.
5815/// \param[in] FS The underlying file system, in which the file resides. By
5816/// default, the file system is the real file system.
5817/// \param[in] AllowUnknownOptions If true, unknown format options only
5818/// emit a warning. If false, errors are emitted on unknown format
5819/// options.
5820///
5821/// \returns FormatStyle as specified by ``StyleName``. If ``StyleName`` is
5822/// "file" and no file is found, returns ``FallbackStyle``. If no style could be
5823/// determined, returns an Error.
5825getStyle(StringRef StyleName, StringRef FileName, StringRef FallbackStyle,
5826 StringRef Code = "", llvm::vfs::FileSystem *FS = nullptr,
5827 bool AllowUnknownOptions = false,
5828 llvm::SourceMgr::DiagHandlerTy DiagHandler = nullptr);
5829
5830// Guesses the language from the ``FileName`` and ``Code`` to be formatted.
5831// Defaults to FormatStyle::LK_Cpp.
5832FormatStyle::LanguageKind guessLanguage(StringRef FileName, StringRef Code);
5833
5834// Returns a string representation of ``Language``.
5836 switch (Language) {
5837 case FormatStyle::LK_C:
5838 return "C";
5840 return "C++";
5842 return "CSharp";
5844 return "Objective-C";
5846 return "Java";
5848 return "JavaScript";
5850 return "Json";
5852 return "Proto";
5854 return "TableGen";
5856 return "TextProto";
5858 return "Verilog";
5859 default:
5860 return "Unknown";
5861 }
5862}
5863
5864bool isClangFormatOn(StringRef Comment);
5865bool isClangFormatOff(StringRef Comment);
5866
5867} // end namespace format
5868} // end namespace clang
5869
5870template <>
5871struct std::is_error_code_enum<clang::format::ParseError> : std::true_type {};
5872
5873#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:434
const char * name() const noexcept override
Definition: Format.cpp:1367
std::string message(int EV) const override
Definition: Format.cpp:1371
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:4119
const char * DefaultFallbackStyle
The suggested predefined style to use as the fallback style in getStyle.
Definition: Format.cpp:4232
FormatStyle getWebKitStyle()
Returns a format style complying with Webkit's style guide: http://www.webkit.org/coding/coding-style...
Definition: Format.cpp:1985
std::error_code make_error_code(ParseError e)
Definition: Format.cpp:1358
FormatStyle getClangFormatStyle()
Definition: Format.cpp:2053
FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language=FormatStyle::LK_Cpp)
Returns a format style complying with the LLVM coding standards: http://llvm.org/docs/CodingStandards...
Definition: Format.cpp:1525
FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language)
Returns a format style complying with one of Google's style guides: http://google-styleguide....
Definition: Format.cpp:1754
std::string configurationAsText(const FormatStyle &Style)
Gets configuration in a YAML string.
Definition: Format.cpp:2210
FormatStyle getMicrosoftStyle(FormatStyle::LanguageKind Language)
Returns a format style complying with Microsoft style guide: https://docs.microsoft....
Definition: Format.cpp:2024
std::error_code parseConfiguration(llvm::MemoryBufferRef Config, FormatStyle *Style, bool AllowUnknownOptions=false, llvm::SourceMgr::DiagHandlerTy DiagHandler=nullptr, void *DiagHandlerCtx=nullptr, bool IsDotHFile=false)
Parse configuration from YAML-formatted text.
Definition: Format.cpp:2136
const std::error_category & getParseCategory()
Definition: Format.cpp:1354
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:4057
FormatStyle::LanguageKind guessLanguage(StringRef FileName, StringRef Code)
Definition: Format.cpp:4207
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:4251
const char * DefaultFormatStyle
The suggested format style to use by default.
Definition: Format.cpp:4230
FormatStyle getGNUStyle()
Returns a format style complying with GNU Coding Standards: http://www.gnu.org/prep/standards/standar...
Definition: Format.cpp:2009
bool isClangFormatOff(StringRef Comment)
Definition: Format.cpp:4436
LangOptions getFormattingLangOpts(const FormatStyle &Style=getLLVMStyle())
Returns the LangOpts that the formatter expects you to set.
Definition: Format.cpp:4077
FormatStyle getMozillaStyle()
Returns a format style complying with Mozilla's style guide: https://firefox-source-docs....
Definition: Format.cpp:1959
bool getPredefinedStyle(StringRef Name, FormatStyle::LanguageKind Language, FormatStyle *Style)
Gets a predefined style for the specified language by name.
Definition: Format.cpp:2075
Expected< tooling::Replacements > cleanupAroundReplacements(StringRef Code, const tooling::Replacements &Replaces, const FormatStyle &Style)
Returns the replacements corresponding to applying Replaces and cleaning up the code after that on su...
Definition: Format.cpp:3812
tooling::Replacements reformat(const FormatStyle &Style, StringRef Code, ArrayRef< tooling::Range > Ranges, StringRef FileName="<stdin>", FormattingAttemptStatus *Status=nullptr)
Reformats the given Ranges in Code.
Definition: Format.cpp:4024
bool isClangFormatOn(StringRef Comment)
Definition: Format.cpp:4432
tooling::Replacements sortUsingDeclarations(const FormatStyle &Style, StringRef Code, ArrayRef< tooling::Range > Ranges, StringRef FileName="<stdin>")
Sort consecutive using declarations in the given Ranges in Code.
Definition: Format.cpp:4067
FormatStyle getChromiumStyle(FormatStyle::LanguageKind Language)
Returns a format style complying with Chromium's style guide: http://www.chromium....
Definition: Format.cpp:1900
tooling::Replacements cleanup(const FormatStyle &Style, StringRef Code, ArrayRef< tooling::Range > Ranges, StringRef FileName="<stdin>")
Clean up any erroneous/redundant code in the given Ranges in Code.
Definition: Format.cpp:4035
Expected< tooling::Replacements > formatReplacements(StringRef Code, const tooling::Replacements &Replaces, const FormatStyle &Style)
Returns the replacements corresponding to applying and formatting Replaces on success; otheriwse,...
Definition: Format.cpp:3700
FormatStyle getNoStyle()
Returns style indicating formatting should be not applied at all.
Definition: Format.cpp:2067
tooling::Replacements sortIncludes(const FormatStyle &Style, StringRef Code, ArrayRef< tooling::Range > Ranges, StringRef FileName, unsigned *Cursor=nullptr)
Returns the replacements necessary to sort all #include blocks that are affected by Ranges.
Definition: Format.cpp:3659
tooling::Replacements separateDefinitionBlocks(const FormatStyle &Style, StringRef Code, ArrayRef< tooling::Range > Ranges, StringRef FileName="<stdin>")
Inserts or removes empty lines separating definition blocks including classes, structs,...
StringRef getLanguageName(FormatStyle::LanguageKind Language)
Definition: Format.h:5835
The JSON file list parser is used to communicate input to InstallAPI.
Language
The language for the input, used to select and validate the language standard and possible actions.
Definition: LangStandard.h:23
Diagnostic wrappers for TextAPI types for error reporting.
Definition: Dominators.h:30
#define true
Definition: stdbool.h:25
#define false
Definition: stdbool.h:26
bool AcrossEmptyLines
Whether to align across empty lines.
Definition: Format.h:203
bool PadOperators
Only for AlignConsecutiveAssignments.
Definition: Format.h:277
bool AlignFunctionDeclarations
Only for AlignConsecutiveDeclarations.
Definition: Format.h:242
bool AlignFunctionPointers
Only for AlignConsecutiveDeclarations.
Definition: Format.h:258
bool operator!=(const AlignConsecutiveStyle &R) const
Definition: Format.h:286
bool operator==(const AlignConsecutiveStyle &R) const
Definition: Format.h:278
bool Enabled
Whether aligning is enabled.
Definition: Format.h:186
bool AlignCompound
Only for AlignConsecutiveAssignments.
Definition: Format.h:228
bool AcrossComments
Whether to align across comments.
Definition: Format.h:216
Precise control over the wrapping of braces.
Definition: Format.h:1365
bool SplitEmptyRecord
If false, empty record (e.g.
Definition: Format.h:1575
bool AfterClass
Wrap class definitions.
Definition: Format.h:1391
bool AfterStruct
Wrap struct definitions.
Definition: Format.h:1458
bool AfterUnion
Wrap union definitions.
Definition: Format.h:1472
bool AfterEnum
Wrap enum definitions.
Definition: Format.h:1406
bool IndentBraces
Indent the wrapped braces themselves.
Definition: Format.h:1549
bool AfterObjCDeclaration
Wrap ObjC definitions (interfaces, implementations...).
Definition: Format.h:1444
bool AfterNamespace
Wrap namespace definitions.
Definition: Format.h:1438
bool SplitEmptyNamespace
If false, empty namespace body can be put on a single line.
Definition: Format.h:1587
BraceWrappingAfterControlStatementStyle AfterControlStatement
Wrap control statements (if/for/while/switch/..).
Definition: Format.h:1394
bool AfterFunction
Wrap function definitions.
Definition: Format.h:1422
bool SplitEmptyFunction
If false, empty function body can be put on a single line.
Definition: Format.h:1563
bool AfterExternBlock
Wrap extern blocks.
Definition: Format.h:1486
std::map< LanguageKind, FormatStyle > MapType
Definition: Format.h:5564
std::optional< FormatStyle > Get(LanguageKind Language) const
Definition: Format.cpp:2226
Separator format of integer literals of different bases.
Definition: Format.h:3122
int8_t BinaryMinDigits
Format separators in binary literals with a minimum number of digits.
Definition: Format.h:3138
bool operator==(const IntegerLiteralSeparatorStyle &R) const
Definition: Format.h:3170
int8_t Binary
Format separators in binary literals.
Definition: Format.h:3130
int8_t DecimalMinDigits
Format separators in decimal literals with a minimum number of digits.
Definition: Format.h:3153
int8_t Decimal
Format separators in decimal literals.
Definition: Format.h:3145
int8_t HexMinDigits
Format separators in hexadecimal literals with a minimum number of digits.
Definition: Format.h:3169
int8_t Hex
Format separators in hexadecimal literals.
Definition: Format.h:3160
Options regarding which empty lines are kept.
Definition: Format.h:3271
bool AtStartOfFile
Keep empty lines at start of file.
Definition: Format.h:3284
bool AtEndOfFile
Keep empty lines at end of file.
Definition: Format.h:3273
bool operator==(const KeepEmptyLinesStyle &R) const
Definition: Format.h:3285
bool AtStartOfBlock
Keep empty lines at start of a block.
Definition: Format.h:3282
See documentation of RawStringFormats.
Definition: Format.h:3905
std::string CanonicalDelimiter
The canonical delimiter for this language.
Definition: Format.h:3913
LanguageKind Language
The language of this raw string.
Definition: Format.h:3907
std::string BasedOnStyle
The style name on which this raw string format is based on.
Definition: Format.h:3917
std::vector< std::string > EnclosingFunctions
A list of enclosing function names that match this language.
Definition: Format.h:3911
bool operator==(const RawStringFormat &Other) const
Definition: Format.h:3918
std::vector< std::string > Delimiters
A list of raw string delimiters that match this language.
Definition: Format.h:3909
bool operator==(const ShortCaseStatementsAlignmentStyle &R) const
Definition: Format.h:429
bool AcrossEmptyLines
Whether to align across empty lines.
Definition: Format.h:374
bool AlignCaseColons
Whether aligned case labels are aligned on the colon, or on the tokens after the colon.
Definition: Format.h:428
bool AcrossComments
Whether to align across comments.
Definition: Format.h:393
bool AlignCaseArrows
Whether to align the case arrows when aligning short case expressions.
Definition: Format.h:410
bool operator==(const SortIncludesOptions &R) const
Definition: Format.h:4397
bool operator!=(const SortIncludesOptions &R) const
Definition: Format.h:4401
bool IgnoreCase
Whether or not includes are sorted in a case-insensitive fashion.
Definition: Format.h:4387
bool IgnoreExtension
When sorting includes in each block, only take file extensions into account if two includes compare e...
Definition: Format.h:4396
bool Enabled
If true, includes are sorted based on the other suboptions below.
Definition: Format.h:4375
Precise control over the spacing before parentheses.
Definition: Format.h:4671
bool AfterControlStatements
If true, put space between control statement keywords (for/if/while...) and opening parentheses.
Definition: Format.h:4678
bool AfterOverloadedOperator
If true, put a space between operator overloading and opening parentheses.
Definition: Format.h:4721
bool AfterRequiresInExpression
If true, put space between requires keyword in a requires expression and opening parentheses.
Definition: Format.h:4748
bool AfterFunctionDeclarationName
If true, put a space between function declaration name and opening parentheses.
Definition: Format.h:4692
bool AfterRequiresInClause
If true, put space between requires keyword in a requires clause and opening parentheses,...
Definition: Format.h:4738
bool AfterForeachMacros
If true, put space between foreach macros and opening parentheses.
Definition: Format.h:4685
bool AfterNot
If true, put a space between alternative operator not and the opening parenthesis.
Definition: Format.h:4713
bool AfterFunctionDefinitionName
If true, put a space between function definition name and opening parentheses.
Definition: Format.h:4699
bool BeforeNonEmptyParentheses
If true, put a space before opening parentheses only if the parentheses are not empty.
Definition: Format.h:4756
bool operator==(const SpaceBeforeParensCustom &Other) const
Definition: Format.h:4766
bool AfterIfMacros
If true, put space between if macros and opening parentheses.
Definition: Format.h:4706
bool AfterPlacementOperator
If true, put a space between operator new/delete and opening parenthesis.
Definition: Format.h:4729
If true, spaces may be inserted into C style casts.
Definition: Format.h:4930
unsigned Maximum
The maximum number of spaces at the start of the comment.
Definition: Format.h:4934
unsigned Minimum
The minimum number of spaces at the start of the comment.
Definition: Format.h:4932
Precise control over the spacing in parentheses.
Definition: Format.h:5009
bool operator==(const SpacesInParensCustom &R) const
Definition: Format.h:5066
bool ExceptDoubleParentheses
Override any of the following options to prevent addition of space when both opening and closing pare...
Definition: Format.h:5020
bool Other
Put a space in parentheses not covered by preceding options.
Definition: Format.h:5052
bool InEmptyParentheses
Insert a space in empty parentheses, i.e.
Definition: Format.h:5046
bool InCStyleCasts
Put a space in C style casts.
Definition: Format.h:5035
bool operator!=(const SpacesInParensCustom &R) const
Definition: Format.h:5072
bool InConditionalStatements
Put a space in parentheses only inside conditional statements (for/if/while/switch....
Definition: Format.h:5028
SpacesInParensCustom(bool ExceptDoubleParentheses, bool InConditionalStatements, bool InCStyleCasts, bool InEmptyParentheses, bool Other)
Definition: Format.h:5058
TrailingCommentsAlignmentKinds Kind
Specifies the way to align trailing comments.
Definition: Format.h:601
bool operator!=(const TrailingCommentsAlignmentStyle &R) const
Definition: Format.h:629
bool operator==(const TrailingCommentsAlignmentStyle &R) const
Definition: Format.h:626
unsigned OverEmptyLines
How many empty lines to apply alignment.
Definition: Format.h:624
The FormatStyle is used to configure the formatting to follow specific guidelines.
Definition: Format.h:55
UseTabStyle
This option is deprecated.
Definition: Format.h:5265
@ UT_AlignWithSpaces
Use tabs for line continuation and indentation, and spaces for alignment.
Definition: Format.h:5275
@ UT_ForContinuationAndIndentation
Fill all leading whitespace with tabs, and use spaces for alignment that appears within a line (e....
Definition: Format.h:5272
@ UT_ForIndentation
Use tabs only for indentation.
Definition: Format.h:5269
@ UT_Always
Use tabs whenever we need to fill whitespace that spans at least from one tab stop to the next one.
Definition: Format.h:5278
@ UT_Never
Never use tab.
Definition: Format.h:5267
bool SpaceBeforeInheritanceColon
If false, spaces will be removed before inheritance colon.
Definition: Format.h:4589
unsigned ContinuationIndentWidth
Indent width for line continuations.
Definition: Format.h:2550
bool AlwaysBreakBeforeMultilineStrings
This option is renamed to BreakAfterReturnType.
Definition: Format.h:1124
LanguageStandard Standard
Parse and format C++ constructs compatible with this standard.
Definition: Format.h:5137
bool BreakAdjacentStringLiterals
Break between adjacent string literals.
Definition: Format.h:1616
ReturnTypeBreakingStyle BreakAfterReturnType
The function declaration return type breaking style to use.
Definition: Format.h:1707
bool isTableGen() const
Definition: Format.h:3391
LanguageKind
Supported languages.
Definition: Format.h:3351
@ LK_C
Should be used for C.
Definition: Format.h:3355
@ LK_CSharp
Should be used for C#.
Definition: Format.h:3359
@ LK_None
Do not use.
Definition: Format.h:3353
@ LK_Java
Should be used for Java.
Definition: Format.h:3361
@ LK_Cpp
Should be used for C++.
Definition: Format.h:3357
@ LK_JavaScript
Should be used for JavaScript.
Definition: Format.h:3363
@ LK_ObjC
Should be used for Objective-C, Objective-C++.
Definition: Format.h:3367
@ LK_Verilog
Should be used for Verilog and SystemVerilog.
Definition: Format.h:3379
@ LK_TableGen
Should be used for TableGen code.
Definition: Format.h:3372
@ LK_Proto
Should be used for Protocol Buffers (https://developers.google.com/protocol-buffers/).
Definition: Format.h:3370
@ LK_Json
Should be used for JSON.
Definition: Format.h:3365
@ LK_TextProto
Should be used for Protocol Buffer messages in text format (https://developers.google....
Definition: Format.h:3375
bool Cpp11BracedListStyle
If true, format braced lists as best suited for C++11 braced lists.
Definition: Format.h:2574
SortIncludesOptions SortIncludes
Controls if and how clang-format will sort #includes.
Definition: Format.h:4408
BreakInheritanceListStyle BreakInheritanceList
The inheritance list style to use.
Definition: Format.h:2501
std::string OneLineFormatOffRegex
A regular expression that describes markers for turning formatting off for one line.
Definition: Format.h:3681
unsigned IndentWidth
The number of columns to use for indentation.
Definition: Format.h:3021
std::vector< std::string > AttributeMacros
This option is renamed to BreakTemplateDeclarations.
Definition: Format.h:1194
ShortLambdaStyle
Different styles for merging short lambdas containing at most one statement.
Definition: Format.h:954
@ SLS_All
Merge all lambdas fitting on a single line.
Definition: Format.h:978
@ SLS_Inline
Merge lambda into a single line if the lambda is argument of a function.
Definition: Format.h:972
@ SLS_None
Never merge lambdas into a single line.
Definition: Format.h:956
@ SLS_Empty
Only merge empty lambdas.
Definition: Format.h:964
SeparateDefinitionStyle
The style if definition blocks should be separated.
Definition: Format.h:4288
@ SDS_Never
Remove any empty line between definition blocks.
Definition: Format.h:4294
@ SDS_Always
Insert an empty line between definition blocks.
Definition: Format.h:4292
@ SDS_Leave
Leave definition blocks as they are.
Definition: Format.h:4290
bool IndentRequiresClause
Indent the requires clause in a template.
Definition: Format.h:3007
SpacesInAnglesStyle SpacesInAngles
The SpacesInAnglesStyle to use for template argument lists.
Definition: Format.h:4903
bool KeepFormFeed
This option is deprecated.
Definition: Format.h:3310
bool IndentCaseLabels
Indent case labels one level from the switch statement.
Definition: Format.h:2879
std::vector< RawStringFormat > RawStringFormats
Defines hints for detecting supported languages code blocks in raw strings.
Definition: Format.h:3962
std::vector< std::string > VariableTemplates
A vector of non-keyword identifiers that should be interpreted as variable template names.
Definition: Format.h:5292
SortJavaStaticImportOptions
Position for Java Static imports.
Definition: Format.h:4411
@ SJSIO_Before
Static imports are placed before non-static imports.
Definition: Format.h:4418
@ SJSIO_After
Static imports are placed after non-static imports.
Definition: Format.h:4425
PPDirectiveIndentStyle IndentPPDirectives
The preprocessor directive indenting style to use.
Definition: Format.h:2984
bool RemoveSemicolon
Remove semicolons after the closing braces of functions and constructors/destructors.
Definition: Format.h:4156
std::vector< std::string > Macros
A list of macros of the form <definition>=<expansion> .
Definition: Format.h:3489
EnumTrailingCommaStyle
Styles for enum trailing commas.
Definition: Format.h:2708
@ ETC_Remove
Remove trailing commas.
Definition: Format.h:2726
@ ETC_Insert
Insert trailing commas.
Definition: Format.h:2720
@ ETC_Leave
Don't insert or remove trailing commas.
Definition: Format.h:2714
bool SpaceBeforeJsonColon
If true, a space will be added before a JSON colon.
Definition: Format.h:4600
TrailingCommaStyle
The style of inserting trailing commas into container literals.
Definition: Format.h:3074
@ TCS_Wrapped
Insert trailing commas in container literals that were wrapped over multiple lines.
Definition: Format.h:3082
@ TCS_None
Do not insert trailing commas.
Definition: Format.h:3076
unsigned PenaltyBreakBeforeFirstCallParameter
The penalty for breaking a function call after call(.
Definition: Format.h:3751
bool SpaceBeforeCtorInitializerColon
If false, spaces will be removed before constructor initializer colon.
Definition: Format.h:4581
BinPackParametersStyle
Different way to try to fit all parameters on a line.
Definition: Format.h:1232
@ BPPS_OnePerLine
Put all parameters on the current line if they fit.
Definition: Format.h:1248
@ BPPS_BinPack
Bin-pack parameters.
Definition: Format.h:1238
@ BPPS_AlwaysOnePerLine
Always put each parameter on its own line.
Definition: Format.h:1255
BinaryOperatorStyle BreakBeforeBinaryOperators
The way to wrap binary operators.
Definition: Format.h:1781
bool IndentExportBlock
If true, clang-format will indent the body of an export { ... } block.
Definition: Format.h:2892
BinPackStyle
The style of wrapping parameters on the same line (bin-packed) or on one line each.
Definition: Format.h:1730
@ BPS_Never
Never bin-pack parameters.
Definition: Format.h:1736
@ BPS_Auto
Automatically determine parameter bin-packing behavior.
Definition: Format.h:1732
@ BPS_Always
Always bin-pack parameters.
Definition: Format.h:1734
BitFieldColonSpacingStyle BitFieldColonSpacing
The BitFieldColonSpacingStyle to use for bitfields.
Definition: Format.h:1289
ReflowCommentsStyle
Types of comment reflow style.
Definition: Format.h:3991
@ RCS_IndentOnly
Only apply indentation rules, moving comments left or right, without changing formatting inside the c...
Definition: Format.h:4008
@ RCS_Never
Leave comments untouched.
Definition: Format.h:3999
@ RCS_Always
Apply indentation rules and reflow long comments into new lines, trying to obey the ColumnLimit.
Definition: Format.h:4019
EmptyLineBeforeAccessModifierStyle
Different styles for empty line before access modifiers.
Definition: Format.h:2645
@ ELBAMS_LogicalBlock
Add empty line only when access modifier starts a new logical block.
Definition: Format.h:2680
@ ELBAMS_Never
Remove all empty lines before access modifiers.
Definition: Format.h:2660
@ ELBAMS_Always
Always add empty line before access modifiers unless access modifier is at the start of struct or cla...
Definition: Format.h:2700
@ ELBAMS_Leave
Keep existing empty lines before access modifiers.
Definition: Format.h:2662
unsigned SpacesBeforeTrailingComments
If true, spaces may be inserted into ().
Definition: Format.h:4880
BreakConstructorInitializersStyle
Different ways to break initializers.
Definition: Format.h:2349
@ BCIS_AfterColon
Break constructor initializers after the colon and commas.
Definition: Format.h:2371
@ BCIS_BeforeColon
Break constructor initializers before the colon and after the commas.
Definition: Format.h:2356
@ BCIS_BeforeComma
Break constructor initializers before the colon and commas, and align the commas with the colon.
Definition: Format.h:2364
IndentExternBlockStyle
Indents extern blocks.
Definition: Format.h:2895
@ IEBS_AfterExternBlock
Backwards compatible with AfterExternBlock's indenting.
Definition: Format.h:2913
@ IEBS_Indent
Indents extern blocks.
Definition: Format.h:2927
@ IEBS_NoIndent
Does not indent extern blocks.
Definition: Format.h:2920
bool IndentCaseBlocks
Indent case label blocks one level from the case label.
Definition: Format.h:2860
bool InsertBraces
Insert braces after control statements (if, else, for, do, and while) in C++ unless the control state...
Definition: Format.h:3067
BreakBeforeConceptDeclarationsStyle BreakBeforeConceptDeclarations
The concept declaration style to use.
Definition: Format.h:2240
BreakTemplateDeclarationsStyle BreakTemplateDeclarations
The template declaration breaking style to use.
Definition: Format.h:2505
bool DerivePointerAlignment
This option is deprecated.
Definition: Format.h:2587
std::vector< std::string > MacrosSkippedByRemoveParentheses
A vector of function-like macros whose invocations should be skipped by RemoveParentheses.
Definition: Format.h:3494
BinaryOperatorStyle
The style of breaking before or after binary operators.
Definition: Format.h:1740
@ BOS_All
Break before operators.
Definition: Format.h:1776
@ BOS_None
Break after operators.
Definition: Format.h:1752
@ BOS_NonAssignment
Break before operators that aren't assignments.
Definition: Format.h:1764
LineEndingStyle
Line ending style.
Definition: Format.h:3403
@ LE_DeriveLF
Use \n unless the input has more lines ending in \r\n.
Definition: Format.h:3409
@ LE_DeriveCRLF
Use \r\n unless the input has more lines ending in \n.
Definition: Format.h:3411
bool SpacesInSquareBrackets
If true, spaces will be inserted after [ and before ].
Definition: Format.h:5102
bool IndentWrappedFunctionNames
Indent if a function definition or declaration is wrapped after the type.
Definition: Format.h:3035
AlignConsecutiveStyle AlignConsecutiveTableGenBreakingDAGArgColons
Style of aligning consecutive TableGen DAGArg operator colons.
Definition: Format.h:465
WrapNamespaceBodyWithEmptyLinesStyle WrapNamespaceBodyWithEmptyLines
Wrap namespace body with empty lines.
Definition: Format.h:5356
bool FixNamespaceComments
If true, clang-format adds missing namespace end comments for namespaces and fixes invalid existing o...
Definition: Format.h:2769
bool ObjCSpaceBeforeProtocolList
Add a space in front of an Objective-C protocol list, i.e.
Definition: Format.h:3660
TrailingCommentsAlignmentKinds
Enums for AlignTrailingComments.
Definition: Format.h:568
@ TCAS_Never
Don't align trailing comments but other formatter applies.
Definition: Format.h:595
@ TCAS_Leave
Leave trailing comments as they are.
Definition: Format.h:577
@ TCAS_Always
Align trailing comments.
Definition: Format.h:586
RemoveParenthesesStyle RemoveParentheses
Remove redundant parentheses.
Definition: Format.h:4138
std::string MacroBlockBegin
A regular expression matching macros that start a block.
Definition: Format.h:3445
LanguageKind Language
The language that this format style targets.
Definition: Format.h:3400
SpacesInParensStyle
Different ways to put a space before opening and closing parentheses.
Definition: Format.h:4972
@ SIPO_Custom
Configure each individual space in parentheses in SpacesInParensOptions.
Definition: Format.h:4984
@ SIPO_Never
Never put a space in parentheses.
Definition: Format.h:4981
bool RemoveBracesLLVM
Remove optional braces of control statements (if, else, for, and while) in C++ according to the LLVM ...
Definition: Format.h:4079
BracketAlignmentStyle
Different styles for aligning after open brackets.
Definition: Format.h:66
@ BAS_DontAlign
Don't align, instead use ContinuationIndentWidth, e.g.:
Definition: Format.h:78
@ BAS_AlwaysBreak
Always break after an open bracket, if the parameters don't fit on a single line, e....
Definition: Format.h:85
@ BAS_BlockIndent
Always break after an open bracket, if the parameters don't fit on a single line.
Definition: Format.h:99
@ BAS_Align
Align parameters on the open bracket, e.g.:
Definition: Format.h:72
static FormatStyleSet BuildStyleSetFromConfiguration(const FormatStyle &MainStyle, const std::vector< FormatStyle > &ConfigurationStyles)
BreakBeforeInlineASMColonStyle
Different ways to break ASM parameters.
Definition: Format.h:2243
@ BBIAS_Always
Always break before inline ASM colon.
Definition: Format.h:2264
@ BBIAS_OnlyMultiline
Break before inline ASM colon if the line length is longer than column limit.
Definition: Format.h:2257
@ BBIAS_Never
No break before inline ASM colon.
Definition: Format.h:2248
bool VerilogBreakBetweenInstancePorts
For Verilog, put each port on its own line in module instantiations.
Definition: Format.h:5306
unsigned TabWidth
The number of columns used for tab stops.
Definition: Format.h:5222
PPDirectiveIndentStyle
Options for indenting preprocessor directives.
Definition: Format.h:2952
@ PPDIS_BeforeHash
Indents directives before the hash.
Definition: Format.h:2979
@ PPDIS_None
Does not indent any directives.
Definition: Format.h:2961
@ PPDIS_AfterHash
Indents directives after the hash.
Definition: Format.h:2970
LambdaBodyIndentationKind
Indentation logic for lambda bodies.
Definition: Format.h:3313
@ LBI_OuterScope
For statements within block scope, align lambda body relative to the indentation level of the outer s...
Definition: Format.h:3335
@ LBI_Signature
Align lambda body relative to the lambda signature.
Definition: Format.h:3321
std::vector< std::string > JavaImportGroups
A vector of prefixes ordered by the desired groups for Java imports.
Definition: Format.h:3214
bool AllowShortCaseLabelsOnASingleLine
If true, short case labels will be contracted to a single line.
Definition: Format.h:793
unsigned PenaltyBreakFirstLessLess
The penalty for breaking before the first <<.
Definition: Format.h:3763
std::vector< std::string > StatementAttributeLikeMacros
Macros which are ignored in front of a statement, as if they were an attribute.
Definition: Format.h:5154
unsigned ObjCBlockIndentWidth
The number of characters to use for indentation of ObjC blocks.
Definition: Format.h:3603
bool AllowShortLoopsOnASingleLine
If true, while (true) continue; can be put on a single line.
Definition: Format.h:989
int AccessModifierOffset
The extra indent or outdent of access modifiers, e.g.
Definition: Format.h:63
std::vector< std::string > QualifierOrder
The order in which the qualifiers appear.
Definition: Format.h:3902
bool AllowShortEnumsOnASingleLine
Allow short enums on a single line.
Definition: Format.h:826
ShortBlockStyle
Different styles for merging short blocks containing at most one statement.
Definition: Format.h:737
@ SBS_Always
Always merge short blocks into a single line.
Definition: Format.h:760
@ SBS_Empty
Only merge empty blocks.
Definition: Format.h:754
@ SBS_Never
Never merge blocks into a single line.
Definition: Format.h:746
std::optional< FormatStyle > GetLanguageStyle(LanguageKind Language) const
Definition: Format.cpp:2257
std::vector< std::string > IfMacros
A vector of macros that should be interpreted as conditionals instead of as function calls.
Definition: Format.h:2810
NamespaceIndentationKind NamespaceIndentation
The indentation used for namespaces.
Definition: Format.h:3546
bool BreakArrays
If true, clang-format will always break after a Json array [ otherwise it will scan until the closing...
Definition: Format.h:1726
bool BreakAfterJavaFieldAnnotations
Break after each annotation on a field in Java files.
Definition: Format.h:2400
ShortIfStyle
Different styles for handling short if statements.
Definition: Format.h:882
@ SIS_WithoutElse
Put short ifs on the same line only if there is no else statement.
Definition: Format.h:915
@ SIS_Never
Never put short ifs on the same line.
Definition: Format.h:899
@ SIS_OnlyFirstIf
Put short ifs, but not else ifs nor else statements, on the same line.
Definition: Format.h:931
@ SIS_AllIfsAndElse
Always put short ifs, else ifs and else statements on the same line.
Definition: Format.h:945
std::vector< std::string > ObjCPropertyAttributeOrder
The order in which ObjC property attributes should appear.
Definition: Format.h:3650
bool ExperimentalAutoDetectBinPacking
If true, clang-format detects whether function calls and definitions are formatted with one parameter...
Definition: Format.h:2753
bool ObjCBreakBeforeNestedBlockParam
Break parameters list into lines when there is nested block parameters in a function call.
Definition: Format.h:3627
OperandAlignmentStyle AlignOperands
If true, horizontally align operands of binary and ternary expressions.
Definition: Format.h:565
unsigned PenaltyBreakOpenParenthesis
The penalty for breaking after (.
Definition: Format.h:3767
unsigned PenaltyBreakBeforeMemberAccess
The penalty for breaking before a member access operator (.
Definition: Format.h:3755
BreakTemplateDeclarationsStyle
Different ways to break after the template declaration.
Definition: Format.h:1127
@ BTDS_No
Do not force break before declaration.
Definition: Format.h:1147
@ BTDS_MultiLine
Force break after template declaration only when the following declaration spans multiple lines.
Definition: Format.h:1158
@ BTDS_Yes
Always break after template declaration.
Definition: Format.h:1169
@ BTDS_Leave
Do not change the line breaking before the declaration.
Definition: Format.h:1137
bool AllowShortCompoundRequirementOnASingleLine
Allow short compound requirement on a single line.
Definition: Format.h:812
SpacesInParensStyle SpacesInParens
If true, spaces will be inserted after ( and before ).
Definition: Format.h:4998
SpacesInParensCustom SpacesInParensOptions
Control of individual spaces in parentheses.
Definition: Format.h:5091
std::vector< std::string > ForEachMacros
A vector of macros that should be interpreted as foreach loops instead of as function calls.
Definition: Format.h:2787
ReferenceAlignmentStyle ReferenceAlignment
Reference alignment style (overrides PointerAlignment for references).
Definition: Format.h:3987
BreakBinaryOperationsStyle BreakBinaryOperations
The break binary operations style to use.
Definition: Format.h:2346
AlignConsecutiveStyle AlignConsecutiveTableGenDefinitionColons
Style of aligning consecutive TableGen definition colons.
Definition: Format.h:485
TrailingCommaStyle InsertTrailingCommas
If set to TCS_Wrapped will insert trailing commas in container literals (arrays and objects) that wra...
Definition: Format.h:3101
unsigned PenaltyBreakTemplateDeclaration
The penalty for breaking after template declaration.
Definition: Format.h:3779
SpaceBeforeParensCustom SpaceBeforeParensOptions
Control of individual space before parentheses.
Definition: Format.h:4795
BreakConstructorInitializersStyle BreakConstructorInitializers
The break constructor initializers style to use.
Definition: Format.h:2376
bool RemoveEmptyLinesInUnwrappedLines
Remove empty lines within unwrapped lines.
Definition: Format.h:4102
bool BreakStringLiterals
Allow breaking string literals when formatting.
Definition: Format.h:2443
bool SpaceAfterLogicalNot
If true, a space is inserted after the logical not operator (!).
Definition: Format.h:4492
SpaceBeforeParensStyle
Different ways to put a space before opening parentheses.
Definition: Format.h:4603
@ SBPO_Never
This is deprecated and replaced by Custom below, with all SpaceBeforeParensOptions but AfterPlacement...
Definition: Format.h:4607
@ SBPO_Custom
Configure each individual space before parentheses in SpaceBeforeParensOptions.
Definition: Format.h:4656
@ SBPO_NonEmptyParentheses
Put a space before opening parentheses only if the parentheses are not empty.
Definition: Format.h:4641
@ SBPO_ControlStatementsExceptControlMacros
Same as SBPO_ControlStatements except this option doesn't apply to ForEach and If macros.
Definition: Format.h:4630
@ SBPO_ControlStatements
Put a space before opening parentheses only after control statement keywords (for/if/while....
Definition: Format.h:4617
@ SBPO_Always
Always put a space before opening parentheses, except when it's prohibited by the syntax rules (in fu...
Definition: Format.h:4653
PackConstructorInitializersStyle
Different ways to try to fit all constructor initializers on a line.
Definition: Format.h:3684
@ PCIS_NextLineOnly
Put all constructor initializers on the next line if they fit.
Definition: Format.h:3738
@ PCIS_Never
Always put each constructor initializer on its own line.
Definition: Format.h:3691
@ PCIS_CurrentLine
Put all constructor initializers on the current line if they fit.
Definition: Format.h:3709
@ PCIS_BinPack
Bin-pack constructor initializers.
Definition: Format.h:3698
@ PCIS_NextLine
Same as PCIS_CurrentLine except that if all constructor initializers do not fit on the current line,...
Definition: Format.h:3723
std::vector< std::string > TypeNames
A vector of non-keyword identifiers that should be interpreted as type names.
Definition: Format.h:5241
bool isTextProto() const
Definition: Format.h:3389
bool ObjCSpaceAfterProperty
Add a space after @property in Objective-C, i.e.
Definition: Format.h:3655
BraceBreakingStyle BreakBeforeBraces
The brace breaking style to use.
Definition: Format.h:2216
BreakInheritanceListStyle
Different ways to break inheritance list.
Definition: Format.h:2464
@ BILS_AfterColon
Break inheritance list after the colon and commas.
Definition: Format.h:2489
@ BILS_AfterComma
Break inheritance list only after the commas.
Definition: Format.h:2496
@ BILS_BeforeColon
Break inheritance list before the colon and after the commas.
Definition: Format.h:2472
@ BILS_BeforeComma
Break inheritance list before the colon and commas, and align the commas with the colon.
Definition: Format.h:2481
bool isCSharp() const
Definition: Format.h:3384
unsigned PenaltyExcessCharacter
The penalty for each character outside of the column limit.
Definition: Format.h:3783
std::vector< std::string > WhitespaceSensitiveMacros
A vector of macros which are whitespace-sensitive and should not be touched.
Definition: Format.h:5323
std::vector< std::string > TemplateNames
A vector of non-keyword identifiers that should be interpreted as template names.
Definition: Format.h:5231
DAGArgStyle
Different ways to control the format inside TableGen DAGArg.
Definition: Format.h:5193
@ DAS_BreakElements
Break inside DAGArg after each list element but for the last.
Definition: Format.h:5205
@ DAS_DontBreak
Never break inside DAGArg.
Definition: Format.h:5198
@ DAS_BreakAll
Break inside DAGArg after the operator and the all elements.
Definition: Format.h:5213
unsigned ConstructorInitializerIndentWidth
This option is deprecated.
Definition: Format.h:2539
BreakBeforeNoexceptSpecifierStyle
Different ways to break before a noexcept specifier.
Definition: Format.h:695
@ BBNSS_Never
No line break allowed.
Definition: Format.h:705
@ BBNSS_Always
Line breaks are allowed.
Definition: Format.h:728
@ BBNSS_OnlyWithParen
For a simple noexcept there is no line break allowed, but when we have a condition it is.
Definition: Format.h:716
bool CompactNamespaces
If true, consecutive namespace declarations will be on the same line.
Definition: Format.h:2529
RequiresClausePositionStyle
The possible positions for the requires clause.
Definition: Format.h:4160
@ RCPS_OwnLineWithBrace
As with OwnLine, except, unless otherwise prohibited, place a following open brace (of a function def...
Definition: Format.h:4199
@ RCPS_OwnLine
Always put the requires clause on its own line (possibly followed by a semicolon).
Definition: Format.h:4181
@ RCPS_WithPreceding
Try to put the clause together with the preceding part of a declaration.
Definition: Format.h:4216
@ RCPS_SingleLine
Try to put everything in the same line if possible.
Definition: Format.h:4254
@ RCPS_WithFollowing
Try to put the requires clause together with the class or function declaration.
Definition: Format.h:4230
bool operator==(const FormatStyle &R) const
Definition: Format.h:5358
LanguageStandard
Supported language standards for parsing and formatting C++ constructs.
Definition: Format.h:5112
@ LS_Cpp17
Parse and format as C++17.
Definition: Format.h:5121
@ LS_Latest
Parse and format using the latest supported language version.
Definition: Format.h:5126
@ LS_Cpp11
Parse and format as C++11.
Definition: Format.h:5117
@ LS_Auto
Automatic detection based on the input.
Definition: Format.h:5128
@ LS_Cpp03
Parse and format as C++03.
Definition: Format.h:5115
@ LS_Cpp14
Parse and format as C++14.
Definition: Format.h:5119
@ LS_Cpp20
Parse and format as C++20.
Definition: Format.h:5123
BraceWrappingAfterControlStatementStyle
Different ways to wrap braces after control statements.
Definition: Format.h:1325
@ BWACS_Always
Always wrap braces after a control statement.
Definition: Format.h:1355
@ BWACS_Never
Never wrap braces after a control statement.
Definition: Format.h:1334
@ BWACS_MultiLine
Only wrap braces after a multi-line control statement.
Definition: Format.h:1345
RequiresClausePositionStyle RequiresClausePosition
The position of the requires clause.
Definition: Format.h:4259
JavaScriptQuoteStyle
Quotation styles for JavaScript strings.
Definition: Format.h:3218
@ JSQS_Double
Always use double quotes.
Definition: Format.h:3236
@ JSQS_Single
Always use single quotes.
Definition: Format.h:3230
@ JSQS_Leave
Leave string quotes as they are.
Definition: Format.h:3224
bool SpaceAfterCStyleCast
If true, a space is inserted after C style casts.
Definition: Format.h:4484
AlignConsecutiveStyle AlignConsecutiveBitFields
Style of aligning consecutive bit fields.
Definition: Format.h:323
int PPIndentWidth
The number of columns to use for indentation of preprocessor statements.
Definition: Format.h:3830
AlignConsecutiveStyle AlignConsecutiveDeclarations
Style of aligning consecutive declarations.
Definition: Format.h:334
IntegerLiteralSeparatorStyle IntegerLiteralSeparator
Format integer literal separators (' for C++ and _ for C#, Java, and JavaScript).
Definition: Format.h:3180
SpaceAroundPointerQualifiersStyle SpaceAroundPointerQualifiers
Defines in which cases to put a space before or after pointer qualifiers.
Definition: Format.h:4541
DefinitionReturnTypeBreakingStyle AlwaysBreakAfterDefinitionReturnType
The function definition return type breaking style to use.
Definition: Format.h:1104
bool SpaceBeforeAssignmentOperators
If false, spaces will be removed before assignment operators.
Definition: Format.h:4550
BreakBeforeInlineASMColonStyle BreakBeforeInlineASMColon
The inline ASM colon style to use.
Definition: Format.h:2269
WrapNamespaceBodyWithEmptyLinesStyle
Different styles for wrapping namespace body with empty lines.
Definition: Format.h:5326
@ WNBWELS_Always
Always have at least one empty line at the beginning and the end of namespace body except that the nu...
Definition: Format.h:5348
@ WNBWELS_Leave
Keep existing newlines at the beginning and the end of namespace body.
Definition: Format.h:5351
@ WNBWELS_Never
Remove all empty lines at the beginning and the end of namespace body.
Definition: Format.h:5335
SpaceInEmptyBracesStyle SpaceInEmptyBraces
Specifies when to insert a space in empty braces.
Definition: Format.h:4854
BraceBreakingStyle
Different ways to attach braces to their surrounding context.
Definition: Format.h:1784
@ BS_Mozilla
Like Attach, but break before braces on enum, function, and record definitions.
Definition: Format.h:1929
@ BS_Whitesmiths
Like Allman but always indent braces and line up code with braces.
Definition: Format.h:2099
@ BS_Allman
Always break before braces.
Definition: Format.h:2039
@ BS_Stroustrup
Like Attach, but break before function definitions, catch, and else.
Definition: Format.h:1979
@ BS_Linux
Like Attach, but break before braces on function, namespace and class definitions.
Definition: Format.h:1879
@ BS_WebKit
Like Attach, but break before functions.
Definition: Format.h:2209
@ BS_Custom
Configure each individual brace in BraceWrapping.
Definition: Format.h:2211
@ BS_GNU
Always break before braces and add an extra level of indentation to braces of control statements,...
Definition: Format.h:2162
@ BS_Attach
Always attach braces to surrounding context.
Definition: Format.h:1829
AttributeBreakingStyle
Different ways to break after attributes.
Definition: Format.h:1619
@ ABS_Leave
Leave the line breaking after attributes as is.
Definition: Format.h:1673
@ ABS_Never
Never break after attributes.
Definition: Format.h:1695
@ ABS_Always
Always break after attributes.
Definition: Format.h:1648
bool BinPackArguments
If false, a function call's arguments will either be all on the same line or will have one line each.
Definition: Format.h:1213
ShortLambdaStyle AllowShortLambdasOnASingleLine
Dependent on the value, auto lambda []() { return 0; } can be put on a single line.
Definition: Format.h:984
bool BinPackLongBracedList
If BinPackLongBracedList is true it overrides BinPackArguments if there are 20 or more items in a bra...
Definition: Format.h:1229
unsigned PenaltyBreakScopeResolution
The penalty for breaking after ::.
Definition: Format.h:3771
unsigned PenaltyReturnTypeOnItsOwnLine
Penalty for putting the return type of a function onto its own line.
Definition: Format.h:3792
BitFieldColonSpacingStyle
Styles for adding spacing around : in bitfield definitions.
Definition: Format.h:1263
@ BFCS_Both
Add one space on each side of the :
Definition: Format.h:1268
@ BFCS_Before
Add space before the : only.
Definition: Format.h:1279
@ BFCS_None
Add no space around the : (except when needed for AlignConsecutiveBitFields).
Definition: Format.h:1274
@ BFCS_After
Add space after the : only (space may be added before if needed for AlignConsecutiveBitFields).
Definition: Format.h:1285
PointerAlignmentStyle PointerAlignment
Pointer and reference alignment style.
Definition: Format.h:3815
bool BreakBeforeTemplateCloser
If true, break before a template closing bracket (>) when there is a line break after the matching op...
Definition: Format.h:2296
int BracedInitializerIndentWidth
The number of columns to use to indent the contents of braced init lists.
Definition: Format.h:1322
ShortFunctionStyle
Different styles for merging short functions containing at most one statement.
Definition: Format.h:830
@ SFS_Inline
Only merge functions defined inside a class.
Definition: Format.h:865
@ SFS_All
Merge all functions fitting on a single line.
Definition: Format.h:873
@ SFS_Empty
Only merge empty functions.
Definition: Format.h:854
@ SFS_None
Never merge functions into a single line.
Definition: Format.h:832
@ SFS_InlineOnly
Only merge functions defined inside a class.
Definition: Format.h:846
bool BreakFunctionDefinitionParameters
If true, clang-format will always break before function definition parameters.
Definition: Format.h:2390
RequiresExpressionIndentationKind
Indentation logic for requires expression bodies.
Definition: Format.h:4262
@ REI_Keyword
Align requires expression body relative to the requires keyword.
Definition: Format.h:4280
@ REI_OuterScope
Align requires expression body relative to the indentation level of the outer scope the requires expr...
Definition: Format.h:4272
PackConstructorInitializersStyle PackConstructorInitializers
The pack constructor initializers style to use.
Definition: Format.h:3743
BreakBeforeConceptDeclarationsStyle
Different ways to break before concept declarations.
Definition: Format.h:2219
@ BBCDS_Allowed
Breaking between template declaration and concept is allowed.
Definition: Format.h:2228
@ BBCDS_Never
Keep the template declaration line together with concept.
Definition: Format.h:2224
@ BBCDS_Always
Always break before concept, putting it in the line after the template declaration.
Definition: Format.h:2235
ReflowCommentsStyle ReflowComments
Comment reformatting style.
Definition: Format.h:4025
KeepEmptyLinesStyle KeepEmptyLines
Which empty lines are kept.
Definition: Format.h:3294
bool AllowAllParametersOfDeclarationOnNextLine
This option is deprecated.
Definition: Format.h:692
BracketAlignmentStyle AlignAfterOpenBracket
If true, horizontally aligns arguments after an open bracket.
Definition: Format.h:107
AlignConsecutiveStyle AlignConsecutiveTableGenCondOperatorColons
Style of aligning consecutive TableGen cond operator colons.
Definition: Format.h:475
bool isProto() const
Definition: Format.h:3390
BinPackParametersStyle BinPackParameters
The bin pack parameters style to use.
Definition: Format.h:1260
bool AllowShortCaseExpressionOnASingleLine
Whether to merge a short switch labeled rule into a single line.
Definition: Format.h:779
unsigned MaxEmptyLinesToKeep
The maximum number of consecutive empty lines to keep.
Definition: Format.h:3508
bool SpaceBeforeSquareBrackets
If true, spaces will be before [.
Definition: Format.h:4805
BinPackStyle ObjCBinPackProtocolList
Controls bin-packing Objective-C protocol conformance list items into as few lines as possible when t...
Definition: Format.h:3592
bool isVerilog() const
Definition: Format.h:3388
ShortCaseStatementsAlignmentStyle AlignConsecutiveShortCaseStatements
Style of aligning consecutive short case labels.
Definition: Format.h:450
EscapedNewlineAlignmentStyle AlignEscapedNewlines
Options for aligning backslashes in escaped newlines.
Definition: Format.h:526
SpacesInLineComment SpacesInLineCommentPrefix
How many spaces are allowed at the start of a line comment.
Definition: Format.h:4969
std::string CommentPragmas
A regular expression that describes comments with special meaning, which should not be split into lin...
Definition: Format.h:2461
bool isJavaScript() const
Definition: Format.h:3387
DAGArgStyle TableGenBreakInsideDAGArg
The styles of the line break inside the DAGArg in TableGen.
Definition: Format.h:5218
JavaScriptQuoteStyle JavaScriptQuotes
The JavaScriptQuoteStyle to use for JavaScript strings.
Definition: Format.h:3241
bool SpacesInContainerLiterals
If true, spaces will be inserted around if/for/switch/while conditions.
Definition: Format.h:4921
SortJavaStaticImportOptions SortJavaStaticImport
When sorting Java imports, by default static imports are placed before non-static imports.
Definition: Format.h:4432
SpaceAroundPointerQualifiersStyle
Different ways to put a space before opening parentheses.
Definition: Format.h:4511
@ SAPQ_After
Ensure that there is a space after pointer qualifiers.
Definition: Format.h:4530
@ SAPQ_Default
Don't ensure spaces around pointer qualifiers and use PointerAlignment instead.
Definition: Format.h:4518
@ SAPQ_Both
Ensure that there is a space both before and after pointer qualifiers.
Definition: Format.h:4536
@ SAPQ_Before
Ensure that there is a space before pointer qualifiers.
Definition: Format.h:4524
bool SpaceBeforeRangeBasedForLoopColon
If false, spaces will be removed before range-based for loop colon.
Definition: Format.h:4814
bool DisableFormat
Disables formatting completely.
Definition: Format.h:2591
EmptyLineAfterAccessModifierStyle
Different styles for empty line after access modifiers.
Definition: Format.h:2596
@ ELAAMS_Always
Always add empty line after access modifiers if there are none.
Definition: Format.h:2635
@ ELAAMS_Never
Remove all empty lines after access modifiers.
Definition: Format.h:2611
@ ELAAMS_Leave
Keep existing empty lines after access modifiers.
Definition: Format.h:2614
DefinitionReturnTypeBreakingStyle
Different ways to break after the function definition return type.
Definition: Format.h:997
@ DRTBS_All
Always break after the return type.
Definition: Format.h:1002
@ DRTBS_TopLevel
Always break after the return types of top-level functions.
Definition: Format.h:1004
@ DRTBS_None
Break after return type automatically.
Definition: Format.h:1000
bool AllowShortNamespacesOnASingleLine
If true, namespace a { class b; } can be put on a single line.
Definition: Format.h:993
std::vector< std::string > NamespaceMacros
A vector of macros which are used to open namespace blocks.
Definition: Format.h:3559
AttributeBreakingStyle BreakAfterAttributes
Break after a group of C++11 attributes before variable or function (including constructor/destructor...
Definition: Format.h:1703
TrailingCommentsAlignmentStyle AlignTrailingComments
Control of trailing comments.
Definition: Format.h:652
ArrayInitializerAlignmentStyle
Different style for aligning array initializers.
Definition: Format.h:110
@ AIAS_Left
Align array column and left justify the columns e.g.:
Definition: Format.h:120
@ AIAS_Right
Align array column and right justify the columns e.g.:
Definition: Format.h:130
@ AIAS_None
Don't align array initializer columns.
Definition: Format.h:132
LambdaBodyIndentationKind LambdaBodyIndentation
The indentation style of lambda bodies.
Definition: Format.h:3344
QualifierAlignmentStyle QualifierAlignment
Different ways to arrange specifiers and qualifiers (e.g.
Definition: Format.h:3876
BreakBinaryOperationsStyle
Different ways to break binary operations.
Definition: Format.h:2314
@ BBO_OnePerLine
Binary operations will either be all on the same line, or each operation will have one line each.
Definition: Format.h:2331
@ BBO_Never
Don't break binary operations.
Definition: Format.h:2320
@ BBO_RespectPrecedence
Binary operations of a particular precedence that exceed the column limit will have one line each.
Definition: Format.h:2341
bool IndentGotoLabels
Indent goto labels.
Definition: Format.h:2949
BraceWrappingFlags BraceWrapping
Control of individual brace wrapping cases.
Definition: Format.h:1603
EscapedNewlineAlignmentStyle
Different styles for aligning escaped newlines.
Definition: Format.h:488
@ ENAS_DontAlign
Don't align escaped newlines.
Definition: Format.h:496
@ ENAS_Left
Align escaped newlines as far left as possible.
Definition: Format.h:504
@ ENAS_Right
Align escaped newlines in the right-most column.
Definition: Format.h:521
@ ENAS_LeftWithLastLine
Align escaped newlines as far left as possible, using the last line of the preprocessor directive as ...
Definition: Format.h:513
AlignConsecutiveStyle AlignConsecutiveMacros
Style of aligning consecutive macro definitions.
Definition: Format.h:302
std::vector< std::string > StatementMacros
A vector of macros that should be interpreted as complete statements.
Definition: Format.h:5164
SpacesInAnglesStyle
Styles for adding spacing after < and before > in template argument lists.
Definition: Format.h:4884
@ SIAS_Never
Remove spaces after < and before >.
Definition: Format.h:4890
@ SIAS_Always
Add spaces after < and before >.
Definition: Format.h:4896
@ SIAS_Leave
Keep a single space after < and before > if any spaces were present.
Definition: Format.h:4899
SortUsingDeclarationsOptions
Using declaration sorting options.
Definition: Format.h:4435
@ SUD_LexicographicNumeric
Using declarations are sorted in the order defined as follows: Split the strings by :: and discard an...
Definition: Format.h:4471
@ SUD_Lexicographic
Using declarations are sorted in the order defined as follows: Split the strings by :: and discard an...
Definition: Format.h:4456
@ SUD_Never
Using declarations are never sorted.
Definition: Format.h:4444
AlignConsecutiveStyle AlignConsecutiveAssignments
Style of aligning consecutive assignments.
Definition: Format.h:312
friend std::error_code parseConfiguration(llvm::MemoryBufferRef Config, FormatStyle *Style, bool AllowUnknownOptions, llvm::SourceMgr::DiagHandlerTy DiagHandler, void *DiagHandlerCtxt, bool IsDotHFile)
Parse configuration from YAML-formatted text.
Definition: Format.cpp:2136
SpaceInEmptyBracesStyle
This option is deprecated.
Definition: Format.h:4821
@ SIEB_Always
Always insert a space in empty braces.
Definition: Format.h:4829
@ SIEB_Block
Only insert a space in empty blocks.
Definition: Format.h:4837
@ SIEB_Never
Never insert a space in empty braces.
Definition: Format.h:4845
ShortIfStyle AllowShortIfStatementsOnASingleLine
Dependent on the value, if (a) return; can be put on a single line.
Definition: Format.h:950
RemoveParenthesesStyle
Types of redundant parentheses to remove.
Definition: Format.h:4105
@ RPS_Leave
Do not remove parentheses.
Definition: Format.h:4112
@ RPS_ReturnStatement
Also remove parentheses enclosing the expression in a return/co_return statement.
Definition: Format.h:4127
@ RPS_MultipleParentheses
Replace multiple parentheses with single parentheses.
Definition: Format.h:4119
std::vector< std::string > TableGenBreakingDAGArgOperators
Works only when TableGenBreakInsideDAGArg is not DontBreak.
Definition: Format.h:5190
EmptyLineBeforeAccessModifierStyle EmptyLineBeforeAccessModifier
Defines in which cases to put empty line before access modifiers.
Definition: Format.h:2705
EnumTrailingCommaStyle EnumTrailingComma
Insert a comma (if missing) or remove the comma at the end of an enum enumerator list.
Definition: Format.h:2738
bool SpaceBeforeCaseColon
If false, spaces will be removed before case colon.
Definition: Format.h:4560
BreakBeforeNoexceptSpecifierStyle AllowBreakBeforeNoexceptSpecifier
Controls if there could be a line break before a noexcept specifier.
Definition: Format.h:733
bool JavaScriptWrapImports
Whether to wrap JavaScript import/export statements.
Definition: Format.h:3257
bool SkipMacroDefinitionBody
Do not format macro definition body.
Definition: Format.h:4369
unsigned PenaltyBreakAssignment
The penalty for breaking around an assignment operator.
Definition: Format.h:3747
PointerAlignmentStyle
The &, && and * alignment style.
Definition: Format.h:3795
@ PAS_Left
Align pointer to the left.
Definition: Format.h:3800
@ PAS_Middle
Align pointer in the middle.
Definition: Format.h:3810
@ PAS_Right
Align pointer to the right.
Definition: Format.h:3805
unsigned PenaltyBreakString
The penalty for each line break introduced inside a string literal.
Definition: Format.h:3775
RequiresExpressionIndentationKind RequiresExpressionIndentation
The indentation used for requires expression bodies.
Definition: Format.h:4285
bool SpaceAfterTemplateKeyword
If true, a space will be inserted after the template keyword.
Definition: Format.h:4508
unsigned PenaltyIndentedWhitespace
Penalty for each character of whitespace indentation (counted relative to leading non-whitespace colu...
Definition: Format.h:3788
ArrayInitializerAlignmentStyle AlignArrayOfStructures
If not None, when using initialization for an array of structs aligns the fields into columns.
Definition: Format.h:143
NamespaceIndentationKind
Different ways to indent namespace contents.
Definition: Format.h:3511
@ NI_None
Don't indent in namespaces.
Definition: Format.h:3521
@ NI_All
Indent in all namespaces.
Definition: Format.h:3541
@ NI_Inner
Indent only in inner namespaces (nested in other namespaces).
Definition: Format.h:3531
ShortBlockStyle AllowShortBlocksOnASingleLine
Dependent on the value, while (true) { continue; } can be put on a single line.
Definition: Format.h:766
std::string MacroBlockEnd
A regular expression matching macros that end a block.
Definition: Format.h:3449
ShortFunctionStyle AllowShortFunctionsOnASingleLine
Dependent on the value, int f() { return 0; } can be put on a single line.
Definition: Format.h:879
bool AllowAllArgumentsOnNextLine
If a function call or braced initializer list doesn't fit on a line, allow putting all arguments onto...
Definition: Format.h:669
unsigned PenaltyBreakComment
The penalty for each line break introduced inside a comment.
Definition: Format.h:3759
bool SpaceAfterOperatorKeyword
If true, a space will be inserted after the operator keyword.
Definition: Format.h:4500
ReturnTypeBreakingStyle
Different ways to break after the function definition or declaration return type.
Definition: Format.h:1009
@ RTBS_TopLevelDefinitions
Always break after the return type of top-level definitions.
Definition: Format.h:1098
@ RTBS_ExceptShortType
Same as Automatic above, except that there is no break after short return types.
Definition: Format.h:1034
@ RTBS_All
Always break after the return type.
Definition: Format.h:1052
@ RTBS_TopLevel
Always break after the return types of top-level functions.
Definition: Format.h:1067
@ RTBS_None
This is deprecated. See Automatic below.
Definition: Format.h:1011
@ RTBS_Automatic
Break after return type based on PenaltyReturnTypeOnItsOwnLine.
Definition: Format.h:1022
@ RTBS_AllDefinitions
Always break after the return type of function definitions.
Definition: Format.h:1084
ReferenceAlignmentStyle
The & and && alignment style.
Definition: Format.h:3965
@ RAS_Right
Align reference to the right.
Definition: Format.h:3977
@ RAS_Left
Align reference to the left.
Definition: Format.h:3972
@ RAS_Pointer
Align reference like PointerAlignment.
Definition: Format.h:3967
@ RAS_Middle
Align reference in the middle.
Definition: Format.h:3982
EmptyLineAfterAccessModifierStyle EmptyLineAfterAccessModifier
Defines when to put an empty line after access modifiers.
Definition: Format.h:2642
bool IndentAccessModifiers
Specify whether access modifiers should have their own indentation level.
Definition: Format.h:2837
bool InsertNewlineAtEOF
Insert a newline at end of file if missing.
Definition: Format.h:3071
SpaceBeforeParensStyle SpaceBeforeParens
Defines in which cases to put a space before opening parentheses.
Definition: Format.h:4661
bool SpaceBeforeCpp11BracedList
If true, a space will be inserted before a C++11 braced list used to initialize an object (after the ...
Definition: Format.h:4572
UseTabStyle UseTab
The way to use tab characters in the resulting file.
Definition: Format.h:5283
QualifierAlignmentStyle
Different specifiers and qualifiers alignment styles.
Definition: Format.h:3833
@ QAS_Right
Change specifiers/qualifiers to be right-aligned.
Definition: Format.h:3852
@ QAS_Custom
Change specifiers/qualifiers to be aligned based on QualifierOrder.
Definition: Format.h:3864
@ QAS_Left
Change specifiers/qualifiers to be left-aligned.
Definition: Format.h:3846
@ QAS_Leave
Don't change specifiers/qualifiers to either Left or Right alignment (default).
Definition: Format.h:3840
std::vector< std::string > TypenameMacros
A vector of macros that should be interpreted as type declarations instead of as function calls.
Definition: Format.h:5258
OperandAlignmentStyle
Different styles for aligning operands.
Definition: Format.h:529
@ OAS_Align
Horizontally align operands of binary and ternary expressions.
Definition: Format.h:549
@ OAS_AlignAfterOperator
Horizontally align operands of binary and ternary expressions.
Definition: Format.h:559
@ OAS_DontAlign
Do not align operands of binary and ternary expressions.
Definition: Format.h:533
LineEndingStyle LineEnding
Line ending style (\n or \r\n) to use.
Definition: Format.h:3416
bool BreakBeforeTernaryOperators
If true, ternary operators will be placed after line breaks.
Definition: Format.h:2311
unsigned ShortNamespaceLines
The maximal number of unwrapped lines that a short namespace spans.
Definition: Format.h:4365
SortUsingDeclarationsOptions SortUsingDeclarations
Controls if and how clang-format will sort using declarations.
Definition: Format.h:4476
IndentExternBlockStyle IndentExternBlock
IndentExternBlockStyle is the type of indenting of extern blocks.
Definition: Format.h:2932
SeparateDefinitionStyle SeparateDefinitionBlocks
Specifies the use of empty lines to separate definition blocks, including classes,...
Definition: Format.h:4343
tooling::IncludeStyle IncludeStyle
Definition: Format.h:2789
unsigned ColumnLimit
The column limit.
Definition: Format.h:2451
Represents the status of a formatting attempt.
Definition: Format.h:5705
bool FormatComplete
A value of false means that any of the affected ranges were not formatted due to a non-recoverable sy...
Definition: Format.h:5708
unsigned Line
If FormatComplete is false, Line records a one-based original line number at which a syntax error mig...
Definition: Format.h:5713
Style for sorting and grouping C++ #include directives.
Definition: IncludeStyle.h:20
MainIncludeCharDiscriminator MainIncludeChar
When guessing whether a #include is the "main" include, only the include directives that use the spec...
Definition: IncludeStyle.h:168
std::string IncludeIsMainRegex
Specify a regular expression of suffixes that are allowed in the file-to-main-include mapping.
Definition: IncludeStyle.h:132
std::string IncludeIsMainSourceRegex
Specify a regular expression for files being formatted that are allowed to be considered "main" in th...
Definition: IncludeStyle.h:153
IncludeBlocksStyle IncludeBlocks
Dependent on the value, multiple #include blocks can be sorted as one and divided based on category.
Definition: IncludeStyle.h:54
std::vector< IncludeCategory > IncludeCategories
Regular expressions denoting the different #include categories used for ordering #includes.
Definition: IncludeStyle.h:118