clang 24.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
21#include "llvm/ADT/ArrayRef.h"
22#include "llvm/Support/Regex.h"
23#include "llvm/Support/SourceMgr.h"
24#include "llvm/Support/VirtualFileSystemFwd.h"
25#include <optional>
26#include <system_error>
27
28namespace clang {
29namespace format {
30
41class ParseErrorCategory final : public std::error_category {
42public:
43 const char *name() const noexcept override;
44 std::string message(int EV) const override;
45};
46const std::error_category &getParseCategory();
47std::error_code make_error_code(ParseError e);
48
49/// The `FormatStyle` is used to configure the formatting to follow
50/// specific guidelines.
52 // If the BasedOn: was InheritParentConfig and this style needs the file from
53 // the parent directories. It is not part of the actual style for formatting.
54 // Thus the // instead of ///.
55 std::string InheritConfig;
56
57 /// The extra indent or outdent of access modifiers, e.g. `public:`.
58 /// \version 3.3
60
61 /// If `true`, horizontally aligns arguments after an open bracket.
62 ///
63 /// \code
64 /// true: vs. false
65 /// someLongFunction(argument1, someLongFunction(argument1,
66 /// argument2); argument2);
67 /// \endcode
68 ///
69 /// \note
70 /// As of clang-format 22 this option is a bool with the previous
71 /// option of `Align` replaced with `true`, `DontAlign` replaced
72 /// with `false`, and the options of `AlwaysBreak` and `BlockIndent`
73 /// replaced with `true` and with setting of new style options using
74 /// `BreakAfterOpenBracketBracedList`, `BreakAfterOpenBracketFunction`,
75 /// `BreakAfterOpenBracketIf`, `BreakBeforeCloseBracketBracedList`,
76 /// `BreakBeforeCloseBracketFunction`, and `BreakBeforeCloseBracketIf`.
77 /// \endnote
78 ///
79 /// This applies to round brackets (parentheses), angle brackets and square
80 /// brackets.
81 /// \version 3.8
83
84 /// Different style for aligning array initializers.
86 /// Align array column and left justify the columns e.g.:
87 /// \code
88 /// struct test demo[] =
89 /// {
90 /// {56, 23, "hello"},
91 /// {-1, 93463, "world"},
92 /// {7, 5, "!!" }
93 /// };
94 /// \endcode
96 /// Align array column and right justify the columns e.g.:
97 /// \code
98 /// struct test demo[] =
99 /// {
100 /// {56, 23, "hello"},
101 /// {-1, 93463, "world"},
102 /// { 7, 5, "!!"}
103 /// };
104 /// \endcode
106 /// Don't align array initializer columns.
108 };
109 /// If not `None`, when using initialization for an array of structs
110 /// aligns the fields into columns.
111 ///
112 /// \note
113 /// As of clang-format 15 this option only applied to arrays with equal
114 /// number of columns per row.
115 /// \endnote
116 ///
117 /// \version 13
119
120 /// Alignment options.
121 ///
122 /// They can also be read as a whole for compatibility. The choices are:
123 ///
124 /// * `None`
125 /// * `Consecutive`
126 /// * `AcrossEmptyLines`
127 /// * `AcrossComments`
128 /// * `AcrossEmptyLinesAndComments`
129 ///
130 /// For example, to align across empty lines and not across comments, either
131 /// of these work.
132 /// \code
133 /// <option-name>: AcrossEmptyLines
134 ///
135 /// <option-name>:
136 /// Enabled: true
137 /// AcrossEmptyLines: true
138 /// AcrossComments: false
139 /// \endcode
141 /// Whether aligning is enabled.
142 /// \code
143 /// #define SHORT_NAME 42
144 /// #define LONGER_NAME 0x007f
145 /// #define EVEN_LONGER_NAME (2)
146 /// #define foo(x) (x * x)
147 /// #define bar(y, z) (y + z)
148 ///
149 /// int a = 1;
150 /// int somelongname = 2;
151 /// double c = 3;
152 ///
153 /// int aaaa : 1;
154 /// int b : 12;
155 /// int ccc : 8;
156 ///
157 /// int aaaa = 12;
158 /// float b = 23;
159 /// std::string ccc;
160 /// \endcode
162 /// Whether to align across empty lines.
163 /// \code
164 /// true:
165 /// int a = 1;
166 /// int somelongname = 2;
167 /// double c = 3;
168 ///
169 /// int d = 3;
170 ///
171 /// false:
172 /// int a = 1;
173 /// int somelongname = 2;
174 /// double c = 3;
175 ///
176 /// int d = 3;
177 /// \endcode
179 /// Whether to align across comments.
180 /// \code
181 /// true:
182 /// int d = 3;
183 /// /* A comment. */
184 /// double e = 4;
185 ///
186 /// false:
187 /// int d = 3;
188 /// /* A comment. */
189 /// double e = 4;
190 /// \endcode
192 /// Only for `AlignConsecutiveAssignments`. Whether compound assignments
193 /// like `+=` are aligned along with `=`.
194 /// \code
195 /// true:
196 /// a &= 2;
197 /// bbb = 2;
198 ///
199 /// false:
200 /// a &= 2;
201 /// bbb = 2;
202 /// \endcode
204 /// Only for `AlignConsecutiveDeclarations`. Whether function declarations
205 /// are aligned.
206 /// \code
207 /// true:
208 /// unsigned int f1(void);
209 /// void f2(void);
210 /// size_t f3(void);
211 ///
212 /// false:
213 /// unsigned int f1(void);
214 /// void f2(void);
215 /// size_t f3(void);
216 /// \endcode
218 /// Only for `AlignConsecutiveDeclarations`. Whether function pointers are
219 /// aligned.
220 /// \code
221 /// true:
222 /// unsigned i;
223 /// int &r;
224 /// int *p;
225 /// int (*f)();
226 ///
227 /// false:
228 /// unsigned i;
229 /// int &r;
230 /// int *p;
231 /// int (*f)();
232 /// \endcode
234 /// Only for `AlignConsecutiveAssignments`.
235 /// Whether enum assignments are aligned. If `Enabled` is `false`,
236 /// setting this to `true` forces alignment for enum assignments only.
237 /// If `Enabled` is `true`, enum assignments are always aligned.
239 /// Only for `AlignConsecutiveAssignments`. Whether short assignment
240 /// operators are left-padded to the same length as long ones in order to
241 /// put all assignment operators to the right of the left hand side.
242 /// \code
243 /// true:
244 /// a >>= 2;
245 /// bbb = 2;
246 ///
247 /// a = 2;
248 /// bbb >>= 2;
249 ///
250 /// false:
251 /// a >>= 2;
252 /// bbb = 2;
253 ///
254 /// a = 2;
255 /// bbb >>= 2;
256 /// \endcode
258 bool operator==(const AlignConsecutiveStyle &R) const {
259 return Enabled == R.Enabled && AcrossEmptyLines == R.AcrossEmptyLines &&
260 AcrossComments == R.AcrossComments &&
261 AlignCompound == R.AlignCompound &&
262 AlignFunctionDeclarations == R.AlignFunctionDeclarations &&
263 AlignFunctionPointers == R.AlignFunctionPointers &&
264 EnumAssignments == R.EnumAssignments &&
265 PadOperators == R.PadOperators;
266 }
267 bool operator!=(const AlignConsecutiveStyle &R) const {
268 return !(*this == R);
269 }
270 };
271
272 /// Style of aligning consecutive assignments.
273 ///
274 /// `Consecutive` will result in formattings like:
275 /// \code
276 /// int a = 1;
277 /// int somelongname = 2;
278 /// double c = 3;
279 /// \endcode
280 /// \version 3.8
282
283 /// Style of aligning consecutive bit fields.
284 ///
285 /// `Consecutive` will align the bitfield separators of consecutive lines.
286 /// This will result in formattings like:
287 /// \code
288 /// int aaaa : 1;
289 /// int b : 12;
290 /// int ccc : 8;
291 /// \endcode
292 /// \version 11
294
295 /// Style of aligning consecutive declarations.
296 ///
297 /// `Consecutive` will align the declaration names of consecutive lines.
298 /// This will result in formattings like:
299 /// \code
300 /// int aaaa = 12;
301 /// float b = 23;
302 /// std::string ccc;
303 /// \endcode
304 /// \version 3.8
306
307 /// Style of aligning consecutive macro definitions.
308 ///
309 /// `Consecutive` will result in formattings like:
310 /// \code
311 /// #define SHORT_NAME 42
312 /// #define LONGER_NAME 0x007f
313 /// #define EVEN_LONGER_NAME (2)
314 /// #define foo(x) (x * x)
315 /// #define bar(y, z) (y + z)
316 /// \endcode
317 /// \version 9
319
320 /// Alignment options.
321 ///
323 /// Whether aligning is enabled.
324 /// \code
325 /// true:
326 /// switch (level) {
327 /// case log::info: return "info:";
328 /// case log::warning: return "warning:";
329 /// default: return "";
330 /// }
331 ///
332 /// false:
333 /// switch (level) {
334 /// case log::info: return "info:";
335 /// case log::warning: return "warning:";
336 /// default: return "";
337 /// }
338 /// \endcode
340 /// Whether to align across empty lines.
341 /// \code
342 /// true:
343 /// switch (level) {
344 /// case log::info: return "info:";
345 /// case log::warning: return "warning:";
346 ///
347 /// default: return "";
348 /// }
349 ///
350 /// false:
351 /// switch (level) {
352 /// case log::info: return "info:";
353 /// case log::warning: return "warning:";
354 ///
355 /// default: return "";
356 /// }
357 /// \endcode
359 /// Whether to align across comments.
360 /// \code
361 /// true:
362 /// switch (level) {
363 /// case log::info: return "info:";
364 /// case log::warning: return "warning:";
365 /// /* A comment. */
366 /// default: return "";
367 /// }
368 ///
369 /// false:
370 /// switch (level) {
371 /// case log::info: return "info:";
372 /// case log::warning: return "warning:";
373 /// /* A comment. */
374 /// default: return "";
375 /// }
376 /// \endcode
378 /// Whether to align the case arrows when aligning short case expressions.
379 /// \code{.java}
380 /// true:
381 /// i = switch (day) {
382 /// case THURSDAY, SATURDAY -> 8;
383 /// case WEDNESDAY -> 9;
384 /// default -> 0;
385 /// };
386 ///
387 /// false:
388 /// i = switch (day) {
389 /// case THURSDAY, SATURDAY -> 8;
390 /// case WEDNESDAY -> 9;
391 /// default -> 0;
392 /// };
393 /// \endcode
395 /// Whether aligned case labels are aligned on the colon, or on the tokens
396 /// after the colon.
397 /// \code
398 /// true:
399 /// switch (level) {
400 /// case log::info : return "info:";
401 /// case log::warning: return "warning:";
402 /// default : return "";
403 /// }
404 ///
405 /// false:
406 /// switch (level) {
407 /// case log::info: return "info:";
408 /// case log::warning: return "warning:";
409 /// default: return "";
410 /// }
411 /// \endcode
414 return Enabled == R.Enabled && AcrossEmptyLines == R.AcrossEmptyLines &&
415 AcrossComments == R.AcrossComments &&
416 AlignCaseArrows == R.AlignCaseArrows &&
417 AlignCaseColons == R.AlignCaseColons;
418 }
419 };
420
421 /// Style of aligning consecutive short case labels.
422 /// Only applies if `AllowShortCaseExpressionOnASingleLine` or
423 /// `AllowShortCaseLabelsOnASingleLine` is `true`.
424 ///
425 /// \code{.yaml}
426 /// # Example of usage:
427 /// AlignConsecutiveShortCaseStatements:
428 /// Enabled: true
429 /// AcrossEmptyLines: true
430 /// AcrossComments: true
431 /// AlignCaseColons: false
432 /// \endcode
433 /// \version 17
435
436 /// Style of aligning consecutive TableGen DAGArg operator colons.
437 /// If enabled, align the colon inside DAGArg which have line break inside.
438 /// This works only when TableGenBreakInsideDAGArg is BreakElements or
439 /// BreakAll and the DAGArg is not excepted by
440 /// TableGenBreakingDAGArgOperators's effect.
441 /// \code
442 /// let dagarg = (ins
443 /// a :$src1,
444 /// aa :$src2,
445 /// aaa:$src3
446 /// )
447 /// \endcode
448 /// \version 19
450
451 /// Style of aligning consecutive TableGen cond operator colons.
452 /// Align the colons of cases inside !cond operators.
453 /// \code
454 /// !cond(!eq(size, 1) : 1,
455 /// !eq(size, 16): 1,
456 /// true : 0)
457 /// \endcode
458 /// \version 19
460
461 /// Style of aligning consecutive TableGen definition colons.
462 /// This aligns the inheritance colons of consecutive definitions.
463 /// \code
464 /// def Def : Parent {}
465 /// def DefDef : Parent {}
466 /// def DefDefDef : Parent {}
467 /// \endcode
468 /// \version 19
470
471 /// Different styles for aligning escaped newlines.
473 /// Don't align escaped newlines.
474 /// \code
475 /// #define A \
476 /// int aaaa; \
477 /// int b; \
478 /// int dddddddddd;
479 /// \endcode
481 /// Align escaped newlines as far left as possible.
482 /// \code
483 /// #define A \
484 /// int aaaa; \
485 /// int b; \
486 /// int dddddddddd;
487 /// \endcode
489 /// Align escaped newlines as far left as possible, using the last line of
490 /// the preprocessor directive as the reference if it's the longest.
491 /// \code
492 /// #define A \
493 /// int aaaa; \
494 /// int b; \
495 /// int dddddddddd;
496 /// \endcode
498 /// Align escaped newlines in the right-most column.
499 /// \code
500 /// #define A \
501 /// int aaaa; \
502 /// int b; \
503 /// int dddddddddd;
504 /// \endcode
506 };
507
508 /// Options for aligning backslashes in escaped newlines.
509 /// \version 5
511
512 /// Different styles for aligning operands.
514 /// Do not align operands of binary and ternary expressions.
515 /// The wrapped lines are indented `ContinuationIndentWidth` spaces from
516 /// the start of the line.
518 /// Horizontally align operands of binary and ternary expressions.
519 ///
520 /// Specifically, this aligns operands of a single expression that needs
521 /// to be split over multiple lines, e.g.:
522 /// \code
523 /// int aaa = bbbbbbbbbbbbbbb +
524 /// ccccccccccccccc;
525 /// \endcode
526 ///
527 /// When `BreakBeforeBinaryOperators` is set, the wrapped operator is
528 /// aligned with the operand on the first line.
529 /// \code
530 /// int aaa = bbbbbbbbbbbbbbb
531 /// + ccccccccccccccc;
532 /// \endcode
534 /// Horizontally align operands of binary and ternary expressions.
535 ///
536 /// This is similar to `OAS_Align`, except when
537 /// `BreakBeforeBinaryOperators` is set, the operator is un-indented so
538 /// that the wrapped operand is aligned with the operand on the first line.
539 /// \code
540 /// int aaa = bbbbbbbbbbbbbbb
541 /// + ccccccccccccccc;
542 /// \endcode
544 };
545
546 /// If `true`, horizontally align operands of binary and ternary
547 /// expressions.
548 /// \version 3.5
550
551 /// Enums for AlignTrailingComments
553 /// Leave trailing comments as they are.
554 /// \code
555 /// int a; // comment
556 /// int ab; // comment
557 ///
558 /// int abc; // comment
559 /// int abcd; // comment
560 /// \endcode
562 /// Align trailing comments.
563 /// \code
564 /// int a; // comment
565 /// int ab; // comment
566 ///
567 /// int abc; // comment
568 /// int abcd; // comment
569 /// \endcode
571 /// Don't align trailing comments but other formatter applies.
572 /// \code
573 /// int a; // comment
574 /// int ab; // comment
575 ///
576 /// int abc; // comment
577 /// int abcd; // comment
578 /// \endcode
580 };
581
582 /// Alignment options
584 /// Specifies the way to align trailing comments.
586 /// How many empty lines to apply alignment.
587 /// When both `MaxEmptyLinesToKeep` and `OverEmptyLines` are set to 2,
588 /// it formats like below.
589 /// \code
590 /// int a; // all these
591 ///
592 /// int ab; // comments are
593 ///
594 ///
595 /// int abcdef; // aligned
596 /// \endcode
597 ///
598 /// When `MaxEmptyLinesToKeep` is set to 2 and `OverEmptyLines` is set
599 /// to 1, it formats like below.
600 /// \code
601 /// int a; // these are
602 ///
603 /// int ab; // aligned
604 ///
605 ///
606 /// int abcdef; // but this isn't
607 /// \endcode
609 /// If comments following preprocessor directive should be aligned with
610 /// comments that don't.
611 /// \code
612 /// true: false:
613 /// #define A // Comment vs. #define A // Comment
614 /// #define AB // Aligned #define AB // Aligned
615 /// int i; // Aligned int i; // Not aligned
616 /// \endcode
618
620 return Kind == R.Kind && OverEmptyLines == R.OverEmptyLines &&
621 AlignPPAndNotPP == R.AlignPPAndNotPP;
622 }
624 return !(*this == R);
625 }
626 };
627
628 /// Control of trailing comments.
629 ///
630 /// The alignment stops at closing braces after a line break, and only
631 /// followed by other closing braces, a (`do-`) `while`, a lambda call, or
632 /// a semicolon.
633 ///
634 /// \note
635 /// As of clang-format 16 this option is not a bool but can be set
636 /// to the options. Conventional bool options still can be parsed as before.
637 /// \endnote
638 ///
639 /// \code{.yaml}
640 /// # Example of usage:
641 /// AlignTrailingComments:
642 /// Kind: Always
643 /// OverEmptyLines: 2
644 /// \endcode
645 /// \version 3.7
647
648 /// If a function call or braced initializer list doesn't fit on a line, allow
649 /// putting all arguments onto the next line, even if `BinPackArguments` is
650 /// `false`.
651 /// \code
652 /// true:
653 /// callFunction(
654 /// a, b, c, d);
655 ///
656 /// false:
657 /// callFunction(a,
658 /// b,
659 /// c,
660 /// d);
661 /// \endcode
662 /// \version 9
664
665 /// This option is **deprecated**. See `NextLine` of
666 /// `PackConstructorInitializers`.
667 /// \version 9
668 // bool AllowAllConstructorInitializersOnNextLine;
669
670 /// If the function declaration doesn't fit on a line,
671 /// allow putting all parameters of a function declaration onto
672 /// the next line even if `BinPackParameters` is `OnePerLine`.
673 /// \code
674 /// true:
675 /// void myFunction(
676 /// int a, int b, int c, int d, int e);
677 ///
678 /// false:
679 /// void myFunction(int a,
680 /// int b,
681 /// int c,
682 /// int d,
683 /// int e);
684 /// \endcode
685 /// \version 3.3
687
688 /// Different ways to break before a noexcept specifier.
690 /// No line break allowed.
691 /// \code
692 /// void foo(int arg1,
693 /// double arg2) noexcept;
694 ///
695 /// void bar(int arg1, double arg2) noexcept(
696 /// noexcept(baz(arg1)) &&
697 /// noexcept(baz(arg2)));
698 /// \endcode
700 /// For a simple `noexcept` there is no line break allowed, but when we
701 /// have a condition it is.
702 /// \code
703 /// void foo(int arg1,
704 /// double arg2) noexcept;
705 ///
706 /// void bar(int arg1, double arg2)
707 /// noexcept(noexcept(baz(arg1)) &&
708 /// noexcept(baz(arg2)));
709 /// \endcode
711 /// Line breaks are allowed. But note that because of the associated
712 /// penalties `clang-format` often prefers not to break before the
713 /// `noexcept`.
714 /// \code
715 /// void foo(int arg1,
716 /// double arg2) noexcept;
717 ///
718 /// void bar(int arg1, double arg2)
719 /// noexcept(noexcept(baz(arg1)) &&
720 /// noexcept(baz(arg2)));
721 /// \endcode
723 };
724
725 /// Controls if there could be a line break before a `noexcept` specifier.
726 /// \version 18
728
729 /// Allow breaking before `Q_Property` keywords `READ`, `WRITE`, etc. as
730 /// if they were preceded by a comma (`,`). This allows them to be formatted
731 /// according to `BinPackParameters`.
732 /// \version 22
734
735 /// Different styles for merging short blocks containing at most one
736 /// statement.
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 ///
831 /// They can be read as a whole for compatibility. The choices are:
832 ///
833 /// * `None`
834 /// Never merge functions into a single line.
835 ///
836 /// * `InlineOnly`
837 /// Only merge functions defined inside a class. Same as `inline`,
838 /// except it does not imply `empty`: i.e. top level empty functions
839 /// are not merged either. See `Inline` of `ShortFunctionStyle`.
840 /// \code
841 /// class Foo {
842 /// void f() { foo(); }
843 /// };
844 /// void f() {
845 /// foo();
846 /// }
847 /// void f() {
848 /// }
849 /// \endcode
850 ///
851 /// * `Empty`
852 /// Only merge empty functions. See `Empty` of `ShortFunctionStyle`.
853 /// \code
854 /// void f() {}
855 /// void f2() {
856 /// bar2();
857 /// }
858 /// \endcode
859 ///
860 /// * `Inline`
861 /// Only merge functions defined inside a class. Implies `empty`. See
862 /// `Inline` and `Empty` of `ShortFunctionStyle`.
863 /// \code
864 /// class Foo {
865 /// void f() { foo(); }
866 /// };
867 /// void f() {
868 /// foo();
869 /// }
870 /// void f() {}
871 /// \endcode
872 ///
873 /// * `All`
874 /// Merge all functions fitting on a single line.
875 /// \code
876 /// class Foo {
877 /// void f() { foo(); }
878 /// };
879 /// void f() { bar(); }
880 /// \endcode
881 ///
882 /// Also can be specified as a nested configuration flag:
883 /// \code{.yaml}
884 /// # Example of usage:
885 /// AllowShortFunctionsOnASingleLine: InlineOnly
886 ///
887 /// # or more granular control:
888 /// AllowShortFunctionsOnASingleLine:
889 /// Empty: false
890 /// Inline: true
891 /// Other: false
892 /// \endcode
894 /// Merge top-level empty functions.
895 /// \code
896 /// void f() {}
897 /// void f2() {
898 /// bar2();
899 /// }
900 /// void f3() { /* comment */ }
901 /// \endcode
902 bool Empty;
903 /// Merge functions defined inside a class.
904 /// \code
905 /// class Foo {
906 /// void f() { foo(); }
907 /// void g() {}
908 /// };
909 /// void f() {
910 /// foo();
911 /// }
912 /// void f() {
913 /// }
914 /// \endcode
915 bool Inline;
916 /// Merge all functions fitting on a single line. Please note that this
917 /// control does not include Empty
918 /// \code
919 /// class Foo {
920 /// void f() { foo(); }
921 /// };
922 /// void f() { bar(); }
923 /// \endcode
924 bool Other;
925
926 bool operator==(const ShortFunctionStyle &R) const {
927 return Empty == R.Empty && Inline == R.Inline && Other == R.Other;
928 }
929 bool operator!=(const ShortFunctionStyle &R) const { return !(*this == R); }
933 bool isAll() const { return Empty && Inline && Other; }
935 return ShortFunctionStyle(true, false, false);
936 }
938 return ShortFunctionStyle(true, true, false);
939 }
941 return ShortFunctionStyle(false, true, false);
942 }
944 return ShortFunctionStyle(true, true, true);
945 }
946 };
947
948 /// Dependent on the value, `int f() { return 0; }` can be put on a
949 /// single line.
950 /// \version 3.5
952
953 /// Different styles for handling short if statements.
955 /// Never put short ifs on the same line.
956 /// \code
957 /// if (a)
958 /// return;
959 ///
960 /// if (b)
961 /// return;
962 /// else
963 /// return;
964 ///
965 /// if (c)
966 /// return;
967 /// else {
968 /// return;
969 /// }
970 /// \endcode
972 /// Put short ifs on the same line only if there is no else statement.
973 /// \code
974 /// if (a) return;
975 ///
976 /// if (b)
977 /// return;
978 /// else
979 /// return;
980 ///
981 /// if (c)
982 /// return;
983 /// else {
984 /// return;
985 /// }
986 /// \endcode
988 /// Put short ifs, but not else ifs nor else statements, on the same line.
989 /// \code
990 /// if (a) return;
991 ///
992 /// if (b) return;
993 /// else if (b)
994 /// return;
995 /// else
996 /// return;
997 ///
998 /// if (c) return;
999 /// else {
1000 /// return;
1001 /// }
1002 /// \endcode
1004 /// Always put short ifs, else ifs and else statements on the same
1005 /// line.
1006 /// \code
1007 /// if (a) return;
1008 ///
1009 /// if (b) return;
1010 /// else return;
1011 ///
1012 /// if (c) return;
1013 /// else {
1014 /// return;
1015 /// }
1016 /// \endcode
1018 };
1019
1020 /// Dependent on the value, `if (a) return;` can be put on a single line.
1021 /// \version 3.3
1023
1024 /// Different styles for merging short lambdas containing at most one
1025 /// statement.
1027 /// Never merge lambdas into a single line.
1029 /// Only merge empty lambdas.
1030 /// \code
1031 /// auto lambda = [](int a) {};
1032 /// auto lambda2 = [](int a) {
1033 /// return a;
1034 /// };
1035 /// \endcode
1037 /// Merge lambda into a single line if the lambda is argument of a function.
1038 /// \code
1039 /// auto lambda = [](int x, int y) {
1040 /// return x < y;
1041 /// };
1042 /// sort(a.begin(), a.end(), [](int x, int y) { return x < y; });
1043 /// \endcode
1045 /// Merge all lambdas fitting on a single line.
1046 /// \code
1047 /// auto lambda = [](int a) {};
1048 /// auto lambda2 = [](int a) { return a; };
1049 /// \endcode
1051 };
1052
1053 /// Dependent on the value, `auto lambda []() { return 0; }` can be put on a
1054 /// single line.
1055 /// \version 9
1057
1058 /// If `true`, `while (true) continue;` can be put on a single
1059 /// line.
1060 /// \version 3.7
1062
1063 /// If `true`, `namespace a { class b; }` can be put on a single line.
1064 /// \version 20
1066
1067 /// Different styles for merging short records (`class`,`struct`, and
1068 /// `union`).
1070 /// Never merge records into a single line.
1072 /// Only merge empty records if the opening brace was not wrapped,
1073 /// i.e. the corresponding `BraceWrapping.After...` option was not set.
1075 /// Only merge empty records.
1076 /// \code
1077 /// struct foo {};
1078 /// struct bar
1079 /// {
1080 /// int i;
1081 /// };
1082 /// \endcode
1084 /// Merge all records that fit on a single line.
1085 /// \code
1086 /// struct foo {};
1087 /// struct bar { int i; };
1088 /// \endcode
1090 };
1091
1092 /// Dependent on the value, `struct bar { int i; };` can be put on a single
1093 /// line.
1094 /// \version 23
1096
1097 /// Different ways to break after the function definition return type.
1098 /// This option is **deprecated** and is retained for backwards compatibility.
1100 /// Break after return type automatically.
1101 /// `PenaltyReturnTypeOnItsOwnLine` is taken into account.
1103 /// Always break after the return type.
1105 /// Always break after the return types of top-level functions.
1107 };
1108
1109 /// Different ways to break after the function definition or
1110 /// declaration return type.
1112 /// This is **deprecated**. See `Automatic` below.
1114 /// Break after return type based on `PenaltyReturnTypeOnItsOwnLine`.
1115 /// \code
1116 /// class A {
1117 /// int f() { return 0; };
1118 /// };
1119 /// int f();
1120 /// int f() { return 1; }
1121 /// int
1122 /// LongName::AnotherLongName();
1123 /// \endcode
1125 /// Same as `Automatic` above, except that there is no break after short
1126 /// return types.
1127 /// \code
1128 /// class A {
1129 /// int f() { return 0; };
1130 /// };
1131 /// int f();
1132 /// int f() { return 1; }
1133 /// int LongName::
1134 /// AnotherLongName();
1135 /// \endcode
1137 /// Always break after the return type.
1138 /// \code
1139 /// class A {
1140 /// int
1141 /// f() {
1142 /// return 0;
1143 /// };
1144 /// };
1145 /// int
1146 /// f();
1147 /// int
1148 /// f() {
1149 /// return 1;
1150 /// }
1151 /// int
1152 /// LongName::AnotherLongName();
1153 /// \endcode
1155 /// Always break after the return types of top-level functions.
1156 /// \code
1157 /// class A {
1158 /// int f() { return 0; };
1159 /// };
1160 /// int
1161 /// f();
1162 /// int
1163 /// f() {
1164 /// return 1;
1165 /// }
1166 /// int
1167 /// LongName::AnotherLongName();
1168 /// \endcode
1170 /// Always break after the return type of function definitions.
1171 /// \code
1172 /// class A {
1173 /// int
1174 /// f() {
1175 /// return 0;
1176 /// };
1177 /// };
1178 /// int f();
1179 /// int
1180 /// f() {
1181 /// return 1;
1182 /// }
1183 /// int
1184 /// LongName::AnotherLongName();
1185 /// \endcode
1187 /// Always break after the return type of top-level definitions.
1188 /// \code
1189 /// class A {
1190 /// int f() { return 0; };
1191 /// };
1192 /// int f();
1193 /// int
1194 /// f() {
1195 /// return 1;
1196 /// }
1197 /// int
1198 /// LongName::AnotherLongName();
1199 /// \endcode
1201 };
1202
1203 /// The function definition return type breaking style to use. This
1204 /// option is **deprecated** and is retained for backwards compatibility.
1205 /// \version 3.7
1207
1208 /// This option is renamed to `BreakAfterReturnType`.
1209 /// \version 3.8
1210 /// @deprecated
1211 // ReturnTypeBreakingStyle AlwaysBreakAfterReturnType;
1212
1213 /// If `true`, always break before multiline string literals.
1214 ///
1215 /// This flag is mean to make cases where there are multiple multiline strings
1216 /// in a file look more consistent. Thus, it will only take effect if wrapping
1217 /// the string at that point leads to it being indented
1218 /// `ContinuationIndentWidth` spaces from the start of the line.
1219 /// \code
1220 /// true: false:
1221 /// aaaa = vs. aaaa = "bbbb"
1222 /// "bbbb" "cccc";
1223 /// "cccc";
1224 /// \endcode
1225 /// \version 3.4
1227
1228 /// Different ways to break after the template declaration.
1230 /// Do not change the line breaking before the declaration.
1231 /// \code
1232 /// template <typename T>
1233 /// T foo() {
1234 /// }
1235 /// template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa,
1236 /// int bbbbbbbbbbbbbbbbbbbbb) {
1237 /// }
1238 /// \endcode
1240 /// Do not force break before declaration.
1241 /// `PenaltyBreakTemplateDeclaration` is taken into account.
1242 /// \code
1243 /// template <typename T> T foo() {
1244 /// }
1245 /// template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa,
1246 /// int bbbbbbbbbbbbbbbbbbbbb) {
1247 /// }
1248 /// \endcode
1250 /// Force break after template declaration only when the following
1251 /// declaration spans multiple lines.
1252 /// \code
1253 /// template <typename T> T foo() {
1254 /// }
1255 /// template <typename T>
1256 /// T foo(int aaaaaaaaaaaaaaaaaaaaa,
1257 /// int bbbbbbbbbbbbbbbbbbbbb) {
1258 /// }
1259 /// \endcode
1261 /// Always break after template declaration.
1262 /// \code
1263 /// template <typename T>
1264 /// T foo() {
1265 /// }
1266 /// template <typename T>
1267 /// T foo(int aaaaaaaaaaaaaaaaaaaaa,
1268 /// int bbbbbbbbbbbbbbbbbbbbb) {
1269 /// }
1270 /// \endcode
1272 };
1273
1274 /// This option is renamed to `BreakTemplateDeclarations`.
1275 /// \version 3.4
1276 /// @deprecated
1277 // BreakTemplateDeclarationsStyle AlwaysBreakTemplateDeclarations;
1278
1279 /// A vector of strings that should be interpreted as attributes/qualifiers
1280 /// instead of identifiers. This can be useful for language extensions or
1281 /// static analyzer annotations.
1282 ///
1283 /// For example:
1284 /// \code
1285 /// x = (char *__capability)&y;
1286 /// int function(void) __unused;
1287 /// void only_writes_to_buffer(char *__output buffer);
1288 /// \endcode
1289 ///
1290 /// In the .clang-format configuration file, this can be configured like:
1291 /// \code{.yaml}
1292 /// AttributeMacros: [__capability, __output, __unused]
1293 /// \endcode
1294 ///
1295 /// \version 12
1296 std::vector<std::string> AttributeMacros;
1297
1298 /// This option is **deprecated**. See `BinPack` of `PackArguments`.
1299 /// \version 3.7
1300 // bool BinPackArguments;
1301
1302 /// If `BinPackLongBracedList` is `true` it overrides
1303 /// `BinPackArguments` if there are 20 or more items in a braced
1304 /// initializer list.
1305 /// \code
1306 /// BinPackLongBracedList: false vs. BinPackLongBracedList: true
1307 /// vector<int> x{ vector<int> x{1, 2, ...,
1308 /// 20, 21};
1309 /// 1,
1310 /// 2,
1311 /// ...,
1312 /// 20,
1313 /// 21};
1314 /// \endcode
1315 /// \version 21
1317
1318 /// This option is **deprecated**. See `BinPack` of `PackParameters`.
1319 /// \version 3.7
1320 // BinPackParametersStyle BinPackParameters;
1321
1322 /// Styles for adding spacing around `:` in bitfield definitions.
1324 /// Add one space on each side of the `:`
1325 /// \code
1326 /// unsigned bf : 2;
1327 /// \endcode
1329 /// Add no space around the `:` (except when needed for
1330 /// `AlignConsecutiveBitFields`).
1331 /// \code
1332 /// unsigned bf:2;
1333 /// \endcode
1335 /// Add space before the `:` only
1336 /// \code
1337 /// unsigned bf :2;
1338 /// \endcode
1340 /// Add space after the `:` only (space may be added before if
1341 /// needed for `AlignConsecutiveBitFields`).
1342 /// \code
1343 /// unsigned bf: 2;
1344 /// \endcode
1346 };
1347 /// The BitFieldColonSpacingStyle to use for bitfields.
1348 /// \version 12
1350
1351 /// The number of columns to use to indent the contents of braced init lists.
1352 /// If unset or negative, `ContinuationIndentWidth` is used.
1353 /// \code
1354 /// AlignAfterOpenBracket: AlwaysBreak
1355 /// BracedInitializerIndentWidth: 2
1356 ///
1357 /// void f() {
1358 /// SomeClass c{
1359 /// "foo",
1360 /// "bar",
1361 /// "baz",
1362 /// };
1363 /// auto s = SomeStruct{
1364 /// .foo = "foo",
1365 /// .bar = "bar",
1366 /// .baz = "baz",
1367 /// };
1368 /// SomeArrayT a[3] = {
1369 /// {
1370 /// foo,
1371 /// bar,
1372 /// },
1373 /// {
1374 /// foo,
1375 /// bar,
1376 /// },
1377 /// SomeArrayT{},
1378 /// };
1379 /// }
1380 /// \endcode
1381 /// \version 17
1383
1384 /// Different ways to wrap braces after control statements.
1386 /// Never wrap braces after a control statement.
1387 /// \code
1388 /// if (foo()) {
1389 /// } else {
1390 /// }
1391 /// for (int i = 0; i < 10; ++i) {
1392 /// }
1393 /// \endcode
1395 /// Only wrap braces after a multi-line control statement.
1396 /// \code
1397 /// if (foo && bar &&
1398 /// baz)
1399 /// {
1400 /// quux();
1401 /// }
1402 /// while (foo || bar) {
1403 /// }
1404 /// \endcode
1406 /// Always wrap braces after a control statement.
1407 /// \code
1408 /// if (foo())
1409 /// {
1410 /// } else
1411 /// {}
1412 /// for (int i = 0; i < 10; ++i)
1413 /// {}
1414 /// \endcode
1416 };
1417
1418 /// Precise control over the wrapping of braces.
1419 /// \code{.yaml}
1420 /// # Should be declared this way:
1421 /// BreakBeforeBraces: Custom
1422 /// BraceWrapping:
1423 /// AfterClass: true
1424 /// \endcode
1426 /// Wrap case labels.
1427 /// \code
1428 /// false: true:
1429 /// switch (foo) { vs. switch (foo) {
1430 /// case 1: { case 1:
1431 /// bar(); {
1432 /// break; bar();
1433 /// } break;
1434 /// default: { }
1435 /// plop(); default:
1436 /// } {
1437 /// } plop();
1438 /// }
1439 /// }
1440 /// \endcode
1442 /// Wrap class definitions.
1443 /// \code
1444 /// true:
1445 /// class foo
1446 /// {};
1447 ///
1448 /// false:
1449 /// class foo {};
1450 /// \endcode
1452
1453 /// Wrap control statements (`if`/`for`/`while`/`switch`/..).
1455 /// Wrap enum definitions.
1456 /// \code
1457 /// true:
1458 /// enum X : int
1459 /// {
1460 /// B
1461 /// };
1462 ///
1463 /// false:
1464 /// enum X : int { B };
1465 /// \endcode
1467 /// Wrap function definitions.
1468 /// \code
1469 /// true:
1470 /// void foo()
1471 /// {
1472 /// bar();
1473 /// bar2();
1474 /// }
1475 ///
1476 /// false:
1477 /// void foo() {
1478 /// bar();
1479 /// bar2();
1480 /// }
1481 /// \endcode
1483 /// Wrap namespace definitions.
1484 /// \code
1485 /// true:
1486 /// namespace
1487 /// {
1488 /// int foo();
1489 /// int bar();
1490 /// }
1491 ///
1492 /// false:
1493 /// namespace {
1494 /// int foo();
1495 /// int bar();
1496 /// }
1497 /// \endcode
1499 /// Wrap ObjC definitions (interfaces, implementations...).
1500 /// \note
1501 /// @autoreleasepool and @synchronized blocks are wrapped
1502 /// according to `AfterControlStatement` flag.
1503 /// \endnote
1505 /// Wrap requires expression body.
1506 /// \code
1507 /// true:
1508 /// template <typename T>
1509 /// concept C = requires(T t)
1510 /// {
1511 /// foo(t);
1512 /// };
1513 ///
1514 /// false:
1515 /// template <typename T>
1516 /// concept C = requires(T t) {
1517 /// foo(t);
1518 /// };
1519 /// \endcode
1521 /// Wrap struct definitions.
1522 /// \code
1523 /// true:
1524 /// struct foo
1525 /// {
1526 /// int x;
1527 /// };
1528 ///
1529 /// false:
1530 /// struct foo {
1531 /// int x;
1532 /// };
1533 /// \endcode
1535 /// Wrap union definitions.
1536 /// \code
1537 /// true:
1538 /// union foo
1539 /// {
1540 /// int x;
1541 /// }
1542 ///
1543 /// false:
1544 /// union foo {
1545 /// int x;
1546 /// }
1547 /// \endcode
1549 /// Wrap export blocks.
1550 /// \code
1551 /// true: false:
1552 /// export vs. export {
1553 /// { int foo();
1554 /// int foo(); }
1555 /// }
1556 /// \endcode
1558 /// Wrap extern blocks.
1559 /// \code
1560 /// true:
1561 /// extern "C"
1562 /// {
1563 /// int foo();
1564 /// }
1565 ///
1566 /// false:
1567 /// extern "C" {
1568 /// int foo();
1569 /// }
1570 /// \endcode
1571 bool AfterExternBlock; // Partially superseded by IndentExternBlock
1572 /// Wrap before `catch`.
1573 /// \code
1574 /// true:
1575 /// try {
1576 /// foo();
1577 /// }
1578 /// catch () {
1579 /// }
1580 ///
1581 /// false:
1582 /// try {
1583 /// foo();
1584 /// } catch () {
1585 /// }
1586 /// \endcode
1588 /// Wrap before `else`.
1589 /// \code
1590 /// true:
1591 /// if (foo()) {
1592 /// }
1593 /// else {
1594 /// }
1595 ///
1596 /// false:
1597 /// if (foo()) {
1598 /// } else {
1599 /// }
1600 /// \endcode
1602 /// Wrap lambda block.
1603 /// \code
1604 /// true:
1605 /// connect(
1606 /// []()
1607 /// {
1608 /// foo();
1609 /// bar();
1610 /// });
1611 ///
1612 /// false:
1613 /// connect([]() {
1614 /// foo();
1615 /// bar();
1616 /// });
1617 /// \endcode
1619 /// Wrap before `while`.
1620 /// \code
1621 /// true:
1622 /// do {
1623 /// foo();
1624 /// }
1625 /// while (1);
1626 ///
1627 /// false:
1628 /// do {
1629 /// foo();
1630 /// } while (1);
1631 /// \endcode
1633 /// Indent the wrapped braces themselves.
1635 /// If `false`, empty function body can be put on a single line.
1636 /// This option is used only if the opening brace of the function has
1637 /// already been wrapped, i.e. the `AfterFunction` brace wrapping mode is
1638 /// set, and the function could/should not be put on a single line (as per
1639 /// `AllowShortFunctionsOnASingleLine` and constructor formatting
1640 /// options).
1641 /// \code
1642 /// false: true:
1643 /// int f() vs. int f()
1644 /// {} {
1645 /// }
1646 /// \endcode
1647 ///
1649 /// If `false`, empty record (e.g. class, struct or union) body
1650 /// can be put on a single line. This option is used only if the opening
1651 /// brace of the record has already been wrapped, i.e. the `AfterClass`
1652 /// (for classes) brace wrapping mode is set.
1653 /// \code
1654 /// false: true:
1655 /// class Foo vs. class Foo
1656 /// {} {
1657 /// }
1658 /// \endcode
1659 ///
1661 /// If `false`, empty namespace body can be put on a single line.
1662 /// This option is used only if the opening brace of the namespace has
1663 /// already been wrapped, i.e. the `AfterNamespace` brace wrapping mode is
1664 /// set.
1665 /// \code
1666 /// false: true:
1667 /// namespace Foo vs. namespace Foo
1668 /// {} {
1669 /// }
1670 /// \endcode
1671 ///
1673 };
1674
1675 /// Control of individual brace wrapping cases.
1676 ///
1677 /// If `BreakBeforeBraces` is set to `Custom`, use this to specify how
1678 /// each individual brace case should be handled. Otherwise, this is ignored.
1679 /// \code{.yaml}
1680 /// # Example of usage:
1681 /// BreakBeforeBraces: Custom
1682 /// BraceWrapping:
1683 /// AfterEnum: true
1684 /// AfterStruct: false
1685 /// SplitEmptyFunction: false
1686 /// \endcode
1687 /// \version 3.8
1689
1690 /// Break between adjacent string literals.
1691 /// \code
1692 /// true:
1693 /// return "Code"
1694 /// "\0\52\26\55\55\0"
1695 /// "x013"
1696 /// "\02\xBA";
1697 /// false:
1698 /// return "Code" "\0\52\26\55\55\0" "x013" "\02\xBA";
1699 /// \endcode
1700 /// \version 18
1702
1703 /// Different ways to break after the last attribute of a group before a
1704 /// declaration or control statement.
1706 /// Always break after the last attribute of the group.
1707 /// \code
1708 /// [[maybe_unused]]
1709 /// const int i;
1710 /// [[gnu::const]] [[maybe_unused]]
1711 /// int j;
1712 ///
1713 /// [[nodiscard]]
1714 /// inline int f();
1715 /// [[gnu::const]] [[nodiscard]]
1716 /// int g();
1717 ///
1718 /// [[likely]]
1719 /// if (a)
1720 /// f();
1721 /// else
1722 /// g();
1723 ///
1724 /// switch (b) {
1725 /// [[unlikely]]
1726 /// case 1:
1727 /// ++b;
1728 /// break;
1729 /// [[likely]]
1730 /// default:
1731 /// return;
1732 /// }
1733 /// \endcode
1735 /// Leave the line breaking after the last attribute of the group as is.
1736 /// \code
1737 /// [[maybe_unused]] const int i;
1738 /// [[gnu::const]] [[maybe_unused]]
1739 /// int j;
1740 ///
1741 /// [[nodiscard]] inline int f();
1742 /// [[gnu::const]] [[nodiscard]]
1743 /// int g();
1744 ///
1745 /// [[likely]] if (a)
1746 /// f();
1747 /// else
1748 /// g();
1749 ///
1750 /// switch (b) {
1751 /// [[unlikely]] case 1:
1752 /// ++b;
1753 /// break;
1754 /// [[likely]]
1755 /// default:
1756 /// return;
1757 /// }
1758 /// \endcode
1760 /// Same as `Leave` except that it applies to all attributes of the group.
1761 /// \code
1762 /// [[deprecated("Don't use this version")]]
1763 /// [[nodiscard]]
1764 /// bool foo() {
1765 /// return true;
1766 /// }
1767 ///
1768 /// [[deprecated("Don't use this version")]]
1769 /// [[nodiscard]] bool bar() {
1770 /// return true;
1771 /// }
1772 /// \endcode
1774 /// Never break after the last attribute of the group.
1775 /// \code
1776 /// [[maybe_unused]] const int i;
1777 /// [[gnu::const]] [[maybe_unused]] int j;
1778 ///
1779 /// [[nodiscard]] inline int f();
1780 /// [[gnu::const]] [[nodiscard]] int g();
1781 ///
1782 /// [[likely]] if (a)
1783 /// f();
1784 /// else
1785 /// g();
1786 ///
1787 /// switch (b) {
1788 /// [[unlikely]] case 1:
1789 /// ++b;
1790 /// break;
1791 /// [[likely]] default:
1792 /// return;
1793 /// }
1794 /// \endcode
1796 };
1797
1798 /// Break after a group of C++11 attributes before variable or function
1799 /// (including constructor/destructor) declaration/definition names or before
1800 /// control statements, i.e. `if`, `switch` (including `case` and
1801 /// `default` labels), `for`, and `while` statements.
1802 /// \version 16
1804
1805 /// Force break after the left bracket of a braced initializer list (when
1806 /// `Cpp11BracedListStyle` is `true`) when the list exceeds the column
1807 /// limit.
1808 /// \code
1809 /// true: false:
1810 /// vector<int> x { vs. vector<int> x {1,
1811 /// 1, 2, 3} 2, 3}
1812 /// \endcode
1813 /// \version 22
1815
1816 /// Force break after the left parenthesis of a function (declaration,
1817 /// definition, call) when the parameters exceed the column limit.
1818 /// \code
1819 /// true: false:
1820 /// foo ( vs. foo (a,
1821 /// a , b) b)
1822 /// \endcode
1823 /// \version 22
1825
1826 /// Force break after the left parenthesis of an if control statement
1827 /// when the expression exceeds the column limit.
1828 /// \code
1829 /// true: false:
1830 /// if constexpr ( vs. if constexpr (a ||
1831 /// a || b) b)
1832 /// \endcode
1833 /// \version 22
1835
1836 /// Force break after the left parenthesis of a loop control statement
1837 /// when the expression exceeds the column limit.
1838 /// \code
1839 /// true: false:
1840 /// while ( vs. while (a &&
1841 /// a && b) { b) {
1842 /// \endcode
1843 /// \version 22
1845
1846 /// Force break after the left parenthesis of a switch control statement
1847 /// when the expression exceeds the column limit.
1848 /// \code
1849 /// true: false:
1850 /// switch ( vs. switch (a +
1851 /// a + b) { b) {
1852 /// \endcode
1853 /// \version 22
1855
1856 /// The function declaration return type breaking style to use.
1857 /// \version 19
1859
1860 /// If `true`, clang-format will always break after a Json array `[`
1861 /// otherwise it will scan until the closing `]` to determine if it should
1862 /// add newlines between elements (prettier compatible).
1863 ///
1864 /// \note
1865 /// This is currently only for formatting JSON.
1866 /// \endnote
1867 /// \code
1868 /// true: false:
1869 /// [ vs. [1, 2, 3, 4]
1870 /// 1,
1871 /// 2,
1872 /// 3,
1873 /// 4
1874 /// ]
1875 /// \endcode
1876 /// \version 16
1878
1879 /// The style of wrapping parameters on the same line (bin-packed) or
1880 /// on one line each.
1882 /// Automatically determine parameter bin-packing behavior.
1884 /// Always bin-pack parameters.
1886 /// Never bin-pack parameters.
1888 };
1889
1890 /// The style of breaking before or after binary operators.
1892 /// Break after operators.
1893 /// \code
1894 /// LooooooooooongType loooooooooooooooooooooongVariable =
1895 /// someLooooooooooooooooongFunction();
1896 ///
1897 /// bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
1898 /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ==
1899 /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
1900 /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa >
1901 /// ccccccccccccccccccccccccccccccccccccccccc;
1902 /// \endcode
1904 /// Break before operators that aren't assignments.
1905 /// \code
1906 /// LooooooooooongType loooooooooooooooooooooongVariable =
1907 /// someLooooooooooooooooongFunction();
1908 ///
1909 /// bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1910 /// + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1911 /// == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1912 /// && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1913 /// > ccccccccccccccccccccccccccccccccccccccccc;
1914 /// \endcode
1916 /// Break before operators.
1917 /// \code
1918 /// LooooooooooongType loooooooooooooooooooooongVariable
1919 /// = someLooooooooooooooooongFunction();
1920 ///
1921 /// bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1922 /// + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1923 /// == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1924 /// && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1925 /// > ccccccccccccccccccccccccccccccccccccccccc;
1926 /// \endcode
1928 };
1929
1930 /// The way to wrap binary operators.
1931 /// \version 3.6
1933
1934 /// Different ways to attach braces to their surrounding context.
1936 /// Always attach braces to surrounding context.
1937 /// \code
1938 /// namespace N {
1939 /// enum E {
1940 /// E1,
1941 /// E2,
1942 /// };
1943 ///
1944 /// class C {
1945 /// public:
1946 /// C();
1947 /// };
1948 ///
1949 /// bool baz(int i) {
1950 /// try {
1951 /// do {
1952 /// switch (i) {
1953 /// case 1: {
1954 /// foobar();
1955 /// break;
1956 /// }
1957 /// default: {
1958 /// break;
1959 /// }
1960 /// }
1961 /// } while (--i);
1962 /// return true;
1963 /// } catch (...) {
1964 /// handleError();
1965 /// return false;
1966 /// }
1967 /// }
1968 ///
1969 /// void foo(bool b) {
1970 /// if (b) {
1971 /// baz(2);
1972 /// } else {
1973 /// baz(5);
1974 /// }
1975 /// }
1976 ///
1977 /// void bar() { foo(true); }
1978 /// } // namespace N
1979 /// \endcode
1981 /// Like `Attach`, but break before braces on function, namespace and
1982 /// class definitions.
1983 /// \code
1984 /// namespace N
1985 /// {
1986 /// enum E {
1987 /// E1,
1988 /// E2,
1989 /// };
1990 ///
1991 /// class C
1992 /// {
1993 /// public:
1994 /// C();
1995 /// };
1996 ///
1997 /// bool baz(int i)
1998 /// {
1999 /// try {
2000 /// do {
2001 /// switch (i) {
2002 /// case 1: {
2003 /// foobar();
2004 /// break;
2005 /// }
2006 /// default: {
2007 /// break;
2008 /// }
2009 /// }
2010 /// } while (--i);
2011 /// return true;
2012 /// } catch (...) {
2013 /// handleError();
2014 /// return false;
2015 /// }
2016 /// }
2017 ///
2018 /// void foo(bool b)
2019 /// {
2020 /// if (b) {
2021 /// baz(2);
2022 /// } else {
2023 /// baz(5);
2024 /// }
2025 /// }
2026 ///
2027 /// void bar() { foo(true); }
2028 /// } // namespace N
2029 /// \endcode
2031 /// Like `Attach`, but break before braces on enum, function, and record
2032 /// definitions.
2033 /// \code
2034 /// namespace N {
2035 /// enum E
2036 /// {
2037 /// E1,
2038 /// E2,
2039 /// };
2040 ///
2041 /// class C
2042 /// {
2043 /// public:
2044 /// C();
2045 /// };
2046 ///
2047 /// bool baz(int i)
2048 /// {
2049 /// try {
2050 /// do {
2051 /// switch (i) {
2052 /// case 1: {
2053 /// foobar();
2054 /// break;
2055 /// }
2056 /// default: {
2057 /// break;
2058 /// }
2059 /// }
2060 /// } while (--i);
2061 /// return true;
2062 /// } catch (...) {
2063 /// handleError();
2064 /// return false;
2065 /// }
2066 /// }
2067 ///
2068 /// void foo(bool b)
2069 /// {
2070 /// if (b) {
2071 /// baz(2);
2072 /// } else {
2073 /// baz(5);
2074 /// }
2075 /// }
2076 ///
2077 /// void bar() { foo(true); }
2078 /// } // namespace N
2079 /// \endcode
2081 /// Like `Attach`, but break before function definitions, `catch`, and
2082 /// `else`.
2083 /// \code
2084 /// namespace N {
2085 /// enum E {
2086 /// E1,
2087 /// E2,
2088 /// };
2089 ///
2090 /// class C {
2091 /// public:
2092 /// C();
2093 /// };
2094 ///
2095 /// bool baz(int i)
2096 /// {
2097 /// try {
2098 /// do {
2099 /// switch (i) {
2100 /// case 1: {
2101 /// foobar();
2102 /// break;
2103 /// }
2104 /// default: {
2105 /// break;
2106 /// }
2107 /// }
2108 /// } while (--i);
2109 /// return true;
2110 /// }
2111 /// catch (...) {
2112 /// handleError();
2113 /// return false;
2114 /// }
2115 /// }
2116 ///
2117 /// void foo(bool b)
2118 /// {
2119 /// if (b) {
2120 /// baz(2);
2121 /// }
2122 /// else {
2123 /// baz(5);
2124 /// }
2125 /// }
2126 ///
2127 /// void bar() { foo(true); }
2128 /// } // namespace N
2129 /// \endcode
2131 /// Always break before braces.
2132 /// \code
2133 /// namespace N
2134 /// {
2135 /// enum E
2136 /// {
2137 /// E1,
2138 /// E2,
2139 /// };
2140 ///
2141 /// class C
2142 /// {
2143 /// public:
2144 /// C();
2145 /// };
2146 ///
2147 /// bool baz(int i)
2148 /// {
2149 /// try
2150 /// {
2151 /// do
2152 /// {
2153 /// switch (i)
2154 /// {
2155 /// case 1:
2156 /// {
2157 /// foobar();
2158 /// break;
2159 /// }
2160 /// default:
2161 /// {
2162 /// break;
2163 /// }
2164 /// }
2165 /// } while (--i);
2166 /// return true;
2167 /// }
2168 /// catch (...)
2169 /// {
2170 /// handleError();
2171 /// return false;
2172 /// }
2173 /// }
2174 ///
2175 /// void foo(bool b)
2176 /// {
2177 /// if (b)
2178 /// {
2179 /// baz(2);
2180 /// }
2181 /// else
2182 /// {
2183 /// baz(5);
2184 /// }
2185 /// }
2186 ///
2187 /// void bar() { foo(true); }
2188 /// } // namespace N
2189 /// \endcode
2191 /// Like `Allman` but always indent braces and line up code with braces.
2192 /// \code
2193 /// namespace N
2194 /// {
2195 /// enum E
2196 /// {
2197 /// E1,
2198 /// E2,
2199 /// };
2200 ///
2201 /// class C
2202 /// {
2203 /// public:
2204 /// C();
2205 /// };
2206 ///
2207 /// bool baz(int i)
2208 /// {
2209 /// try
2210 /// {
2211 /// do
2212 /// {
2213 /// switch (i)
2214 /// {
2215 /// case 1:
2216 /// {
2217 /// foobar();
2218 /// break;
2219 /// }
2220 /// default:
2221 /// {
2222 /// break;
2223 /// }
2224 /// }
2225 /// } while (--i);
2226 /// return true;
2227 /// }
2228 /// catch (...)
2229 /// {
2230 /// handleError();
2231 /// return false;
2232 /// }
2233 /// }
2234 ///
2235 /// void foo(bool b)
2236 /// {
2237 /// if (b)
2238 /// {
2239 /// baz(2);
2240 /// }
2241 /// else
2242 /// {
2243 /// baz(5);
2244 /// }
2245 /// }
2246 ///
2247 /// void bar() { foo(true); }
2248 /// } // namespace N
2249 /// \endcode
2251 /// Always break before braces and add an extra level of indentation to
2252 /// braces of control statements, not to those of class, function
2253 /// or other definitions.
2254 /// \code
2255 /// namespace N
2256 /// {
2257 /// enum E
2258 /// {
2259 /// E1,
2260 /// E2,
2261 /// };
2262 ///
2263 /// class C
2264 /// {
2265 /// public:
2266 /// C();
2267 /// };
2268 ///
2269 /// bool baz(int i)
2270 /// {
2271 /// try
2272 /// {
2273 /// do
2274 /// {
2275 /// switch (i)
2276 /// {
2277 /// case 1:
2278 /// {
2279 /// foobar();
2280 /// break;
2281 /// }
2282 /// default:
2283 /// {
2284 /// break;
2285 /// }
2286 /// }
2287 /// }
2288 /// while (--i);
2289 /// return true;
2290 /// }
2291 /// catch (...)
2292 /// {
2293 /// handleError();
2294 /// return false;
2295 /// }
2296 /// }
2297 ///
2298 /// void foo(bool b)
2299 /// {
2300 /// if (b)
2301 /// {
2302 /// baz(2);
2303 /// }
2304 /// else
2305 /// {
2306 /// baz(5);
2307 /// }
2308 /// }
2309 ///
2310 /// void bar() { foo(true); }
2311 /// } // namespace N
2312 /// \endcode
2314 /// Like `Attach`, but break before functions.
2315 /// \code
2316 /// namespace N {
2317 /// enum E {
2318 /// E1,
2319 /// E2,
2320 /// };
2321 ///
2322 /// class C {
2323 /// public:
2324 /// C();
2325 /// };
2326 ///
2327 /// bool baz(int i)
2328 /// {
2329 /// try {
2330 /// do {
2331 /// switch (i) {
2332 /// case 1: {
2333 /// foobar();
2334 /// break;
2335 /// }
2336 /// default: {
2337 /// break;
2338 /// }
2339 /// }
2340 /// } while (--i);
2341 /// return true;
2342 /// } catch (...) {
2343 /// handleError();
2344 /// return false;
2345 /// }
2346 /// }
2347 ///
2348 /// void foo(bool b)
2349 /// {
2350 /// if (b) {
2351 /// baz(2);
2352 /// } else {
2353 /// baz(5);
2354 /// }
2355 /// }
2356 ///
2357 /// void bar() { foo(true); }
2358 /// } // namespace N
2359 /// \endcode
2361 /// Configure each individual brace in `BraceWrapping`.
2363 };
2364
2365 /// The brace breaking style to use.
2366 /// \version 3.7
2368
2369 /// Force break before the right bracket of a braced initializer list (when
2370 /// `Cpp11BracedListStyle` is `true`) when the list exceeds the column
2371 /// limit. The break before the right bracket is only made if there is a
2372 /// break after the opening bracket.
2373 /// \code
2374 /// true: false:
2375 /// vector<int> x { vs. vector<int> x {
2376 /// 1, 2, 3 1, 2, 3}
2377 /// }
2378 /// \endcode
2379 /// \version 22
2381
2382 /// Force break before the right parenthesis of a function (declaration,
2383 /// definition, call) when the parameters exceed the column limit.
2384 /// \code
2385 /// true: false:
2386 /// foo ( vs. foo (
2387 /// a , b a , b)
2388 /// )
2389 /// \endcode
2390 /// \version 22
2392
2393 /// Force break before the right parenthesis of an if control statement
2394 /// when the expression exceeds the column limit. The break before the
2395 /// closing parenthesis is only made if there is a break after the opening
2396 /// parenthesis.
2397 /// \code
2398 /// true: false:
2399 /// if constexpr ( vs. if constexpr (
2400 /// a || b a || b )
2401 /// )
2402 /// \endcode
2403 /// \version 22
2405
2406 /// Force break before the right parenthesis of a loop control statement
2407 /// when the expression exceeds the column limit. The break before the
2408 /// closing parenthesis is only made if there is a break after the opening
2409 /// parenthesis.
2410 /// \code
2411 /// true: false:
2412 /// while ( vs. while (
2413 /// a && b a && b) {
2414 /// ) {
2415 /// \endcode
2416 /// \version 22
2418
2419 /// Force break before the right parenthesis of a switch control statement
2420 /// when the expression exceeds the column limit. The break before the
2421 /// closing parenthesis is only made if there is a break after the opening
2422 /// parenthesis.
2423 /// \code
2424 /// true: false:
2425 /// switch ( vs. switch (
2426 /// a + b a + b) {
2427 /// ) {
2428 /// \endcode
2429 /// \version 22
2431
2432 /// Different ways to break before concept declarations.
2434 /// Keep the template declaration line together with `concept`.
2435 /// \code
2436 /// template <typename T> concept C = ...;
2437 /// \endcode
2439 /// Breaking between template declaration and `concept` is allowed. The
2440 /// actual behavior depends on the content and line breaking rules and
2441 /// penalties.
2443 /// Always break before `concept`, putting it in the line after the
2444 /// template declaration.
2445 /// \code
2446 /// template <typename T>
2447 /// concept C = ...;
2448 /// \endcode
2450 };
2451
2452 /// The concept declaration style to use.
2453 /// \version 12
2455
2456 /// Different ways to break ASM parameters.
2458 /// No break before inline ASM colon.
2459 /// \code
2460 /// asm volatile("string", : : val);
2461 /// \endcode
2463 /// Break before inline ASM colon if the line length is longer than column
2464 /// limit.
2465 /// \code
2466 /// asm volatile("string", : : val);
2467 /// asm("cmoveq %1, %2, %[result]"
2468 /// : [result] "=r"(result)
2469 /// : "r"(test), "r"(new), "[result]"(old));
2470 /// \endcode
2472 /// Always break before inline ASM colon.
2473 /// \code
2474 /// asm volatile("string",
2475 /// :
2476 /// : val);
2477 /// \endcode
2479 };
2480
2481 /// The inline ASM colon style to use.
2482 /// \version 16
2484
2485 /// Different ways to break before the function return type.
2487 /// Do not force a break before the return type.
2489 /// Always break before the return type.
2490 /// \code
2491 /// static inline
2492 /// void f();
2493 /// \endcode
2495 /// Break before the return type of top-level functions only.
2497 /// Break before the return type of function definitions only.
2499 /// Break before the return type of top-level definitions only.
2501 };
2502
2503 /// The function declaration/definition return type breaking style to use.
2504 /// Trailing return types (`auto f() -> T`) are not affected. To have
2505 /// identifier macros (e.g. `__always_inline`) treated as specifiers,
2506 /// add them to `AttributeMacros`.
2507 /// \version 23
2509
2510 /// If `true`, break before a template closing bracket (`>`) when there is
2511 /// a line break after the matching opening bracket (`<`).
2512 /// \code
2513 /// true:
2514 /// template <typename Foo, typename Bar>
2515 ///
2516 /// template <typename Foo,
2517 /// typename Bar>
2518 ///
2519 /// template <
2520 /// typename Foo,
2521 /// typename Bar
2522 /// >
2523 ///
2524 /// false:
2525 /// template <typename Foo, typename Bar>
2526 ///
2527 /// template <typename Foo,
2528 /// typename Bar>
2529 ///
2530 /// template <
2531 /// typename Foo,
2532 /// typename Bar>
2533 /// \endcode
2534 /// \version 21
2536
2537 /// If `true`, ternary operators will be placed after line breaks.
2538 /// \code
2539 /// true:
2540 /// veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription
2541 /// ? firstValue
2542 /// : SecondValueVeryVeryVeryVeryLong;
2543 ///
2544 /// false:
2545 /// veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ?
2546 /// firstValue :
2547 /// SecondValueVeryVeryVeryVeryLong;
2548 /// \endcode
2549 /// \version 3.7
2551
2552 /// Different ways to break binary operations.
2554 /// Don't break binary operations
2555 /// \code
2556 /// aaa + bbbb * ccccc - ddddd +
2557 /// eeeeeeeeeeeeeeee;
2558 /// \endcode
2560
2561 /// Binary operations will either be all on the same line, or each operation
2562 /// will have one line each.
2563 /// \code
2564 /// aaa +
2565 /// bbbb *
2566 /// ccccc -
2567 /// ddddd +
2568 /// eeeeeeeeeeeeeeee;
2569 /// \endcode
2571
2572 /// Binary operations of a particular precedence that exceed the column
2573 /// limit will have one line each.
2574 /// \code
2575 /// aaa +
2576 /// bbbb * ccccc -
2577 /// ddddd +
2578 /// eeeeeeeeeeeeeeee;
2579 /// \endcode
2581 };
2582
2583 /// A rule that specifies how to break a specific set of binary operators.
2584 /// \version 23
2586 /// The list of operators this rule applies to, e.g. `&&`, `||`, `|`.
2587 /// Alternative spellings (e.g. `and` for `&&`) are accepted.
2588 std::vector<tok::TokenKind> Operators;
2589 /// The break style for these operators (defaults to `OnePerLine`).
2591 /// Minimum number of operands in a chain before the rule triggers.
2592 /// For example, `a && b && c` is a chain of length 3.
2593 /// `0` means always break (when the line is too long).
2596 return Operators == R.Operators && Style == R.Style &&
2597 MinChainLength == R.MinChainLength;
2598 }
2600 return !(*this == R);
2601 }
2602 };
2603
2604 /// Options for `BreakBinaryOperations`.
2605 ///
2606 /// If specified as a simple string (e.g. `OnePerLine`), it behaves like
2607 /// the original enum and applies to all binary operators.
2608 ///
2609 /// If specified as a struct, allows per-operator configuration:
2610 /// \code{.yaml}
2611 /// BreakBinaryOperations:
2612 /// Default: Never
2613 /// PerOperator:
2614 /// - Operators: ['&&', '||']
2615 /// Style: OnePerLine
2616 /// MinChainLength: 3
2617 /// \endcode
2618 /// \version 23
2620 /// The default break style for operators not covered by `PerOperator`.
2622 /// Per-operator override rules.
2623 std::vector<BinaryOperationBreakRule> PerOperator;
2626 for (const auto &Rule : PerOperator) {
2627 if (llvm::find(Rule.Operators, Kind) != Rule.Operators.end())
2628 return &Rule;
2629 // clang-format splits ">>" into two ">" tokens for template parsing.
2630 // Match ">" against ">>" rules so that per-operator rules for ">>"
2631 // (stream extraction / right shift) work correctly.
2632 if (Kind == tok::greater &&
2633 llvm::find(Rule.Operators, tok::greatergreater) !=
2634 Rule.Operators.end()) {
2635 return &Rule;
2636 }
2637 }
2638 return nullptr;
2639 }
2641 if (const auto *Rule = findRuleForOperator(Kind))
2642 return Rule->Style;
2643 return Default;
2644 }
2646 if (const auto *Rule = findRuleForOperator(Kind))
2647 return Rule->MinChainLength;
2648 return 0;
2649 }
2651 return Default == R.Default && PerOperator == R.PerOperator;
2652 }
2654 return !(*this == R);
2655 }
2656 };
2657
2658 /// The break binary operations style to use.
2659 /// \version 20
2661
2662 /// Different ways to break initializers.
2664 /// Break constructor initializers before the colon and after the commas.
2665 /// \code
2666 /// Constructor()
2667 /// : initializer1(),
2668 /// initializer2()
2669 /// \endcode
2671 /// Break constructor initializers before the colon and commas, and align
2672 /// the commas with the colon.
2673 /// \code
2674 /// Constructor()
2675 /// : initializer1()
2676 /// , initializer2()
2677 /// \endcode
2679 /// Break constructor initializers after the colon and commas.
2680 /// \code
2681 /// Constructor() :
2682 /// initializer1(),
2683 /// initializer2()
2684 /// \endcode
2686 /// Break constructor initializers only after the commas.
2687 /// \code
2688 /// Constructor() : initializer1(),
2689 /// initializer2()
2690 /// \endcode
2692 };
2693
2694 /// The break constructor initializers style to use.
2695 /// \version 5
2697
2698 /// If `true`, clang-format will always break before function declaration
2699 /// parameters.
2700 /// \code
2701 /// true:
2702 /// void functionDeclaration(
2703 /// int A, int B);
2704 ///
2705 /// false:
2706 /// void functionDeclaration(int A, int B);
2707 ///
2708 /// \endcode
2709 /// \version 23
2711
2712 /// If `true`, clang-format will always break before function definition
2713 /// parameters.
2714 /// \code
2715 /// true:
2716 /// void functionDefinition(
2717 /// int A, int B) {}
2718 ///
2719 /// false:
2720 /// void functionDefinition(int A, int B) {}
2721 ///
2722 /// \endcode
2723 /// \version 19
2725
2726 /// Break after each annotation on a field in Java files.
2727 /// \code{.java}
2728 /// true: false:
2729 /// @Partial vs. @Partial @Mock DataLoad loader;
2730 /// @Mock
2731 /// DataLoad loader;
2732 /// \endcode
2733 /// \version 3.8
2735
2736 /// Allow breaking string literals when formatting.
2737 ///
2738 /// In C, C++, and Objective-C:
2739 /// \code
2740 /// true:
2741 /// const char* x = "veryVeryVeryVeryVeryVe"
2742 /// "ryVeryVeryVeryVeryVery"
2743 /// "VeryLongString";
2744 ///
2745 /// false:
2746 /// const char* x =
2747 /// "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
2748 /// \endcode
2749 ///
2750 /// In C# and Java:
2751 /// \code
2752 /// true:
2753 /// string x = "veryVeryVeryVeryVeryVe" +
2754 /// "ryVeryVeryVeryVeryVery" +
2755 /// "VeryLongString";
2756 ///
2757 /// false:
2758 /// string x =
2759 /// "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
2760 /// \endcode
2761 ///
2762 /// C# interpolated strings are not broken.
2763 ///
2764 /// In Verilog:
2765 /// \code
2766 /// true:
2767 /// string x = {"veryVeryVeryVeryVeryVe",
2768 /// "ryVeryVeryVeryVeryVery",
2769 /// "VeryLongString"};
2770 ///
2771 /// false:
2772 /// string x =
2773 /// "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
2774 /// \endcode
2775 ///
2776 /// \version 3.9
2778
2779 /// The column limit.
2780 ///
2781 /// A column limit of `0` means that there is no column limit. In this case,
2782 /// clang-format will respect the input's line breaking decisions within
2783 /// statements unless they contradict other rules.
2784 /// \version 3.7
2785 unsigned ColumnLimit;
2786
2787 /// A regular expression that describes comments with special meaning,
2788 /// which should not be split into lines or otherwise changed.
2789 /// \code
2790 /// // CommentPragmas: '^ FOOBAR pragma:'
2791 /// // Will leave the following line unaffected
2792 /// #include <vector> // FOOBAR pragma: keep
2793 /// \endcode
2794 /// \version 3.7
2795 std::string CommentPragmas;
2796
2797 /// Different ways to break inheritance list.
2799 /// Break inheritance list before the colon and after the commas.
2800 /// \code
2801 /// class Foo
2802 /// : Base1,
2803 /// Base2
2804 /// {};
2805 /// \endcode
2807 /// Break inheritance list before the colon and commas, and align
2808 /// the commas with the colon.
2809 /// \code
2810 /// class Foo
2811 /// : Base1
2812 /// , Base2
2813 /// {};
2814 /// \endcode
2816 /// Break inheritance list after the colon and commas.
2817 /// \code
2818 /// class Foo :
2819 /// Base1,
2820 /// Base2
2821 /// {};
2822 /// \endcode
2824 /// Break inheritance list only after the commas.
2825 /// \code
2826 /// class Foo : Base1,
2827 /// Base2
2828 /// {};
2829 /// \endcode
2831 };
2832
2833 /// The inheritance list style to use.
2834 /// \version 7
2836
2837 /// The template declaration breaking style to use.
2838 /// \version 19
2840
2841 /// Keep the break keyword and the following case label on the same line.
2842 ///
2843 /// \code
2844 /// false: true:
2845 /// switch (n) { vs. switch (n) {
2846 /// case 1: case 1:
2847 /// foo(); foo();
2848 /// break; break; case 2:
2849 /// case 2: bar();
2850 /// bar(); }
2851 /// }
2852 /// \endcode
2853 /// \version 24
2855
2856 /// If `true`, consecutive namespace declarations will be on the same
2857 /// line. If `false`, each namespace is declared on a new line.
2858 /// \code
2859 /// true:
2860 /// namespace Foo { namespace Bar {
2861 /// }}
2862 ///
2863 /// false:
2864 /// namespace Foo {
2865 /// namespace Bar {
2866 /// }
2867 /// }
2868 /// \endcode
2869 ///
2870 /// If it does not fit on a single line, the overflowing namespaces get
2871 /// wrapped:
2872 /// \code
2873 /// namespace Foo { namespace Bar {
2874 /// namespace Extra {
2875 /// }}}
2876 /// \endcode
2877 /// \version 5
2879
2880 /// This option is **deprecated**. See `CurrentLine` of
2881 /// `PackConstructorInitializers`.
2882 /// \version 3.7
2883 // bool ConstructorInitializerAllOnOneLineOrOnePerLine;
2884
2885 /// The number of characters to use for indentation of constructor
2886 /// initializer lists as well as inheritance lists.
2887 /// \version 3.7
2889
2890 /// Indent width for line continuations.
2891 /// \code
2892 /// ContinuationIndentWidth: 2
2893 ///
2894 /// int i = // VeryVeryVeryVeryVeryLongComment
2895 /// longFunction( // Again a long comment
2896 /// arg);
2897 /// \endcode
2898 /// \version 3.7
2900
2901 /// Different ways to handle braced lists.
2903 /// Best suited for pre C++11 braced lists.
2904 ///
2905 /// * Spaces inside the braced list.
2906 /// * Line break before the closing brace.
2907 /// * Indentation with the block indent.
2908 ///
2909 /// \code
2910 /// vector<int> x{ 1, 2, 3, 4 };
2911 /// vector<T> x{ {}, {}, {}, {} };
2912 /// f(MyMap[{ composite, key }]);
2913 /// new int[3]{ 1, 2, 3 };
2914 /// Type name{ // Comment
2915 /// value
2916 /// };
2917 /// \endcode
2919 /// Best suited for C++11 braced lists.
2920 ///
2921 /// * No spaces inside the braced list.
2922 /// * No line break before the closing brace.
2923 /// * Indentation with the continuation indent.
2924 ///
2925 /// Fundamentally, C++11 braced lists are formatted exactly like function
2926 /// calls would be formatted in their place. If the braced list follows a
2927 /// name (e.g. a type or variable name), clang-format formats as if the
2928 /// `{}` were the parentheses of a function call with that name. If there
2929 /// is no name, a zero-length name is assumed.
2930 /// \code
2931 /// vector<int> x{1, 2, 3, 4};
2932 /// vector<T> x{{}, {}, {}, {}};
2933 /// f(MyMap[{composite, key}]);
2934 /// new int[3]{1, 2, 3};
2935 /// Type name{ // Comment
2936 /// value};
2937 /// \endcode
2939 /// Same as `FunctionCall`, except for the handling of a comment at the
2940 /// begin, it then aligns everything following with the comment.
2941 ///
2942 /// * No spaces inside the braced list. (Even for a comment at the first
2943 /// position.)
2944 /// * No line break before the closing brace.
2945 /// * Indentation with the continuation indent, except when followed by a
2946 /// line comment, then it uses the block indent.
2947 ///
2948 /// \code
2949 /// vector<int> x{1, 2, 3, 4};
2950 /// vector<T> x{{}, {}, {}, {}};
2951 /// f(MyMap[{composite, key}]);
2952 /// new int[3]{1, 2, 3};
2953 /// Type name{// Comment
2954 /// value};
2955 /// \endcode
2957 };
2958
2959 /// The style to handle braced lists.
2960 /// \version 3.4
2962
2963 /// This option is **deprecated**. See `DeriveLF` and `DeriveCRLF` of
2964 /// `LineEnding`.
2965 /// \version 10
2966 // bool DeriveLineEnding;
2967
2968 /// If `true`, analyze the formatted file for the most common
2969 /// alignment of `&` and `*`.
2970 /// Pointer and reference alignment styles are going to be updated according
2971 /// to the preferences found in the file.
2972 /// `PointerAlignment` is then used only as fallback.
2973 /// \version 3.7
2975
2976 /// Disables formatting completely.
2977 /// \version 3.7
2979
2980 /// Different styles for empty line after access modifiers.
2981 /// `EmptyLineBeforeAccessModifier` configuration handles the number of
2982 /// empty lines between two access modifiers.
2984 /// Remove all empty lines after access modifiers.
2985 /// \code
2986 /// struct foo {
2987 /// private:
2988 /// int i;
2989 /// protected:
2990 /// int j;
2991 /// /* comment */
2992 /// public:
2993 /// foo() {}
2994 /// private:
2995 /// protected:
2996 /// };
2997 /// \endcode
2999 /// Keep existing empty lines after access modifiers.
3000 /// MaxEmptyLinesToKeep is applied instead.
3002 /// Always add empty line after access modifiers if there are none.
3003 /// MaxEmptyLinesToKeep is applied also.
3004 /// \code
3005 /// struct foo {
3006 /// private:
3007 ///
3008 /// int i;
3009 /// protected:
3010 ///
3011 /// int j;
3012 /// /* comment */
3013 /// public:
3014 ///
3015 /// foo() {}
3016 /// private:
3017 ///
3018 /// protected:
3019 ///
3020 /// };
3021 /// \endcode
3023 };
3024
3025 /// Defines when to put an empty line after access modifiers.
3026 /// `EmptyLineBeforeAccessModifier` configuration handles the number of
3027 /// empty lines between two access modifiers.
3028 /// \version 13
3030
3031 /// Different styles for empty line before access modifiers.
3033 /// Remove all empty lines before access modifiers.
3034 /// \code
3035 /// struct foo {
3036 /// private:
3037 /// int i;
3038 /// protected:
3039 /// int j;
3040 /// /* comment */
3041 /// public:
3042 /// foo() {}
3043 /// private:
3044 /// protected:
3045 /// };
3046 /// \endcode
3048 /// Keep existing empty lines before access modifiers.
3050 /// Add empty line only when access modifier starts a new logical block.
3051 /// Logical block is a group of one or more member fields or functions.
3052 /// \code
3053 /// struct foo {
3054 /// private:
3055 /// int i;
3056 ///
3057 /// protected:
3058 /// int j;
3059 /// /* comment */
3060 /// public:
3061 /// foo() {}
3062 ///
3063 /// private:
3064 /// protected:
3065 /// };
3066 /// \endcode
3068 /// Always add empty line before access modifiers unless access modifier
3069 /// is at the start of struct or class definition.
3070 /// \code
3071 /// struct foo {
3072 /// private:
3073 /// int i;
3074 ///
3075 /// protected:
3076 /// int j;
3077 /// /* comment */
3078 ///
3079 /// public:
3080 /// foo() {}
3081 ///
3082 /// private:
3083 ///
3084 /// protected:
3085 /// };
3086 /// \endcode
3088 };
3089
3090 /// Defines in which cases to put empty line before access modifiers.
3091 /// \version 12
3093
3094 /// Styles for `enum` trailing commas.
3096 /// Don't insert or remove trailing commas.
3097 /// \code
3098 /// enum { a, b, c, };
3099 /// enum Color { red, green, blue };
3100 /// \endcode
3102 /// Insert trailing commas.
3103 /// \code
3104 /// enum { a, b, c, };
3105 /// enum Color { red, green, blue, };
3106 /// \endcode
3108 /// Remove trailing commas.
3109 /// \code
3110 /// enum { a, b, c };
3111 /// enum Color { red, green, blue };
3112 /// \endcode
3114 };
3115
3116 /// Insert a comma (if missing) or remove the comma at the end of an `enum`
3117 /// enumerator list.
3118 /// \warning
3119 /// Setting this option to any value other than `Leave` could lead to
3120 /// incorrect code formatting due to clang-format's lack of complete semantic
3121 /// information. As such, extra care should be taken to review code changes
3122 /// made by this option.
3123 /// \endwarning
3124 /// \version 21
3126
3127 /// If `true`, clang-format detects whether function calls and
3128 /// definitions are formatted with one parameter per line.
3129 ///
3130 /// Each call can be bin-packed, one-per-line or inconclusive. If it is
3131 /// inconclusive, e.g. completely on one line, but a decision needs to be
3132 /// made, clang-format analyzes whether there are other bin-packed cases in
3133 /// the input file and act accordingly.
3134 ///
3135 /// \note
3136 /// This is an experimental flag, that might go away or be renamed. Do
3137 /// not use this in config files, etc. Use at your own risk.
3138 /// \endnote
3139 /// \version 3.7
3141
3142 /// If `true`, clang-format adds missing namespace end comments for
3143 /// namespaces and fixes invalid existing ones. This doesn't affect short
3144 /// namespaces, which are controlled by `ShortNamespaceLines`.
3145 /// \code
3146 /// true: false:
3147 /// namespace longNamespace { vs. namespace longNamespace {
3148 /// void foo(); void foo();
3149 /// void bar(); void bar();
3150 /// } // namespace a }
3151 /// namespace shortNamespace { namespace shortNamespace {
3152 /// void baz(); void baz();
3153 /// } }
3154 /// \endcode
3155 /// \version 5
3157
3158 /// A vector of macros that should be interpreted as foreach loops
3159 /// instead of as function calls.
3160 ///
3161 /// These are expected to be macros of the form:
3162 /// \code
3163 /// FOREACH(<variable-declaration>, ...)
3164 /// <loop-body>
3165 /// \endcode
3166 ///
3167 /// In the .clang-format configuration file, this can be configured like:
3168 /// \code{.yaml}
3169 /// ForEachMacros: [RANGES_FOR, FOREACH]
3170 /// \endcode
3171 ///
3172 /// For example: BOOST_FOREACH.
3173 /// \version 3.7
3174 std::vector<std::string> ForEachMacros;
3175
3177
3178 /// A vector of macros that should be interpreted as conditionals
3179 /// instead of as function calls.
3180 ///
3181 /// These are expected to be macros of the form:
3182 /// \code
3183 /// IF(...)
3184 /// <conditional-body>
3185 /// else IF(...)
3186 /// <conditional-body>
3187 /// \endcode
3188 ///
3189 /// In the .clang-format configuration file, this can be configured like:
3190 /// \code{.yaml}
3191 /// IfMacros: [IF]
3192 /// \endcode
3193 ///
3194 /// For example:
3195 /// [KJ_IF_MAYBE](https://github.com/capnproto/capnproto/blob/master/kjdoc/tour.md#maybes)
3196 /// \version 13
3197 std::vector<std::string> IfMacros;
3198
3199 /// Modes for indenting access modifiers and record members.
3201 /// Use `AccessModifierOffset` for access modifiers and indent members one
3202 /// level below the record.
3203 /// \code
3204 /// struct S {
3205 /// int before;
3206 ///
3207 /// public:
3208 /// int after;
3209 /// };
3210 /// \endcode
3212 /// Give access modifiers their own indentation level and indent all
3213 /// members two levels below the record. Value of the `AccessModifierOffset`
3214 /// is ignored.
3215 /// \code
3216 /// struct S {
3217 /// int before;
3218 ///
3219 /// public:
3220 /// int after;
3221 /// };
3222 /// \endcode
3224 /// In C, C++, and Objective-C, indent members one level until the first
3225 /// explicit access modifier, then two levels. Other languages use the
3226 /// `Always` behavior. Value of the `AccessModifierOffset` is ignored.
3227 /// \code
3228 /// struct S {
3229 /// int before;
3230 ///
3231 /// public:
3232 /// int after;
3233 /// };
3234 /// \endcode
3236 };
3237
3238 /// Specify how access modifiers and record members are indented.
3239 /// \version 13
3241
3242 /// Indent case label blocks one level from the case label.
3243 ///
3244 /// When `false`, the block following the case label uses the same
3245 /// indentation level as for the case label, treating the case label the same
3246 /// as an if-statement.
3247 /// When `true`, the block gets indented as a scope block.
3248 /// \code
3249 /// false: true:
3250 /// switch (fool) { vs. switch (fool) {
3251 /// case 1: { case 1:
3252 /// bar(); {
3253 /// } break; bar();
3254 /// default: { }
3255 /// plop(); break;
3256 /// } default:
3257 /// } {
3258 /// plop();
3259 /// }
3260 /// }
3261 /// \endcode
3262 /// \version 11
3264
3265 /// Indent case labels one level from the switch statement.
3266 ///
3267 /// When `false`, use the same indentation level as for the switch
3268 /// statement. Switch statement body is always indented one level more than
3269 /// case labels (except the first block following the case label, which
3270 /// itself indents the code - unless IndentCaseBlocks is enabled).
3271 /// \code
3272 /// false: true:
3273 /// switch (fool) { vs. switch (fool) {
3274 /// case 1: case 1:
3275 /// bar(); bar();
3276 /// break; break;
3277 /// default: default:
3278 /// plop(); plop();
3279 /// } }
3280 /// \endcode
3281 /// \version 3.3
3283
3284 /// If `true`, clang-format will indent the body of an `export { ... }`
3285 /// block. This doesn't affect the formatting of anything else related to
3286 /// exported declarations.
3287 /// \code
3288 /// true: false:
3289 /// export { vs. export {
3290 /// void foo(); void foo();
3291 /// void bar(); void bar();
3292 /// } }
3293 /// \endcode
3294 /// \version 20
3296
3297 /// Indents extern blocks
3299 /// Backwards compatible with AfterExternBlock's indenting.
3300 /// \code
3301 /// IndentExternBlock: AfterExternBlock
3302 /// BraceWrapping.AfterExternBlock: true
3303 /// extern "C"
3304 /// {
3305 /// void foo();
3306 /// }
3307 /// \endcode
3308 ///
3309 /// \code
3310 /// IndentExternBlock: AfterExternBlock
3311 /// BraceWrapping.AfterExternBlock: false
3312 /// extern "C" {
3313 /// void foo();
3314 /// }
3315 /// \endcode
3317 /// Does not indent extern blocks.
3318 /// \code
3319 /// extern "C" {
3320 /// void foo();
3321 /// }
3322 /// \endcode
3324 /// Indents extern blocks.
3325 /// \code
3326 /// extern "C" {
3327 /// void foo();
3328 /// }
3329 /// \endcode
3331 };
3332
3333 /// IndentExternBlockStyle is the type of indenting of extern blocks.
3334 /// \version 11
3336
3337 /// Options for indenting goto labels.
3339 /// Do not indent goto labels.
3340 /// \code
3341 /// int f() {
3342 /// if (foo()) {
3343 /// label1:
3344 /// bar();
3345 /// }
3346 /// label2:
3347 /// return 1;
3348 /// }
3349 /// \endcode
3351 /// Indent goto labels to the enclosing block (previous indenting level).
3352 /// \code
3353 /// int f() {
3354 /// if (foo()) {
3355 /// label1:
3356 /// bar();
3357 /// }
3358 /// label2:
3359 /// return 1;
3360 /// }
3361 /// \endcode
3363 /// Indent goto labels to the surrounding statements (current indenting
3364 /// level).
3365 /// \code
3366 /// int f() {
3367 /// if (foo()) {
3368 /// label1:
3369 /// bar();
3370 /// }
3371 /// label2:
3372 /// return 1;
3373 /// }
3374 /// \endcode
3376 /// Indent goto labels to half the indentation of the surrounding code.
3377 /// If the indentation width is an odd number, it will round up.
3378 /// \code
3379 /// int f() {
3380 /// if (foo()) {
3381 /// label1:
3382 /// bar();
3383 /// }
3384 /// label2:
3385 /// return 1;
3386 /// }
3387 /// \endcode
3389 };
3390
3391 /// The goto label indenting style to use.
3392 /// \version 10
3394
3395 /// Options for indenting preprocessor directives.
3397 /// Does not indent any directives.
3398 /// \code
3399 /// #if FOO
3400 /// #if BAR
3401 /// #include <foo>
3402 /// #endif
3403 /// #endif
3404 /// \endcode
3406 /// Indents directives after the hash.
3407 /// \code
3408 /// #if FOO
3409 /// # if BAR
3410 /// # include <foo>
3411 /// # endif
3412 /// #endif
3413 /// \endcode
3415 /// Indents directives before the hash.
3416 /// \code
3417 /// #if FOO
3418 /// #if BAR
3419 /// #include <foo>
3420 /// #endif
3421 /// #endif
3422 /// \endcode
3424 /// Leaves indentation of directives as-is.
3425 /// \note
3426 /// Ignores `PPIndentWidth`.
3427 /// \endnote
3428 /// \code
3429 /// #if FOO
3430 /// #if BAR
3431 /// #include <foo>
3432 /// #endif
3433 /// #endif
3434 /// \endcode
3436 };
3437
3438 /// The preprocessor directive indenting style to use.
3439 /// \version 6
3441
3442 /// Indent the requires clause in a template. This only applies when
3443 /// `RequiresClausePosition` is `OwnLine`, `OwnLineWithBrace`,
3444 /// or `WithFollowing`.
3445 ///
3446 /// In clang-format 12, 13 and 14 it was named `IndentRequires`.
3447 /// \code
3448 /// true:
3449 /// template <typename It>
3450 /// requires Iterator<It>
3451 /// void sort(It begin, It end) {
3452 /// //....
3453 /// }
3454 ///
3455 /// false:
3456 /// template <typename It>
3457 /// requires Iterator<It>
3458 /// void sort(It begin, It end) {
3459 /// //....
3460 /// }
3461 /// \endcode
3462 /// \version 15
3464
3465 /// The number of columns to use for indentation.
3466 /// \code
3467 /// IndentWidth: 3
3468 ///
3469 /// void f() {
3470 /// someFunction();
3471 /// if (true, false) {
3472 /// f();
3473 /// }
3474 /// }
3475 /// \endcode
3476 /// \version 3.7
3477 unsigned IndentWidth;
3478
3479 /// Indent if a function definition or declaration is wrapped after the
3480 /// type.
3481 /// \code
3482 /// true:
3483 /// LoooooooooooooooooooooooooooooooooooooooongReturnType
3484 /// LoooooooooooooooooooooooooooooooongFunctionDeclaration();
3485 ///
3486 /// false:
3487 /// LoooooooooooooooooooooooooooooooooooooooongReturnType
3488 /// LoooooooooooooooooooooooooooooooongFunctionDeclaration();
3489 /// \endcode
3490 /// \version 3.7
3492
3493 /// Insert braces after control statements (`if`, `else`, `for`, `do`,
3494 /// and `while`) in C++ unless the control statements are inside macro
3495 /// definitions or the braces would enclose preprocessor directives.
3496 /// \warning
3497 /// Setting this option to `true` could lead to incorrect code formatting
3498 /// due to clang-format's lack of complete semantic information. As such,
3499 /// extra care should be taken to review code changes made by this option.
3500 /// \endwarning
3501 /// \code
3502 /// false: true:
3503 ///
3504 /// if (isa<FunctionDecl>(D)) vs. if (isa<FunctionDecl>(D)) {
3505 /// handleFunctionDecl(D); handleFunctionDecl(D);
3506 /// else if (isa<VarDecl>(D)) } else if (isa<VarDecl>(D)) {
3507 /// handleVarDecl(D); handleVarDecl(D);
3508 /// else } else {
3509 /// return; return;
3510 /// }
3511 ///
3512 /// while (i--) vs. while (i--) {
3513 /// for (auto *A : D.attrs()) for (auto *A : D.attrs()) {
3514 /// handleAttr(A); handleAttr(A);
3515 /// }
3516 /// }
3517 ///
3518 /// do vs. do {
3519 /// --i; --i;
3520 /// while (i); } while (i);
3521 /// \endcode
3522 /// \version 15
3524
3525 /// Insert a newline at end of file if missing.
3526 /// \version 16
3528
3529 /// The style of inserting trailing commas into container literals.
3531 /// Do not insert trailing commas.
3533 /// Insert trailing commas in container literals that were wrapped over
3534 /// multiple lines. Note that this is conceptually incompatible with
3535 /// bin-packing, because the trailing comma is used as an indicator
3536 /// that a container should be formatted one-per-line (i.e. not bin-packed).
3537 /// So inserting a trailing comma counteracts bin-packing.
3539 };
3540
3541 /// If set to `TCS_Wrapped` will insert trailing commas in container
3542 /// literals (arrays and objects) that wrap across multiple lines.
3543 /// It is currently only available for JavaScript
3544 /// and disabled by default `TCS_None`.
3545 /// `InsertTrailingCommas` cannot be used together with `BinPackArguments`
3546 /// as inserting the comma disables bin-packing.
3547 /// \code
3548 /// TSC_Wrapped:
3549 /// const someArray = [
3550 /// aaaaaaaaaaaaaaaaaaaaaaaaaa,
3551 /// aaaaaaaaaaaaaaaaaaaaaaaaaa,
3552 /// aaaaaaaaaaaaaaaaaaaaaaaaaa,
3553 /// // ^ inserted
3554 /// ]
3555 /// \endcode
3556 /// \version 11
3558
3559 /// Separator format of integer literals of different bases.
3560 ///
3561 /// If negative, remove separators. If `0`, leave the literal as is. If
3562 /// positive, insert separators between digits starting from the rightmost
3563 /// digit.
3564 ///
3565 /// For example, the config below will leave separators in binary literals
3566 /// alone, insert separators in decimal literals to separate the digits into
3567 /// groups of 3, and remove separators in hexadecimal literals.
3568 /// \code
3569 /// IntegerLiteralSeparator:
3570 /// Binary: 0
3571 /// Decimal: 3
3572 /// Hex: -1
3573 /// \endcode
3574 ///
3575 /// You can also specify a minimum number of digits
3576 /// (`BinaryMinDigitsInsert`, `DecimalMinDigitsInsert`, and
3577 /// `HexMinDigitsInsert`) the integer literal must have in order for the
3578 /// separators to be inserted, and a maximum number of digits
3579 /// (`BinaryMaxDigitsRemove`, `DecimalMaxDigitsRemove`, and
3580 /// `HexMaxDigitsRemove`) until the separators are removed. This divides the
3581 /// literals in 3 regions, always without separator (up until including
3582 /// `xxxMaxDigitsRemove`), maybe with, or without separators (up until
3583 /// excluding `xxxMinDigitsInsert`), and finally always with separators.
3584 /// \note
3585 /// `BinaryMinDigits`, `DecimalMinDigits`, and `HexMinDigits` are
3586 /// deprecated and renamed to `BinaryMinDigitsInsert`,
3587 /// `DecimalMinDigitsInsert`, and `HexMinDigitsInsert`, respectively.
3588 /// \endnote
3590 /// Format separators in binary literals.
3591 /// \code{.text}
3592 /// /* -1: */ b = 0b100111101101;
3593 /// /* 0: */ b = 0b10011'11'0110'1;
3594 /// /* 3: */ b = 0b100'111'101'101;
3595 /// /* 4: */ b = 0b1001'1110'1101;
3596 /// \endcode
3598 /// Format separators in binary literals with a minimum number of digits.
3599 /// \code{.text}
3600 /// // Binary: 3
3601 /// // BinaryMinDigitsInsert: 7
3602 /// b1 = 0b101101;
3603 /// b2 = 0b1'101'101;
3604 /// \endcode
3606 /// Remove separators in binary literals with a maximum number of digits.
3607 /// \code{.text}
3608 /// // Binary: 3
3609 /// // BinaryMinDigitsInsert: 7
3610 /// // BinaryMaxDigitsRemove: 4
3611 /// b0 = 0b1011; // Always removed.
3612 /// b1 = 0b101101; // Not added.
3613 /// b2 = 0b1'01'101; // Not removed, not corrected.
3614 /// b3 = 0b1'101'101; // Always added.
3615 /// b4 = 0b10'1101; // Corrected to 0b101'101.
3616 /// \endcode
3618 /// Format separators in decimal literals.
3619 /// \code{.text}
3620 /// /* -1: */ d = 18446744073709550592ull;
3621 /// /* 0: */ d = 184467'440737'0'95505'92ull;
3622 /// /* 3: */ d = 18'446'744'073'709'550'592ull;
3623 /// \endcode
3625 /// Format separators in decimal literals with a minimum number of digits.
3626 /// \code{.text}
3627 /// // Decimal: 3
3628 /// // DecimalMinDigitsInsert: 5
3629 /// d1 = 2023;
3630 /// d2 = 10'000;
3631 /// \endcode
3633 /// Remove separators in decimal literals with a maximum number of digits.
3634 /// \code{.text}
3635 /// // Decimal: 3
3636 /// // DecimalMinDigitsInsert: 7
3637 /// // DecimalMaxDigitsRemove: 4
3638 /// d0 = 2023; // Always removed.
3639 /// d1 = 123456; // Not added.
3640 /// d2 = 1'23'456; // Not removed, not corrected.
3641 /// d3 = 5'000'000; // Always added.
3642 /// d4 = 1'23'45; // Corrected to 12'345.
3643 /// \endcode
3645 /// Format separators in hexadecimal literals.
3646 /// \code{.text}
3647 /// /* -1: */ h = 0xDEADBEEFDEADBEEFuz;
3648 /// /* 0: */ h = 0xDEAD'BEEF'DE'AD'BEE'Fuz;
3649 /// /* 2: */ h = 0xDE'AD'BE'EF'DE'AD'BE'EFuz;
3650 /// \endcode
3652 /// Format separators in hexadecimal literals with a minimum number of
3653 /// digits.
3654 /// \code{.text}
3655 /// // Hex: 2
3656 /// // HexMinDigitsInsert: 6
3657 /// h1 = 0xABCDE;
3658 /// h2 = 0xAB'CD'EF;
3659 /// \endcode
3661 /// Remove separators in hexadecimal literals with a maximum number of
3662 /// digits.
3663 /// \code{.text}
3664 /// // Hex: 2
3665 /// // HexMinDigitsInsert: 6
3666 /// // HexMaxDigitsRemove: 4
3667 /// h0 = 0xAFFE; // Always removed.
3668 /// h1 = 0xABCDE; // Not added.
3669 /// h2 = 0xABC'DE; // Not removed, not corrected.
3670 /// h3 = 0xAB'CD'EF; // Always added.
3671 /// h4 = 0xABCD'E; // Corrected to 0xA'BC'DE.
3672 /// \endcode
3675 return Binary == R.Binary &&
3676 BinaryMinDigitsInsert == R.BinaryMinDigitsInsert &&
3677 BinaryMaxDigitsRemove == R.BinaryMaxDigitsRemove &&
3678 Decimal == R.Decimal &&
3679 DecimalMinDigitsInsert == R.DecimalMinDigitsInsert &&
3680 DecimalMaxDigitsRemove == R.DecimalMaxDigitsRemove &&
3681 Hex == R.Hex && HexMinDigitsInsert == R.HexMinDigitsInsert &&
3682 HexMaxDigitsRemove == R.HexMaxDigitsRemove;
3683 }
3685 return !operator==(R);
3686 }
3687 };
3688
3689 /// Format integer literal separators (`'` for C/C++ and `_` for C#, Java,
3690 /// and JavaScript).
3691 /// \version 16
3693
3694 /// A vector of prefixes ordered by the desired groups for Java imports.
3695 ///
3696 /// One group's prefix can be a subset of another - the longest prefix is
3697 /// always matched. Within a group, the imports are ordered lexicographically.
3698 /// Static imports are grouped separately and follow the same group rules.
3699 /// By default, static imports are placed before non-static imports,
3700 /// but this behavior is changed by another option,
3701 /// `SortJavaStaticImport`.
3702 ///
3703 /// In the .clang-format configuration file, this can be configured like
3704 /// in the following yaml example. This will result in imports being
3705 /// formatted as in the Java example below.
3706 /// \code{.yaml}
3707 /// JavaImportGroups: [com.example, com, org]
3708 /// \endcode
3709 ///
3710 /// \code{.java}
3711 /// import static com.example.function1;
3712 ///
3713 /// import static com.test.function2;
3714 ///
3715 /// import static org.example.function3;
3716 ///
3717 /// import com.example.ClassA;
3718 /// import com.example.Test;
3719 /// import com.example.a.ClassB;
3720 ///
3721 /// import com.test.ClassC;
3722 ///
3723 /// import org.example.ClassD;
3724 /// \endcode
3725 /// \version 8
3726 std::vector<std::string> JavaImportGroups;
3727
3728 /// Quotation styles for JavaScript strings. Does not affect template
3729 /// strings.
3731 /// Leave string quotes as they are.
3732 /// \code{.js}
3733 /// string1 = "foo";
3734 /// string2 = 'bar';
3735 /// \endcode
3737 /// Always use single quotes.
3738 /// \code{.js}
3739 /// string1 = 'foo';
3740 /// string2 = 'bar';
3741 /// \endcode
3743 /// Always use double quotes.
3744 /// \code{.js}
3745 /// string1 = "foo";
3746 /// string2 = "bar";
3747 /// \endcode
3749 };
3750
3751 /// The JavaScriptQuoteStyle to use for JavaScript strings.
3752 /// \version 3.9
3754
3755 // clang-format off
3756 /// Whether to wrap JavaScript import/export statements.
3757 /// \code{.js}
3758 /// true:
3759 /// import {
3760 /// VeryLongImportsAreAnnoying,
3761 /// VeryLongImportsAreAnnoying,
3762 /// VeryLongImportsAreAnnoying,
3763 /// } from "some/module.js"
3764 ///
3765 /// false:
3766 /// import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js"
3767 /// \endcode
3768 /// \version 3.9
3770 // clang-format on
3771
3772 /// Options regarding which empty lines are kept.
3773 ///
3774 /// For example, the config below will remove empty lines at start of the
3775 /// file, end of the file, and start of blocks.
3776 ///
3777 /// \code
3778 /// KeepEmptyLines:
3779 /// AtEndOfBlock: false
3780 /// AtEndOfFile: false
3781 /// AtStartOfBlock: false
3782 /// AtStartOfFile: false
3783 /// \endcode
3785 /// Keep empty lines at end of a block.
3786 /// \code
3787 /// true: false:
3788 /// if (foo) { vs. if (foo) {
3789 /// bar(); bar();
3790 /// }
3791 /// }
3792 /// \endcode
3794 /// Keep empty lines at end of file.
3796 /// Keep empty lines at start of a block.
3797 /// \code
3798 /// true: false:
3799 /// if (foo) { vs. if (foo) {
3800 /// bar();
3801 /// bar(); }
3802 /// }
3803 /// \endcode
3805 /// Keep empty lines at start of file.
3807 bool operator==(const KeepEmptyLinesStyle &R) const {
3808 return AtEndOfBlock == R.AtEndOfBlock && AtEndOfFile == R.AtEndOfFile &&
3809 AtStartOfBlock == R.AtStartOfBlock &&
3810 AtStartOfFile == R.AtStartOfFile;
3811 }
3812 };
3813 /// Which empty lines are kept. See `MaxEmptyLinesToKeep` for how many
3814 /// consecutive empty lines are kept.
3815 /// \version 19
3817
3818 /// This option is **deprecated**. See `AtEndOfFile` of `KeepEmptyLines`.
3819 /// \version 17
3820 // bool KeepEmptyLinesAtEOF;
3821
3822 /// This option is **deprecated**. See `AtStartOfBlock` of
3823 /// `KeepEmptyLines`.
3824 /// \version 3.7
3825 // bool KeepEmptyLinesAtTheStartOfBlocks;
3826
3827 /// Keep the form feed character if it's immediately preceded and followed by
3828 /// a newline. Multiple form feeds and newlines within a whitespace range are
3829 /// replaced with a single newline and form feed followed by the remaining
3830 /// newlines. (See
3831 /// www.gnu.org/prep/standards/html_node/Formatting.html#:~:text=formfeed.)
3832 /// \version 20
3834
3835 /// Indentation logic for lambda bodies.
3837 /// Align lambda body relative to the lambda signature. This is the default.
3838 /// \code
3839 /// someMethod(
3840 /// [](SomeReallyLongLambdaSignatureArgument foo) {
3841 /// return;
3842 /// });
3843 /// \endcode
3845 /// For statements within block scope, align lambda body relative to the
3846 /// indentation level of the outer scope the lambda signature resides in.
3847 /// \code
3848 /// someMethod(
3849 /// [](SomeReallyLongLambdaSignatureArgument foo) {
3850 /// return;
3851 /// });
3852 ///
3853 /// someMethod(someOtherMethod(
3854 /// [](SomeReallyLongLambdaSignatureArgument foo) {
3855 /// return;
3856 /// }));
3857 /// \endcode
3859 };
3860
3861 /// The indentation style of lambda bodies. `Signature` (the default)
3862 /// causes the lambda body to be indented one additional level relative to
3863 /// the indentation level of the signature. `OuterScope` forces the lambda
3864 /// body to be indented one additional level relative to the parent scope
3865 /// containing the lambda signature.
3866 /// \version 13
3868
3869 /// Supported languages.
3870 ///
3871 /// When stored in a configuration file, specifies the language, that the
3872 /// configuration targets. When passed to the `reformat()` function, enables
3873 /// syntax features specific to the language.
3875 /// Do not use.
3877 /// Should be used for C.
3879 /// Should be used for C++.
3881 /// Should be used for C#.
3883 /// Should be used for Java.
3885 /// Should be used for JavaScript.
3887 /// Should be used for JSON.
3889 /// Should be used for Objective-C, Objective-C++.
3891 /// Should be used for [Protocol Buffers](https://protobuf.dev/)
3893 /// Should be used for TableGen code.
3895 /// Should be used for [Protocol Buffer](https://protobuf.dev/) messages in
3896 /// text format
3898 /// Should be used for Verilog and SystemVerilog.
3899 /// https://standards.ieee.org/ieee/1800/6700/
3900 /// https://sci-hub.st/10.1109/IEEESTD.2018.8299595
3902 };
3903 bool isCpp() const {
3904 return Language == LK_Cpp || Language == LK_C || Language == LK_ObjC;
3905 }
3906 bool isCSharp() const { return Language == LK_CSharp; }
3907 bool isJson() const { return Language == LK_Json; }
3908 bool isJava() const { return Language == LK_Java; }
3909 bool isJavaScript() const { return Language == LK_JavaScript; }
3910 bool isVerilog() const { return Language == LK_Verilog; }
3911 bool isTextProto() const { return Language == LK_TextProto; }
3912 bool isProto() const { return Language == LK_Proto || isTextProto(); }
3913 bool isTableGen() const { return Language == LK_TableGen; }
3914
3915 /// The language that this format style targets.
3916 /// \note
3917 /// You can specify the language (`C`, `Cpp`, or `ObjC`) for `.h`
3918 /// files by adding a `// clang-format Language:` line before the first
3919 /// non-comment (and non-empty) line, e.g. `// clang-format Language: Cpp`.
3920 /// \endnote
3921 /// \version 3.5
3923
3924 /// Line ending style.
3926 /// Use `\n`.
3928 /// Use `\r\n`.
3930 /// Use `\n` unless the input has more lines ending in `\r\n`.
3932 /// Use `\r\n` unless the input has more lines ending in `\n`.
3934 };
3935
3936 /// Line ending style (`\n` or `\r\n`) to use.
3937 /// \version 16
3939
3940 /// A regular expression matching macros that start a block.
3941 /// \code
3942 /// # With:
3943 /// MacroBlockBegin: "^NS_MAP_BEGIN|\
3944 /// NS_TABLE_HEAD$"
3945 /// MacroBlockEnd: "^\
3946 /// NS_MAP_END|\
3947 /// NS_TABLE_.*_END$"
3948 ///
3949 /// NS_MAP_BEGIN
3950 /// foo();
3951 /// NS_MAP_END
3952 ///
3953 /// NS_TABLE_HEAD
3954 /// bar();
3955 /// NS_TABLE_FOO_END
3956 ///
3957 /// # Without:
3958 /// NS_MAP_BEGIN
3959 /// foo();
3960 /// NS_MAP_END
3961 ///
3962 /// NS_TABLE_HEAD
3963 /// bar();
3964 /// NS_TABLE_FOO_END
3965 /// \endcode
3966 /// \version 3.7
3967 std::string MacroBlockBegin;
3968
3969 /// A regular expression matching macros that end a block.
3970 /// \version 3.7
3971 std::string MacroBlockEnd;
3972
3973 /// A list of macros of the form \c <definition>=<expansion> .
3974 ///
3975 /// Code will be parsed with macros expanded, in order to determine how to
3976 /// interpret and format the macro arguments.
3977 ///
3978 /// For example, the code:
3979 /// \code
3980 /// A(a*b);
3981 /// \endcode
3982 ///
3983 /// will usually be interpreted as a call to a function A, and the
3984 /// multiplication expression will be formatted as `a * b`.
3985 ///
3986 /// If we specify the macro definition:
3987 /// \code{.yaml}
3988 /// Macros:
3989 /// - A(x)=x
3990 /// \endcode
3991 ///
3992 /// the code will now be parsed as a declaration of the variable b of type a*,
3993 /// and formatted as `a* b` (depending on pointer-binding rules).
3994 ///
3995 /// Features and restrictions:
3996 ///
3997 /// - Both function-like macros and object-like macros are supported.
3998 /// - Macro arguments must be used exactly once in the expansion.
3999 /// - No recursive expansion; macros referencing other macros will be
4000 /// ignored.
4001 /// - Overloading by arity is supported: for example, given the macro
4002 /// definitions A=x, A()=y, A(a)=a
4003 ///
4004 /// \code
4005 /// A; -> x;
4006 /// A(); -> y;
4007 /// A(z); -> z;
4008 /// A(a, b); // will not be expanded.
4009 /// \endcode
4010 ///
4011 /// \version 17
4012 std::vector<std::string> Macros;
4014 /// A vector of function-like macros whose invocations should be skipped by
4015 /// `RemoveParentheses`.
4016 /// \version 21
4017 std::vector<std::string> MacrosSkippedByRemoveParentheses;
4018
4019 /// The maximum number of consecutive empty lines to keep.
4020 /// \code
4021 /// MaxEmptyLinesToKeep: 1 vs. MaxEmptyLinesToKeep: 0
4022 /// int f() { int f() {
4023 /// int = 1; int i = 1;
4024 /// i = foo();
4025 /// i = foo(); return i;
4026 /// }
4027 /// return i;
4028 /// }
4029 /// \endcode
4030 /// \version 3.7
4031 unsigned MaxEmptyLinesToKeep;
4032
4033 /// Different ways to indent namespace contents.
4035 /// Don't indent in namespaces.
4036 /// \code
4037 /// namespace out {
4038 /// int i;
4039 /// namespace in {
4040 /// int i;
4041 /// }
4042 /// }
4043 /// \endcode
4044 NI_None,
4045 /// Indent only in inner namespaces (nested in other namespaces).
4046 /// \code
4047 /// namespace out {
4048 /// int i;
4049 /// namespace in {
4050 /// int i;
4051 /// }
4052 /// }
4053 /// \endcode
4054 NI_Inner,
4055 /// Indent in all namespaces.
4056 /// \code
4057 /// namespace out {
4058 /// int i;
4059 /// namespace in {
4060 /// int i;
4061 /// }
4062 /// }
4063 /// \endcode
4064 NI_All
4066
4067 /// The indentation used for namespaces.
4068 /// \version 3.7
4069 NamespaceIndentationKind NamespaceIndentation;
4070
4071 /// A vector of macros which are used to open namespace blocks.
4072 ///
4073 /// These are expected to be macros of the form:
4074 /// \code
4075 /// NAMESPACE(<namespace-name>, ...) {
4076 /// <namespace-content>
4077 /// }
4078 /// \endcode
4079 ///
4080 /// For example: TESTSUITE
4081 /// \version 9
4082 std::vector<std::string> NamespaceMacros;
4084 /// Control over each component in a numeric literal.
4086 /// Leave this component of the literal as is.
4088 /// Format this component with uppercase characters.
4089 NLCS_Upper,
4090 /// Format this component with lowercase characters.
4091 NLCS_Lower,
4092 };
4093
4094 /// Separate control for each numeric literal component.
4095 ///
4096 /// For example, the config below will leave exponent letters alone, reformat
4097 /// hexadecimal digits in lowercase, reformat numeric literal prefixes in
4098 /// uppercase, and reformat suffixes in lowercase.
4099 /// \code
4100 /// NumericLiteralCase:
4101 /// ExponentLetter: Leave
4102 /// HexDigit: Lower
4103 /// Prefix: Upper
4104 /// Suffix: Lower
4105 /// \endcode
4107 /// Format floating point exponent separator letter case.
4108 /// \code
4109 /// float a = 6.02e23 + 1.0E10; // Leave
4110 /// float a = 6.02E23 + 1.0E10; // Upper
4111 /// float a = 6.02e23 + 1.0e10; // Lower
4112 /// \endcode
4114 /// Format hexadecimal digit case.
4115 /// \code
4116 /// a = 0xaBcDeF; // Leave
4117 /// a = 0xABCDEF; // Upper
4118 /// a = 0xabcdef; // Lower
4119 /// \endcode
4121 /// Format integer prefix case.
4122 /// \code
4123 /// a = 0XF0 | 0b1; // Leave
4124 /// a = 0XF0 | 0B1; // Upper
4125 /// a = 0xF0 | 0b1; // Lower
4126 /// \endcode
4128 /// Format suffix case. This option excludes case-sensitive reserved
4129 /// suffixes, such as `min` in C++.
4130 /// \code
4131 /// a = 1uLL; // Leave
4132 /// a = 1ULL; // Upper
4133 /// a = 1ull; // Lower
4134 /// \endcode
4136
4137 bool operator==(const NumericLiteralCaseStyle &R) const {
4138 return ExponentLetter == R.ExponentLetter && HexDigit == R.HexDigit &&
4139 Prefix == R.Prefix && Suffix == R.Suffix;
4140 }
4141
4142 bool operator!=(const NumericLiteralCaseStyle &R) const {
4143 return !(*this == R);
4144 }
4146
4147 /// Capitalization style for numeric literals.
4148 /// \version 22
4149 NumericLiteralCaseStyle NumericLiteralCase;
4150
4151 /// Controls bin-packing Objective-C protocol conformance list
4152 /// items into as few lines as possible when they go over `ColumnLimit`.
4153 ///
4154 /// If `Auto` (the default), delegates to the value in
4155 /// `BinPackParameters`. If that is `BinPack`, bin-packs Objective-C
4156 /// protocol conformance list items into as few lines as possible
4157 /// whenever they go over `ColumnLimit`.
4158 ///
4159 /// If `Always`, always bin-packs Objective-C protocol conformance
4160 /// list items into as few lines as possible whenever they go over
4161 /// `ColumnLimit`.
4162 ///
4163 /// If `Never`, lays out Objective-C protocol conformance list items
4164 /// onto individual lines whenever they go over `ColumnLimit`.
4165 ///
4166 /// \code{.objc}
4167 /// Always (or Auto, if BinPackParameters==BinPack):
4168 /// @interface ccccccccccccc () <
4169 /// ccccccccccccc, ccccccccccccc,
4170 /// ccccccccccccc, ccccccccccccc> {
4171 /// }
4172 ///
4173 /// Never (or Auto, if BinPackParameters!=BinPack):
4174 /// @interface ddddddddddddd () <
4175 /// ddddddddddddd,
4176 /// ddddddddddddd,
4177 /// ddddddddddddd,
4178 /// ddddddddddddd> {
4179 /// }
4180 /// \endcode
4181 /// \version 7
4183
4184 /// The number of characters to use for indentation of ObjC blocks.
4185 /// \code{.objc}
4186 /// ObjCBlockIndentWidth: 4
4187 ///
4188 /// [operation setCompletionBlock:^{
4189 /// [self onOperationDone];
4190 /// }];
4191 /// \endcode
4192 /// \version 3.7
4193 unsigned ObjCBlockIndentWidth;
4194
4195 /// Break parameters list into lines when there is nested block
4196 /// parameters in a function call.
4197 /// \code
4198 /// false:
4199 /// - (void)_aMethod
4200 /// {
4201 /// [self.test1 t:self w:self callback:^(typeof(self) self, NSNumber
4202 /// *u, NSNumber *v) {
4203 /// u = c;
4204 /// }]
4205 /// }
4206 /// true:
4207 /// - (void)_aMethod
4208 /// {
4209 /// [self.test1 t:self
4210 /// w:self
4211 /// callback:^(typeof(self) self, NSNumber *u, NSNumber *v) {
4212 /// u = c;
4213 /// }]
4214 /// }
4215 /// \endcode
4216 /// \version 11
4218
4219 /// The order in which ObjC property attributes should appear.
4220 ///
4221 /// Attributes in code will be sorted in the order specified. Any attributes
4222 /// encountered that are not mentioned in this array will be sorted last, in
4223 /// stable order. Comments between attributes will leave the attributes
4224 /// untouched.
4225 /// \warning
4226 /// Using this option could lead to incorrect code formatting due to
4227 /// clang-format's lack of complete semantic information. As such, extra
4228 /// care should be taken to review code changes made by this option.
4229 /// \endwarning
4230 /// \code{.yaml}
4231 /// ObjCPropertyAttributeOrder: [
4232 /// class, direct,
4233 /// atomic, nonatomic,
4234 /// assign, retain, strong, copy, weak, unsafe_unretained,
4235 /// readonly, readwrite, getter, setter,
4236 /// nullable, nonnull, null_resettable, null_unspecified
4237 /// ]
4238 /// \endcode
4239 /// \version 18
4240 std::vector<std::string> ObjCPropertyAttributeOrder;
4241
4242 /// Add or remove a space between the '-'/'+' and the return type in
4243 /// Objective-C method declarations. i.e
4244 /// \code{.objc}
4245 /// false: true:
4246 ///
4247 /// -(void)method vs. - (void)method
4248 /// \endcode
4249 /// \version 23
4252 /// Add a space after `@property` in Objective-C, i.e. use
4253 /// `@property (readonly)` instead of `@property(readonly)`.
4254 /// \version 3.7
4257 /// Add a space in front of an Objective-C protocol list, i.e. use
4258 /// `Foo <Protocol>` instead of `Foo<Protocol>`.
4259 /// \version 3.7
4261
4262 /// A regular expression that describes markers for turning formatting off for
4263 /// one line. If it matches a comment that is the only token of a line,
4264 /// clang-format skips the comment and the next line. Otherwise, clang-format
4265 /// skips lines containing a matched token.
4266 /// \note
4267 /// This option does not apply to `IntegerLiteralSeparator` and
4268 /// `NumericLiteralCase`.
4269 /// \endnote
4270 /// \code
4271 /// // OneLineFormatOffRegex: ^(// NOLINT|logger$)
4272 /// // results in the output below:
4273 /// int a;
4274 /// int b ; // NOLINT
4275 /// int c;
4276 /// // NOLINTNEXTLINE
4277 /// int d ;
4278 /// int e;
4279 /// s = "// NOLINT";
4280 /// logger() ;
4281 /// logger2();
4282 /// my_logger();
4283 /// \endcode
4284 /// \version 21
4285 std::string OneLineFormatOffRegex;
4286
4287 /// Different ways to try to fit all arguments on a line.
4289 /// Bin-pack arguments.
4290 /// \code
4291 /// void f() {
4292 /// f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa,
4293 /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
4294 /// }
4295 /// \endcode
4297 /// Put all arguments on the current line if they fit.
4298 /// Otherwise, put each one on its own line.
4299 /// \code
4300 /// void f() {
4301 /// f(aaaaaaaaaaaaaaaaaaaa,
4302 /// aaaaaaaaaaaaaaaaaaaa,
4303 /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
4304 /// }
4305 /// \endcode
4307 /// Use the `BreakAfter` option to handle argument packing instead.
4308 /// If the `BreakAfter` limit is not exceeded, behave like `BinPack`.
4310 };
4311
4312 /// Options related to packing arguments of function calls.
4314
4315 /// The bin pack arguments style to use.
4316 /// \version 3.7
4318
4319 /// An argument list with more arguments than the specified number will be
4320 /// formatted with one argument per line. This option must be used with
4321 /// `BinPack: UseBreakAfter`.
4322 /// \code
4323 /// PackArguments:
4324 /// BinPack: UseBreakAfter
4325 /// BreakAfter: 3
4326 ///
4327 /// void f() {
4328 /// foo(1);
4329 ///
4330 /// bar(1, 2, 3);
4331 ///
4332 /// baz(1,
4333 /// 2,
4334 /// 3,
4335 /// 4);
4336 /// }
4337 /// \endcode
4338 /// \version 23
4339 unsigned BreakAfter;
4341 bool operator==(const PackArgumentsStyle &R) const {
4342 return BinPack == R.BinPack && BreakAfter == R.BreakAfter;
4343 }
4344 bool operator!=(const PackArgumentsStyle &R) const {
4345 return !operator==(R);
4346 }
4348
4349 /// Options related to packing arguments of function calls.
4350 /// \version 23
4352
4353 /// Different ways to try to fit all constructor initializers on a line.
4355 /// Always put each constructor initializer on its own line.
4356 /// \code
4357 /// Constructor()
4358 /// : a(),
4359 /// b()
4360 /// \endcode
4361 PCIS_Never,
4362 /// Bin-pack constructor initializers.
4363 /// \code
4364 /// Constructor()
4365 /// : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(),
4366 /// cccccccccccccccccccc()
4367 /// \endcode
4369 /// Put all constructor initializers on the current line if they fit.
4370 /// Otherwise, put each one on its own line.
4371 /// \code
4372 /// Constructor() : a(), b()
4373 ///
4374 /// Constructor()
4375 /// : aaaaaaaaaaaaaaaaaaaa(),
4376 /// bbbbbbbbbbbbbbbbbbbb(),
4377 /// ddddddddddddd()
4378 /// \endcode
4380 /// Same as `PCIS_CurrentLine` except that if all constructor initializers
4381 /// do not fit on the current line, try to fit them on the next line.
4382 /// \code
4383 /// Constructor() : a(), b()
4384 ///
4385 /// Constructor()
4386 /// : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), ddddddddddddd()
4387 ///
4388 /// Constructor()
4389 /// : aaaaaaaaaaaaaaaaaaaa(),
4390 /// bbbbbbbbbbbbbbbbbbbb(),
4391 /// cccccccccccccccccccc()
4392 /// \endcode
4394 /// Put all constructor initializers on the next line if they fit.
4395 /// Otherwise, put each one on its own line.
4396 /// \code
4397 /// Constructor()
4398 /// : a(), b()
4399 ///
4400 /// Constructor()
4401 /// : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), ddddddddddddd()
4402 ///
4403 /// Constructor()
4404 /// : aaaaaaaaaaaaaaaaaaaa(),
4405 /// bbbbbbbbbbbbbbbbbbbb(),
4406 /// cccccccccccccccccccc()
4407 /// \endcode
4410
4411 /// The pack constructor initializers style to use.
4412 /// \version 14
4414
4415 /// Different ways to try to fit all parameters on a line.
4417 /// Bin-pack parameters.
4418 /// \code
4419 /// void f(int a, int bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
4420 /// int ccccccccccccccccccccccccccccccccccccccccccc);
4421 /// \endcode
4423 /// Put all parameters on the current line if they fit.
4424 /// Otherwise, put each one on its own line.
4425 /// \code
4426 /// void f(int a, int b, int c);
4427 ///
4428 /// void f(int a,
4429 /// int b,
4430 /// int ccccccccccccccccccccccccccccccccccccc);
4431 /// \endcode
4433 /// Always put each parameter on its own line.
4434 /// \code
4435 /// void f(int a,
4436 /// int b,
4437 /// int c);
4438 /// \endcode
4440 /// Use the `BreakAfter` option to handle parameter packing instead.
4441 /// If the `BreakAfter` limit is not exceeded, behave like `BinPack`.
4444
4445 /// Options related to packing parameters of function declarations and
4446 /// definitions.
4448
4449 /// The bin pack parameters style to use.
4450 /// \version 3.7
4452
4453 /// A parameter list with more parameters than the specified number will be
4454 /// formatted with one parameter per line. This option must be used with
4455 /// `BinPack: UseBreakAfter`.
4456 /// \code
4457 /// PackParameters:
4458 /// BinPack: UseBreakAfter
4459 /// BreakAfter: 3
4460 ///
4461 /// void foo(int a);
4462 ///
4463 /// void bar(int a, int b, int c);
4464 ///
4465 /// void baz(int a,
4466 /// int b,
4467 /// int c,
4468 /// int d);
4469 /// \endcode
4470 /// \version 23
4471 unsigned BreakAfter;
4473 bool operator==(const PackParametersStyle &R) const {
4474 return BinPack == R.BinPack && BreakAfter == R.BreakAfter;
4475 }
4476 bool operator!=(const PackParametersStyle &R) const {
4477 return !operator==(R);
4478 }
4479 };
4481 /// Options related to packing parameters of function declarations and
4482 /// definitions.
4483 /// \version 23
4485
4486 /// The penalty for breaking around an assignment operator.
4487 /// \version 5
4489
4490 /// The penalty for breaking a function call after `call(`.
4491 /// \version 3.7
4493
4494 /// The penalty for breaking before a member access operator (`.`, `->`).
4495 /// \version 20
4497
4498 /// The penalty for each line break introduced inside a comment.
4499 /// \version 3.7
4501
4502 /// The penalty for breaking before the first `<<`.
4503 /// \version 3.7
4505
4506 /// The penalty for breaking after `(`.
4507 /// \version 14
4509
4510 /// The penalty for breaking after `::`.
4511 /// \version 18
4513
4514 /// The penalty for each line break introduced inside a string literal.
4515 /// \version 3.7
4517
4518 /// The penalty for breaking after template declaration.
4519 /// \version 7
4521
4522 /// The penalty for each character outside of the column limit.
4523 /// \version 3.7
4524 unsigned PenaltyExcessCharacter;
4526 /// Penalty for each character of whitespace indentation
4527 /// (counted relative to leading non-whitespace column).
4528 /// \version 12
4530
4531 /// Penalty for putting the return type of a function onto its own line.
4532 /// \version 3.7
4534
4535 /// The `&`, `&&` and `*` alignment style.
4537 /// Align pointer to the left.
4538 /// \code
4539 /// int* a;
4540 /// \endcode
4541 PAS_Left,
4542 /// Align pointer to the right.
4543 /// \code
4544 /// int *a;
4545 /// \endcode
4546 PAS_Right,
4547 /// Align pointer in the middle.
4548 /// \code
4549 /// int * a;
4550 /// \endcode
4553
4554 /// Pointer and reference alignment style.
4555 /// \version 3.7
4556 PointerAlignmentStyle PointerAlignment;
4557
4558 /// The number of columns to use for indentation of preprocessor statements.
4559 /// When set to -1 (default) `IndentWidth` is used also for preprocessor
4560 /// statements.
4561 /// \code
4562 /// PPIndentWidth: 1
4563 ///
4564 /// #ifdef __linux__
4565 /// # define FOO
4566 /// #else
4567 /// # define BAR
4568 /// #endif
4569 /// \endcode
4570 /// \version 13
4571 int PPIndentWidth;
4572
4573 /// Different specifiers and qualifiers alignment styles.
4575 /// Don't change specifiers/qualifiers to either Left or Right alignment
4576 /// (default).
4577 /// \code
4578 /// int const a;
4579 /// const int *a;
4580 /// \endcode
4581 QAS_Leave,
4582 /// Change specifiers/qualifiers to be left-aligned.
4583 /// \code
4584 /// const int a;
4585 /// const int *a;
4586 /// \endcode
4587 QAS_Left,
4588 /// Change specifiers/qualifiers to be right-aligned.
4589 /// \code
4590 /// int const a;
4591 /// int const *a;
4592 /// \endcode
4593 QAS_Right,
4594 /// Change specifiers/qualifiers to be aligned based on `QualifierOrder`.
4595 /// With:
4596 /// \code{.yaml}
4597 /// QualifierOrder: [inline, static, type, const]
4598 /// \endcode
4599 ///
4600 /// \code
4601 ///
4602 /// int const a;
4603 /// int const *a;
4604 /// \endcode
4606 };
4607
4608 /// Different ways to arrange specifiers and qualifiers (e.g. const/volatile).
4609 /// \warning
4610 /// Setting `QualifierAlignment` to something other than `Leave`, COULD
4611 /// lead to incorrect code formatting due to incorrect decisions made due to
4612 /// clang-formats lack of complete semantic information.
4613 /// As such extra care should be taken to review code changes made by the use
4614 /// of this option.
4615 /// \endwarning
4616 /// \version 14
4618
4619 /// The order in which the qualifiers appear.
4620 /// The order is an array that can contain any of the following:
4621 ///
4622 /// * `const`
4623 /// * `inline`
4624 /// * `static`
4625 /// * `friend`
4626 /// * `constexpr`
4627 /// * `volatile`
4628 /// * `restrict`
4629 /// * `typedef`
4630 /// * `consteval`
4631 /// * `constinit`
4632 /// * `thread_local`
4633 /// * `extern`
4634 /// * `mutable`
4635 /// * `signed`
4636 /// * `unsigned`
4637 /// * `long`
4638 /// * `short`
4639 /// * `explicit`
4640 /// * `type`
4641 ///
4642 /// \note
4643 /// It must contain `type`.
4644 /// \endnote
4645 ///
4646 /// Items to the left of `type` will be placed to the left of the type and
4647 /// aligned in the order supplied. Items to the right of `type` will be
4648 /// placed to the right of the type and aligned in the order supplied.
4649 /// If only one of `signed` and `unsigned` is specified, both are placed at
4650 /// that position. The same applies to `long` and `short`. Specifying both
4651 /// members of a pair allows them to be placed independently.
4652 ///
4653 /// \code{.yaml}
4654 /// QualifierOrder: [inline, static, type, const, volatile]
4655 /// \endcode
4656 /// \version 14
4657 std::vector<std::string> QualifierOrder;
4659 /// See documentation of `RawStringFormats`.
4661 /// The language of this raw string.
4663 /// A list of raw string delimiters that match this language.
4664 std::vector<std::string> Delimiters;
4665 /// A list of enclosing function names that match this language.
4666 std::vector<std::string> EnclosingFunctions;
4667 /// The canonical delimiter for this language.
4669 /// The style name on which this raw string format is based on.
4670 /// If not specified, the raw string format is based on the style that this
4671 /// format is based on.
4672 std::string BasedOnStyle;
4673 bool operator==(const RawStringFormat &Other) const {
4674 return Language == Other.Language && Delimiters == Other.Delimiters &&
4675 EnclosingFunctions == Other.EnclosingFunctions &&
4676 CanonicalDelimiter == Other.CanonicalDelimiter &&
4677 BasedOnStyle == Other.BasedOnStyle;
4678 }
4679 };
4680
4681 /// Defines hints for detecting supported languages code blocks in raw
4682 /// strings.
4683 ///
4684 /// A raw string with a matching delimiter or a matching enclosing function
4685 /// name will be reformatted assuming the specified language based on the
4686 /// style for that language defined in the .clang-format file. If no style has
4687 /// been defined in the .clang-format file for the specific language, a
4688 /// predefined style given by `BasedOnStyle` is used. If `BasedOnStyle` is
4689 /// not found, the formatting is based on `LLVM` style. A matching delimiter
4690 /// takes precedence over a matching enclosing function name for determining
4691 /// the language of the raw string contents.
4692 ///
4693 /// If a canonical delimiter is specified, occurrences of other delimiters for
4694 /// the same language will be updated to the canonical if possible.
4695 ///
4696 /// There should be at most one specification per language and each delimiter
4697 /// and enclosing function should not occur in multiple specifications.
4698 ///
4699 /// To configure this in the .clang-format file, use:
4700 /// \code{.yaml}
4701 /// RawStringFormats:
4702 /// - Language: TextProto
4703 /// Delimiters:
4704 /// - pb
4705 /// - proto
4706 /// EnclosingFunctions:
4707 /// - PARSE_TEXT_PROTO
4708 /// BasedOnStyle: google
4709 /// - Language: Cpp
4710 /// Delimiters:
4711 /// - cc
4712 /// - cpp
4713 /// BasedOnStyle: LLVM
4714 /// CanonicalDelimiter: cc
4715 /// \endcode
4716 /// \version 6
4717 std::vector<RawStringFormat> RawStringFormats;
4719 /// The `&` and `&&` alignment style.
4721 /// Align reference like `PointerAlignment`.
4723 /// Align reference to the left.
4724 /// \code
4725 /// int& a;
4726 /// \endcode
4727 RAS_Left,
4728 /// Align reference to the right.
4729 /// \code
4730 /// int &a;
4731 /// \endcode
4732 RAS_Right,
4733 /// Align reference in the middle.
4734 /// \code
4735 /// int & a;
4736 /// \endcode
4739
4740 /// Reference alignment style (overrides `PointerAlignment` for references).
4741 /// \version 13
4743
4744 // clang-format off
4745 /// Types of comment reflow style.
4747 /// Leave comments untouched.
4748 /// \code
4749 /// // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
4750 /// /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */
4751 /// /* third veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
4752 /// * and a misaligned second line */
4753 /// \endcode
4754 RCS_Never,
4755 /// Only apply indentation rules, moving comments left or right, without
4756 /// changing formatting inside the comments.
4757 /// \code
4758 /// // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
4759 /// /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */
4760 /// /* third veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
4761 /// * and a misaligned second line */
4762 /// \endcode
4764 /// Apply indentation rules and reflow long comments into new lines, trying
4765 /// to obey the `ColumnLimit`.
4766 /// \code
4767 /// // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
4768 /// // information
4769 /// /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
4770 /// * information */
4771 /// /* third veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
4772 /// * information and a misaligned second line */
4773 /// \endcode
4775 };
4776 // clang-format on
4777
4778 /// Comment reformatting style.
4779 /// \version 3.8
4781
4782 /// Remove optional braces of control statements (`if`, `else`, `for`,
4783 /// and `while`) in C++ according to the LLVM coding style.
4784 /// \warning
4785 /// This option will be renamed and expanded to support other styles.
4786 /// \endwarning
4787 /// \warning
4788 /// Setting this option to `true` could lead to incorrect code formatting
4789 /// due to clang-format's lack of complete semantic information. As such,
4790 /// extra care should be taken to review code changes made by this option.
4791 /// \endwarning
4792 /// \code
4793 /// false: true:
4794 ///
4795 /// if (isa<FunctionDecl>(D)) { vs. if (isa<FunctionDecl>(D))
4796 /// handleFunctionDecl(D); handleFunctionDecl(D);
4797 /// } else if (isa<VarDecl>(D)) { else if (isa<VarDecl>(D))
4798 /// handleVarDecl(D); handleVarDecl(D);
4799 /// }
4800 ///
4801 /// if (isa<VarDecl>(D)) { vs. if (isa<VarDecl>(D)) {
4802 /// for (auto *A : D.attrs()) { for (auto *A : D.attrs())
4803 /// if (shouldProcessAttr(A)) { if (shouldProcessAttr(A))
4804 /// handleAttr(A); handleAttr(A);
4805 /// } }
4806 /// }
4807 /// }
4808 ///
4809 /// if (isa<FunctionDecl>(D)) { vs. if (isa<FunctionDecl>(D))
4810 /// for (auto *A : D.attrs()) { for (auto *A : D.attrs())
4811 /// handleAttr(A); handleAttr(A);
4812 /// }
4813 /// }
4814 ///
4815 /// if (auto *D = (T)(D)) { vs. if (auto *D = (T)(D)) {
4816 /// if (shouldProcess(D)) { if (shouldProcess(D))
4817 /// handleVarDecl(D); handleVarDecl(D);
4818 /// } else { else
4819 /// markAsIgnored(D); markAsIgnored(D);
4820 /// } }
4821 /// }
4822 ///
4823 /// if (a) { vs. if (a)
4824 /// b(); b();
4825 /// } else { else if (c)
4826 /// if (c) { d();
4827 /// d(); else
4828 /// } else { e();
4829 /// e();
4830 /// }
4831 /// }
4832 /// \endcode
4833 /// \version 14
4834 bool RemoveBracesLLVM;
4835
4836 /// Remove empty lines within unwrapped lines.
4837 /// \code
4838 /// false: true:
4839 ///
4840 /// int c vs. int c = a + b;
4841 ///
4842 /// = a + b;
4843 ///
4844 /// enum : unsigned vs. enum : unsigned {
4845 /// AA = 0,
4846 /// { BB
4847 /// AA = 0, } myEnum;
4848 /// BB
4849 /// } myEnum;
4850 ///
4851 /// while ( vs. while (true) {
4852 /// }
4853 /// true) {
4854 /// }
4855 /// \endcode
4856 /// \version 20
4858
4859 /// Types of redundant parentheses to remove.
4861 /// Do not remove parentheses.
4862 /// \code
4863 /// class __declspec((dllimport)) X {};
4864 /// co_return (((0)));
4865 /// return ((a + b) - ((c + d)));
4866 /// \endcode
4867 RPS_Leave,
4868 /// Replace multiple parentheses with single parentheses.
4869 /// \code
4870 /// class __declspec(dllimport) X {};
4871 /// co_return (0);
4872 /// return ((a + b) - (c + d));
4873 /// \endcode
4875 /// Also remove parentheses enclosing the expression in a
4876 /// `return`/`co_return` statement.
4877 /// \code
4878 /// class __declspec(dllimport) X {};
4879 /// co_return 0;
4880 /// return (a + b) - (c + d);
4881 /// \endcode
4883 };
4884
4885 /// Remove redundant parentheses.
4886 /// \warning
4887 /// Setting this option to any value other than `Leave` could lead to
4888 /// incorrect code formatting due to clang-format's lack of complete semantic
4889 /// information. As such, extra care should be taken to review code changes
4890 /// made by this option.
4891 /// \endwarning
4892 /// \version 17
4894
4895 /// Remove semicolons after the closing braces of functions and
4896 /// constructors/destructors.
4897 /// \warning
4898 /// Setting this option to `true` could lead to incorrect code formatting
4899 /// due to clang-format's lack of complete semantic information. As such,
4900 /// extra care should be taken to review code changes made by this option.
4901 /// \endwarning
4902 /// \code
4903 /// false: true:
4904 ///
4905 /// int max(int a, int b) { int max(int a, int b) {
4906 /// return a > b ? a : b; return a > b ? a : b;
4907 /// }; }
4908 ///
4909 /// \endcode
4910 /// \version 16
4912
4913 /// The possible positions for the requires clause. The `IndentRequires`
4914 /// option is only used if the `requires` is put on the start of a line.
4916 /// Always put the `requires` clause on its own line (possibly followed by
4917 /// a semicolon).
4918 /// \code
4919 /// template <typename T>
4920 /// requires C<T>
4921 /// struct Foo {...
4922 ///
4923 /// template <typename T>
4924 /// void bar(T t)
4925 /// requires C<T>;
4926 ///
4927 /// template <typename T>
4928 /// requires C<T>
4929 /// void bar(T t) {...
4930 ///
4931 /// template <typename T>
4932 /// void baz(T t)
4933 /// requires C<T>
4934 /// {...
4935 /// \endcode
4937 /// As with `OwnLine`, except, unless otherwise prohibited, place a
4938 /// following open brace (of a function definition) to follow on the same
4939 /// line.
4940 /// \code
4941 /// void bar(T t)
4942 /// requires C<T> {
4943 /// return;
4944 /// }
4945 ///
4946 /// void bar(T t)
4947 /// requires C<T> {}
4948 ///
4949 /// template <typename T>
4950 /// requires C<T>
4951 /// void baz(T t) {
4952 /// ...
4953 /// \endcode
4955 /// Try to put the clause together with the preceding part of a declaration.
4956 /// For class templates: stick to the template declaration.
4957 /// For function templates: stick to the template declaration.
4958 /// For function declaration followed by a requires clause: stick to the
4959 /// parameter list.
4960 /// \code
4961 /// template <typename T> requires C<T>
4962 /// struct Foo {...
4963 ///
4964 /// template <typename T> requires C<T>
4965 /// void bar(T t) {...
4966 ///
4967 /// template <typename T>
4968 /// void baz(T t) requires C<T>
4969 /// {...
4970 /// \endcode
4972 /// Try to put the `requires` clause together with the class or function
4973 /// declaration.
4974 /// \code
4975 /// template <typename T>
4976 /// requires C<T> struct Foo {...
4977 ///
4978 /// template <typename T>
4979 /// requires C<T> void bar(T t) {...
4980 ///
4981 /// template <typename T>
4982 /// void baz(T t)
4983 /// requires C<T> {...
4984 /// \endcode
4986 /// Try to put everything in the same line if possible. Otherwise normal
4987 /// line breaking rules take over.
4988 /// \code
4989 /// // Fitting:
4990 /// template <typename T> requires C<T> struct Foo {...
4991 ///
4992 /// template <typename T> requires C<T> void bar(T t) {...
4993 ///
4994 /// template <typename T> void bar(T t) requires C<T> {...
4995 ///
4996 /// // Not fitting, one possible example:
4997 /// template <typename LongName>
4998 /// requires C<LongName>
4999 /// struct Foo {...
5000 ///
5001 /// template <typename LongName>
5002 /// requires C<LongName>
5003 /// void bar(LongName ln) {
5004 ///
5005 /// template <typename LongName>
5006 /// void bar(LongName ln)
5007 /// requires C<LongName> {
5008 /// \endcode
5011
5012 /// The position of the `requires` clause.
5013 /// \version 15
5015
5016 /// Indentation logic for requires expression bodies.
5018 /// Align requires expression body relative to the indentation level of the
5019 /// outer scope the requires expression resides in.
5020 /// This is the default.
5021 /// \code
5022 /// template <typename T>
5023 /// concept C = requires(T t) {
5024 /// ...
5025 /// }
5026 /// \endcode
5028 /// Align requires expression body relative to the `requires` keyword.
5029 /// \code
5030 /// template <typename T>
5031 /// concept C = requires(T t) {
5032 /// ...
5033 /// }
5034 /// \endcode
5037
5038 /// The indentation used for requires expression bodies.
5039 /// \version 16
5042 /// The style if definition blocks should be separated.
5044 /// Leave definition blocks as they are.
5046 /// Insert an empty line between definition blocks.
5047 SDS_Always,
5048 /// Remove any empty line between definition blocks.
5049 SDS_Never
5050 };
5051
5052 /// Specifies the use of empty lines to separate definition blocks, including
5053 /// classes, structs, enums, and functions.
5054 /// \code
5055 /// Never v.s. Always
5056 /// #include <cstring> #include <cstring>
5057 /// struct Foo {
5058 /// int a, b, c; struct Foo {
5059 /// }; int a, b, c;
5060 /// namespace Ns { };
5061 /// class Bar {
5062 /// public: namespace Ns {
5063 /// struct Foobar { class Bar {
5064 /// int a; public:
5065 /// int b; struct Foobar {
5066 /// }; int a;
5067 /// private: int b;
5068 /// int t; };
5069 /// int method1() {
5070 /// // ... private:
5071 /// } int t;
5072 /// enum List {
5073 /// ITEM1, int method1() {
5074 /// ITEM2 // ...
5075 /// }; }
5076 /// template<typename T>
5077 /// int method2(T x) { enum List {
5078 /// // ... ITEM1,
5079 /// } ITEM2
5080 /// int i, j, k; };
5081 /// int method3(int par) {
5082 /// // ... template<typename T>
5083 /// } int method2(T x) {
5084 /// }; // ...
5085 /// class C {}; }
5086 /// }
5087 /// int i, j, k;
5088 ///
5089 /// int method3(int par) {
5090 /// // ...
5091 /// }
5092 /// };
5093 ///
5094 /// class C {};
5095 /// }
5096 /// \endcode
5097 /// \version 14
5099
5100 /// The maximal number of unwrapped lines that a short namespace spans.
5101 /// Defaults to 1.
5102 ///
5103 /// This determines the maximum length of short namespaces by counting
5104 /// unwrapped lines (i.e. containing neither opening nor closing
5105 /// namespace brace) and makes `FixNamespaceComments` omit adding
5106 /// end comments for those.
5107 /// \code
5108 /// ShortNamespaceLines: 1 vs. ShortNamespaceLines: 0
5109 /// namespace a { namespace a {
5110 /// int foo; int foo;
5111 /// } } // namespace a
5112 ///
5113 /// ShortNamespaceLines: 1 vs. ShortNamespaceLines: 0
5114 /// namespace b { namespace b {
5115 /// int foo; int foo;
5116 /// int bar; int bar;
5117 /// } // namespace b } // namespace b
5118 /// \endcode
5119 /// \version 13
5121
5122 /// Do not format macro definition body.
5123 /// \version 18
5125
5126 /// Includes sorting options.
5127 struct SortIncludesOptions {
5128 /// If `true`, includes are sorted based on the other suboptions below.
5129 /// (`Never` is deprecated by `Enabled: false`.)
5130 bool Enabled;
5131 /// Whether or not includes are sorted in a case-insensitive fashion.
5132 /// (`CaseSensitive` and `CaseInsensitive` are deprecated by
5133 /// `IgnoreCase: false` and `IgnoreCase: true`, respectively.)
5134 /// \code
5135 /// true: false:
5136 /// #include "A/B.h" vs. #include "A/B.h"
5137 /// #include "A/b.h" #include "A/b.h"
5138 /// #include "a/b.h" #include "B/A.h"
5139 /// #include "B/A.h" #include "B/a.h"
5140 /// #include "B/a.h" #include "a/b.h"
5141 /// \endcode
5142 bool IgnoreCase;
5143 /// When sorting includes in each block, only take file extensions into
5144 /// account if two includes compare equal otherwise.
5145 /// \code
5146 /// true: false:
5147 /// # include "A.h" vs. # include "A-util.h"
5148 /// # include "A.inc" # include "A.h"
5149 /// # include "A-util.h" # include "A.inc"
5150 /// \endcode
5151 bool IgnoreExtension;
5152 /// Whether or not includes are sorted by natural ordering i.e., whether
5153 /// embedded runs of digits are compared as numbers rather than sequences of
5154 /// characters.
5155 /// \code
5156 /// true: false:
5157 /// #include "A2.h" vs. #include "A10.h"
5158 /// #include "A10.h" #include "A2.h"
5159 /// \endcode
5160 bool Natural;
5161 /// When `true`, sort includes so that files in a directory appear
5162 /// before subdirectories at each level, recursively. Within a level,
5163 /// files and folders are each sorted alphabetically.
5164 /// When `false` (default), sorts includes purely alphabetically.
5165 ///
5166 /// This option is a secondary sort key within each `Priority` group
5167 /// defined by `IncludeCategories`. Includes in different `Priority`
5168 /// groups are still separated by that primary ordering.
5169 /// \code
5170 /// true: false (default):
5171 /// #include "x.h" vs. #include "bar/alpha/e.h"
5172 /// #include "y.h" #include "bar/alpha/f.h"
5173 /// #include "z.h" #include "bar/beta/d.h"
5174 /// #include "bar/g.h" #include "bar/g.h"
5175 /// #include "bar/h.h" #include "bar/h.h"
5176 /// #include "bar/i.h" #include "bar/i.h"
5177 /// #include "bar/alpha/e.h" #include "foo/a.h"
5178 /// #include "bar/alpha/f.h" #include "x.h"
5179 /// #include "bar/beta/d.h" #include "y.h"
5180 /// #include "foo/a.h" #include "z.h"
5181 /// \endcode
5182 bool FilesBeforeFolders;
5183 bool operator==(const SortIncludesOptions &R) const {
5184 return Enabled == R.Enabled && IgnoreCase == R.IgnoreCase &&
5185 IgnoreExtension == R.IgnoreExtension && Natural == R.Natural &&
5186 FilesBeforeFolders == R.FilesBeforeFolders;
5187 }
5188 bool operator!=(const SortIncludesOptions &R) const {
5189 return !(*this == R);
5190 }
5192
5193 /// Controls if and how clang-format will sort `#includes`.
5194 /// \version 3.8
5196
5197 /// Position for Java Static imports.
5199 /// Static imports are placed before non-static imports.
5200 /// \code{.java}
5201 /// import static org.example.function1;
5202 ///
5203 /// import org.example.ClassA;
5204 /// \endcode
5206 /// Static imports are placed after non-static imports.
5207 /// \code{.java}
5208 /// import org.example.ClassA;
5209 ///
5210 /// import static org.example.function1;
5211 /// \endcode
5213 };
5214
5215 /// When sorting Java imports, by default static imports are placed before
5216 /// non-static imports. If `JavaStaticImportAfterImport` is `After`,
5217 /// static imports are placed after non-static imports.
5218 /// \version 12
5220
5221 /// Using declaration sorting options.
5223 /// Using declarations are never sorted.
5224 /// \code
5225 /// using std::chrono::duration_cast;
5226 /// using std::move;
5227 /// using boost::regex;
5228 /// using boost::regex_constants::icase;
5229 /// using std::string;
5230 /// \endcode
5231 SUD_Never,
5232 /// Using declarations are sorted in the order defined as follows:
5233 /// Split the strings by `::` and discard any initial empty strings. Sort
5234 /// the lists of names lexicographically, and within those groups, names are
5235 /// in case-insensitive lexicographic order.
5236 /// \code
5237 /// using boost::regex;
5238 /// using boost::regex_constants::icase;
5239 /// using std::chrono::duration_cast;
5240 /// using std::move;
5241 /// using std::string;
5242 /// \endcode
5244 /// Using declarations are sorted in the order defined as follows:
5245 /// Split the strings by `::` and discard any initial empty strings. The
5246 /// last element of each list is a non-namespace name; all others are
5247 /// namespace names. Sort the lists of names lexicographically, where the
5248 /// sort order of individual names is that all non-namespace names come
5249 /// before all namespace names, and within those groups, names are in
5250 /// case-insensitive lexicographic order.
5251 /// \code
5252 /// using boost::regex;
5253 /// using boost::regex_constants::icase;
5254 /// using std::move;
5255 /// using std::string;
5256 /// using std::chrono::duration_cast;
5257 /// \endcode
5260
5261 /// Controls if and how clang-format will sort using declarations.
5262 /// \version 5
5263 SortUsingDeclarationsOptions SortUsingDeclarations;
5264
5265 /// If `true`, a space is inserted after C style casts.
5266 /// \code
5267 /// true: false:
5268 /// (int) i; vs. (int)i;
5269 /// \endcode
5270 /// \version 3.5
5272
5273 /// If `true`, a space is inserted after the logical not operator (`!`).
5274 /// \code
5275 /// true: false:
5276 /// ! someExpression(); vs. !someExpression();
5277 /// \endcode
5278 /// \version 9
5280
5281 /// If `true`, a space will be inserted after the `operator` keyword.
5282 /// \code
5283 /// true: false:
5284 /// bool operator ==(int a); vs. bool operator==(int a);
5285 /// \endcode
5286 /// \version 21
5288
5289 /// If \c true, a space will be inserted after the `template` keyword.
5290 /// \code
5291 /// true: false:
5292 /// template <int> void foo(); vs. template<int> void foo();
5293 /// \endcode
5294 /// \version 4
5296
5297 /// Different ways to put a space before opening parentheses.
5299 /// Don't ensure spaces around pointer qualifiers and use PointerAlignment
5300 /// instead.
5301 /// \code
5302 /// PointerAlignment: Left PointerAlignment: Right
5303 /// void* const* x = NULL; vs. void *const *x = NULL;
5304 /// \endcode
5306 /// Ensure that there is a space before pointer qualifiers.
5307 /// \code
5308 /// PointerAlignment: Left PointerAlignment: Right
5309 /// void* const* x = NULL; vs. void * const *x = NULL;
5310 /// \endcode
5312 /// Ensure that there is a space after pointer qualifiers.
5313 /// \code
5314 /// PointerAlignment: Left PointerAlignment: Right
5315 /// void* const * x = NULL; vs. void *const *x = NULL;
5316 /// \endcode
5317 SAPQ_After,
5318 /// Ensure that there is a space both before and after pointer qualifiers.
5319 /// \code
5320 /// PointerAlignment: Left PointerAlignment: Right
5321 /// void* const * x = NULL; vs. void * const *x = NULL;
5322 /// \endcode
5323 SAPQ_Both,
5325
5326 /// Defines in which cases to put a space before or after pointer qualifiers
5327 /// \version 12
5328 SpaceAroundPointerQualifiersStyle SpaceAroundPointerQualifiers;
5329
5330 /// If `false`, spaces will be removed before assignment operators.
5331 /// \code
5332 /// true: false:
5333 /// int a = 5; vs. int a= 5;
5334 /// a += 42; a+= 42;
5335 /// \endcode
5336 /// \version 3.7
5338
5339 /// If `false`, spaces will be removed before case colon.
5340 /// \code
5341 /// true: false
5342 /// switch (x) { vs. switch (x) {
5343 /// case 1 : break; case 1: break;
5344 /// } }
5345 /// \endcode
5346 /// \version 12
5348
5349 /// If `true`, a space will be inserted before a C++11 braced list
5350 /// used to initialize an object (after the preceding identifier or type).
5351 /// \code
5352 /// true: false:
5353 /// Foo foo { bar }; vs. Foo foo{ bar };
5354 /// Foo {}; Foo{};
5355 /// vector<int> { 1, 2, 3 }; vector<int>{ 1, 2, 3 };
5356 /// new int[3] { 1, 2, 3 }; new int[3]{ 1, 2, 3 };
5357 /// \endcode
5358 /// \version 7
5360
5361 /// If `false`, spaces will be removed before constructor initializer
5362 /// colon.
5363 /// \code
5364 /// true: false:
5365 /// Foo::Foo() : a(a) {} Foo::Foo(): a(a) {}
5366 /// \endcode
5367 /// \version 7
5369
5370 /// If `false`, spaces will be removed before enum underlying type colon.
5371 /// \code
5372 /// true: false:
5373 /// enum E : int {} enum E: int {}
5374 /// \endcode
5375 /// \version 23
5377
5378 /// If `false`, spaces will be removed before inheritance colon.
5379 /// \code
5380 /// true: false:
5381 /// class Foo : Bar {} vs. class Foo: Bar {}
5382 /// \endcode
5383 /// \version 7
5385
5386 /// If `true`, a space will be added before a JSON colon. For other
5387 /// languages, e.g. JavaScript, use `SpacesInContainerLiterals` instead.
5388 /// \code
5389 /// true: false:
5390 /// { {
5391 /// "key" : "value" vs. "key": "value"
5392 /// } }
5393 /// \endcode
5394 /// \version 17
5396
5397 /// Different ways to put a space before opening parentheses.
5399 /// This is **deprecated** and replaced by `Custom` below, with all
5400 /// `SpaceBeforeParensOptions` but `AfterPlacementOperator` set to
5401 /// `false`.
5402 SBPO_Never,
5403 /// Put a space before opening parentheses only after control statement
5404 /// keywords (`for/if/while...`).
5405 /// \code
5406 /// void f() {
5407 /// if (true) {
5408 /// f();
5409 /// }
5410 /// }
5411 /// \endcode
5413 /// Same as `SBPO_ControlStatements` except this option doesn't apply to
5414 /// ForEach and If macros. This is useful in projects where ForEach/If
5415 /// macros are treated as function calls instead of control statements.
5416 /// `SBPO_ControlStatementsExceptForEachMacros` remains an alias for
5417 /// backward compatibility.
5418 /// \code
5419 /// void f() {
5420 /// Q_FOREACH(...) {
5421 /// f();
5422 /// }
5423 /// }
5424 /// \endcode
5426 /// Put a space before opening parentheses only if the parentheses are not
5427 /// empty.
5428 /// \code
5429 /// void() {
5430 /// if (true) {
5431 /// f();
5432 /// g (x, y, z);
5433 /// }
5434 /// }
5435 /// \endcode
5437 /// Always put a space before opening parentheses, except when it's
5438 /// prohibited by the syntax rules (in function-like macro definitions) or
5439 /// when determined by other style rules (after unary operators, opening
5440 /// parentheses, etc.)
5441 /// \code
5442 /// void f () {
5443 /// if (true) {
5444 /// f ();
5445 /// }
5446 /// }
5447 /// \endcode
5449 /// Configure each individual space before parentheses in
5450 /// `SpaceBeforeParensOptions`.
5453
5454 /// Defines in which cases to put a space before opening parentheses.
5455 /// \version 3.5
5456 SpaceBeforeParensStyle SpaceBeforeParens;
5457
5458 /// Precise control over the spacing before parentheses.
5459 /// \code{.yaml}
5460 /// # Should be declared this way:
5461 /// SpaceBeforeParens: Custom
5462 /// SpaceBeforeParensOptions:
5463 /// AfterControlStatements: true
5464 /// AfterFunctionDefinitionName: true
5465 /// \endcode
5467 /// If `true`, put space between control statement keywords
5468 /// (for/if/while...) and opening parentheses.
5469 /// \code
5470 /// true: false:
5471 /// if (...) {} vs. if(...) {}
5472 /// \endcode
5474 /// If `true`, put space between foreach macros and opening parentheses.
5475 /// \code
5476 /// true: false:
5477 /// FOREACH (...) vs. FOREACH(...)
5478 /// <loop-body> <loop-body>
5479 /// \endcode
5480 bool AfterForeachMacros;
5481 /// If `true`, put a space between function declaration name and opening
5482 /// parentheses.
5483 /// \code
5484 /// true: false:
5485 /// void f (); vs. void f();
5486 /// \endcode
5488 /// If `true`, put a space between function definition name and opening
5489 /// parentheses.
5490 /// \code
5491 /// true: false:
5492 /// void f () {} vs. void f() {}
5493 /// \endcode
5495 /// If `true`, put space between if macros and opening parentheses.
5496 /// \code
5497 /// true: false:
5498 /// IF (...) vs. IF(...)
5499 /// <conditional-body> <conditional-body>
5500 /// \endcode
5501 bool AfterIfMacros;
5502 /// If `true`, put a space between alternative operator `not` and the
5503 /// opening parenthesis.
5504 /// \code
5505 /// true: false:
5506 /// return not (a || b); vs. return not(a || b);
5507 /// \endcode
5508 bool AfterNot;
5509 /// If `true`, put a space between operator overloading and opening
5510 /// parentheses.
5511 /// \code
5512 /// true: false:
5513 /// void operator++ (int a); vs. void operator++(int a);
5514 /// object.operator++ (10); object.operator++(10);
5515 /// \endcode
5517 /// If `true`, put a space between operator `new`/`delete` and opening
5518 /// parenthesis.
5519 /// \code
5520 /// true: false:
5521 /// new (buf) T; vs. new(buf) T;
5522 /// delete (buf) T; delete(buf) T;
5523 /// \endcode
5525 /// If `true`, put space between requires keyword in a requires clause and
5526 /// opening parentheses, if there is one.
5527 /// \code
5528 /// true: false:
5529 /// template<typename T> vs. template<typename T>
5530 /// requires (A<T> && B<T>) requires(A<T> && B<T>)
5531 /// ... ...
5532 /// \endcode
5534 /// If `true`, put space between requires keyword in a requires expression
5535 /// and opening parentheses.
5536 /// \code
5537 /// true: false:
5538 /// template<typename T> vs. template<typename T>
5539 /// concept C = requires (T t) { concept C = requires(T t) {
5540 /// ... ...
5541 /// } }
5542 /// \endcode
5544 /// If `true`, put a space before opening parentheses only if the
5545 /// parentheses are not empty.
5546 /// \code
5547 /// true: false:
5548 /// void f (int a); vs. void f();
5560
5561 bool operator==(const SpaceBeforeParensCustom &Other) const {
5562 return AfterControlStatements == Other.AfterControlStatements &&
5563 AfterForeachMacros == Other.AfterForeachMacros &&
5565 Other.AfterFunctionDeclarationName &&
5566 AfterFunctionDefinitionName == Other.AfterFunctionDefinitionName &&
5567 AfterIfMacros == Other.AfterIfMacros &&
5568 AfterNot == Other.AfterNot &&
5569 AfterOverloadedOperator == Other.AfterOverloadedOperator &&
5570 AfterPlacementOperator == Other.AfterPlacementOperator &&
5571 AfterRequiresInClause == Other.AfterRequiresInClause &&
5572 AfterRequiresInExpression == Other.AfterRequiresInExpression &&
5573 BeforeNonEmptyParentheses == Other.BeforeNonEmptyParentheses;
5574 }
5575 };
5576
5577 /// Control of individual space before parentheses.
5578 ///
5579 /// If `SpaceBeforeParens` is set to `Custom`, use this to specify
5580 /// how each individual space before parentheses case should be handled.
5581 /// Otherwise, this is ignored.
5582 /// \code{.yaml}
5583 /// # Example of usage:
5584 /// SpaceBeforeParens: Custom
5585 /// SpaceBeforeParensOptions:
5586 /// AfterControlStatements: true
5587 /// AfterFunctionDefinitionName: true
5588 /// \endcode
5589 /// \version 14
5591
5592 /// If `true`, spaces will be before `[`.
5593 /// Lambdas will not be affected. Only the first `[` will get a space added.
5594 /// \code
5595 /// true: false:
5596 /// int a [5]; vs. int a[5];
5597 /// int a [5][5]; vs. int a[5][5];
5598 /// \endcode
5599 /// \version 10
5601
5602 /// If `false`, spaces will be removed before range-based for loop
5603 /// colon.
5604 /// \code
5605 /// true: false:
5606 /// for (auto v : values) {} vs. for(auto v: values) {}
5607 /// \endcode
5608 /// \version 7
5610
5611 /// This option is **deprecated**. See `Block` of `SpaceInEmptyBraces`.
5612 /// \version 10
5613 // bool SpaceInEmptyBlock;
5614
5615 /// Style of when to insert a space in empty braces.
5617 /// Always insert a space in empty braces.
5618 /// \code
5619 /// void f() { }
5620 /// class Unit { };
5621 /// auto a = [] { };
5622 /// int x{ };
5623 /// \endcode
5625 /// Only insert a space in empty blocks.
5626 /// \code
5627 /// void f() { }
5628 /// class Unit { };
5629 /// auto a = [] { };
5630 /// int x{};
5631 /// \endcode
5632 SIEB_Block,
5633 /// Never insert a space in empty braces.
5634 /// \code
5635 /// void f() {}
5636 /// class Unit {};
5637 /// auto a = [] {};
5638 /// int x{};
5639 /// \endcode
5641 };
5642
5643 /// Specifies when to insert a space in empty braces.
5644 /// \note
5645 /// This option doesn't apply to initializer braces if
5646 /// `Cpp11BracedListStyle` is not `Block`.
5647 /// \endnote
5648 /// \version 22
5650
5651 /// If `true`, spaces may be inserted into `()`.
5652 /// This option is **deprecated**. See `InEmptyParentheses` of
5653 /// `SpacesInParensOptions`.
5654 /// \version 3.7
5655 // bool SpaceInEmptyParentheses;
5656
5657 /// The number of spaces before trailing line comments
5658 /// (`//` - comments).
5659 ///
5660 /// This does not affect trailing block comments (`/*` - comments) as those
5661 /// commonly have different usage patterns and a number of special cases. In
5662 /// the case of Verilog, it doesn't affect a comment right after the opening
5663 /// parenthesis in the port or parameter list in a module header, because it
5664 /// is probably for the port on the following line instead of the parenthesis
5665 /// it follows.
5666 /// \code
5667 /// SpacesBeforeTrailingComments: 3
5668 /// void f() {
5669 /// if (true) { // foo1
5670 /// f(); // bar
5671 /// } // foo
5672 /// }
5673 /// \endcode
5674 /// \version 3.7
5676
5677 /// Styles for adding spacing after `<` and before `>`
5678 /// in template argument lists.
5680 /// Remove spaces after `<` and before `>`.
5681 /// \code
5682 /// static_cast<int>(arg);
5683 /// std::function<void(int)> fct;
5684 /// \endcode
5685 SIAS_Never,
5686 /// Add spaces after `<` and before `>`.
5687 /// \code
5688 /// static_cast< int >(arg);
5689 /// std::function< void(int) > fct;
5690 /// \endcode
5692 /// Keep a single space after `<` and before `>` if any spaces were
5693 /// present. Option `Standard: Cpp03` takes precedence.
5695 };
5696 /// The SpacesInAnglesStyle to use for template argument lists.
5697 /// \version 3.4
5699
5700 /// Styles for controlling spacing after `/*` and before `*/` in block
5701 /// comments.
5703 /// Remove spaces after `/*` and before `*/`.
5704 /// \code
5705 /// /*comment*/
5706 /// \endcode
5708 /// Add spaces after `/*` and before `*/`.
5709 /// \code
5710 /// /* comment */
5711 /// \endcode
5713 /// Leave existing spaces unchanged.
5716
5717 /// The SpacesInBlockCommentsStyle to use for ordinary block comments.
5718 /// Documentation comments such as `/** ... */` and `/*! ... */`
5719 /// and parameter comments ending with `=` before the closing `*/` are
5720 /// left unchanged.
5721 /// \version 24
5722 SpacesInBlockCommentsStyle SpacesInBlockComments;
5723
5724 /// If `true`, spaces will be inserted around if/for/switch/while
5725 /// conditions.
5726 /// This option is **deprecated**. See `InConditionalStatements` of
5727 /// `SpacesInParensOptions`.
5728 /// \version 10
5729 // bool SpacesInConditionalStatement;
5730
5731 /// If `true`, spaces are inserted inside container literals (e.g. ObjC and
5732 /// Javascript array and dict literals). For JSON, use
5733 /// `SpaceBeforeJsonColon` instead.
5734 /// \code{.js}
5735 /// true: false:
5736 /// var arr = [ 1, 2, 3 ]; vs. var arr = [1, 2, 3];
5737 /// f({a : 1, b : 2, c : 3}); f({a: 1, b: 2, c: 3});
5738 /// \endcode
5739 /// \version 3.7
5741
5742 /// If `true`, spaces may be inserted into C style casts.
5743 /// This option is **deprecated**. See `InCStyleCasts` of
5744 /// `SpacesInParensOptions`.
5745 /// \version 3.7
5746 // bool SpacesInCStyleCastParentheses;
5748 /// Control of spaces within a single line comment.
5750 /// The minimum number of spaces at the start of the comment.
5751 unsigned Minimum;
5752 /// The maximum number of spaces at the start of the comment.
5753 unsigned Maximum;
5754 };
5755
5756 /// How many spaces are allowed at the start of a line comment. To disable the
5757 /// maximum set it to `-1`, apart from that the maximum takes precedence
5758 /// over the minimum.
5759 /// \code
5760 /// Minimum = 1
5761 /// Maximum = -1
5762 /// // One space is forced
5763 ///
5764 /// // but more spaces are possible
5765 ///
5766 /// Minimum = 0
5767 /// Maximum = 0
5768 /// //Forces to start every comment directly after the slashes
5769 /// \endcode
5770 ///
5771 /// Note that in line comment sections the relative indent of the subsequent
5772 /// lines is kept, that means the following:
5773 /// \code
5774 /// before: after:
5775 /// Minimum: 1
5776 /// //if (b) { // if (b) {
5777 /// // return true; // return true;
5778 /// //} // }
5779 ///
5780 /// Maximum: 0
5781 /// /// List: ///List:
5782 /// /// - Foo /// - Foo
5783 /// /// - Bar /// - Bar
5784 /// \endcode
5785 ///
5786 /// This option has only effect if `ReflowComments` is set to `true`.
5787 /// \version 13
5789
5790 /// Different ways to put a space before opening and closing parentheses.
5792 /// Never put a space in parentheses.
5793 /// \code
5794 /// void f() {
5795 /// if(true) {
5796 /// f();
5797 /// }
5798 /// }
5799 /// \endcode
5800 SIPO_Never,
5801 /// Configure each individual space in parentheses in
5802 /// `SpacesInParensOptions`.
5804 };
5805
5806 /// If `true`, spaces will be inserted after `(` and before `)`.
5807 /// This option is **deprecated**. The previous behavior is preserved by using
5808 /// `SpacesInParens` with `Custom` and by setting all
5809 /// `SpacesInParensOptions` to `true` except for `InCStyleCasts` and
5810 /// `InEmptyParentheses`.
5811 /// \version 3.7
5812 // bool SpacesInParentheses;
5814 /// Defines in which cases spaces will be inserted after `(` and before
5815 /// `)`.
5816 /// \version 17
5818
5819 /// Precise control over the spacing in parentheses.
5820 /// \code{.yaml}
5821 /// # Should be declared this way:
5822 /// SpacesInParens: Custom
5823 /// SpacesInParensOptions:
5824 /// ExceptDoubleParentheses: false
5825 /// InConditionalStatements: true
5826 /// Other: true
5827 /// \endcode
5828 struct SpacesInParensCustom {
5829 /// Override any of the following options to prevent addition of space
5830 /// when both opening and closing parentheses use multiple parentheses.
5831 /// \code
5832 /// true:
5833 /// __attribute__(( noreturn ))
5834 /// __decltype__(( x ))
5835 /// if (( a = b ))
5836 /// \endcode
5837 /// false:
5838 /// Uses the applicable option.
5840 /// Put a space in parentheses only inside conditional statements
5841 /// (`for/if/while/switch...`).
5842 /// \code
5843 /// true: false:
5844 /// if ( a ) { ... } vs. if (a) { ... }
5845 /// while ( i < 5 ) { ... } while (i < 5) { ... }
5846 /// \endcode
5848 /// Put a space in C style casts.
5849 /// \code
5850 /// true: false:
5851 /// x = ( int32 )y vs. x = (int32)y
5852 /// y = (( int (*)(int) )foo)(x); y = ((int (*)(int))foo)(x);
5853 /// \endcode
5854 bool InCStyleCasts;
5855 /// Insert a space in empty parentheses, i.e. `()`.
5856 /// \code
5857 /// true: false:
5858 /// void f( ) { vs. void f() {
5859 /// int x[] = {foo( ), bar( )}; int x[] = {foo(), bar()};
5860 /// if (true) { if (true) {
5861 /// f( ); f();
5862 /// } }
5863 /// } }
5864 /// \endcode
5865 bool InEmptyParentheses;
5866 /// Put a space in parentheses not covered by preceding options.
5867 /// \code
5868 /// true: false:
5869 /// t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete;
5870 /// \endcode
5871 bool Other;
5872
5887 InConditionalStatements == R.InConditionalStatements &&
5888 InCStyleCasts == R.InCStyleCasts &&
5889 InEmptyParentheses == R.InEmptyParentheses && Other == R.Other;
5890 }
5891 bool operator!=(const SpacesInParensCustom &R) const {
5892 return !(*this == R);
5893 }
5894 };
5895
5896 /// Control of individual spaces in parentheses.
5897 ///
5898 /// If `SpacesInParens` is set to `Custom`, use this to specify
5899 /// how each individual space in parentheses case should be handled.
5900 /// Otherwise, this is ignored.
5901 /// \code{.yaml}
5902 /// # Example of usage:
5903 /// SpacesInParens: Custom
5904 /// SpacesInParensOptions:
5905 /// ExceptDoubleParentheses: false
5906 /// InConditionalStatements: true
5907 /// InEmptyParentheses: true
5908 /// \endcode
5909 /// \version 17
5911
5912 /// If `true`, spaces will be inserted after `[` and before `]`.
5913 /// Lambdas without arguments or unspecified size array declarations will not
5914 /// be affected.
5915 /// \code
5916 /// true: false:
5917 /// int a[ 5 ]; vs. int a[5];
5918 /// std::unique_ptr<int[]> foo() {} // Won't be affected
5919 /// \endcode
5920 /// \version 3.7
5922
5923 /// Supported language standards for parsing and formatting C++ constructs.
5924 /// \code
5925 /// Latest: vector<set<int>>
5926 /// c++03 vs. vector<set<int> >
5927 /// \endcode
5928 ///
5929 /// The correct way to spell a specific language version is e.g. `c++11`.
5930 /// The historical aliases `Cpp03` and `Cpp11` are deprecated.
5931 enum LanguageStandard : int8_t {
5932 /// Parse and format as C++03.
5933 /// `Cpp03` is a deprecated alias for `c++03`
5934 LS_Cpp03, // c++03
5935 /// Parse and format as C++11.
5936 LS_Cpp11, // c++11
5937 /// Parse and format as C++14.
5938 LS_Cpp14, // c++14
5939 /// Parse and format as C++17.
5940 LS_Cpp17, // c++17
5941 /// Parse and format as C++20.
5942 LS_Cpp20, // c++20
5943 /// Parse and format as C++23.
5944 LS_Cpp23, // c++23
5945 /// Parse and format as C++26.
5946 LS_Cpp26, // c++26
5947 /// Parse and format using the latest supported language version.
5948 /// `Cpp11` is a deprecated alias for `Latest`
5949 LS_Latest,
5950 /// Automatic detection based on the input.
5951 LS_Auto,
5952 };
5953
5954 /// Parse and format C++ constructs compatible with this standard.
5955 /// \code
5956 /// c++03: latest:
5957 /// vector<set<int> > x; vs. vector<set<int>> x;
5958 /// \endcode
5959 /// \version 3.7
5961
5962 /// Macros which are ignored in front of a statement, as if they were an
5963 /// attribute. So that they are not parsed as identifier, for example for Qts
5964 /// emit.
5965 /// \code
5966 /// AlignConsecutiveDeclarations: true
5967 /// StatementAttributeLikeMacros: []
5968 /// unsigned char data = 'x';
5969 /// emit signal(data); // This is parsed as variable declaration.
5970 ///
5971 /// AlignConsecutiveDeclarations: true
5972 /// StatementAttributeLikeMacros: [emit]
5973 /// unsigned char data = 'x';
5974 /// emit signal(data); // Now it's fine again.
5975 /// \endcode
5976 /// \version 12
5977 std::vector<std::string> StatementAttributeLikeMacros;
5978
5979 /// A vector of macros that should be interpreted as complete statements.
5980 ///
5981 /// Typical macros are expressions and require a semicolon to be added.
5982 /// Sometimes this is not the case, and this allows to make clang-format aware
5983 /// of such cases.
5984 ///
5985 /// For example: Q_UNUSED
5986 /// \version 8
5987 std::vector<std::string> StatementMacros;
5988
5989 /// Works only when TableGenBreakInsideDAGArg is not DontBreak.
5990 /// The string list needs to consist of identifiers in TableGen.
5991 /// If any identifier is specified, this limits the line breaks by
5992 /// TableGenBreakInsideDAGArg option only on DAGArg values beginning with
5993 /// the specified identifiers.
5994 ///
5995 /// For example the configuration,
5996 /// \code{.yaml}
5997 /// TableGenBreakInsideDAGArg: BreakAll
5998 /// TableGenBreakingDAGArgOperators: [ins, outs]
5999 /// \endcode
6000 ///
6001 /// makes the line break only occurs inside DAGArgs beginning with the
6002 /// specified identifiers `ins` and `outs`.
6003 ///
6004 /// \code
6005 /// let DAGArgIns = (ins
6006 /// i32:$src1,
6007 /// i32:$src2
6008 /// );
6009 /// let DAGArgOtherID = (other i32:$other1, i32:$other2);
6010 /// let DAGArgBang = (!cast<SomeType>("Some") i32:$src1, i32:$src2)
6011 /// \endcode
6012 /// \version 19
6013 std::vector<std::string> TableGenBreakingDAGArgOperators;
6014
6015 /// Different ways to control the format inside TableGen DAGArg.
6016 enum DAGArgStyle : int8_t {
6017 /// Never break inside DAGArg.
6018 /// \code
6019 /// let DAGArgIns = (ins i32:$src1, i32:$src2);
6020 /// \endcode
6022 /// Break inside DAGArg after each list element but for the last.
6023 /// This aligns to the first element.
6024 /// \code
6025 /// let DAGArgIns = (ins i32:$src1,
6026 /// i32:$src2);
6027 /// \endcode
6029 /// Break inside DAGArg after the operator and the all elements.
6030 /// \code
6031 /// let DAGArgIns = (ins
6032 /// i32:$src1,
6033 /// i32:$src2
6034 /// );
6035 /// \endcode
6038
6039 /// The styles of the line break inside the DAGArg in TableGen.
6040 /// \version 19
6042
6043 /// The number of columns used for tab stops.
6044 /// \version 3.7
6045 unsigned TabWidth;
6046
6047 /// A vector of non-keyword identifiers that should be interpreted as template
6048 /// names.
6049 ///
6050 /// A `<` after a template name is annotated as a template opener instead of
6051 /// a binary operator.
6052 ///
6053 /// \version 20
6054 std::vector<std::string> TemplateNames;
6055
6056 /// A vector of non-keyword identifiers that should be interpreted as type
6057 /// names.
6058 ///
6059 /// A `*`, `&`, or `&&` between a type name and another non-keyword
6060 /// identifier is annotated as a pointer or reference token instead of a
6061 /// binary operator.
6062 ///
6063 /// \version 17
6064 std::vector<std::string> TypeNames;
6065
6066 /// A vector of macros that should be interpreted as type declarations instead
6067 /// of as function calls.
6068 ///
6069 /// These are expected to be macros of the form:
6070 /// \code
6071 /// STACK_OF(...)
6072 /// \endcode
6073 ///
6074 /// In the .clang-format configuration file, this can be configured like:
6075 /// \code{.yaml}
6076 /// TypenameMacros: [STACK_OF, LIST]
6077 /// \endcode
6078 ///
6079 /// For example: OpenSSL STACK_OF, BSD LIST_ENTRY.
6080 /// \version 9
6081 std::vector<std::string> TypenameMacros;
6082
6083 /// This option is **deprecated**. See `LF` and `CRLF` of `LineEnding`.
6084 /// \version 10
6085 // bool UseCRLF;
6087 /// Different ways to use tab in formatting.
6089 /// Never use tab.
6090 UT_Never,
6091 /// Use tabs only for indentation.
6093 /// Fill all leading whitespace with tabs, and use spaces for alignment that
6094 /// appears within a line (e.g. consecutive assignments and declarations).
6096 /// Use tabs for line continuation and indentation, and spaces for
6097 /// alignment.
6099 /// Use tabs whenever we need to fill whitespace that spans at least from
6100 /// one tab stop to the next one.
6101 UT_Always
6103
6104 /// The way to use tab characters in the resulting file.
6105 /// \version 3.7
6106 UseTabStyle UseTab;
6107
6108 /// A vector of non-keyword identifiers that should be interpreted as variable
6109 /// template names.
6110 ///
6111 /// A `)` after a variable template instantiation is **not** annotated as
6112 /// the closing parenthesis of C-style cast operator.
6113 ///
6114 /// \version 20
6115 std::vector<std::string> VariableTemplates;
6116
6117 /// For Verilog, put each port on its own line in module instantiations.
6118 /// \code
6119 /// true:
6120 /// ffnand ff1(.q(),
6121 /// .qbar(out1),
6122 /// .clear(in1),
6123 /// .preset(in2));
6124 ///
6125 /// false:
6126 /// ffnand ff1(.q(), .qbar(out1), .clear(in1), .preset(in2));
6127 /// \endcode
6128 /// \version 17
6130
6131 /// A vector of macros which are whitespace-sensitive and should not
6132 /// be touched.
6133 ///
6134 /// These are expected to be macros of the form:
6135 /// \code
6136 /// STRINGIZE(...)
6137 /// \endcode
6138 ///
6139 /// In the .clang-format configuration file, this can be configured like:
6140 /// \code{.yaml}
6141 /// WhitespaceSensitiveMacros: [STRINGIZE, PP_STRINGIZE]
6142 /// \endcode
6143 ///
6144 /// For example: BOOST_PP_STRINGIZE
6145 /// \version 11
6146 std::vector<std::string> WhitespaceSensitiveMacros;
6147
6148 /// Different styles for wrapping namespace body with empty lines.
6150 /// Remove all empty lines at the beginning and the end of namespace body.
6151 /// \code
6152 /// namespace N1 {
6153 /// namespace N2 {
6154 /// function();
6155 /// }
6156 /// }
6157 /// \endcode
6159 /// Always have at least one empty line at the beginning and the end of
6160 /// namespace body except that the number of empty lines between consecutive
6161 /// nested namespace definitions is not increased.
6162 /// \code
6163 /// namespace N1 {
6164 /// namespace N2 {
6165 ///
6166 /// function();
6167 ///
6168 /// }
6169 /// }
6170 /// \endcode
6172 /// Keep existing newlines at the beginning and the end of namespace body.
6173 /// `MaxEmptyLinesToKeep` still applies.
6176
6177 /// Wrap namespace body with empty lines.
6178 /// \version 20
6180
6181 bool operator==(const FormatStyle &R) const {
6182 return AccessModifierOffset == R.AccessModifierOffset &&
6183 AlignAfterOpenBracket == R.AlignAfterOpenBracket &&
6184 AlignArrayOfStructures == R.AlignArrayOfStructures &&
6185 AlignConsecutiveAssignments == R.AlignConsecutiveAssignments &&
6186 AlignConsecutiveBitFields == R.AlignConsecutiveBitFields &&
6187 AlignConsecutiveDeclarations == R.AlignConsecutiveDeclarations &&
6188 AlignConsecutiveMacros == R.AlignConsecutiveMacros &&
6190 R.AlignConsecutiveShortCaseStatements &&
6192 R.AlignConsecutiveTableGenBreakingDAGArgColons &&
6194 R.AlignConsecutiveTableGenCondOperatorColons &&
6196 R.AlignConsecutiveTableGenDefinitionColons &&
6197 AlignEscapedNewlines == R.AlignEscapedNewlines &&
6198 AlignOperands == R.AlignOperands &&
6199 AlignTrailingComments == R.AlignTrailingComments &&
6200 AllowAllArgumentsOnNextLine == R.AllowAllArgumentsOnNextLine &&
6202 R.AllowAllParametersOfDeclarationOnNextLine &&
6204 R.AllowBreakBeforeNoexceptSpecifier &&
6205 AllowBreakBeforeQtProperty == R.AllowBreakBeforeQtProperty &&
6206 AllowShortBlocksOnASingleLine == R.AllowShortBlocksOnASingleLine &&
6208 R.AllowShortCaseExpressionOnASingleLine &&
6210 R.AllowShortCaseLabelsOnASingleLine &&
6212 R.AllowShortCompoundRequirementOnASingleLine &&
6213 AllowShortEnumsOnASingleLine == R.AllowShortEnumsOnASingleLine &&
6215 R.AllowShortFunctionsOnASingleLine &&
6217 R.AllowShortIfStatementsOnASingleLine &&
6218 AllowShortLambdasOnASingleLine == R.AllowShortLambdasOnASingleLine &&
6219 AllowShortLoopsOnASingleLine == R.AllowShortLoopsOnASingleLine &&
6221 R.AllowShortNamespacesOnASingleLine &&
6222 AllowShortRecordOnASingleLine == R.AllowShortRecordOnASingleLine &&
6224 R.AlwaysBreakBeforeMultilineStrings &&
6225 AttributeMacros == R.AttributeMacros &&
6226 BinPackLongBracedList == R.BinPackLongBracedList &&
6227 BitFieldColonSpacing == R.BitFieldColonSpacing &&
6228 BracedInitializerIndentWidth == R.BracedInitializerIndentWidth &&
6229 BreakAdjacentStringLiterals == R.BreakAdjacentStringLiterals &&
6230 BreakAfterAttributes == R.BreakAfterAttributes &&
6231 BreakAfterJavaFieldAnnotations == R.BreakAfterJavaFieldAnnotations &&
6233 R.BreakAfterOpenBracketBracedList &&
6234 BreakAfterOpenBracketFunction == R.BreakAfterOpenBracketFunction &&
6235 BreakAfterOpenBracketIf == R.BreakAfterOpenBracketIf &&
6236 BreakAfterOpenBracketLoop == R.BreakAfterOpenBracketLoop &&
6237 BreakAfterOpenBracketSwitch == R.BreakAfterOpenBracketSwitch &&
6238 BreakAfterReturnType == R.BreakAfterReturnType &&
6239 BreakArrays == R.BreakArrays &&
6240 BreakBeforeBinaryOperators == R.BreakBeforeBinaryOperators &&
6241 BreakBeforeBraces == R.BreakBeforeBraces &&
6243 R.BreakBeforeCloseBracketBracedList &&
6245 R.BreakBeforeCloseBracketFunction &&
6246 BreakBeforeCloseBracketIf == R.BreakBeforeCloseBracketIf &&
6247 BreakBeforeCloseBracketLoop == R.BreakBeforeCloseBracketLoop &&
6248 BreakBeforeCloseBracketSwitch == R.BreakBeforeCloseBracketSwitch &&
6249 BreakBeforeConceptDeclarations == R.BreakBeforeConceptDeclarations &&
6250 BreakBeforeInlineASMColon == R.BreakBeforeInlineASMColon &&
6251 BreakBeforeReturnType == R.BreakBeforeReturnType &&
6252 BreakBeforeTemplateCloser == R.BreakBeforeTemplateCloser &&
6253 BreakBeforeTernaryOperators == R.BreakBeforeTernaryOperators &&
6254 BreakBinaryOperations == R.BreakBinaryOperations &&
6255 BreakConstructorInitializers == R.BreakConstructorInitializers &&
6257 R.BreakFunctionDeclarationParameters &&
6259 R.BreakFunctionDefinitionParameters &&
6260 BreakInheritanceList == R.BreakInheritanceList &&
6261 BreakStringLiterals == R.BreakStringLiterals &&
6262 BreakTemplateDeclarations == R.BreakTemplateDeclarations &&
6263 ColumnLimit == R.ColumnLimit && CommentPragmas == R.CommentPragmas &&
6264 CompactCaseLabels == R.CompactCaseLabels &&
6265 CompactNamespaces == R.CompactNamespaces &&
6267 R.ConstructorInitializerIndentWidth &&
6268 ContinuationIndentWidth == R.ContinuationIndentWidth &&
6269 Cpp11BracedListStyle == R.Cpp11BracedListStyle &&
6270 DerivePointerAlignment == R.DerivePointerAlignment &&
6271 DisableFormat == R.DisableFormat &&
6272 EmptyLineAfterAccessModifier == R.EmptyLineAfterAccessModifier &&
6273 EmptyLineBeforeAccessModifier == R.EmptyLineBeforeAccessModifier &&
6274 EnumTrailingComma == R.EnumTrailingComma &&
6276 R.ExperimentalAutoDetectBinPacking &&
6277 FixNamespaceComments == R.FixNamespaceComments &&
6278 ForEachMacros == R.ForEachMacros &&
6279 IncludeStyle.IncludeBlocks == R.IncludeStyle.IncludeBlocks &&
6280 IncludeStyle.IncludeCategories == R.IncludeStyle.IncludeCategories &&
6281 IncludeStyle.IncludeIsMainRegex ==
6282 R.IncludeStyle.IncludeIsMainRegex &&
6283 IncludeStyle.IncludeIsMainSourceRegex ==
6284 R.IncludeStyle.IncludeIsMainSourceRegex &&
6285 IncludeStyle.MainIncludeChar == R.IncludeStyle.MainIncludeChar &&
6286 IndentAccessModifiers == R.IndentAccessModifiers &&
6287 IndentCaseBlocks == R.IndentCaseBlocks &&
6288 IndentCaseLabels == R.IndentCaseLabels &&
6289 IndentExportBlock == R.IndentExportBlock &&
6290 IndentExternBlock == R.IndentExternBlock &&
6291 IndentGotoLabels == R.IndentGotoLabels &&
6292 IndentPPDirectives == R.IndentPPDirectives &&
6293 IndentRequiresClause == R.IndentRequiresClause &&
6294 IndentWidth == R.IndentWidth &&
6295 IndentWrappedFunctionNames == R.IndentWrappedFunctionNames &&
6296 InsertBraces == R.InsertBraces &&
6297 InsertNewlineAtEOF == R.InsertNewlineAtEOF &&
6298 IntegerLiteralSeparator == R.IntegerLiteralSeparator &&
6299 JavaImportGroups == R.JavaImportGroups &&
6300 JavaScriptQuotes == R.JavaScriptQuotes &&
6301 JavaScriptWrapImports == R.JavaScriptWrapImports &&
6302 KeepEmptyLines == R.KeepEmptyLines &&
6303 KeepFormFeed == R.KeepFormFeed && Language == R.Language &&
6304 LambdaBodyIndentation == R.LambdaBodyIndentation &&
6305 LineEnding == R.LineEnding && MacroBlockBegin == R.MacroBlockBegin &&
6306 MacroBlockEnd == R.MacroBlockEnd && Macros == R.Macros &&
6308 R.MacrosSkippedByRemoveParentheses &&
6309 MaxEmptyLinesToKeep == R.MaxEmptyLinesToKeep &&
6310 NamespaceIndentation == R.NamespaceIndentation &&
6311 NamespaceMacros == R.NamespaceMacros &&
6312 NumericLiteralCase == R.NumericLiteralCase &&
6313 ObjCBinPackProtocolList == R.ObjCBinPackProtocolList &&
6314 ObjCBlockIndentWidth == R.ObjCBlockIndentWidth &&
6316 R.ObjCBreakBeforeNestedBlockParam &&
6317 ObjCPropertyAttributeOrder == R.ObjCPropertyAttributeOrder &&
6319 R.ObjCSpaceAfterMethodDeclarationPrefix &&
6320 ObjCSpaceAfterProperty == R.ObjCSpaceAfterProperty &&
6321 ObjCSpaceBeforeProtocolList == R.ObjCSpaceBeforeProtocolList &&
6322 OneLineFormatOffRegex == R.OneLineFormatOffRegex &&
6323 PackArguments == R.PackArguments &&
6324 PackConstructorInitializers == R.PackConstructorInitializers &&
6325 PackParameters == R.PackParameters &&
6326 PenaltyBreakAssignment == R.PenaltyBreakAssignment &&
6328 R.PenaltyBreakBeforeFirstCallParameter &&
6329 PenaltyBreakBeforeMemberAccess == R.PenaltyBreakBeforeMemberAccess &&
6330 PenaltyBreakComment == R.PenaltyBreakComment &&
6331 PenaltyBreakFirstLessLess == R.PenaltyBreakFirstLessLess &&
6332 PenaltyBreakOpenParenthesis == R.PenaltyBreakOpenParenthesis &&
6333 PenaltyBreakScopeResolution == R.PenaltyBreakScopeResolution &&
6334 PenaltyBreakString == R.PenaltyBreakString &&
6336 R.PenaltyBreakTemplateDeclaration &&
6337 PenaltyExcessCharacter == R.PenaltyExcessCharacter &&
6338 PenaltyReturnTypeOnItsOwnLine == R.PenaltyReturnTypeOnItsOwnLine &&
6339 PointerAlignment == R.PointerAlignment &&
6340 QualifierAlignment == R.QualifierAlignment &&
6341 QualifierOrder == R.QualifierOrder &&
6342 RawStringFormats == R.RawStringFormats &&
6343 ReferenceAlignment == R.ReferenceAlignment &&
6344 RemoveBracesLLVM == R.RemoveBracesLLVM &&
6346 R.RemoveEmptyLinesInUnwrappedLines &&
6347 RemoveParentheses == R.RemoveParentheses &&
6348 RemoveSemicolon == R.RemoveSemicolon &&
6349 RequiresClausePosition == R.RequiresClausePosition &&
6350 RequiresExpressionIndentation == R.RequiresExpressionIndentation &&
6351 SeparateDefinitionBlocks == R.SeparateDefinitionBlocks &&
6352 ShortNamespaceLines == R.ShortNamespaceLines &&
6353 SkipMacroDefinitionBody == R.SkipMacroDefinitionBody &&
6354 SortIncludes == R.SortIncludes &&
6355 SortJavaStaticImport == R.SortJavaStaticImport &&
6356 SpaceAfterCStyleCast == R.SpaceAfterCStyleCast &&
6357 SpaceAfterLogicalNot == R.SpaceAfterLogicalNot &&
6358 SpaceAfterOperatorKeyword == R.SpaceAfterOperatorKeyword &&
6359 SpaceAfterTemplateKeyword == R.SpaceAfterTemplateKeyword &&
6360 SpaceBeforeAssignmentOperators == R.SpaceBeforeAssignmentOperators &&
6361 SpaceBeforeCaseColon == R.SpaceBeforeCaseColon &&
6362 SpaceBeforeCpp11BracedList == R.SpaceBeforeCpp11BracedList &&
6364 R.SpaceBeforeCtorInitializerColon &&
6365 SpaceBeforeInheritanceColon == R.SpaceBeforeInheritanceColon &&
6366 SpaceBeforeJsonColon == R.SpaceBeforeJsonColon &&
6367 SpaceBeforeParens == R.SpaceBeforeParens &&
6368 SpaceBeforeParensOptions == R.SpaceBeforeParensOptions &&
6369 SpaceAroundPointerQualifiers == R.SpaceAroundPointerQualifiers &&
6371 R.SpaceBeforeRangeBasedForLoopColon &&
6372 SpaceBeforeSquareBrackets == R.SpaceBeforeSquareBrackets &&
6373 SpaceInEmptyBraces == R.SpaceInEmptyBraces &&
6374 SpacesBeforeTrailingComments == R.SpacesBeforeTrailingComments &&
6375 SpacesInAngles == R.SpacesInAngles &&
6376 SpacesInBlockComments == R.SpacesInBlockComments &&
6377 SpacesInContainerLiterals == R.SpacesInContainerLiterals &&
6378 SpacesInLineCommentPrefix.Minimum ==
6379 R.SpacesInLineCommentPrefix.Minimum &&
6380 SpacesInLineCommentPrefix.Maximum ==
6381 R.SpacesInLineCommentPrefix.Maximum &&
6382 SpacesInParens == R.SpacesInParens &&
6383 SpacesInParensOptions == R.SpacesInParensOptions &&
6384 SpacesInSquareBrackets == R.SpacesInSquareBrackets &&
6385 Standard == R.Standard &&
6386 StatementAttributeLikeMacros == R.StatementAttributeLikeMacros &&
6387 StatementMacros == R.StatementMacros &&
6389 R.TableGenBreakingDAGArgOperators &&
6390 TableGenBreakInsideDAGArg == R.TableGenBreakInsideDAGArg &&
6391 TabWidth == R.TabWidth && TemplateNames == R.TemplateNames &&
6392 TypeNames == R.TypeNames && TypenameMacros == R.TypenameMacros &&
6393 UseTab == R.UseTab && VariableTemplates == R.VariableTemplates &&
6395 R.VerilogBreakBetweenInstancePorts &&
6396 WhitespaceSensitiveMacros == R.WhitespaceSensitiveMacros &&
6397 WrapNamespaceBodyWithEmptyLines == R.WrapNamespaceBodyWithEmptyLines;
6398 }
6399
6400 std::optional<FormatStyle> GetLanguageStyle(LanguageKind Language) const;
6401
6402 // Stores per-language styles. A FormatStyle instance inside has an empty
6403 // StyleSet. A FormatStyle instance returned by the Get method has its
6404 // StyleSet set to a copy of the originating StyleSet, effectively keeping the
6405 // internal representation of that StyleSet alive.
6407 // The memory management and ownership reminds of a birds nest: chicks
6408 // leaving the nest take photos of the nest with them.
6409 struct FormatStyleSet {
6410 typedef std::map<LanguageKind, FormatStyle> MapType;
6411
6412 std::optional<FormatStyle> Get(LanguageKind Language) const;
6413
6414 // Adds \p Style to this FormatStyleSet. Style must not have an associated
6415 // FormatStyleSet.
6416 // Style.Language should be different than LK_None. If this FormatStyleSet
6417 // already contains an entry for Style.Language, that gets replaced with the
6418 // passed Style.
6419 void Add(FormatStyle Style);
6420
6421 // Clears this FormatStyleSet.
6422 void Clear();
6423
6424 private:
6425 std::shared_ptr<MapType> Styles;
6426 };
6427
6428 static FormatStyleSet BuildStyleSetFromConfiguration(
6429 const FormatStyle &MainStyle,
6430 const std::vector<FormatStyle> &ConfigurationStyles);
6431
6432private:
6433 FormatStyleSet StyleSet;
6434
6435 friend std::error_code
6436 parseConfiguration(llvm::MemoryBufferRef Config, FormatStyle *Style,
6437 bool AllowUnknownOptions,
6438 llvm::SourceMgr::DiagHandlerTy DiagHandler,
6439 void *DiagHandlerCtxt, bool IsDotHFile);
6440};
6441
6442/// Returns a format style complying with the LLVM coding standards:
6443/// http://llvm.org/docs/CodingStandards.html.
6446
6447/// Returns a format style complying with one of Google's style guides:
6448/// http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml.
6449/// http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml.
6450/// https://developers.google.com/protocol-buffers/docs/style.
6452
6453/// Returns a format style complying with Chromium's style guide:
6454/// http://www.chromium.org/developers/coding-style.
6456
6457/// Returns a format style complying with Mozilla's style guide:
6458/// https://firefox-source-docs.mozilla.org/code-quality/coding-style/index.html.
6460
6461/// Returns a format style complying with Webkit's style guide:
6462/// http://www.webkit.org/coding/coding-style.html
6464
6465/// Returns a format style complying with GNU Coding Standards:
6466/// http://www.gnu.org/prep/standards/standards.html
6468
6469/// Returns a format style complying with Microsoft style guide:
6470/// https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017
6472
6474
6475/// Returns style indicating formatting should be not applied at all.
6477
6478/// Gets a predefined style for the specified language by name.
6479///
6480/// Currently supported names: LLVM, Google, Chromium, Mozilla. Names are
6481/// compared case-insensitively.
6482///
6483/// Returns `true` if the Style has been set.
6485 FormatStyle *Style);
6486
6487/// Parse configuration from YAML-formatted text.
6488///
6489/// Style->Language is used to get the base style, if the `BasedOnStyle`
6490/// option is present.
6491///
6492/// The FormatStyleSet of Style is reset.
6493///
6494/// When `BasedOnStyle` is not present, options not present in the YAML
6495/// document, are retained in \p Style.
6496///
6497/// If AllowUnknownOptions is true, no errors are emitted if unknown
6498/// format options are occurred.
6499///
6500/// If set all diagnostics are emitted through the DiagHandler.
6501std::error_code
6502parseConfiguration(llvm::MemoryBufferRef Config, FormatStyle *Style,
6503 bool AllowUnknownOptions = false,
6504 llvm::SourceMgr::DiagHandlerTy DiagHandler = nullptr,
6505 void *DiagHandlerCtx = nullptr, bool IsDotHFile = false);
6506
6507/// Like above but accepts an unnamed buffer.
6508inline std::error_code parseConfiguration(StringRef Config, FormatStyle *Style,
6509 bool AllowUnknownOptions = false,
6510 bool IsDotHFile = false) {
6511 return parseConfiguration(llvm::MemoryBufferRef(Config, "YAML"), Style,
6512 AllowUnknownOptions, /*DiagHandler=*/nullptr,
6513 /*DiagHandlerCtx=*/nullptr, IsDotHFile);
6514}
6515
6516/// Gets configuration in a YAML string.
6517std::string configurationAsText(const FormatStyle &Style);
6518
6519/// Returns the replacements necessary to sort all `#include` blocks
6520/// that are affected by `Ranges`.
6521tooling::Replacements sortIncludes(const FormatStyle &Style, StringRef Code,
6523 StringRef FileName,
6524 unsigned *Cursor = nullptr);
6525
6526/// Returns the replacements corresponding to applying and formatting
6527/// \p Replaces on success; otheriwse, return an llvm::Error carrying
6528/// llvm::StringError.
6530formatReplacements(StringRef Code, const tooling::Replacements &Replaces,
6531 const FormatStyle &Style);
6532
6533/// Returns the replacements corresponding to applying \p Replaces and
6534/// cleaning up the code after that on success; otherwise, return an llvm::Error
6535/// carrying llvm::StringError.
6536/// This also supports inserting/deleting C++ #include directives:
6537/// * If a replacement has offset UINT_MAX, length 0, and a replacement text
6538/// that is an #include directive, this will insert the #include into the
6539/// correct block in the \p Code.
6540/// * If a replacement has offset UINT_MAX, length 1, and a replacement text
6541/// that is the name of the header to be removed, the header will be removed
6542/// from \p Code if it exists.
6543/// The include manipulation is done via `tooling::HeaderInclude`, see its
6544/// documentation for more details on how include insertion points are found and
6545/// what edits are produced.
6547cleanupAroundReplacements(StringRef Code, const tooling::Replacements &Replaces,
6548 const FormatStyle &Style);
6549
6550/// Represents the status of a formatting attempt.
6552 /// A value of `false` means that any of the affected ranges were not
6553 /// formatted due to a non-recoverable syntax error.
6554 bool FormatComplete = true;
6555
6556 /// If `FormatComplete` is false, `Line` records a one-based
6557 /// original line number at which a syntax error might have occurred. This is
6558 /// based on a best-effort analysis and could be imprecise.
6559 unsigned Line = 0;
6560};
6561
6562/// Reformats the given \p Ranges in \p Code.
6563///
6564/// Each range is extended on either end to its next bigger logic unit, i.e.
6565/// everything that might influence its formatting or might be influenced by its
6566/// formatting.
6567///
6568/// Returns the `Replacements` necessary to make all \p Ranges comply with
6569/// \p Style.
6570///
6571/// If `Status` is non-null, its value will be populated with the status of
6572/// this formatting attempt. See \c FormattingAttemptStatus.
6573tooling::Replacements reformat(const FormatStyle &Style, StringRef Code,
6575 StringRef FileName = "<stdin>",
6576 FormattingAttemptStatus *Status = nullptr);
6577
6578/// Same as above, except if `IncompleteFormat` is non-null, its value
6579/// will be set to true if any of the affected ranges were not formatted due to
6580/// a non-recoverable syntax error.
6581tooling::Replacements reformat(const FormatStyle &Style, StringRef Code,
6583 StringRef FileName, bool *IncompleteFormat);
6584
6585/// Clean up any erroneous/redundant code in the given \p Ranges in \p
6586/// Code.
6587///
6588/// Returns the `Replacements` that clean up all \p Ranges in \p Code.
6589tooling::Replacements cleanup(const FormatStyle &Style, StringRef Code,
6591 StringRef FileName = "<stdin>");
6592
6593/// Fix namespace end comments in the given \p Ranges in \p Code.
6594///
6595/// Returns the `Replacements` that fix the namespace comments in all
6596/// \p Ranges in \p Code.
6598 StringRef Code,
6600 StringRef FileName = "<stdin>");
6601
6602/// Inserts or removes empty lines separating definition blocks including
6603/// classes, structs, functions, namespaces, and enums in the given \p Ranges in
6604/// \p Code.
6605///
6606/// Returns the `Replacements` that inserts or removes empty lines separating
6607/// definition blocks in all \p Ranges in \p Code.
6609 StringRef Code,
6611 StringRef FileName = "<stdin>");
6612
6613/// Sort consecutive using declarations in the given \p Ranges in
6614/// \p Code.
6615///
6616/// Returns the `Replacements` that sort the using declarations in all
6617/// \p Ranges in \p Code.
6619 StringRef Code,
6621 StringRef FileName = "<stdin>");
6622
6623/// Returns the `LangOpts` that the formatter expects you to set.
6624///
6625/// \param Style determines specific settings for lexing mode.
6627
6628/// Description to be used for help text for a `llvm::cl` option for
6629/// specifying format style. The description is closely related to the operation
6630/// of `getStyle()`.
6631extern const char *StyleOptionHelpDescription;
6632
6633/// The suggested format style to use by default. This allows tools using
6634/// `getStyle` to have a consistent default style.
6635/// Different builds can modify the value to the preferred styles.
6636extern const char *DefaultFormatStyle;
6637
6638/// The suggested predefined style to use as the fallback style in `getStyle`.
6639/// Different builds can modify the value to the preferred styles.
6640extern const char *DefaultFallbackStyle;
6641
6642/// Construct a FormatStyle based on `StyleName`.
6643///
6644/// `StyleName` can take several forms:
6645/// * "{<key>: <value>, ...}" - Set specic style parameters.
6646/// * "<style name>" - One of the style names supported by getPredefinedStyle().
6647/// * "file" - Load style configuration from a file called `.clang-format`
6648/// located in one of the parent directories of `FileName` or the current
6649/// directory if `FileName` is empty.
6650/// * "file:<format_file_path>" to explicitly specify the configuration file to
6651/// use.
6652///
6653/// \param[in] StyleName Style name to interpret according to the description
6654/// above.
6655/// \param[in] FileName Path to start search for .clang-format if `StyleName`
6656/// == "file".
6657/// \param[in] FallbackStyle The name of a predefined style used to fallback to
6658/// in case \p StyleName is "file" and no file can be found.
6659/// \param[in] Code The actual code to be formatted. Used to determine the
6660/// language if the filename isn't sufficient.
6661/// \param[in] FS The underlying file system, in which the file resides. By
6662/// default, the file system is the real file system.
6663/// \param[in] AllowUnknownOptions If true, unknown format options only
6664/// emit a warning. If false, errors are emitted on unknown format
6665/// options.
6666///
6667/// \returns FormatStyle as specified by `StyleName`. If `StyleName` is
6668/// "file" and no file is found, returns `FallbackStyle`. If no style could be
6669/// determined, returns an Error.
6671getStyle(StringRef StyleName, StringRef FileName, StringRef FallbackStyle,
6672 StringRef Code = "", llvm::vfs::FileSystem *FS = nullptr,
6673 bool AllowUnknownOptions = false,
6674 llvm::SourceMgr::DiagHandlerTy DiagHandler = nullptr);
6675
6676// Guesses the language from the `FileName` and `Code` to be formatted.
6677// Defaults to FormatStyle::LK_Cpp.
6678FormatStyle::LanguageKind guessLanguage(StringRef FileName, StringRef Code);
6679
6680// Returns a string representation of `Language`.
6682 switch (Language) {
6683 case FormatStyle::LK_C:
6684 return "C";
6686 return "C++";
6688 return "CSharp";
6690 return "Objective-C";
6692 return "Java";
6694 return "JavaScript";
6696 return "Json";
6698 return "Proto";
6700 return "TableGen";
6702 return "TextProto";
6704 return "Verilog";
6705 default:
6706 return "Unknown";
6707 }
6708}
6709
6710bool isClangFormatOn(StringRef Comment);
6711bool isClangFormatOff(StringRef Comment);
6712
6713} // end namespace format
6714} // end namespace clang
6715
6716template <>
6717struct std::is_error_code_enum<clang::format::ParseError> : std::true_type {};
6718
6719#endif // LLVM_CLANG_FORMAT_FORMAT_H
Defines the clang::LangOptions interface.
Defines the clang::TokenKind enum and support functions.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
const char * name() const noexcept override
Definition Format.cpp:1714
std::string message(int EV) const override
Definition Format.cpp:1718
Maintains a set of replacements that are conflict-free.
const char * StyleOptionHelpDescription
Description to be used for help text for a llvm::cl option for specifying format style.
Definition Format.cpp:4624
const char * DefaultFallbackStyle
The suggested predefined style to use as the fallback style in getStyle.
Definition Format.cpp:4745
FormatStyle getWebKitStyle()
Returns a format style complying with Webkit's style guide: http://www.webkit.org/coding/coding-style...
Definition Format.cpp:2374
std::error_code make_error_code(ParseError e)
Definition Format.cpp:1705
FormatStyle getClangFormatStyle()
Definition Format.cpp:2442
static std::string format(StringRef NumericLiteral, const FormatStyle &Style)
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:1880
FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language)
Returns a format style complying with one of Google's style guides: http://google-styleguide....
Definition Format.cpp:2135
std::string configurationAsText(const FormatStyle &Style)
Gets configuration in a YAML string.
Definition Format.cpp:2626
FormatStyle getMicrosoftStyle(FormatStyle::LanguageKind Language)
Returns a format style complying with Microsoft style guide: https://docs.microsoft....
Definition Format.cpp:2413
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:2529
const std::error_category & getParseCategory()
Definition Format.cpp:1701
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:4558
FormatStyle::LanguageKind guessLanguage(StringRef FileName, StringRef Code)
Definition Format.cpp:4720
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:4764
const char * DefaultFormatStyle
The suggested format style to use by default.
Definition Format.cpp:4743
FormatStyle getGNUStyle()
Returns a format style complying with GNU Coding Standards: http://www.gnu.org/prep/standards/standar...
Definition Format.cpp:2398
bool isClangFormatOff(StringRef Comment)
Definition Format.cpp:4984
LangOptions getFormattingLangOpts(const FormatStyle &Style=getLLVMStyle())
Returns the LangOpts that the formatter expects you to set.
Definition Format.cpp:4578
FormatStyle getMozillaStyle()
Returns a format style complying with Mozilla's style guide: https://firefox-source-docs....
Definition Format.cpp:2347
bool getPredefinedStyle(StringRef Name, FormatStyle::LanguageKind Language, FormatStyle *Style)
Gets a predefined style for the specified language by name.
Definition Format.cpp:2464
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:4303
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:4525
bool isClangFormatOn(StringRef Comment)
Definition Format.cpp:4980
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:4568
FormatStyle getChromiumStyle(FormatStyle::LanguageKind Language)
Returns a format style complying with Chromium's style guide: http://www.chromium....
Definition Format.cpp:2287
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:4536
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:4192
FormatStyle getNoStyle()
Returns style indicating formatting should be not applied at all.
Definition Format.cpp:2456
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:4151
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:6681
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Definition TokenKinds.h:33
Top level wrappers for InstallAPI frontend operations.
Language
The language for the input, used to select and validate the language standard and possible actions.
__builtin_bitreverse32 uint32_t __builtin_riscv_aaddu_u32 __builtin_riscv_asubu_u32 __builtin_elementwise_add_sat __builtin_elementwise_sub_sat int32_t uint32_t uint32_t __builtin_riscv_mhacc_i32 __builtin_riscv_mhaccu_u32 __builtin_riscv_mhaccsu_i32 __builtin_riscv_mulq_i32 __builtin_riscv_mqwacc_i64 __packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 int8_t
#define false
Definition stdbool.h:26
#define true
Definition stdbool.h:25
The FormatStyle is used to configure the formatting to follow specific guidelines.
Definition Format.h:51
LanguageKind
Supported languages.
Definition Format.h:3874
@ LK_Cpp
Should be used for C++.
Definition Format.h:3880
bool AcrossEmptyLines
Whether to align across empty lines.
Definition Format.h:178
bool PadOperators
Only for AlignConsecutiveAssignments.
Definition Format.h:257
bool AlignFunctionDeclarations
Only for AlignConsecutiveDeclarations.
Definition Format.h:217
bool AlignFunctionPointers
Only for AlignConsecutiveDeclarations.
Definition Format.h:233
bool operator!=(const AlignConsecutiveStyle &R) const
Definition Format.h:267
bool operator==(const AlignConsecutiveStyle &R) const
Definition Format.h:258
bool Enabled
Whether aligning is enabled.
Definition Format.h:161
bool AlignCompound
Only for AlignConsecutiveAssignments.
Definition Format.h:203
bool AcrossComments
Whether to align across comments.
Definition Format.h:191
bool EnumAssignments
Only for AlignConsecutiveAssignments.
Definition Format.h:238
A rule that specifies how to break a specific set of binary operators.
Definition Format.h:2585
unsigned MinChainLength
Minimum number of operands in a chain before the rule triggers.
Definition Format.h:2594
BreakBinaryOperationsStyle Style
The break style for these operators (defaults to OnePerLine).
Definition Format.h:2590
std::vector< tok::TokenKind > Operators
The list of operators this rule applies to, e.g.
Definition Format.h:2588
bool operator!=(const BinaryOperationBreakRule &R) const
Definition Format.h:2599
bool operator==(const BinaryOperationBreakRule &R) const
Definition Format.h:2595
Precise control over the wrapping of braces.
Definition Format.h:1425
bool SplitEmptyRecord
If false, empty record (e.g.
Definition Format.h:1660
bool AfterClass
Wrap class definitions.
Definition Format.h:1451
bool AfterStruct
Wrap struct definitions.
Definition Format.h:1534
bool AfterRequiresExpression
Wrap requires expression body.
Definition Format.h:1520
bool AfterUnion
Wrap union definitions.
Definition Format.h:1548
bool AfterEnum
Wrap enum definitions.
Definition Format.h:1466
bool IndentBraces
Indent the wrapped braces themselves.
Definition Format.h:1634
bool AfterObjCDeclaration
Wrap ObjC definitions (interfaces, implementations...).
Definition Format.h:1504
bool AfterNamespace
Wrap namespace definitions.
Definition Format.h:1498
bool SplitEmptyNamespace
If false, empty namespace body can be put on a single line.
Definition Format.h:1672
BraceWrappingAfterControlStatementStyle AfterControlStatement
Wrap control statements (if/for/while/switch/..).
Definition Format.h:1454
bool AfterFunction
Wrap function definitions.
Definition Format.h:1482
bool SplitEmptyFunction
If false, empty function body can be put on a single line.
Definition Format.h:1648
BreakBinaryOperationsStyle getStyleForOperator(tok::TokenKind Kind) const
Definition Format.h:2640
unsigned getMinChainLengthForOperator(tok::TokenKind Kind) const
Definition Format.h:2645
bool operator==(const BreakBinaryOperationsOptions &R) const
Definition Format.h:2650
BreakBinaryOperationsStyle Default
The default break style for operators not covered by PerOperator.
Definition Format.h:2621
const BinaryOperationBreakRule * findRuleForOperator(tok::TokenKind Kind) const
Definition Format.h:2625
std::vector< BinaryOperationBreakRule > PerOperator
Per-operator override rules.
Definition Format.h:2623
bool operator!=(const BreakBinaryOperationsOptions &R) const
Definition Format.h:2653
std::map< LanguageKind, FormatStyle > MapType
Definition Format.h:6406
std::optional< FormatStyle > Get(LanguageKind Language) const
Definition Format.cpp:2642
Separator format of integer literals of different bases.
Definition Format.h:3589
int8_t DecimalMinDigitsInsert
Format separators in decimal literals with a minimum number of digits.
Definition Format.h:3632
int8_t BinaryMinDigitsInsert
Format separators in binary literals with a minimum number of digits.
Definition Format.h:3605
bool operator==(const IntegerLiteralSeparatorStyle &R) const
Definition Format.h:3674
int8_t Binary
Format separators in binary literals.
Definition Format.h:3597
int8_t HexMaxDigitsRemove
Remove separators in hexadecimal literals with a maximum number of digits.
Definition Format.h:3673
int8_t DecimalMaxDigitsRemove
Remove separators in decimal literals with a maximum number of digits.
Definition Format.h:3644
int8_t Decimal
Format separators in decimal literals.
Definition Format.h:3624
int8_t HexMinDigitsInsert
Format separators in hexadecimal literals with a minimum number of digits.
Definition Format.h:3660
int8_t BinaryMaxDigitsRemove
Remove separators in binary literals with a maximum number of digits.
Definition Format.h:3617
int8_t Hex
Format separators in hexadecimal literals.
Definition Format.h:3651
bool operator!=(const IntegerLiteralSeparatorStyle &R) const
Definition Format.h:3684
Options regarding which empty lines are kept.
Definition Format.h:3784
bool AtStartOfFile
Keep empty lines at start of file.
Definition Format.h:3806
bool AtEndOfBlock
Keep empty lines at end of a block.
Definition Format.h:3793
bool AtEndOfFile
Keep empty lines at end of file.
Definition Format.h:3795
bool operator==(const KeepEmptyLinesStyle &R) const
Definition Format.h:3807
bool AtStartOfBlock
Keep empty lines at start of a block.
Definition Format.h:3804
Separate control for each numeric literal component.
Definition Format.h:4102
NumericLiteralComponentStyle ExponentLetter
Format floating point exponent separator letter case.
Definition Format.h:4109
NumericLiteralComponentStyle Suffix
Format suffix case.
Definition Format.h:4131
bool operator==(const NumericLiteralCaseStyle &R) const
Definition Format.h:4133
NumericLiteralComponentStyle Prefix
Format integer prefix case.
Definition Format.h:4123
bool operator!=(const NumericLiteralCaseStyle &R) const
Definition Format.h:4138
NumericLiteralComponentStyle HexDigit
Format hexadecimal digit case.
Definition Format.h:4116
Options related to packing arguments of function calls.
Definition Format.h:4309
bool operator!=(const PackArgumentsStyle &R) const
Definition Format.h:4340
bool operator==(const PackArgumentsStyle &R) const
Definition Format.h:4337
unsigned BreakAfter
An argument list with more arguments than the specified number will be formatted with one argument pe...
Definition Format.h:4335
BinPackArgumentsStyle BinPack
The bin pack arguments style to use.
Definition Format.h:4313
Options related to packing parameters of function declarations and definitions.
Definition Format.h:4443
BinPackParametersStyle BinPack
The bin pack parameters style to use.
Definition Format.h:4447
bool operator!=(const PackParametersStyle &R) const
Definition Format.h:4472
bool operator==(const PackParametersStyle &R) const
Definition Format.h:4469
unsigned BreakAfter
A parameter list with more parameters than the specified number will be formatted with one parameter ...
Definition Format.h:4467
See documentation of RawStringFormats.
Definition Format.h:4656
std::string CanonicalDelimiter
The canonical delimiter for this language.
Definition Format.h:4664
LanguageKind Language
The language of this raw string.
Definition Format.h:4658
std::string BasedOnStyle
The style name on which this raw string format is based on.
Definition Format.h:4668
std::vector< std::string > EnclosingFunctions
A list of enclosing function names that match this language.
Definition Format.h:4662
bool operator==(const RawStringFormat &Other) const
Definition Format.h:4669
std::vector< std::string > Delimiters
A list of raw string delimiters that match this language.
Definition Format.h:4660
bool operator==(const ShortCaseStatementsAlignmentStyle &R) const
Definition Format.h:413
bool AcrossEmptyLines
Whether to align across empty lines.
Definition Format.h:358
bool AlignCaseColons
Whether aligned case labels are aligned on the colon, or on the tokens after the colon.
Definition Format.h:412
bool AcrossComments
Whether to align across comments.
Definition Format.h:377
bool AlignCaseArrows
Whether to align the case arrows when aligning short case expressions.
Definition Format.h:394
Different styles for merging short functions containing at most one statement.
Definition Format.h:893
ShortFunctionStyle(bool Empty, bool Inline, bool Other)
Definition Format.h:931
static ShortFunctionStyle setAll()
Definition Format.h:943
static ShortFunctionStyle setEmptyOnly()
Definition Format.h:934
bool operator==(const ShortFunctionStyle &R) const
Definition Format.h:926
bool Empty
Merge top-level empty functions.
Definition Format.h:902
static ShortFunctionStyle setInlineOnly()
Definition Format.h:940
bool operator!=(const ShortFunctionStyle &R) const
Definition Format.h:929
static ShortFunctionStyle setEmptyAndInline()
Definition Format.h:937
bool Inline
Merge functions defined inside a class.
Definition Format.h:915
bool Other
Merge all functions fitting on a single line.
Definition Format.h:924
bool Natural
Whether or not includes are sorted by natural ordering i.e., whether embedded runs of digits are comp...
Definition Format.h:5156
bool operator==(const SortIncludesOptions &R) const
Definition Format.h:5179
bool operator!=(const SortIncludesOptions &R) const
Definition Format.h:5184
bool IgnoreCase
Whether or not includes are sorted in a case-insensitive fashion.
Definition Format.h:5138
bool IgnoreExtension
When sorting includes in each block, only take file extensions into account if two includes compare e...
Definition Format.h:5147
bool Enabled
If true, includes are sorted based on the other suboptions below.
Definition Format.h:5126
bool FilesBeforeFolders
When true, sort includes so that files in a directory appear before subdirectories at each level,...
Definition Format.h:5178
Precise control over the spacing before parentheses.
Definition Format.h:5462
bool AfterControlStatements
If true, put space between control statement keywords (for/if/while...) and opening parentheses.
Definition Format.h:5469
bool AfterOverloadedOperator
If true, put a space between operator overloading and opening parentheses.
Definition Format.h:5512
bool AfterRequiresInExpression
If true, put space between requires keyword in a requires expression and opening parentheses.
Definition Format.h:5539
bool AfterFunctionDeclarationName
If true, put a space between function declaration name and opening parentheses.
Definition Format.h:5483
bool AfterRequiresInClause
If true, put space between requires keyword in a requires clause and opening parentheses,...
Definition Format.h:5529
bool AfterForeachMacros
If true, put space between foreach macros and opening parentheses.
Definition Format.h:5476
bool AfterNot
If true, put a space between alternative operator not and the opening parenthesis.
Definition Format.h:5504
bool AfterFunctionDefinitionName
If true, put a space between function definition name and opening parentheses.
Definition Format.h:5490
bool BeforeNonEmptyParentheses
If true, put a space before opening parentheses only if the parentheses are not empty.
Definition Format.h:5547
bool operator==(const SpaceBeforeParensCustom &Other) const
Definition Format.h:5557
bool AfterIfMacros
If true, put space between if macros and opening parentheses.
Definition Format.h:5497
bool AfterPlacementOperator
If true, put a space between operator new/delete and opening parenthesis.
Definition Format.h:5520
If true, spaces may be inserted into C style casts.
Definition Format.h:5745
unsigned Maximum
The maximum number of spaces at the start of the comment.
Definition Format.h:5749
unsigned Minimum
The minimum number of spaces at the start of the comment.
Definition Format.h:5747
Precise control over the spacing in parentheses.
Definition Format.h:5824
bool operator==(const SpacesInParensCustom &R) const
Definition Format.h:5881
bool ExceptDoubleParentheses
Override any of the following options to prevent addition of space when both opening and closing pare...
Definition Format.h:5835
bool Other
Put a space in parentheses not covered by preceding options.
Definition Format.h:5867
bool InEmptyParentheses
Insert a space in empty parentheses, i.e.
Definition Format.h:5861
bool InCStyleCasts
Put a space in C style casts.
Definition Format.h:5850
bool operator!=(const SpacesInParensCustom &R) const
Definition Format.h:5887
bool InConditionalStatements
Put a space in parentheses only inside conditional statements (for/if/while/switch....
Definition Format.h:5843
SpacesInParensCustom(bool ExceptDoubleParentheses, bool InConditionalStatements, bool InCStyleCasts, bool InEmptyParentheses, bool Other)
Definition Format.h:5873
TrailingCommentsAlignmentKinds Kind
Specifies the way to align trailing comments.
Definition Format.h:585
bool operator!=(const TrailingCommentsAlignmentStyle &R) const
Definition Format.h:623
bool operator==(const TrailingCommentsAlignmentStyle &R) const
Definition Format.h:619
unsigned OverEmptyLines
How many empty lines to apply alignment.
Definition Format.h:608
bool AlignPPAndNotPP
If comments following preprocessor directive should be aligned with comments that don't.
Definition Format.h:617
The FormatStyle is used to configure the formatting to follow specific guidelines.
Definition Format.h:51
UseTabStyle
This option is deprecated.
Definition Format.h:6084
@ UT_AlignWithSpaces
Use tabs for line continuation and indentation, and spaces for alignment.
Definition Format.h:6094
@ UT_ForContinuationAndIndentation
Fill all leading whitespace with tabs, and use spaces for alignment that appears within a line (e....
Definition Format.h:6091
@ UT_ForIndentation
Use tabs only for indentation.
Definition Format.h:6088
@ 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:6097
@ UT_Never
Never use tab.
Definition Format.h:6086
bool SpaceBeforeInheritanceColon
If false, spaces will be removed before inheritance colon.
Definition Format.h:5380
unsigned ContinuationIndentWidth
Indent width for line continuations.
Definition Format.h:2899
bool AlwaysBreakBeforeMultilineStrings
This option is renamed to BreakAfterReturnType.
Definition Format.h:1226
LanguageStandard Standard
Parse and format C++ constructs compatible with this standard.
Definition Format.h:5956
bool BreakAdjacentStringLiterals
Break between adjacent string literals.
Definition Format.h:1701
ReturnTypeBreakingStyle BreakAfterReturnType
The function declaration return type breaking style to use.
Definition Format.h:1858
bool isTableGen() const
Definition Format.h:3913
LanguageKind
Supported languages.
Definition Format.h:3874
@ LK_C
Should be used for C.
Definition Format.h:3878
@ LK_CSharp
Should be used for C#.
Definition Format.h:3882
@ LK_Java
Should be used for Java.
Definition Format.h:3884
@ LK_Cpp
Should be used for C++.
Definition Format.h:3880
@ LK_JavaScript
Should be used for JavaScript.
Definition Format.h:3886
@ LK_ObjC
Should be used for Objective-C, Objective-C++.
Definition Format.h:3890
@ LK_Verilog
Should be used for Verilog and SystemVerilog.
Definition Format.h:3901
@ LK_TableGen
Should be used for TableGen code.
Definition Format.h:3894
@ LK_Proto
Should be used for Protocol Buffers
Definition Format.h:3892
@ LK_Json
Should be used for JSON.
Definition Format.h:3888
@ LK_TextProto
Should be used for Protocol Buffer messages in text format.
Definition Format.h:3897
SortIncludesOptions SortIncludes
Controls if and how clang-format will sort #includes.
Definition Format.h:5191
BreakInheritanceListStyle BreakInheritanceList
The inheritance list style to use.
Definition Format.h:2835
std::string OneLineFormatOffRegex
A regular expression that describes markers for turning formatting off for one line.
Definition Format.h:4281
bool BreakAfterOpenBracketIf
Force break after the left parenthesis of an if control statement when the expression exceeds the col...
Definition Format.h:1834
unsigned IndentWidth
The number of columns to use for indentation.
Definition Format.h:3477
std::string InheritConfig
Definition Format.h:55
std::vector< std::string > AttributeMacros
This option is renamed to BreakTemplateDeclarations.
Definition Format.h:1296
ShortLambdaStyle
Different styles for merging short lambdas containing at most one statement.
Definition Format.h:1026
@ SLS_All
Merge all lambdas fitting on a single line.
Definition Format.h:1050
@ SLS_Inline
Merge lambda into a single line if the lambda is argument of a function.
Definition Format.h:1044
@ SLS_None
Never merge lambdas into a single line.
Definition Format.h:1028
@ SLS_Empty
Only merge empty lambdas.
Definition Format.h:1036
SeparateDefinitionStyle
The style if definition blocks should be separated.
Definition Format.h:5039
@ SDS_Never
Remove any empty line between definition blocks.
Definition Format.h:5045
@ SDS_Always
Insert an empty line between definition blocks.
Definition Format.h:5043
@ SDS_Leave
Leave definition blocks as they are.
Definition Format.h:5041
bool IndentRequiresClause
Indent the requires clause in a template.
Definition Format.h:3463
SpacesInAnglesStyle SpacesInAngles
The SpacesInAnglesStyle to use for template argument lists.
Definition Format.h:5694
bool KeepFormFeed
This option is deprecated.
Definition Format.h:3833
bool IndentCaseLabels
Indent case labels one level from the switch statement.
Definition Format.h:3282
std::vector< RawStringFormat > RawStringFormats
Defines hints for detecting supported languages code blocks in raw strings.
Definition Format.h:4713
std::vector< std::string > VariableTemplates
A vector of non-keyword identifiers that should be interpreted as variable template names.
Definition Format.h:6111
SortJavaStaticImportOptions
Position for Java Static imports.
Definition Format.h:5194
@ SJSIO_Before
Static imports are placed before non-static imports.
Definition Format.h:5201
@ SJSIO_After
Static imports are placed after non-static imports.
Definition Format.h:5208
PPDirectiveIndentStyle IndentPPDirectives
The preprocessor directive indenting style to use.
Definition Format.h:3440
bool RemoveSemicolon
Remove semicolons after the closing braces of functions and constructors/destructors.
Definition Format.h:4907
std::vector< std::string > Macros
A list of macros of the form <definition>=<expansion> .
Definition Format.h:4008
EnumTrailingCommaStyle
Styles for enum trailing commas.
Definition Format.h:3095
@ ETC_Remove
Remove trailing commas.
Definition Format.h:3113
@ ETC_Insert
Insert trailing commas.
Definition Format.h:3107
@ ETC_Leave
Don't insert or remove trailing commas.
Definition Format.h:3101
bool SpaceBeforeJsonColon
If true, a space will be added before a JSON colon.
Definition Format.h:5391
TrailingCommaStyle
The style of inserting trailing commas into container literals.
Definition Format.h:3530
@ TCS_Wrapped
Insert trailing commas in container literals that were wrapped over multiple lines.
Definition Format.h:3538
@ TCS_None
Do not insert trailing commas.
Definition Format.h:3532
unsigned PenaltyBreakBeforeFirstCallParameter
The penalty for breaking a function call after call(.
Definition Format.h:4488
bool SpaceBeforeCtorInitializerColon
If false, spaces will be removed before constructor initializer colon.
Definition Format.h:5364
BinPackParametersStyle
Different ways to try to fit all parameters on a line.
Definition Format.h:4412
@ BPPS_OnePerLine
Put all parameters on the current line if they fit.
Definition Format.h:4428
@ BPPS_UseBreakAfter
Use the BreakAfter option to handle parameter packing instead.
Definition Format.h:4438
@ BPPS_BinPack
Bin-pack parameters.
Definition Format.h:4418
@ BPPS_AlwaysOnePerLine
Always put each parameter on its own line.
Definition Format.h:4435
BinaryOperatorStyle BreakBeforeBinaryOperators
The way to wrap binary operators.
Definition Format.h:1932
bool IndentExportBlock
If true, clang-format will indent the body of an export { ... } block.
Definition Format.h:3295
BinPackStyle
The style of wrapping parameters on the same line (bin-packed) or on one line each.
Definition Format.h:1881
@ BPS_Never
Never bin-pack parameters.
Definition Format.h:1887
@ BPS_Auto
Automatically determine parameter bin-packing behavior.
Definition Format.h:1883
@ BPS_Always
Always bin-pack parameters.
Definition Format.h:1885
BitFieldColonSpacingStyle BitFieldColonSpacing
The BitFieldColonSpacingStyle to use for bitfields.
Definition Format.h:1349
ReflowCommentsStyle
Types of comment reflow style.
Definition Format.h:4742
@ RCS_IndentOnly
Only apply indentation rules, moving comments left or right, without changing formatting inside the c...
Definition Format.h:4759
@ RCS_Never
Leave comments untouched.
Definition Format.h:4750
@ RCS_Always
Apply indentation rules and reflow long comments into new lines, trying to obey the ColumnLimit.
Definition Format.h:4770
EmptyLineBeforeAccessModifierStyle
Different styles for empty line before access modifiers.
Definition Format.h:3032
@ ELBAMS_LogicalBlock
Add empty line only when access modifier starts a new logical block.
Definition Format.h:3067
@ ELBAMS_Never
Remove all empty lines before access modifiers.
Definition Format.h:3047
@ ELBAMS_Always
Always add empty line before access modifiers unless access modifier is at the start of struct or cla...
Definition Format.h:3087
@ ELBAMS_Leave
Keep existing empty lines before access modifiers.
Definition Format.h:3049
unsigned SpacesBeforeTrailingComments
If true, spaces may be inserted into ().
Definition Format.h:5671
BreakConstructorInitializersStyle
Different ways to break initializers.
Definition Format.h:2663
@ BCIS_AfterColon
Break constructor initializers after the colon and commas.
Definition Format.h:2685
@ BCIS_AfterComma
Break constructor initializers only after the commas.
Definition Format.h:2691
@ BCIS_BeforeColon
Break constructor initializers before the colon and after the commas.
Definition Format.h:2670
@ BCIS_BeforeComma
Break constructor initializers before the colon and commas, and align the commas with the colon.
Definition Format.h:2678
IndentExternBlockStyle
Indents extern blocks.
Definition Format.h:3298
@ IEBS_AfterExternBlock
Backwards compatible with AfterExternBlock's indenting.
Definition Format.h:3316
@ IEBS_Indent
Indents extern blocks.
Definition Format.h:3330
@ IEBS_NoIndent
Does not indent extern blocks.
Definition Format.h:3323
bool IndentCaseBlocks
Indent case label blocks one level from the case label.
Definition Format.h:3263
bool InsertBraces
Insert braces after control statements (if, else, for, do, and while) in C++ unless the control state...
Definition Format.h:3523
BreakBeforeConceptDeclarationsStyle BreakBeforeConceptDeclarations
The concept declaration style to use.
Definition Format.h:2454
BreakTemplateDeclarationsStyle BreakTemplateDeclarations
The template declaration breaking style to use.
Definition Format.h:2839
bool DerivePointerAlignment
This option is deprecated.
Definition Format.h:2974
std::vector< std::string > MacrosSkippedByRemoveParentheses
A vector of function-like macros whose invocations should be skipped by RemoveParentheses.
Definition Format.h:4013
BinaryOperatorStyle
The style of breaking before or after binary operators.
Definition Format.h:1891
@ BOS_All
Break before operators.
Definition Format.h:1927
@ BOS_None
Break after operators.
Definition Format.h:1903
@ BOS_NonAssignment
Break before operators that aren't assignments.
Definition Format.h:1915
LineEndingStyle
Line ending style.
Definition Format.h:3925
@ LE_DeriveLF
Use \n unless the input has more lines ending in \r\n.
Definition Format.h:3931
@ LE_DeriveCRLF
Use \r\n unless the input has more lines ending in \n.
Definition Format.h:3933
bool SpacesInSquareBrackets
If true, spaces will be inserted after [ and before ].
Definition Format.h:5917
bool IndentWrappedFunctionNames
Indent if a function definition or declaration is wrapped after the type.
Definition Format.h:3491
AlignConsecutiveStyle AlignConsecutiveTableGenBreakingDAGArgColons
Style of aligning consecutive TableGen DAGArg operator colons.
Definition Format.h:449
WrapNamespaceBodyWithEmptyLinesStyle WrapNamespaceBodyWithEmptyLines
Wrap namespace body with empty lines.
Definition Format.h:6175
bool FixNamespaceComments
If true, clang-format adds missing namespace end comments for namespaces and fixes invalid existing o...
Definition Format.h:3156
bool ObjCSpaceBeforeProtocolList
Add a space in front of an Objective-C protocol list, i.e.
Definition Format.h:4256
TrailingCommentsAlignmentKinds
Enums for AlignTrailingComments.
Definition Format.h:552
@ TCAS_Never
Don't align trailing comments but other formatter applies.
Definition Format.h:579
@ TCAS_Leave
Leave trailing comments as they are.
Definition Format.h:561
@ TCAS_Always
Align trailing comments.
Definition Format.h:570
RemoveParenthesesStyle RemoveParentheses
Remove redundant parentheses.
Definition Format.h:4889
std::string MacroBlockBegin
A regular expression matching macros that start a block.
Definition Format.h:3963
LanguageKind Language
The language that this format style targets.
Definition Format.h:3922
NumericLiteralComponentStyle
Control over each component in a numeric literal.
Definition Format.h:4081
@ NLCS_Lower
Format this component with lowercase characters.
Definition Format.h:4087
@ NLCS_Leave
Leave this component of the literal as is.
Definition Format.h:4083
@ NLCS_Upper
Format this component with uppercase characters.
Definition Format.h:4085
bool BreakBeforeCloseBracketFunction
Force break before the right parenthesis of a function (declaration, definition, call) when the param...
Definition Format.h:2391
SpacesInParensStyle
Different ways to put a space before opening and closing parentheses.
Definition Format.h:5787
@ SIPO_Custom
Configure each individual space in parentheses in SpacesInParensOptions.
Definition Format.h:5799
@ SIPO_Never
Never put a space in parentheses.
Definition Format.h:5796
ShortRecordStyle
Different styles for merging short records (class,struct, and union).
Definition Format.h:1069
@ SRS_EmptyAndAttached
Only merge empty records if the opening brace was not wrapped, i.e.
Definition Format.h:1074
@ SRS_Empty
Only merge empty records.
Definition Format.h:1083
@ SRS_Always
Merge all records that fit on a single line.
Definition Format.h:1089
@ SRS_Never
Never merge records into a single line.
Definition Format.h:1071
bool RemoveBracesLLVM
Remove optional braces of control statements (if, else, for, and while) in C++ according to the LLVM ...
Definition Format.h:4830
static FormatStyleSet BuildStyleSetFromConfiguration(const FormatStyle &MainStyle, const std::vector< FormatStyle > &ConfigurationStyles)
BreakBeforeInlineASMColonStyle
Different ways to break ASM parameters.
Definition Format.h:2457
@ BBIAS_Always
Always break before inline ASM colon.
Definition Format.h:2478
@ BBIAS_OnlyMultiline
Break before inline ASM colon if the line length is longer than column limit.
Definition Format.h:2471
@ BBIAS_Never
No break before inline ASM colon.
Definition Format.h:2462
bool VerilogBreakBetweenInstancePorts
For Verilog, put each port on its own line in module instantiations.
Definition Format.h:6125
unsigned TabWidth
The number of columns used for tab stops.
Definition Format.h:6041
BreakBeforeReturnTypeStyle BreakBeforeReturnType
The function declaration/definition return type breaking style to use.
Definition Format.h:2508
PPDirectiveIndentStyle
Options for indenting preprocessor directives.
Definition Format.h:3396
@ PPDIS_Leave
Leaves indentation of directives as-is.
Definition Format.h:3435
@ PPDIS_BeforeHash
Indents directives before the hash.
Definition Format.h:3423
@ PPDIS_None
Does not indent any directives.
Definition Format.h:3405
@ PPDIS_AfterHash
Indents directives after the hash.
Definition Format.h:3414
LambdaBodyIndentationKind
Indentation logic for lambda bodies.
Definition Format.h:3836
@ LBI_OuterScope
For statements within block scope, align lambda body relative to the indentation level of the outer s...
Definition Format.h:3858
@ LBI_Signature
Align lambda body relative to the lambda signature.
Definition Format.h:3844
std::vector< std::string > JavaImportGroups
A vector of prefixes ordered by the desired groups for Java imports.
Definition Format.h:3726
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:4500
std::vector< std::string > StatementAttributeLikeMacros
Macros which are ignored in front of a statement, as if they were an attribute.
Definition Format.h:5973
unsigned ObjCBlockIndentWidth
The number of characters to use for indentation of ObjC blocks.
Definition Format.h:4189
bool AllowShortLoopsOnASingleLine
If true, while (true) continue; can be put on a single line.
Definition Format.h:1061
int AccessModifierOffset
The extra indent or outdent of access modifiers, e.g.
Definition Format.h:59
std::vector< std::string > QualifierOrder
The order in which the qualifiers appear.
Definition Format.h:4653
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:2667
std::vector< std::string > IfMacros
A vector of macros that should be interpreted as conditionals instead of as function calls.
Definition Format.h:3197
bool SpaceBeforeEnumUnderlyingTypeColon
If false, spaces will be removed before enum underlying type colon.
Definition Format.h:5372
NamespaceIndentationKind NamespaceIndentation
The indentation used for namespaces.
Definition Format.h:4065
bool BreakArrays
If true, clang-format will always break after a Json array [ otherwise it will scan until the closing...
Definition Format.h:1877
bool BreakAfterJavaFieldAnnotations
Break after each annotation on a field in Java files.
Definition Format.h:2734
ShortIfStyle
Different styles for handling short if statements.
Definition Format.h:954
@ SIS_WithoutElse
Put short ifs on the same line only if there is no else statement.
Definition Format.h:987
@ SIS_Never
Never put short ifs on the same line.
Definition Format.h:971
@ SIS_OnlyFirstIf
Put short ifs, but not else ifs nor else statements, on the same line.
Definition Format.h:1003
@ SIS_AllIfsAndElse
Always put short ifs, else ifs and else statements on the same line.
Definition Format.h:1017
bool AllowBreakBeforeQtProperty
Allow breaking before Q_Property keywords READ, WRITE, etc.
Definition Format.h:733
std::vector< std::string > ObjCPropertyAttributeOrder
The order in which ObjC property attributes should appear.
Definition Format.h:4236
bool BreakBeforeCloseBracketBracedList
Force break before the right bracket of a braced initializer list (when Cpp11BracedListStyle is true)...
Definition Format.h:2380
bool ExperimentalAutoDetectBinPacking
If true, clang-format detects whether function calls and definitions are formatted with one parameter...
Definition Format.h:3140
bool ObjCBreakBeforeNestedBlockParam
Break parameters list into lines when there is nested block parameters in a function call.
Definition Format.h:4213
bool BreakFunctionDeclarationParameters
If true, clang-format will always break before function declaration parameters.
Definition Format.h:2710
OperandAlignmentStyle AlignOperands
If true, horizontally align operands of binary and ternary expressions.
Definition Format.h:549
unsigned PenaltyBreakOpenParenthesis
The penalty for breaking after (.
Definition Format.h:4504
bool BreakAfterOpenBracketLoop
Force break after the left parenthesis of a loop control statement when the expression exceeds the co...
Definition Format.h:1844
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:2529
unsigned PenaltyBreakBeforeMemberAccess
The penalty for breaking before a member access operator (.
Definition Format.h:4492
BreakTemplateDeclarationsStyle
Different ways to break after the template declaration.
Definition Format.h:1229
@ BTDS_No
Do not force break before declaration.
Definition Format.h:1249
@ BTDS_MultiLine
Force break after template declaration only when the following declaration spans multiple lines.
Definition Format.h:1260
@ BTDS_Yes
Always break after template declaration.
Definition Format.h:1271
@ BTDS_Leave
Do not change the line breaking before the declaration.
Definition Format.h:1239
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:5813
SpacesInParensCustom SpacesInParensOptions
Control of individual spaces in parentheses.
Definition Format.h:5906
std::vector< std::string > ForEachMacros
A vector of macros that should be interpreted as foreach loops instead of as function calls.
Definition Format.h:3174
ReferenceAlignmentStyle ReferenceAlignment
Reference alignment style (overrides PointerAlignment for references).
Definition Format.h:4738
bool CompactCaseLabels
Keep the break keyword and the following case label on the same line.
Definition Format.h:2854
AlignConsecutiveStyle AlignConsecutiveTableGenDefinitionColons
Style of aligning consecutive TableGen definition colons.
Definition Format.h:469
TrailingCommaStyle InsertTrailingCommas
If set to TCS_Wrapped will insert trailing commas in container literals (arrays and objects) that wra...
Definition Format.h:3557
unsigned PenaltyBreakTemplateDeclaration
The penalty for breaking after template declaration.
Definition Format.h:4516
SpaceBeforeParensCustom SpaceBeforeParensOptions
Control of individual space before parentheses.
Definition Format.h:5586
BreakConstructorInitializersStyle BreakConstructorInitializers
The break constructor initializers style to use.
Definition Format.h:2696
bool RemoveEmptyLinesInUnwrappedLines
Remove empty lines within unwrapped lines.
Definition Format.h:4853
bool BreakStringLiterals
Allow breaking string literals when formatting.
Definition Format.h:2777
bool SpaceAfterLogicalNot
If true, a space is inserted after the logical not operator (!).
Definition Format.h:5275
SpaceBeforeParensStyle
Different ways to put a space before opening parentheses.
Definition Format.h:5394
@ SBPO_Never
This is deprecated and replaced by Custom below, with all SpaceBeforeParensOptions but AfterPlacement...
Definition Format.h:5398
@ SBPO_Custom
Configure each individual space before parentheses in SpaceBeforeParensOptions.
Definition Format.h:5447
@ SBPO_NonEmptyParentheses
Put a space before opening parentheses only if the parentheses are not empty.
Definition Format.h:5432
@ SBPO_ControlStatementsExceptControlMacros
Same as SBPO_ControlStatements except this option doesn't apply to ForEach and If macros.
Definition Format.h:5421
@ SBPO_ControlStatements
Put a space before opening parentheses only after control statement keywords (for/if/while....
Definition Format.h:5408
@ SBPO_Always
Always put a space before opening parentheses, except when it's prohibited by the syntax rules (in fu...
Definition Format.h:5444
PackConstructorInitializersStyle
Different ways to try to fit all constructor initializers on a line.
Definition Format.h:4350
@ PCIS_NextLineOnly
Put all constructor initializers on the next line if they fit.
Definition Format.h:4404
@ PCIS_Never
Always put each constructor initializer on its own line.
Definition Format.h:4357
@ PCIS_CurrentLine
Put all constructor initializers on the current line if they fit.
Definition Format.h:4375
@ PCIS_BinPack
Bin-pack constructor initializers.
Definition Format.h:4364
@ PCIS_NextLine
Same as PCIS_CurrentLine except that if all constructor initializers do not fit on the current line,...
Definition Format.h:4389
std::vector< std::string > TypeNames
A vector of non-keyword identifiers that should be interpreted as type names.
Definition Format.h:6060
bool isTextProto() const
Definition Format.h:3911
bool ObjCSpaceAfterProperty
Add a space after @property in Objective-C, i.e.
Definition Format.h:4251
BreakBeforeReturnTypeStyle
Different ways to break before the function return type.
Definition Format.h:2486
@ BBRTS_None
Do not force a break before the return type.
Definition Format.h:2488
@ BBRTS_TopLevelDefinitions
Break before the return type of top-level definitions only.
Definition Format.h:2500
@ BBRTS_TopLevel
Break before the return type of top-level functions only.
Definition Format.h:2496
@ BBRTS_All
Always break before the return type.
Definition Format.h:2494
@ BBRTS_AllDefinitions
Break before the return type of function definitions only.
Definition Format.h:2498
bool BreakAfterOpenBracketSwitch
Force break after the left parenthesis of a switch control statement when the expression exceeds the ...
Definition Format.h:1854
BraceBreakingStyle BreakBeforeBraces
The brace breaking style to use.
Definition Format.h:2367
BreakInheritanceListStyle
Different ways to break inheritance list.
Definition Format.h:2798
@ BILS_AfterColon
Break inheritance list after the colon and commas.
Definition Format.h:2823
@ BILS_AfterComma
Break inheritance list only after the commas.
Definition Format.h:2830
@ BILS_BeforeColon
Break inheritance list before the colon and after the commas.
Definition Format.h:2806
@ BILS_BeforeComma
Break inheritance list before the colon and commas, and align the commas with the colon.
Definition Format.h:2815
SpacesInBlockCommentsStyle
Styles for controlling spacing after /* and before `.
Definition Format.h:5698
@ SIBCS_Always
Add spaces after /* and before `.
Definition Format.h:5708
@ SIBCS_Leave
Leave existing spaces unchanged.
Definition Format.h:5710
@ SIBCS_Never
Remove spaces after /* and before `.
Definition Format.h:5703
unsigned PenaltyExcessCharacter
The penalty for each character outside of the column limit.
Definition Format.h:4520
std::vector< std::string > WhitespaceSensitiveMacros
A vector of macros which are whitespace-sensitive and should not be touched.
Definition Format.h:6142
bool AlignAfterOpenBracket
If true, horizontally aligns arguments after an open bracket.
Definition Format.h:82
std::vector< std::string > TemplateNames
A vector of non-keyword identifiers that should be interpreted as template names.
Definition Format.h:6050
DAGArgStyle
Different ways to control the format inside TableGen DAGArg.
Definition Format.h:6012
@ DAS_BreakElements
Break inside DAGArg after each list element but for the last.
Definition Format.h:6024
@ DAS_DontBreak
Never break inside DAGArg.
Definition Format.h:6017
@ DAS_BreakAll
Break inside DAGArg after the operator and the all elements.
Definition Format.h:6032
unsigned ConstructorInitializerIndentWidth
This option is deprecated.
Definition Format.h:2888
BreakBeforeNoexceptSpecifierStyle
Different ways to break before a noexcept specifier.
Definition Format.h:689
@ BBNSS_Never
No line break allowed.
Definition Format.h:699
@ BBNSS_Always
Line breaks are allowed.
Definition Format.h:722
@ BBNSS_OnlyWithParen
For a simple noexcept there is no line break allowed, but when we have a condition it is.
Definition Format.h:710
bool CompactNamespaces
If true, consecutive namespace declarations will be on the same line.
Definition Format.h:2878
RequiresClausePositionStyle
The possible positions for the requires clause.
Definition Format.h:4911
@ RCPS_OwnLineWithBrace
As with OwnLine, except, unless otherwise prohibited, place a following open brace (of a function def...
Definition Format.h:4950
@ RCPS_OwnLine
Always put the requires clause on its own line (possibly followed by a semicolon).
Definition Format.h:4932
@ RCPS_WithPreceding
Try to put the clause together with the preceding part of a declaration.
Definition Format.h:4967
@ RCPS_SingleLine
Try to put everything in the same line if possible.
Definition Format.h:5005
@ RCPS_WithFollowing
Try to put the requires clause together with the class or function declaration.
Definition Format.h:4981
bool BreakBeforeCloseBracketSwitch
Force break before the right parenthesis of a switch control statement when the expression exceeds th...
Definition Format.h:2430
bool operator==(const FormatStyle &R) const
Definition Format.h:6177
LanguageStandard
Supported language standards for parsing and formatting C++ constructs.
Definition Format.h:5927
@ LS_Cpp17
Parse and format as C++17.
Definition Format.h:5936
@ LS_Cpp26
Parse and format as C++26.
Definition Format.h:5942
@ LS_Cpp23
Parse and format as C++23.
Definition Format.h:5940
@ LS_Latest
Parse and format using the latest supported language version.
Definition Format.h:5945
@ LS_Cpp11
Parse and format as C++11.
Definition Format.h:5932
@ LS_Auto
Automatic detection based on the input.
Definition Format.h:5947
@ LS_Cpp03
Parse and format as C++03.
Definition Format.h:5930
@ LS_Cpp14
Parse and format as C++14.
Definition Format.h:5934
@ LS_Cpp20
Parse and format as C++20.
Definition Format.h:5938
BraceWrappingAfterControlStatementStyle
Different ways to wrap braces after control statements.
Definition Format.h:1385
@ BWACS_Always
Always wrap braces after a control statement.
Definition Format.h:1415
@ BWACS_Never
Never wrap braces after a control statement.
Definition Format.h:1394
@ BWACS_MultiLine
Only wrap braces after a multi-line control statement.
Definition Format.h:1405
RequiresClausePositionStyle RequiresClausePosition
The position of the requires clause.
Definition Format.h:5010
JavaScriptQuoteStyle
Quotation styles for JavaScript strings.
Definition Format.h:3730
@ JSQS_Double
Always use double quotes.
Definition Format.h:3748
@ JSQS_Single
Always use single quotes.
Definition Format.h:3742
@ JSQS_Leave
Leave string quotes as they are.
Definition Format.h:3736
bool SpaceAfterCStyleCast
If true, a space is inserted after C style casts.
Definition Format.h:5267
AlignConsecutiveStyle AlignConsecutiveBitFields
Style of aligning consecutive bit fields.
Definition Format.h:293
int PPIndentWidth
The number of columns to use for indentation of preprocessor statements.
Definition Format.h:4567
AlignConsecutiveStyle AlignConsecutiveDeclarations
Style of aligning consecutive declarations.
Definition Format.h:305
IntegerLiteralSeparatorStyle IntegerLiteralSeparator
Format integer literal separators (‘’ for C/C++ and _` for C#, Java, and JavaScript).
Definition Format.h:3692
SpaceAroundPointerQualifiersStyle SpaceAroundPointerQualifiers
Defines in which cases to put a space before or after pointer qualifiers.
Definition Format.h:5324
IndentAccessModifierStyle
Modes for indenting access modifiers and record members.
Definition Format.h:3200
@ IAMS_Never
Use AccessModifierOffset for access modifiers and indent members one level below the record.
Definition Format.h:3211
@ IAMS_AfterFirstAccessModifier
In C, C++, and Objective-C, indent members one level until the first explicit access modifier,...
Definition Format.h:3235
@ IAMS_Always
Give access modifiers their own indentation level and indent all members two levels below the record.
Definition Format.h:3223
DefinitionReturnTypeBreakingStyle AlwaysBreakAfterDefinitionReturnType
The function definition return type breaking style to use.
Definition Format.h:1206
ShortRecordStyle AllowShortRecordOnASingleLine
Dependent on the value, struct bar { int i; }; can be put on a single line.
Definition Format.h:1095
bool SpaceBeforeAssignmentOperators
If false, spaces will be removed before assignment operators.
Definition Format.h:5333
BreakBeforeInlineASMColonStyle BreakBeforeInlineASMColon
The inline ASM colon style to use.
Definition Format.h:2483
WrapNamespaceBodyWithEmptyLinesStyle
Different styles for wrapping namespace body with empty lines.
Definition Format.h:6145
@ 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:6167
@ WNBWELS_Leave
Keep existing newlines at the beginning and the end of namespace body.
Definition Format.h:6170
@ WNBWELS_Never
Remove all empty lines at the beginning and the end of namespace body.
Definition Format.h:6154
SpaceInEmptyBracesStyle SpaceInEmptyBraces
Specifies when to insert a space in empty braces.
Definition Format.h:5645
BraceBreakingStyle
Different ways to attach braces to their surrounding context.
Definition Format.h:1935
@ BS_Mozilla
Like Attach, but break before braces on enum, function, and record definitions.
Definition Format.h:2080
@ BS_Whitesmiths
Like Allman but always indent braces and line up code with braces.
Definition Format.h:2250
@ BS_Allman
Always break before braces.
Definition Format.h:2190
@ BS_Stroustrup
Like Attach, but break before function definitions, catch, and else.
Definition Format.h:2130
@ BS_Linux
Like Attach, but break before braces on function, namespace and class definitions.
Definition Format.h:2030
@ BS_WebKit
Like Attach, but break before functions.
Definition Format.h:2360
@ BS_Custom
Configure each individual brace in BraceWrapping.
Definition Format.h:2362
@ BS_GNU
Always break before braces and add an extra level of indentation to braces of control statements,...
Definition Format.h:2313
@ BS_Attach
Always attach braces to surrounding context.
Definition Format.h:1980
bool ObjCSpaceAfterMethodDeclarationPrefix
Add or remove a space between the '-'/'+' and the return type in Objective-C method declarations.
Definition Format.h:4246
AttributeBreakingStyle
Different ways to break after the last attribute of a group before a declaration or control statement...
Definition Format.h:1705
@ ABS_Leave
Leave the line breaking after the last attribute of the group as is.
Definition Format.h:1759
@ ABS_Never
Never break after the last attribute of the group.
Definition Format.h:1795
@ ABS_Always
Always break after the last attribute of the group.
Definition Format.h:1734
@ ABS_LeaveAll
Same as Leave except that it applies to all attributes of the group.
Definition Format.h:1773
bool BreakBeforeCloseBracketLoop
Force break before the right parenthesis of a loop control statement when the expression exceeds the ...
Definition Format.h:2417
ShortLambdaStyle AllowShortLambdasOnASingleLine
Dependent on the value, auto lambda []() { return 0; } can be put on a single line.
Definition Format.h:1056
bool BinPackLongBracedList
This option is deprecated.
Definition Format.h:1316
unsigned PenaltyBreakScopeResolution
The penalty for breaking after ::.
Definition Format.h:4508
unsigned PenaltyReturnTypeOnItsOwnLine
Penalty for putting the return type of a function onto its own line.
Definition Format.h:4529
BitFieldColonSpacingStyle
This option is deprecated.
Definition Format.h:1323
@ BFCS_Both
Add one space on each side of the :
Definition Format.h:1328
@ BFCS_Before
Add space before the : only.
Definition Format.h:1339
@ BFCS_None
Add no space around the : (except when needed for AlignConsecutiveBitFields).
Definition Format.h:1334
@ BFCS_After
Add space after the : only (space may be added before if needed for AlignConsecutiveBitFields).
Definition Format.h:1345
PointerAlignmentStyle PointerAlignment
Pointer and reference alignment style.
Definition Format.h:4552
bool BreakBeforeTemplateCloser
If true, break before a template closing bracket (>) when there is a line break after the matching op...
Definition Format.h:2535
int BracedInitializerIndentWidth
The number of columns to use to indent the contents of braced init lists.
Definition Format.h:1382
PackParametersStyle PackParameters
Options related to packing parameters of function declarations and definitions.
Definition Format.h:4480
bool BreakFunctionDefinitionParameters
If true, clang-format will always break before function definition parameters.
Definition Format.h:2724
RequiresExpressionIndentationKind
Indentation logic for requires expression bodies.
Definition Format.h:5013
@ REI_Keyword
Align requires expression body relative to the requires keyword.
Definition Format.h:5031
@ REI_OuterScope
Align requires expression body relative to the indentation level of the outer scope the requires expr...
Definition Format.h:5023
PackConstructorInitializersStyle PackConstructorInitializers
The pack constructor initializers style to use.
Definition Format.h:4409
BreakBeforeConceptDeclarationsStyle
Different ways to break before concept declarations.
Definition Format.h:2433
@ BBCDS_Allowed
Breaking between template declaration and concept is allowed.
Definition Format.h:2442
@ BBCDS_Never
Keep the template declaration line together with concept.
Definition Format.h:2438
@ BBCDS_Always
Always break before concept, putting it in the line after the template declaration.
Definition Format.h:2449
ReflowCommentsStyle ReflowComments
Comment reformatting style.
Definition Format.h:4776
KeepEmptyLinesStyle KeepEmptyLines
Which empty lines are kept.
Definition Format.h:3816
bool AllowAllParametersOfDeclarationOnNextLine
This option is deprecated.
Definition Format.h:686
AlignConsecutiveStyle AlignConsecutiveTableGenCondOperatorColons
Style of aligning consecutive TableGen cond operator colons.
Definition Format.h:459
BracedListStyle
Different ways to handle braced lists.
Definition Format.h:2902
@ BLS_AlignFirstComment
Same as FunctionCall, except for the handling of a comment at the begin, it then aligns everything fo...
Definition Format.h:2956
@ BLS_FunctionCall
Best suited for C++11 braced lists.
Definition Format.h:2938
@ BLS_Block
Best suited for pre C++11 braced lists.
Definition Format.h:2918
bool AllowShortCaseExpressionOnASingleLine
Whether to merge a short switch labeled rule into a single line.
Definition Format.h:779
bool BreakBeforeCloseBracketIf
Force break before the right parenthesis of an if control statement when the expression exceeds the c...
Definition Format.h:2404
unsigned MaxEmptyLinesToKeep
The maximum number of consecutive empty lines to keep.
Definition Format.h:4027
bool SpaceBeforeSquareBrackets
If true, spaces will be before [.
Definition Format.h:5596
BinPackStyle ObjCBinPackProtocolList
Controls bin-packing Objective-C protocol conformance list items into as few lines as possible when t...
Definition Format.h:4178
PackArgumentsStyle PackArguments
Options related to packing arguments of function calls.
Definition Format.h:4347
ShortCaseStatementsAlignmentStyle AlignConsecutiveShortCaseStatements
Style of aligning consecutive short case labels.
Definition Format.h:434
EscapedNewlineAlignmentStyle AlignEscapedNewlines
Options for aligning backslashes in escaped newlines.
Definition Format.h:510
SpacesInLineComment SpacesInLineCommentPrefix
How many spaces are allowed at the start of a line comment.
Definition Format.h:5784
std::string CommentPragmas
A regular expression that describes comments with special meaning, which should not be split into lin...
Definition Format.h:2795
bool isJavaScript() const
Definition Format.h:3909
DAGArgStyle TableGenBreakInsideDAGArg
The styles of the line break inside the DAGArg in TableGen.
Definition Format.h:6037
JavaScriptQuoteStyle JavaScriptQuotes
The JavaScriptQuoteStyle to use for JavaScript strings.
Definition Format.h:3753
bool SpacesInContainerLiterals
If true, spaces will be inserted around if/for/switch/while conditions.
Definition Format.h:5736
SortJavaStaticImportOptions SortJavaStaticImport
When sorting Java imports, by default static imports are placed before non-static imports.
Definition Format.h:5215
BreakBinaryOperationsOptions BreakBinaryOperations
The break binary operations style to use.
Definition Format.h:2660
SpaceAroundPointerQualifiersStyle
Different ways to put a space before opening parentheses.
Definition Format.h:5294
@ SAPQ_After
Ensure that there is a space after pointer qualifiers.
Definition Format.h:5313
@ SAPQ_Default
Don't ensure spaces around pointer qualifiers and use PointerAlignment instead.
Definition Format.h:5301
@ SAPQ_Both
Ensure that there is a space both before and after pointer qualifiers.
Definition Format.h:5319
@ SAPQ_Before
Ensure that there is a space before pointer qualifiers.
Definition Format.h:5307
bool SpaceBeforeRangeBasedForLoopColon
If false, spaces will be removed before range-based for loop colon.
Definition Format.h:5605
bool DisableFormat
Disables formatting completely.
Definition Format.h:2978
EmptyLineAfterAccessModifierStyle
Different styles for empty line after access modifiers.
Definition Format.h:2983
@ ELAAMS_Always
Always add empty line after access modifiers if there are none.
Definition Format.h:3022
@ ELAAMS_Never
Remove all empty lines after access modifiers.
Definition Format.h:2998
@ ELAAMS_Leave
Keep existing empty lines after access modifiers.
Definition Format.h:3001
DefinitionReturnTypeBreakingStyle
Different ways to break after the function definition return type.
Definition Format.h:1099
@ DRTBS_All
Always break after the return type.
Definition Format.h:1104
@ DRTBS_TopLevel
Always break after the return types of top-level functions.
Definition Format.h:1106
@ DRTBS_None
Break after return type automatically.
Definition Format.h:1102
bool AllowShortNamespacesOnASingleLine
If true, namespace a { class b; } can be put on a single line.
Definition Format.h:1065
std::vector< std::string > NamespaceMacros
A vector of macros which are used to open namespace blocks.
Definition Format.h:4078
AttributeBreakingStyle BreakAfterAttributes
Break after a group of C++11 attributes before variable or function (including constructor/destructor...
Definition Format.h:1803
TrailingCommentsAlignmentStyle AlignTrailingComments
Control of trailing comments.
Definition Format.h:646
ArrayInitializerAlignmentStyle
Different style for aligning array initializers.
Definition Format.h:85
@ AIAS_Left
Align array column and left justify the columns e.g.:
Definition Format.h:95
@ AIAS_Right
Align array column and right justify the columns e.g.:
Definition Format.h:105
@ AIAS_None
Don't align array initializer columns.
Definition Format.h:107
LambdaBodyIndentationKind LambdaBodyIndentation
The indentation style of lambda bodies.
Definition Format.h:3867
QualifierAlignmentStyle QualifierAlignment
Different ways to arrange specifiers and qualifiers (e.g.
Definition Format.h:4613
BreakBinaryOperationsStyle
Different ways to break binary operations.
Definition Format.h:2553
@ BBO_OnePerLine
Binary operations will either be all on the same line, or each operation will have one line each.
Definition Format.h:2570
@ BBO_Never
Don't break binary operations.
Definition Format.h:2559
@ BBO_RespectPrecedence
Binary operations of a particular precedence that exceed the column limit will have one line each.
Definition Format.h:2580
BraceWrappingFlags BraceWrapping
Control of individual brace wrapping cases.
Definition Format.h:1688
EscapedNewlineAlignmentStyle
Different styles for aligning escaped newlines.
Definition Format.h:472
@ ENAS_DontAlign
Don't align escaped newlines.
Definition Format.h:480
@ ENAS_Left
Align escaped newlines as far left as possible.
Definition Format.h:488
@ ENAS_Right
Align escaped newlines in the right-most column.
Definition Format.h:505
@ ENAS_LeftWithLastLine
Align escaped newlines as far left as possible, using the last line of the preprocessor directive as ...
Definition Format.h:497
AlignConsecutiveStyle AlignConsecutiveMacros
Style of aligning consecutive macro definitions.
Definition Format.h:318
IndentAccessModifierStyle IndentAccessModifiers
Specify how access modifiers and record members are indented.
Definition Format.h:3240
std::vector< std::string > StatementMacros
A vector of macros that should be interpreted as complete statements.
Definition Format.h:5983
SpacesInAnglesStyle
Styles for adding spacing after < and before > in template argument lists.
Definition Format.h:5675
@ SIAS_Never
Remove spaces after < and before >.
Definition Format.h:5681
@ SIAS_Always
Add spaces after < and before >.
Definition Format.h:5687
@ SIAS_Leave
Keep a single space after < and before > if any spaces were present.
Definition Format.h:5690
BinPackArgumentsStyle
Different ways to try to fit all arguments on a line.
Definition Format.h:4284
@ BPAS_OnePerLine
Put all arguments on the current line if they fit.
Definition Format.h:4302
@ BPAS_BinPack
Bin-pack arguments.
Definition Format.h:4292
@ BPAS_UseBreakAfter
Use the BreakAfter option to handle argument packing instead.
Definition Format.h:4305
SortUsingDeclarationsOptions
Using declaration sorting options.
Definition Format.h:5218
@ SUD_LexicographicNumeric
Using declarations are sorted in the order defined as follows: Split the strings by :: and discard an...
Definition Format.h:5254
@ SUD_Lexicographic
Using declarations are sorted in the order defined as follows: Split the strings by :: and discard an...
Definition Format.h:5239
@ SUD_Never
Using declarations are never sorted.
Definition Format.h:5227
AlignConsecutiveStyle AlignConsecutiveAssignments
Style of aligning consecutive assignments.
Definition Format.h:281
SpaceInEmptyBracesStyle
This option is deprecated.
Definition Format.h:5612
@ SIEB_Always
Always insert a space in empty braces.
Definition Format.h:5620
@ SIEB_Block
Only insert a space in empty blocks.
Definition Format.h:5628
@ SIEB_Never
Never insert a space in empty braces.
Definition Format.h:5636
ShortIfStyle AllowShortIfStatementsOnASingleLine
Dependent on the value, if (a) return; can be put on a single line.
Definition Format.h:1022
RemoveParenthesesStyle
Types of redundant parentheses to remove.
Definition Format.h:4856
@ RPS_Leave
Do not remove parentheses.
Definition Format.h:4863
@ RPS_ReturnStatement
Also remove parentheses enclosing the expression in a return/co_return statement.
Definition Format.h:4878
@ RPS_MultipleParentheses
Replace multiple parentheses with single parentheses.
Definition Format.h:4870
std::vector< std::string > TableGenBreakingDAGArgOperators
Works only when TableGenBreakInsideDAGArg is not DontBreak.
Definition Format.h:6009
EmptyLineBeforeAccessModifierStyle EmptyLineBeforeAccessModifier
Defines in which cases to put empty line before access modifiers.
Definition Format.h:3092
EnumTrailingCommaStyle EnumTrailingComma
Insert a comma (if missing) or remove the comma at the end of an enum enumerator list.
Definition Format.h:3125
bool SpaceBeforeCaseColon
If false, spaces will be removed before case colon.
Definition Format.h:5343
BreakBeforeNoexceptSpecifierStyle AllowBreakBeforeNoexceptSpecifier
Controls if there could be a line break before a noexcept specifier.
Definition Format.h:727
bool JavaScriptWrapImports
Whether to wrap JavaScript import/export statements.
Definition Format.h:3769
bool BreakAfterOpenBracketFunction
Force break after the left parenthesis of a function (declaration, definition, call) when the paramet...
Definition Format.h:1824
bool SkipMacroDefinitionBody
Do not format macro definition body.
Definition Format.h:5120
unsigned PenaltyBreakAssignment
The penalty for breaking around an assignment operator.
Definition Format.h:4484
PointerAlignmentStyle
The &, && and * alignment style.
Definition Format.h:4532
@ PAS_Left
Align pointer to the left.
Definition Format.h:4537
@ PAS_Middle
Align pointer in the middle.
Definition Format.h:4547
@ PAS_Right
Align pointer to the right.
Definition Format.h:4542
unsigned PenaltyBreakString
The penalty for each line break introduced inside a string literal.
Definition Format.h:4512
RequiresExpressionIndentationKind RequiresExpressionIndentation
The indentation used for requires expression bodies.
Definition Format.h:5036
IndentGotoLabelStyle IndentGotoLabels
The goto label indenting style to use.
Definition Format.h:3393
bool SpaceAfterTemplateKeyword
If true, a space will be inserted after the template keyword.
Definition Format.h:5291
unsigned PenaltyIndentedWhitespace
Penalty for each character of whitespace indentation (counted relative to leading non-whitespace colu...
Definition Format.h:4525
ArrayInitializerAlignmentStyle AlignArrayOfStructures
If not None, when using initialization for an array of structs aligns the fields into columns.
Definition Format.h:118
NamespaceIndentationKind
Different ways to indent namespace contents.
Definition Format.h:4030
@ NI_None
Don't indent in namespaces.
Definition Format.h:4040
@ NI_All
Indent in all namespaces.
Definition Format.h:4060
@ NI_Inner
Indent only in inner namespaces (nested in other namespaces).
Definition Format.h:4050
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:3967
ShortFunctionStyle AllowShortFunctionsOnASingleLine
Dependent on the value, int f() { return 0; } can be put on a single line.
Definition Format.h:951
bool AllowAllArgumentsOnNextLine
If a function call or braced initializer list doesn't fit on a line, allow putting all arguments onto...
Definition Format.h:663
unsigned PenaltyBreakComment
The penalty for each line break introduced inside a comment.
Definition Format.h:4496
bool SpaceAfterOperatorKeyword
If true, a space will be inserted after the operator keyword.
Definition Format.h:5283
ReturnTypeBreakingStyle
Different ways to break after the function definition or declaration return type.
Definition Format.h:1111
@ RTBS_TopLevelDefinitions
Always break after the return type of top-level definitions.
Definition Format.h:1200
@ RTBS_ExceptShortType
Same as Automatic above, except that there is no break after short return types.
Definition Format.h:1136
@ RTBS_All
Always break after the return type.
Definition Format.h:1154
@ RTBS_TopLevel
Always break after the return types of top-level functions.
Definition Format.h:1169
@ RTBS_None
This is deprecated. See Automatic below.
Definition Format.h:1113
@ RTBS_Automatic
Break after return type based on PenaltyReturnTypeOnItsOwnLine.
Definition Format.h:1124
@ RTBS_AllDefinitions
Always break after the return type of function definitions.
Definition Format.h:1186
ReferenceAlignmentStyle
The & and && alignment style.
Definition Format.h:4716
@ RAS_Right
Align reference to the right.
Definition Format.h:4728
@ RAS_Left
Align reference to the left.
Definition Format.h:4723
@ RAS_Pointer
Align reference like PointerAlignment.
Definition Format.h:4718
@ RAS_Middle
Align reference in the middle.
Definition Format.h:4733
EmptyLineAfterAccessModifierStyle EmptyLineAfterAccessModifier
Defines when to put an empty line after access modifiers.
Definition Format.h:3029
IndentGotoLabelStyle
Options for indenting goto labels.
Definition Format.h:3338
@ IGLS_InnerIndent
Indent goto labels to the surrounding statements (current indenting level).
Definition Format.h:3375
@ IGLS_OuterIndent
Indent goto labels to the enclosing block (previous indenting level).
Definition Format.h:3362
@ IGLS_HalfIndent
Indent goto labels to half the indentation of the surrounding code.
Definition Format.h:3388
@ IGLS_NoIndent
Do not indent goto labels.
Definition Format.h:3350
bool InsertNewlineAtEOF
Insert a newline at end of file if missing.
Definition Format.h:3527
SpaceBeforeParensStyle SpaceBeforeParens
Defines in which cases to put a space before opening parentheses.
Definition Format.h:5452
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:5355
NumericLiteralCaseStyle NumericLiteralCase
Capitalization style for numeric literals.
Definition Format.h:4145
UseTabStyle UseTab
The way to use tab characters in the resulting file.
Definition Format.h:6102
QualifierAlignmentStyle
Different specifiers and qualifiers alignment styles.
Definition Format.h:4570
@ QAS_Right
Change specifiers/qualifiers to be right-aligned.
Definition Format.h:4589
@ QAS_Custom
Change specifiers/qualifiers to be aligned based on QualifierOrder.
Definition Format.h:4601
@ QAS_Left
Change specifiers/qualifiers to be left-aligned.
Definition Format.h:4583
@ QAS_Leave
Don't change specifiers/qualifiers to either Left or Right alignment (default).
Definition Format.h:4577
std::vector< std::string > TypenameMacros
A vector of macros that should be interpreted as type declarations instead of as function calls.
Definition Format.h:6077
OperandAlignmentStyle
Different styles for aligning operands.
Definition Format.h:513
@ OAS_Align
Horizontally align operands of binary and ternary expressions.
Definition Format.h:533
@ OAS_AlignAfterOperator
Horizontally align operands of binary and ternary expressions.
Definition Format.h:543
@ OAS_DontAlign
Do not align operands of binary and ternary expressions.
Definition Format.h:517
LineEndingStyle LineEnding
Line ending style (\n or \r\n) to use.
Definition Format.h:3938
bool BreakAfterOpenBracketBracedList
Force break after the left bracket of a braced initializer list (when Cpp11BracedListStyle is true) w...
Definition Format.h:1814
bool BreakBeforeTernaryOperators
If true, ternary operators will be placed after line breaks.
Definition Format.h:2550
BracedListStyle Cpp11BracedListStyle
The style to handle braced lists.
Definition Format.h:2961
unsigned ShortNamespaceLines
The maximal number of unwrapped lines that a short namespace spans.
Definition Format.h:5116
SortUsingDeclarationsOptions SortUsingDeclarations
Controls if and how clang-format will sort using declarations.
Definition Format.h:5259
IndentExternBlockStyle IndentExternBlock
IndentExternBlockStyle is the type of indenting of extern blocks.
Definition Format.h:3335
SeparateDefinitionStyle SeparateDefinitionBlocks
Specifies the use of empty lines to separate definition blocks, including classes,...
Definition Format.h:5094
tooling::IncludeStyle IncludeStyle
Definition Format.h:3176
unsigned ColumnLimit
The column limit.
Definition Format.h:2785
Represents the status of a formatting attempt.
Definition Format.h:6551
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:6554
unsigned Line
If FormatComplete is false, Line records a one-based original line number at which a syntax error mig...
Definition Format.h:6559
Style for sorting and grouping C++ include directives.