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 /// If `true`, consecutive namespace declarations will be on the same
2842 /// line. If `false`, each namespace is declared on a new line.
2843 /// \code
2844 /// true:
2845 /// namespace Foo { namespace Bar {
2846 /// }}
2847 ///
2848 /// false:
2849 /// namespace Foo {
2850 /// namespace Bar {
2851 /// }
2852 /// }
2853 /// \endcode
2854 ///
2855 /// If it does not fit on a single line, the overflowing namespaces get
2856 /// wrapped:
2857 /// \code
2858 /// namespace Foo { namespace Bar {
2859 /// namespace Extra {
2860 /// }}}
2861 /// \endcode
2862 /// \version 5
2864
2865 /// This option is **deprecated**. See `CurrentLine` of
2866 /// `PackConstructorInitializers`.
2867 /// \version 3.7
2868 // bool ConstructorInitializerAllOnOneLineOrOnePerLine;
2869
2870 /// The number of characters to use for indentation of constructor
2871 /// initializer lists as well as inheritance lists.
2872 /// \version 3.7
2874
2875 /// Indent width for line continuations.
2876 /// \code
2877 /// ContinuationIndentWidth: 2
2878 ///
2879 /// int i = // VeryVeryVeryVeryVeryLongComment
2880 /// longFunction( // Again a long comment
2881 /// arg);
2882 /// \endcode
2883 /// \version 3.7
2885
2886 /// Different ways to handle braced lists.
2888 /// Best suited for pre C++11 braced lists.
2889 ///
2890 /// * Spaces inside the braced list.
2891 /// * Line break before the closing brace.
2892 /// * Indentation with the block indent.
2893 ///
2894 /// \code
2895 /// vector<int> x{ 1, 2, 3, 4 };
2896 /// vector<T> x{ {}, {}, {}, {} };
2897 /// f(MyMap[{ composite, key }]);
2898 /// new int[3]{ 1, 2, 3 };
2899 /// Type name{ // Comment
2900 /// value
2901 /// };
2902 /// \endcode
2904 /// Best suited for C++11 braced lists.
2905 ///
2906 /// * No spaces inside the braced list.
2907 /// * No line break before the closing brace.
2908 /// * Indentation with the continuation indent.
2909 ///
2910 /// Fundamentally, C++11 braced lists are formatted exactly like function
2911 /// calls would be formatted in their place. If the braced list follows a
2912 /// name (e.g. a type or variable name), clang-format formats as if the
2913 /// `{}` were the parentheses of a function call with that name. If there
2914 /// is no name, a zero-length name is assumed.
2915 /// \code
2916 /// vector<int> x{1, 2, 3, 4};
2917 /// vector<T> x{{}, {}, {}, {}};
2918 /// f(MyMap[{composite, key}]);
2919 /// new int[3]{1, 2, 3};
2920 /// Type name{ // Comment
2921 /// value};
2922 /// \endcode
2924 /// Same as `FunctionCall`, except for the handling of a comment at the
2925 /// begin, it then aligns everything following with the comment.
2926 ///
2927 /// * No spaces inside the braced list. (Even for a comment at the first
2928 /// position.)
2929 /// * No line break before the closing brace.
2930 /// * Indentation with the continuation indent, except when followed by a
2931 /// line comment, then it uses the block indent.
2932 ///
2933 /// \code
2934 /// vector<int> x{1, 2, 3, 4};
2935 /// vector<T> x{{}, {}, {}, {}};
2936 /// f(MyMap[{composite, key}]);
2937 /// new int[3]{1, 2, 3};
2938 /// Type name{// Comment
2939 /// value};
2940 /// \endcode
2942 };
2943
2944 /// The style to handle braced lists.
2945 /// \version 3.4
2947
2948 /// This option is **deprecated**. See `DeriveLF` and `DeriveCRLF` of
2949 /// `LineEnding`.
2950 /// \version 10
2951 // bool DeriveLineEnding;
2952
2953 /// If `true`, analyze the formatted file for the most common
2954 /// alignment of `&` and `*`.
2955 /// Pointer and reference alignment styles are going to be updated according
2956 /// to the preferences found in the file.
2957 /// `PointerAlignment` is then used only as fallback.
2958 /// \version 3.7
2960
2961 /// Disables formatting completely.
2962 /// \version 3.7
2964
2965 /// Different styles for empty line after access modifiers.
2966 /// `EmptyLineBeforeAccessModifier` configuration handles the number of
2967 /// empty lines between two access modifiers.
2969 /// Remove all empty lines after access modifiers.
2970 /// \code
2971 /// struct foo {
2972 /// private:
2973 /// int i;
2974 /// protected:
2975 /// int j;
2976 /// /* comment */
2977 /// public:
2978 /// foo() {}
2979 /// private:
2980 /// protected:
2981 /// };
2982 /// \endcode
2984 /// Keep existing empty lines after access modifiers.
2985 /// MaxEmptyLinesToKeep is applied instead.
2987 /// Always add empty line after access modifiers if there are none.
2988 /// MaxEmptyLinesToKeep is applied also.
2989 /// \code
2990 /// struct foo {
2991 /// private:
2992 ///
2993 /// int i;
2994 /// protected:
2995 ///
2996 /// int j;
2997 /// /* comment */
2998 /// public:
2999 ///
3000 /// foo() {}
3001 /// private:
3002 ///
3003 /// protected:
3004 ///
3005 /// };
3006 /// \endcode
3008 };
3009
3010 /// Defines when to put an empty line after access modifiers.
3011 /// `EmptyLineBeforeAccessModifier` configuration handles the number of
3012 /// empty lines between two access modifiers.
3013 /// \version 13
3015
3016 /// Different styles for empty line before access modifiers.
3018 /// Remove all empty lines before access modifiers.
3019 /// \code
3020 /// struct foo {
3021 /// private:
3022 /// int i;
3023 /// protected:
3024 /// int j;
3025 /// /* comment */
3026 /// public:
3027 /// foo() {}
3028 /// private:
3029 /// protected:
3030 /// };
3031 /// \endcode
3033 /// Keep existing empty lines before access modifiers.
3035 /// Add empty line only when access modifier starts a new logical block.
3036 /// Logical block is a group of one or more member fields or functions.
3037 /// \code
3038 /// struct foo {
3039 /// private:
3040 /// int i;
3041 ///
3042 /// protected:
3043 /// int j;
3044 /// /* comment */
3045 /// public:
3046 /// foo() {}
3047 ///
3048 /// private:
3049 /// protected:
3050 /// };
3051 /// \endcode
3053 /// Always add empty line before access modifiers unless access modifier
3054 /// is at the start of struct or class definition.
3055 /// \code
3056 /// struct foo {
3057 /// private:
3058 /// int i;
3059 ///
3060 /// protected:
3061 /// int j;
3062 /// /* comment */
3063 ///
3064 /// public:
3065 /// foo() {}
3066 ///
3067 /// private:
3068 ///
3069 /// protected:
3070 /// };
3071 /// \endcode
3073 };
3074
3075 /// Defines in which cases to put empty line before access modifiers.
3076 /// \version 12
3078
3079 /// Styles for `enum` trailing commas.
3081 /// Don't insert or remove trailing commas.
3082 /// \code
3083 /// enum { a, b, c, };
3084 /// enum Color { red, green, blue };
3085 /// \endcode
3087 /// Insert trailing commas.
3088 /// \code
3089 /// enum { a, b, c, };
3090 /// enum Color { red, green, blue, };
3091 /// \endcode
3093 /// Remove trailing commas.
3094 /// \code
3095 /// enum { a, b, c };
3096 /// enum Color { red, green, blue };
3097 /// \endcode
3099 };
3100
3101 /// Insert a comma (if missing) or remove the comma at the end of an `enum`
3102 /// enumerator list.
3103 /// \warning
3104 /// Setting this option to any value other than `Leave` could lead to
3105 /// incorrect code formatting due to clang-format's lack of complete semantic
3106 /// information. As such, extra care should be taken to review code changes
3107 /// made by this option.
3108 /// \endwarning
3109 /// \version 21
3111
3112 /// If `true`, clang-format detects whether function calls and
3113 /// definitions are formatted with one parameter per line.
3114 ///
3115 /// Each call can be bin-packed, one-per-line or inconclusive. If it is
3116 /// inconclusive, e.g. completely on one line, but a decision needs to be
3117 /// made, clang-format analyzes whether there are other bin-packed cases in
3118 /// the input file and act accordingly.
3119 ///
3120 /// \note
3121 /// This is an experimental flag, that might go away or be renamed. Do
3122 /// not use this in config files, etc. Use at your own risk.
3123 /// \endnote
3124 /// \version 3.7
3126
3127 /// If `true`, clang-format adds missing namespace end comments for
3128 /// namespaces and fixes invalid existing ones. This doesn't affect short
3129 /// namespaces, which are controlled by `ShortNamespaceLines`.
3130 /// \code
3131 /// true: false:
3132 /// namespace longNamespace { vs. namespace longNamespace {
3133 /// void foo(); void foo();
3134 /// void bar(); void bar();
3135 /// } // namespace a }
3136 /// namespace shortNamespace { namespace shortNamespace {
3137 /// void baz(); void baz();
3138 /// } }
3139 /// \endcode
3140 /// \version 5
3142
3143 /// A vector of macros that should be interpreted as foreach loops
3144 /// instead of as function calls.
3145 ///
3146 /// These are expected to be macros of the form:
3147 /// \code
3148 /// FOREACH(<variable-declaration>, ...)
3149 /// <loop-body>
3150 /// \endcode
3151 ///
3152 /// In the .clang-format configuration file, this can be configured like:
3153 /// \code{.yaml}
3154 /// ForEachMacros: [RANGES_FOR, FOREACH]
3155 /// \endcode
3156 ///
3157 /// For example: BOOST_FOREACH.
3158 /// \version 3.7
3159 std::vector<std::string> ForEachMacros;
3160
3162
3163 /// A vector of macros that should be interpreted as conditionals
3164 /// instead of as function calls.
3165 ///
3166 /// These are expected to be macros of the form:
3167 /// \code
3168 /// IF(...)
3169 /// <conditional-body>
3170 /// else IF(...)
3171 /// <conditional-body>
3172 /// \endcode
3173 ///
3174 /// In the .clang-format configuration file, this can be configured like:
3175 /// \code{.yaml}
3176 /// IfMacros: [IF]
3177 /// \endcode
3178 ///
3179 /// For example:
3180 /// [KJ_IF_MAYBE](https://github.com/capnproto/capnproto/blob/master/kjdoc/tour.md#maybes)
3181 /// \version 13
3182 std::vector<std::string> IfMacros;
3183
3184 /// Modes for indenting access modifiers and record members.
3186 /// Use `AccessModifierOffset` for access modifiers and indent members one
3187 /// level below the record.
3188 /// \code
3189 /// struct S {
3190 /// int before;
3191 ///
3192 /// public:
3193 /// int after;
3194 /// };
3195 /// \endcode
3197 /// Give access modifiers their own indentation level and indent all
3198 /// members two levels below the record. Value of the `AccessModifierOffset`
3199 /// is ignored.
3200 /// \code
3201 /// struct S {
3202 /// int before;
3203 ///
3204 /// public:
3205 /// int after;
3206 /// };
3207 /// \endcode
3209 /// In C, C++, and Objective-C, indent members one level until the first
3210 /// explicit access modifier, then two levels. Other languages use the
3211 /// `Always` behavior. Value of the `AccessModifierOffset` is ignored.
3212 /// \code
3213 /// struct S {
3214 /// int before;
3215 ///
3216 /// public:
3217 /// int after;
3218 /// };
3219 /// \endcode
3221 };
3222
3223 /// Specify how access modifiers and record members are indented.
3224 /// \version 13
3226
3227 /// Indent case label blocks one level from the case label.
3228 ///
3229 /// When `false`, the block following the case label uses the same
3230 /// indentation level as for the case label, treating the case label the same
3231 /// as an if-statement.
3232 /// When `true`, the block gets indented as a scope block.
3233 /// \code
3234 /// false: true:
3235 /// switch (fool) { vs. switch (fool) {
3236 /// case 1: { case 1:
3237 /// bar(); {
3238 /// } break; bar();
3239 /// default: { }
3240 /// plop(); break;
3241 /// } default:
3242 /// } {
3243 /// plop();
3244 /// }
3245 /// }
3246 /// \endcode
3247 /// \version 11
3249
3250 /// Indent case labels one level from the switch statement.
3251 ///
3252 /// When `false`, use the same indentation level as for the switch
3253 /// statement. Switch statement body is always indented one level more than
3254 /// case labels (except the first block following the case label, which
3255 /// itself indents the code - unless IndentCaseBlocks is enabled).
3256 /// \code
3257 /// false: true:
3258 /// switch (fool) { vs. switch (fool) {
3259 /// case 1: case 1:
3260 /// bar(); bar();
3261 /// break; break;
3262 /// default: default:
3263 /// plop(); plop();
3264 /// } }
3265 /// \endcode
3266 /// \version 3.3
3268
3269 /// If `true`, clang-format will indent the body of an `export { ... }`
3270 /// block. This doesn't affect the formatting of anything else related to
3271 /// exported declarations.
3272 /// \code
3273 /// true: false:
3274 /// export { vs. export {
3275 /// void foo(); void foo();
3276 /// void bar(); void bar();
3277 /// } }
3278 /// \endcode
3279 /// \version 20
3281
3282 /// Indents extern blocks
3284 /// Backwards compatible with AfterExternBlock's indenting.
3285 /// \code
3286 /// IndentExternBlock: AfterExternBlock
3287 /// BraceWrapping.AfterExternBlock: true
3288 /// extern "C"
3289 /// {
3290 /// void foo();
3291 /// }
3292 /// \endcode
3293 ///
3294 /// \code
3295 /// IndentExternBlock: AfterExternBlock
3296 /// BraceWrapping.AfterExternBlock: false
3297 /// extern "C" {
3298 /// void foo();
3299 /// }
3300 /// \endcode
3302 /// Does not indent extern blocks.
3303 /// \code
3304 /// extern "C" {
3305 /// void foo();
3306 /// }
3307 /// \endcode
3309 /// Indents extern blocks.
3310 /// \code
3311 /// extern "C" {
3312 /// void foo();
3313 /// }
3314 /// \endcode
3316 };
3317
3318 /// IndentExternBlockStyle is the type of indenting of extern blocks.
3319 /// \version 11
3321
3322 /// Options for indenting goto labels.
3324 /// Do not indent goto labels.
3325 /// \code
3326 /// int f() {
3327 /// if (foo()) {
3328 /// label1:
3329 /// bar();
3330 /// }
3331 /// label2:
3332 /// return 1;
3333 /// }
3334 /// \endcode
3336 /// Indent goto labels to the enclosing block (previous indenting level).
3337 /// \code
3338 /// int f() {
3339 /// if (foo()) {
3340 /// label1:
3341 /// bar();
3342 /// }
3343 /// label2:
3344 /// return 1;
3345 /// }
3346 /// \endcode
3348 /// Indent goto labels to the surrounding statements (current indenting
3349 /// level).
3350 /// \code
3351 /// int f() {
3352 /// if (foo()) {
3353 /// label1:
3354 /// bar();
3355 /// }
3356 /// label2:
3357 /// return 1;
3358 /// }
3359 /// \endcode
3361 /// Indent goto labels to half the indentation of the surrounding code.
3362 /// If the indentation width is an odd number, it will round up.
3363 /// \code
3364 /// int f() {
3365 /// if (foo()) {
3366 /// label1:
3367 /// bar();
3368 /// }
3369 /// label2:
3370 /// return 1;
3371 /// }
3372 /// \endcode
3374 };
3375
3376 /// The goto label indenting style to use.
3377 /// \version 10
3379
3380 /// Options for indenting preprocessor directives.
3382 /// Does not indent any directives.
3383 /// \code
3384 /// #if FOO
3385 /// #if BAR
3386 /// #include <foo>
3387 /// #endif
3388 /// #endif
3389 /// \endcode
3391 /// Indents directives after the hash.
3392 /// \code
3393 /// #if FOO
3394 /// # if BAR
3395 /// # include <foo>
3396 /// # endif
3397 /// #endif
3398 /// \endcode
3400 /// Indents directives before the hash.
3401 /// \code
3402 /// #if FOO
3403 /// #if BAR
3404 /// #include <foo>
3405 /// #endif
3406 /// #endif
3407 /// \endcode
3409 /// Leaves indentation of directives as-is.
3410 /// \note
3411 /// Ignores `PPIndentWidth`.
3412 /// \endnote
3413 /// \code
3414 /// #if FOO
3415 /// #if BAR
3416 /// #include <foo>
3417 /// #endif
3418 /// #endif
3419 /// \endcode
3421 };
3422
3423 /// The preprocessor directive indenting style to use.
3424 /// \version 6
3426
3427 /// Indent the requires clause in a template. This only applies when
3428 /// `RequiresClausePosition` is `OwnLine`, `OwnLineWithBrace`,
3429 /// or `WithFollowing`.
3430 ///
3431 /// In clang-format 12, 13 and 14 it was named `IndentRequires`.
3432 /// \code
3433 /// true:
3434 /// template <typename It>
3435 /// requires Iterator<It>
3436 /// void sort(It begin, It end) {
3437 /// //....
3438 /// }
3439 ///
3440 /// false:
3441 /// template <typename It>
3442 /// requires Iterator<It>
3443 /// void sort(It begin, It end) {
3444 /// //....
3445 /// }
3446 /// \endcode
3447 /// \version 15
3449
3450 /// The number of columns to use for indentation.
3451 /// \code
3452 /// IndentWidth: 3
3453 ///
3454 /// void f() {
3455 /// someFunction();
3456 /// if (true, false) {
3457 /// f();
3458 /// }
3459 /// }
3460 /// \endcode
3461 /// \version 3.7
3462 unsigned IndentWidth;
3463
3464 /// Indent if a function definition or declaration is wrapped after the
3465 /// type.
3466 /// \code
3467 /// true:
3468 /// LoooooooooooooooooooooooooooooooooooooooongReturnType
3469 /// LoooooooooooooooooooooooooooooooongFunctionDeclaration();
3470 ///
3471 /// false:
3472 /// LoooooooooooooooooooooooooooooooooooooooongReturnType
3473 /// LoooooooooooooooooooooooooooooooongFunctionDeclaration();
3474 /// \endcode
3475 /// \version 3.7
3477
3478 /// Insert braces after control statements (`if`, `else`, `for`, `do`,
3479 /// and `while`) in C++ unless the control statements are inside macro
3480 /// definitions or the braces would enclose preprocessor directives.
3481 /// \warning
3482 /// Setting this option to `true` could lead to incorrect code formatting
3483 /// due to clang-format's lack of complete semantic information. As such,
3484 /// extra care should be taken to review code changes made by this option.
3485 /// \endwarning
3486 /// \code
3487 /// false: true:
3488 ///
3489 /// if (isa<FunctionDecl>(D)) vs. if (isa<FunctionDecl>(D)) {
3490 /// handleFunctionDecl(D); handleFunctionDecl(D);
3491 /// else if (isa<VarDecl>(D)) } else if (isa<VarDecl>(D)) {
3492 /// handleVarDecl(D); handleVarDecl(D);
3493 /// else } else {
3494 /// return; return;
3495 /// }
3496 ///
3497 /// while (i--) vs. while (i--) {
3498 /// for (auto *A : D.attrs()) for (auto *A : D.attrs()) {
3499 /// handleAttr(A); handleAttr(A);
3500 /// }
3501 /// }
3502 ///
3503 /// do vs. do {
3504 /// --i; --i;
3505 /// while (i); } while (i);
3506 /// \endcode
3507 /// \version 15
3509
3510 /// Insert a newline at end of file if missing.
3511 /// \version 16
3513
3514 /// The style of inserting trailing commas into container literals.
3516 /// Do not insert trailing commas.
3518 /// Insert trailing commas in container literals that were wrapped over
3519 /// multiple lines. Note that this is conceptually incompatible with
3520 /// bin-packing, because the trailing comma is used as an indicator
3521 /// that a container should be formatted one-per-line (i.e. not bin-packed).
3522 /// So inserting a trailing comma counteracts bin-packing.
3524 };
3525
3526 /// If set to `TCS_Wrapped` will insert trailing commas in container
3527 /// literals (arrays and objects) that wrap across multiple lines.
3528 /// It is currently only available for JavaScript
3529 /// and disabled by default `TCS_None`.
3530 /// `InsertTrailingCommas` cannot be used together with `BinPackArguments`
3531 /// as inserting the comma disables bin-packing.
3532 /// \code
3533 /// TSC_Wrapped:
3534 /// const someArray = [
3535 /// aaaaaaaaaaaaaaaaaaaaaaaaaa,
3536 /// aaaaaaaaaaaaaaaaaaaaaaaaaa,
3537 /// aaaaaaaaaaaaaaaaaaaaaaaaaa,
3538 /// // ^ inserted
3539 /// ]
3540 /// \endcode
3541 /// \version 11
3543
3544 /// Separator format of integer literals of different bases.
3545 ///
3546 /// If negative, remove separators. If `0`, leave the literal as is. If
3547 /// positive, insert separators between digits starting from the rightmost
3548 /// digit.
3549 ///
3550 /// For example, the config below will leave separators in binary literals
3551 /// alone, insert separators in decimal literals to separate the digits into
3552 /// groups of 3, and remove separators in hexadecimal literals.
3553 /// \code
3554 /// IntegerLiteralSeparator:
3555 /// Binary: 0
3556 /// Decimal: 3
3557 /// Hex: -1
3558 /// \endcode
3559 ///
3560 /// You can also specify a minimum number of digits
3561 /// (`BinaryMinDigitsInsert`, `DecimalMinDigitsInsert`, and
3562 /// `HexMinDigitsInsert`) the integer literal must have in order for the
3563 /// separators to be inserted, and a maximum number of digits
3564 /// (`BinaryMaxDigitsRemove`, `DecimalMaxDigitsRemove`, and
3565 /// `HexMaxDigitsRemove`) until the separators are removed. This divides the
3566 /// literals in 3 regions, always without separator (up until including
3567 /// `xxxMaxDigitsRemove`), maybe with, or without separators (up until
3568 /// excluding `xxxMinDigitsInsert`), and finally always with separators.
3569 /// \note
3570 /// `BinaryMinDigits`, `DecimalMinDigits`, and `HexMinDigits` are
3571 /// deprecated and renamed to `BinaryMinDigitsInsert`,
3572 /// `DecimalMinDigitsInsert`, and `HexMinDigitsInsert`, respectively.
3573 /// \endnote
3575 /// Format separators in binary literals.
3576 /// \code{.text}
3577 /// /* -1: */ b = 0b100111101101;
3578 /// /* 0: */ b = 0b10011'11'0110'1;
3579 /// /* 3: */ b = 0b100'111'101'101;
3580 /// /* 4: */ b = 0b1001'1110'1101;
3581 /// \endcode
3583 /// Format separators in binary literals with a minimum number of digits.
3584 /// \code{.text}
3585 /// // Binary: 3
3586 /// // BinaryMinDigitsInsert: 7
3587 /// b1 = 0b101101;
3588 /// b2 = 0b1'101'101;
3589 /// \endcode
3591 /// Remove separators in binary literals with a maximum number of digits.
3592 /// \code{.text}
3593 /// // Binary: 3
3594 /// // BinaryMinDigitsInsert: 7
3595 /// // BinaryMaxDigitsRemove: 4
3596 /// b0 = 0b1011; // Always removed.
3597 /// b1 = 0b101101; // Not added.
3598 /// b2 = 0b1'01'101; // Not removed, not corrected.
3599 /// b3 = 0b1'101'101; // Always added.
3600 /// b4 = 0b10'1101; // Corrected to 0b101'101.
3601 /// \endcode
3603 /// Format separators in decimal literals.
3604 /// \code{.text}
3605 /// /* -1: */ d = 18446744073709550592ull;
3606 /// /* 0: */ d = 184467'440737'0'95505'92ull;
3607 /// /* 3: */ d = 18'446'744'073'709'550'592ull;
3608 /// \endcode
3610 /// Format separators in decimal literals with a minimum number of digits.
3611 /// \code{.text}
3612 /// // Decimal: 3
3613 /// // DecimalMinDigitsInsert: 5
3614 /// d1 = 2023;
3615 /// d2 = 10'000;
3616 /// \endcode
3618 /// Remove separators in decimal literals with a maximum number of digits.
3619 /// \code{.text}
3620 /// // Decimal: 3
3621 /// // DecimalMinDigitsInsert: 7
3622 /// // DecimalMaxDigitsRemove: 4
3623 /// d0 = 2023; // Always removed.
3624 /// d1 = 123456; // Not added.
3625 /// d2 = 1'23'456; // Not removed, not corrected.
3626 /// d3 = 5'000'000; // Always added.
3627 /// d4 = 1'23'45; // Corrected to 12'345.
3628 /// \endcode
3630 /// Format separators in hexadecimal literals.
3631 /// \code{.text}
3632 /// /* -1: */ h = 0xDEADBEEFDEADBEEFuz;
3633 /// /* 0: */ h = 0xDEAD'BEEF'DE'AD'BEE'Fuz;
3634 /// /* 2: */ h = 0xDE'AD'BE'EF'DE'AD'BE'EFuz;
3635 /// \endcode
3637 /// Format separators in hexadecimal literals with a minimum number of
3638 /// digits.
3639 /// \code{.text}
3640 /// // Hex: 2
3641 /// // HexMinDigitsInsert: 6
3642 /// h1 = 0xABCDE;
3643 /// h2 = 0xAB'CD'EF;
3644 /// \endcode
3646 /// Remove separators in hexadecimal literals with a maximum number of
3647 /// digits.
3648 /// \code{.text}
3649 /// // Hex: 2
3650 /// // HexMinDigitsInsert: 6
3651 /// // HexMaxDigitsRemove: 4
3652 /// h0 = 0xAFFE; // Always removed.
3653 /// h1 = 0xABCDE; // Not added.
3654 /// h2 = 0xABC'DE; // Not removed, not corrected.
3655 /// h3 = 0xAB'CD'EF; // Always added.
3656 /// h4 = 0xABCD'E; // Corrected to 0xA'BC'DE.
3657 /// \endcode
3660 return Binary == R.Binary &&
3661 BinaryMinDigitsInsert == R.BinaryMinDigitsInsert &&
3662 BinaryMaxDigitsRemove == R.BinaryMaxDigitsRemove &&
3663 Decimal == R.Decimal &&
3664 DecimalMinDigitsInsert == R.DecimalMinDigitsInsert &&
3665 DecimalMaxDigitsRemove == R.DecimalMaxDigitsRemove &&
3666 Hex == R.Hex && HexMinDigitsInsert == R.HexMinDigitsInsert &&
3667 HexMaxDigitsRemove == R.HexMaxDigitsRemove;
3668 }
3670 return !operator==(R);
3671 }
3672 };
3673
3674 /// Format integer literal separators (`'` for C/C++ and `_` for C#, Java,
3675 /// and JavaScript).
3676 /// \version 16
3678
3679 /// A vector of prefixes ordered by the desired groups for Java imports.
3680 ///
3681 /// One group's prefix can be a subset of another - the longest prefix is
3682 /// always matched. Within a group, the imports are ordered lexicographically.
3683 /// Static imports are grouped separately and follow the same group rules.
3684 /// By default, static imports are placed before non-static imports,
3685 /// but this behavior is changed by another option,
3686 /// `SortJavaStaticImport`.
3687 ///
3688 /// In the .clang-format configuration file, this can be configured like
3689 /// in the following yaml example. This will result in imports being
3690 /// formatted as in the Java example below.
3691 /// \code{.yaml}
3692 /// JavaImportGroups: [com.example, com, org]
3693 /// \endcode
3694 ///
3695 /// \code{.java}
3696 /// import static com.example.function1;
3697 ///
3698 /// import static com.test.function2;
3699 ///
3700 /// import static org.example.function3;
3701 ///
3702 /// import com.example.ClassA;
3703 /// import com.example.Test;
3704 /// import com.example.a.ClassB;
3705 ///
3706 /// import com.test.ClassC;
3707 ///
3708 /// import org.example.ClassD;
3709 /// \endcode
3710 /// \version 8
3711 std::vector<std::string> JavaImportGroups;
3712
3713 /// Quotation styles for JavaScript strings. Does not affect template
3714 /// strings.
3716 /// Leave string quotes as they are.
3717 /// \code{.js}
3718 /// string1 = "foo";
3719 /// string2 = 'bar';
3720 /// \endcode
3722 /// Always use single quotes.
3723 /// \code{.js}
3724 /// string1 = 'foo';
3725 /// string2 = 'bar';
3726 /// \endcode
3728 /// Always use double quotes.
3729 /// \code{.js}
3730 /// string1 = "foo";
3731 /// string2 = "bar";
3732 /// \endcode
3734 };
3735
3736 /// The JavaScriptQuoteStyle to use for JavaScript strings.
3737 /// \version 3.9
3739
3740 // clang-format off
3741 /// Whether to wrap JavaScript import/export statements.
3742 /// \code{.js}
3743 /// true:
3744 /// import {
3745 /// VeryLongImportsAreAnnoying,
3746 /// VeryLongImportsAreAnnoying,
3747 /// VeryLongImportsAreAnnoying,
3748 /// } from "some/module.js"
3749 ///
3750 /// false:
3751 /// import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js"
3752 /// \endcode
3753 /// \version 3.9
3755 // clang-format on
3756
3757 /// Options regarding which empty lines are kept.
3758 ///
3759 /// For example, the config below will remove empty lines at start of the
3760 /// file, end of the file, and start of blocks.
3761 ///
3762 /// \code
3763 /// KeepEmptyLines:
3764 /// AtEndOfBlock: false
3765 /// AtEndOfFile: false
3766 /// AtStartOfBlock: false
3767 /// AtStartOfFile: false
3768 /// \endcode
3770 /// Keep empty lines at end of a block.
3771 /// \code
3772 /// true: false:
3773 /// if (foo) { vs. if (foo) {
3774 /// bar(); bar();
3775 /// }
3776 /// }
3777 /// \endcode
3779 /// Keep empty lines at end of file.
3781 /// Keep empty lines at start of a block.
3782 /// \code
3783 /// true: false:
3784 /// if (foo) { vs. if (foo) {
3785 /// bar();
3786 /// bar(); }
3787 /// }
3788 /// \endcode
3790 /// Keep empty lines at start of file.
3792 bool operator==(const KeepEmptyLinesStyle &R) const {
3793 return AtEndOfBlock == R.AtEndOfBlock && AtEndOfFile == R.AtEndOfFile &&
3794 AtStartOfBlock == R.AtStartOfBlock &&
3795 AtStartOfFile == R.AtStartOfFile;
3796 }
3797 };
3798 /// Which empty lines are kept. See `MaxEmptyLinesToKeep` for how many
3799 /// consecutive empty lines are kept.
3800 /// \version 19
3802
3803 /// This option is **deprecated**. See `AtEndOfFile` of `KeepEmptyLines`.
3804 /// \version 17
3805 // bool KeepEmptyLinesAtEOF;
3806
3807 /// This option is **deprecated**. See `AtStartOfBlock` of
3808 /// `KeepEmptyLines`.
3809 /// \version 3.7
3810 // bool KeepEmptyLinesAtTheStartOfBlocks;
3811
3812 /// Keep the form feed character if it's immediately preceded and followed by
3813 /// a newline. Multiple form feeds and newlines within a whitespace range are
3814 /// replaced with a single newline and form feed followed by the remaining
3815 /// newlines. (See
3816 /// www.gnu.org/prep/standards/html_node/Formatting.html#:~:text=formfeed.)
3817 /// \version 20
3819
3820 /// Indentation logic for lambda bodies.
3822 /// Align lambda body relative to the lambda signature. This is the default.
3823 /// \code
3824 /// someMethod(
3825 /// [](SomeReallyLongLambdaSignatureArgument foo) {
3826 /// return;
3827 /// });
3828 /// \endcode
3830 /// For statements within block scope, align lambda body relative to the
3831 /// indentation level of the outer scope the lambda signature resides in.
3832 /// \code
3833 /// someMethod(
3834 /// [](SomeReallyLongLambdaSignatureArgument foo) {
3835 /// return;
3836 /// });
3837 ///
3838 /// someMethod(someOtherMethod(
3839 /// [](SomeReallyLongLambdaSignatureArgument foo) {
3840 /// return;
3841 /// }));
3842 /// \endcode
3844 };
3845
3846 /// The indentation style of lambda bodies. `Signature` (the default)
3847 /// causes the lambda body to be indented one additional level relative to
3848 /// the indentation level of the signature. `OuterScope` forces the lambda
3849 /// body to be indented one additional level relative to the parent scope
3850 /// containing the lambda signature.
3851 /// \version 13
3853
3854 /// Supported languages.
3855 ///
3856 /// When stored in a configuration file, specifies the language, that the
3857 /// configuration targets. When passed to the `reformat()` function, enables
3858 /// syntax features specific to the language.
3860 /// Do not use.
3862 /// Should be used for C.
3864 /// Should be used for C++.
3866 /// Should be used for C#.
3868 /// Should be used for Java.
3870 /// Should be used for JavaScript.
3872 /// Should be used for JSON.
3874 /// Should be used for Objective-C, Objective-C++.
3876 /// Should be used for [Protocol Buffers](https://protobuf.dev/)
3878 /// Should be used for TableGen code.
3880 /// Should be used for [Protocol Buffer](https://protobuf.dev/) messages in
3881 /// text format
3883 /// Should be used for Verilog and SystemVerilog.
3884 /// https://standards.ieee.org/ieee/1800/6700/
3885 /// https://sci-hub.st/10.1109/IEEESTD.2018.8299595
3887 };
3888 bool isCpp() const {
3889 return Language == LK_Cpp || Language == LK_C || Language == LK_ObjC;
3890 }
3891 bool isCSharp() const { return Language == LK_CSharp; }
3892 bool isJson() const { return Language == LK_Json; }
3893 bool isJava() const { return Language == LK_Java; }
3894 bool isJavaScript() const { return Language == LK_JavaScript; }
3895 bool isVerilog() const { return Language == LK_Verilog; }
3896 bool isTextProto() const { return Language == LK_TextProto; }
3897 bool isProto() const { return Language == LK_Proto || isTextProto(); }
3898 bool isTableGen() const { return Language == LK_TableGen; }
3899
3900 /// The language that this format style targets.
3901 /// \note
3902 /// You can specify the language (`C`, `Cpp`, or `ObjC`) for `.h`
3903 /// files by adding a `// clang-format Language:` line before the first
3904 /// non-comment (and non-empty) line, e.g. `// clang-format Language: Cpp`.
3905 /// \endnote
3906 /// \version 3.5
3908
3909 /// Line ending style.
3911 /// Use `\n`.
3913 /// Use `\r\n`.
3915 /// Use `\n` unless the input has more lines ending in `\r\n`.
3917 /// Use `\r\n` unless the input has more lines ending in `\n`.
3919 };
3920
3921 /// Line ending style (`\n` or `\r\n`) to use.
3922 /// \version 16
3924
3925 /// A regular expression matching macros that start a block.
3926 /// \code
3927 /// # With:
3928 /// MacroBlockBegin: "^NS_MAP_BEGIN|\
3929 /// NS_TABLE_HEAD$"
3930 /// MacroBlockEnd: "^\
3931 /// NS_MAP_END|\
3932 /// NS_TABLE_.*_END$"
3933 ///
3934 /// NS_MAP_BEGIN
3935 /// foo();
3936 /// NS_MAP_END
3937 ///
3938 /// NS_TABLE_HEAD
3939 /// bar();
3940 /// NS_TABLE_FOO_END
3941 ///
3942 /// # Without:
3943 /// NS_MAP_BEGIN
3944 /// foo();
3945 /// NS_MAP_END
3946 ///
3947 /// NS_TABLE_HEAD
3948 /// bar();
3949 /// NS_TABLE_FOO_END
3950 /// \endcode
3951 /// \version 3.7
3952 std::string MacroBlockBegin;
3953
3954 /// A regular expression matching macros that end a block.
3955 /// \version 3.7
3956 std::string MacroBlockEnd;
3957
3958 /// A list of macros of the form \c <definition>=<expansion> .
3959 ///
3960 /// Code will be parsed with macros expanded, in order to determine how to
3961 /// interpret and format the macro arguments.
3962 ///
3963 /// For example, the code:
3964 /// \code
3965 /// A(a*b);
3966 /// \endcode
3967 ///
3968 /// will usually be interpreted as a call to a function A, and the
3969 /// multiplication expression will be formatted as `a * b`.
3970 ///
3971 /// If we specify the macro definition:
3972 /// \code{.yaml}
3973 /// Macros:
3974 /// - A(x)=x
3975 /// \endcode
3976 ///
3977 /// the code will now be parsed as a declaration of the variable b of type a*,
3978 /// and formatted as `a* b` (depending on pointer-binding rules).
3979 ///
3980 /// Features and restrictions:
3981 ///
3982 /// - Both function-like macros and object-like macros are supported.
3983 /// - Macro arguments must be used exactly once in the expansion.
3984 /// - No recursive expansion; macros referencing other macros will be
3985 /// ignored.
3986 /// - Overloading by arity is supported: for example, given the macro
3987 /// definitions A=x, A()=y, A(a)=a
3988 ///
3989 /// \code
3990 /// A; -> x;
3991 /// A(); -> y;
3992 /// A(z); -> z;
3993 /// A(a, b); // will not be expanded.
3994 /// \endcode
3995 ///
3996 /// \version 17
3997 std::vector<std::string> Macros;
3999 /// A vector of function-like macros whose invocations should be skipped by
4000 /// `RemoveParentheses`.
4001 /// \version 21
4002 std::vector<std::string> MacrosSkippedByRemoveParentheses;
4003
4004 /// The maximum number of consecutive empty lines to keep.
4005 /// \code
4006 /// MaxEmptyLinesToKeep: 1 vs. MaxEmptyLinesToKeep: 0
4007 /// int f() { int f() {
4008 /// int = 1; int i = 1;
4009 /// i = foo();
4010 /// i = foo(); return i;
4011 /// }
4012 /// return i;
4013 /// }
4014 /// \endcode
4015 /// \version 3.7
4016 unsigned MaxEmptyLinesToKeep;
4017
4018 /// Different ways to indent namespace contents.
4020 /// Don't indent in namespaces.
4021 /// \code
4022 /// namespace out {
4023 /// int i;
4024 /// namespace in {
4025 /// int i;
4026 /// }
4027 /// }
4028 /// \endcode
4029 NI_None,
4030 /// Indent only in inner namespaces (nested in other namespaces).
4031 /// \code
4032 /// namespace out {
4033 /// int i;
4034 /// namespace in {
4035 /// int i;
4036 /// }
4037 /// }
4038 /// \endcode
4039 NI_Inner,
4040 /// Indent in all namespaces.
4041 /// \code
4042 /// namespace out {
4043 /// int i;
4044 /// namespace in {
4045 /// int i;
4046 /// }
4047 /// }
4048 /// \endcode
4049 NI_All
4051
4052 /// The indentation used for namespaces.
4053 /// \version 3.7
4054 NamespaceIndentationKind NamespaceIndentation;
4055
4056 /// A vector of macros which are used to open namespace blocks.
4057 ///
4058 /// These are expected to be macros of the form:
4059 /// \code
4060 /// NAMESPACE(<namespace-name>, ...) {
4061 /// <namespace-content>
4062 /// }
4063 /// \endcode
4064 ///
4065 /// For example: TESTSUITE
4066 /// \version 9
4067 std::vector<std::string> NamespaceMacros;
4069 /// Control over each component in a numeric literal.
4071 /// Leave this component of the literal as is.
4073 /// Format this component with uppercase characters.
4074 NLCS_Upper,
4075 /// Format this component with lowercase characters.
4076 NLCS_Lower,
4077 };
4078
4079 /// Separate control for each numeric literal component.
4080 ///
4081 /// For example, the config below will leave exponent letters alone, reformat
4082 /// hexadecimal digits in lowercase, reformat numeric literal prefixes in
4083 /// uppercase, and reformat suffixes in lowercase.
4084 /// \code
4085 /// NumericLiteralCase:
4086 /// ExponentLetter: Leave
4087 /// HexDigit: Lower
4088 /// Prefix: Upper
4089 /// Suffix: Lower
4090 /// \endcode
4092 /// Format floating point exponent separator letter case.
4093 /// \code
4094 /// float a = 6.02e23 + 1.0E10; // Leave
4095 /// float a = 6.02E23 + 1.0E10; // Upper
4096 /// float a = 6.02e23 + 1.0e10; // Lower
4097 /// \endcode
4099 /// Format hexadecimal digit case.
4100 /// \code
4101 /// a = 0xaBcDeF; // Leave
4102 /// a = 0xABCDEF; // Upper
4103 /// a = 0xabcdef; // Lower
4104 /// \endcode
4106 /// Format integer prefix case.
4107 /// \code
4108 /// a = 0XF0 | 0b1; // Leave
4109 /// a = 0XF0 | 0B1; // Upper
4110 /// a = 0xF0 | 0b1; // Lower
4111 /// \endcode
4113 /// Format suffix case. This option excludes case-sensitive reserved
4114 /// suffixes, such as `min` in C++.
4115 /// \code
4116 /// a = 1uLL; // Leave
4117 /// a = 1ULL; // Upper
4118 /// a = 1ull; // Lower
4119 /// \endcode
4121
4122 bool operator==(const NumericLiteralCaseStyle &R) const {
4123 return ExponentLetter == R.ExponentLetter && HexDigit == R.HexDigit &&
4124 Prefix == R.Prefix && Suffix == R.Suffix;
4125 }
4126
4127 bool operator!=(const NumericLiteralCaseStyle &R) const {
4128 return !(*this == R);
4129 }
4131
4132 /// Capitalization style for numeric literals.
4133 /// \version 22
4134 NumericLiteralCaseStyle NumericLiteralCase;
4135
4136 /// Controls bin-packing Objective-C protocol conformance list
4137 /// items into as few lines as possible when they go over `ColumnLimit`.
4138 ///
4139 /// If `Auto` (the default), delegates to the value in
4140 /// `BinPackParameters`. If that is `BinPack`, bin-packs Objective-C
4141 /// protocol conformance list items into as few lines as possible
4142 /// whenever they go over `ColumnLimit`.
4143 ///
4144 /// If `Always`, always bin-packs Objective-C protocol conformance
4145 /// list items into as few lines as possible whenever they go over
4146 /// `ColumnLimit`.
4147 ///
4148 /// If `Never`, lays out Objective-C protocol conformance list items
4149 /// onto individual lines whenever they go over `ColumnLimit`.
4150 ///
4151 /// \code{.objc}
4152 /// Always (or Auto, if BinPackParameters==BinPack):
4153 /// @interface ccccccccccccc () <
4154 /// ccccccccccccc, ccccccccccccc,
4155 /// ccccccccccccc, ccccccccccccc> {
4156 /// }
4157 ///
4158 /// Never (or Auto, if BinPackParameters!=BinPack):
4159 /// @interface ddddddddddddd () <
4160 /// ddddddddddddd,
4161 /// ddddddddddddd,
4162 /// ddddddddddddd,
4163 /// ddddddddddddd> {
4164 /// }
4165 /// \endcode
4166 /// \version 7
4168
4169 /// The number of characters to use for indentation of ObjC blocks.
4170 /// \code{.objc}
4171 /// ObjCBlockIndentWidth: 4
4172 ///
4173 /// [operation setCompletionBlock:^{
4174 /// [self onOperationDone];
4175 /// }];
4176 /// \endcode
4177 /// \version 3.7
4178 unsigned ObjCBlockIndentWidth;
4179
4180 /// Break parameters list into lines when there is nested block
4181 /// parameters in a function call.
4182 /// \code
4183 /// false:
4184 /// - (void)_aMethod
4185 /// {
4186 /// [self.test1 t:self w:self callback:^(typeof(self) self, NSNumber
4187 /// *u, NSNumber *v) {
4188 /// u = c;
4189 /// }]
4190 /// }
4191 /// true:
4192 /// - (void)_aMethod
4193 /// {
4194 /// [self.test1 t:self
4195 /// w:self
4196 /// callback:^(typeof(self) self, NSNumber *u, NSNumber *v) {
4197 /// u = c;
4198 /// }]
4199 /// }
4200 /// \endcode
4201 /// \version 11
4203
4204 /// The order in which ObjC property attributes should appear.
4205 ///
4206 /// Attributes in code will be sorted in the order specified. Any attributes
4207 /// encountered that are not mentioned in this array will be sorted last, in
4208 /// stable order. Comments between attributes will leave the attributes
4209 /// untouched.
4210 /// \warning
4211 /// Using this option could lead to incorrect code formatting due to
4212 /// clang-format's lack of complete semantic information. As such, extra
4213 /// care should be taken to review code changes made by this option.
4214 /// \endwarning
4215 /// \code{.yaml}
4216 /// ObjCPropertyAttributeOrder: [
4217 /// class, direct,
4218 /// atomic, nonatomic,
4219 /// assign, retain, strong, copy, weak, unsafe_unretained,
4220 /// readonly, readwrite, getter, setter,
4221 /// nullable, nonnull, null_resettable, null_unspecified
4222 /// ]
4223 /// \endcode
4224 /// \version 18
4225 std::vector<std::string> ObjCPropertyAttributeOrder;
4226
4227 /// Add or remove a space between the '-'/'+' and the return type in
4228 /// Objective-C method declarations. i.e
4229 /// \code{.objc}
4230 /// false: true:
4231 ///
4232 /// -(void)method vs. - (void)method
4233 /// \endcode
4234 /// \version 23
4237 /// Add a space after `@property` in Objective-C, i.e. use
4238 /// `@property (readonly)` instead of `@property(readonly)`.
4239 /// \version 3.7
4242 /// Add a space in front of an Objective-C protocol list, i.e. use
4243 /// `Foo <Protocol>` instead of `Foo<Protocol>`.
4244 /// \version 3.7
4246
4247 /// A regular expression that describes markers for turning formatting off for
4248 /// one line. If it matches a comment that is the only token of a line,
4249 /// clang-format skips the comment and the next line. Otherwise, clang-format
4250 /// skips lines containing a matched token.
4251 /// \note
4252 /// This option does not apply to `IntegerLiteralSeparator` and
4253 /// `NumericLiteralCase`.
4254 /// \endnote
4255 /// \code
4256 /// // OneLineFormatOffRegex: ^(// NOLINT|logger$)
4257 /// // results in the output below:
4258 /// int a;
4259 /// int b ; // NOLINT
4260 /// int c;
4261 /// // NOLINTNEXTLINE
4262 /// int d ;
4263 /// int e;
4264 /// s = "// NOLINT";
4265 /// logger() ;
4266 /// logger2();
4267 /// my_logger();
4268 /// \endcode
4269 /// \version 21
4270 std::string OneLineFormatOffRegex;
4271
4272 /// Different ways to try to fit all arguments on a line.
4274 /// Bin-pack arguments.
4275 /// \code
4276 /// void f() {
4277 /// f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa,
4278 /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
4279 /// }
4280 /// \endcode
4282 /// Put all arguments on the current line if they fit.
4283 /// Otherwise, put each one on its own line.
4284 /// \code
4285 /// void f() {
4286 /// f(aaaaaaaaaaaaaaaaaaaa,
4287 /// aaaaaaaaaaaaaaaaaaaa,
4288 /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
4289 /// }
4290 /// \endcode
4292 /// Use the `BreakAfter` option to handle argument packing instead.
4293 /// If the `BreakAfter` limit is not exceeded, behave like `BinPack`.
4295 };
4296
4297 /// Options related to packing arguments of function calls.
4299
4300 /// The bin pack arguments style to use.
4301 /// \version 3.7
4303
4304 /// An argument list with more arguments than the specified number will be
4305 /// formatted with one argument per line. This option must be used with
4306 /// `BinPack: UseBreakAfter`.
4307 /// \code
4308 /// PackArguments:
4309 /// BinPack: UseBreakAfter
4310 /// BreakAfter: 3
4311 ///
4312 /// void f() {
4313 /// foo(1);
4314 ///
4315 /// bar(1, 2, 3);
4316 ///
4317 /// baz(1,
4318 /// 2,
4319 /// 3,
4320 /// 4);
4321 /// }
4322 /// \endcode
4323 /// \version 23
4324 unsigned BreakAfter;
4326 bool operator==(const PackArgumentsStyle &R) const {
4327 return BinPack == R.BinPack && BreakAfter == R.BreakAfter;
4328 }
4329 bool operator!=(const PackArgumentsStyle &R) const {
4330 return !operator==(R);
4331 }
4333
4334 /// Options related to packing arguments of function calls.
4335 /// \version 23
4337
4338 /// Different ways to try to fit all constructor initializers on a line.
4340 /// Always put each constructor initializer on its own line.
4341 /// \code
4342 /// Constructor()
4343 /// : a(),
4344 /// b()
4345 /// \endcode
4346 PCIS_Never,
4347 /// Bin-pack constructor initializers.
4348 /// \code
4349 /// Constructor()
4350 /// : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(),
4351 /// cccccccccccccccccccc()
4352 /// \endcode
4354 /// Put all constructor initializers on the current line if they fit.
4355 /// Otherwise, put each one on its own line.
4356 /// \code
4357 /// Constructor() : a(), b()
4358 ///
4359 /// Constructor()
4360 /// : aaaaaaaaaaaaaaaaaaaa(),
4361 /// bbbbbbbbbbbbbbbbbbbb(),
4362 /// ddddddddddddd()
4363 /// \endcode
4365 /// Same as `PCIS_CurrentLine` except that if all constructor initializers
4366 /// do not fit on the current line, try to fit them on the next line.
4367 /// \code
4368 /// Constructor() : a(), b()
4369 ///
4370 /// Constructor()
4371 /// : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), ddddddddddddd()
4372 ///
4373 /// Constructor()
4374 /// : aaaaaaaaaaaaaaaaaaaa(),
4375 /// bbbbbbbbbbbbbbbbbbbb(),
4376 /// cccccccccccccccccccc()
4377 /// \endcode
4379 /// Put all constructor initializers on the next line if they fit.
4380 /// Otherwise, put each one on its own line.
4381 /// \code
4382 /// Constructor()
4383 /// : a(), b()
4384 ///
4385 /// Constructor()
4386 /// : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), ddddddddddddd()
4387 ///
4388 /// Constructor()
4389 /// : aaaaaaaaaaaaaaaaaaaa(),
4390 /// bbbbbbbbbbbbbbbbbbbb(),
4391 /// cccccccccccccccccccc()
4392 /// \endcode
4395
4396 /// The pack constructor initializers style to use.
4397 /// \version 14
4399
4400 /// Different ways to try to fit all parameters on a line.
4402 /// Bin-pack parameters.
4403 /// \code
4404 /// void f(int a, int bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
4405 /// int ccccccccccccccccccccccccccccccccccccccccccc);
4406 /// \endcode
4408 /// Put all parameters on the current line if they fit.
4409 /// Otherwise, put each one on its own line.
4410 /// \code
4411 /// void f(int a, int b, int c);
4412 ///
4413 /// void f(int a,
4414 /// int b,
4415 /// int ccccccccccccccccccccccccccccccccccccc);
4416 /// \endcode
4418 /// Always put each parameter on its own line.
4419 /// \code
4420 /// void f(int a,
4421 /// int b,
4422 /// int c);
4423 /// \endcode
4425 /// Use the `BreakAfter` option to handle parameter packing instead.
4426 /// If the `BreakAfter` limit is not exceeded, behave like `BinPack`.
4429
4430 /// Options related to packing parameters of function declarations and
4431 /// definitions.
4433
4434 /// The bin pack parameters style to use.
4435 /// \version 3.7
4437
4438 /// A parameter list with more parameters than the specified number will be
4439 /// formatted with one parameter per line. This option must be used with
4440 /// `BinPack: UseBreakAfter`.
4441 /// \code
4442 /// PackParameters:
4443 /// BinPack: UseBreakAfter
4444 /// BreakAfter: 3
4445 ///
4446 /// void foo(int a);
4447 ///
4448 /// void bar(int a, int b, int c);
4449 ///
4450 /// void baz(int a,
4451 /// int b,
4452 /// int c,
4453 /// int d);
4454 /// \endcode
4455 /// \version 23
4456 unsigned BreakAfter;
4458 bool operator==(const PackParametersStyle &R) const {
4459 return BinPack == R.BinPack && BreakAfter == R.BreakAfter;
4460 }
4461 bool operator!=(const PackParametersStyle &R) const {
4462 return !operator==(R);
4463 }
4464 };
4466 /// Options related to packing parameters of function declarations and
4467 /// definitions.
4468 /// \version 23
4470
4471 /// The penalty for breaking around an assignment operator.
4472 /// \version 5
4474
4475 /// The penalty for breaking a function call after `call(`.
4476 /// \version 3.7
4478
4479 /// The penalty for breaking before a member access operator (`.`, `->`).
4480 /// \version 20
4482
4483 /// The penalty for each line break introduced inside a comment.
4484 /// \version 3.7
4486
4487 /// The penalty for breaking before the first `<<`.
4488 /// \version 3.7
4490
4491 /// The penalty for breaking after `(`.
4492 /// \version 14
4494
4495 /// The penalty for breaking after `::`.
4496 /// \version 18
4498
4499 /// The penalty for each line break introduced inside a string literal.
4500 /// \version 3.7
4502
4503 /// The penalty for breaking after template declaration.
4504 /// \version 7
4506
4507 /// The penalty for each character outside of the column limit.
4508 /// \version 3.7
4509 unsigned PenaltyExcessCharacter;
4511 /// Penalty for each character of whitespace indentation
4512 /// (counted relative to leading non-whitespace column).
4513 /// \version 12
4515
4516 /// Penalty for putting the return type of a function onto its own line.
4517 /// \version 3.7
4519
4520 /// The `&`, `&&` and `*` alignment style.
4522 /// Align pointer to the left.
4523 /// \code
4524 /// int* a;
4525 /// \endcode
4526 PAS_Left,
4527 /// Align pointer to the right.
4528 /// \code
4529 /// int *a;
4530 /// \endcode
4531 PAS_Right,
4532 /// Align pointer in the middle.
4533 /// \code
4534 /// int * a;
4535 /// \endcode
4538
4539 /// Pointer and reference alignment style.
4540 /// \version 3.7
4541 PointerAlignmentStyle PointerAlignment;
4542
4543 /// The number of columns to use for indentation of preprocessor statements.
4544 /// When set to -1 (default) `IndentWidth` is used also for preprocessor
4545 /// statements.
4546 /// \code
4547 /// PPIndentWidth: 1
4548 ///
4549 /// #ifdef __linux__
4550 /// # define FOO
4551 /// #else
4552 /// # define BAR
4553 /// #endif
4554 /// \endcode
4555 /// \version 13
4556 int PPIndentWidth;
4557
4558 /// Different specifiers and qualifiers alignment styles.
4560 /// Don't change specifiers/qualifiers to either Left or Right alignment
4561 /// (default).
4562 /// \code
4563 /// int const a;
4564 /// const int *a;
4565 /// \endcode
4566 QAS_Leave,
4567 /// Change specifiers/qualifiers to be left-aligned.
4568 /// \code
4569 /// const int a;
4570 /// const int *a;
4571 /// \endcode
4572 QAS_Left,
4573 /// Change specifiers/qualifiers to be right-aligned.
4574 /// \code
4575 /// int const a;
4576 /// int const *a;
4577 /// \endcode
4578 QAS_Right,
4579 /// Change specifiers/qualifiers to be aligned based on `QualifierOrder`.
4580 /// With:
4581 /// \code{.yaml}
4582 /// QualifierOrder: [inline, static, type, const]
4583 /// \endcode
4584 ///
4585 /// \code
4586 ///
4587 /// int const a;
4588 /// int const *a;
4589 /// \endcode
4591 };
4592
4593 /// Different ways to arrange specifiers and qualifiers (e.g. const/volatile).
4594 /// \warning
4595 /// Setting `QualifierAlignment` to something other than `Leave`, COULD
4596 /// lead to incorrect code formatting due to incorrect decisions made due to
4597 /// clang-formats lack of complete semantic information.
4598 /// As such extra care should be taken to review code changes made by the use
4599 /// of this option.
4600 /// \endwarning
4601 /// \version 14
4603
4604 /// The order in which the qualifiers appear.
4605 /// The order is an array that can contain any of the following:
4606 ///
4607 /// * `const`
4608 /// * `inline`
4609 /// * `static`
4610 /// * `friend`
4611 /// * `constexpr`
4612 /// * `volatile`
4613 /// * `restrict`
4614 /// * `typedef`
4615 /// * `consteval`
4616 /// * `constinit`
4617 /// * `thread_local`
4618 /// * `extern`
4619 /// * `mutable`
4620 /// * `signed`
4621 /// * `unsigned`
4622 /// * `long`
4623 /// * `short`
4624 /// * `explicit`
4625 /// * `type`
4626 ///
4627 /// \note
4628 /// It must contain `type`.
4629 /// \endnote
4630 ///
4631 /// Items to the left of `type` will be placed to the left of the type and
4632 /// aligned in the order supplied. Items to the right of `type` will be
4633 /// placed to the right of the type and aligned in the order supplied.
4634 /// If only one of `signed` and `unsigned` is specified, both are placed at
4635 /// that position. The same applies to `long` and `short`. Specifying both
4636 /// members of a pair allows them to be placed independently.
4637 ///
4638 /// \code{.yaml}
4639 /// QualifierOrder: [inline, static, type, const, volatile]
4640 /// \endcode
4641 /// \version 14
4642 std::vector<std::string> QualifierOrder;
4644 /// See documentation of `RawStringFormats`.
4646 /// The language of this raw string.
4648 /// A list of raw string delimiters that match this language.
4649 std::vector<std::string> Delimiters;
4650 /// A list of enclosing function names that match this language.
4651 std::vector<std::string> EnclosingFunctions;
4652 /// The canonical delimiter for this language.
4654 /// The style name on which this raw string format is based on.
4655 /// If not specified, the raw string format is based on the style that this
4656 /// format is based on.
4657 std::string BasedOnStyle;
4658 bool operator==(const RawStringFormat &Other) const {
4659 return Language == Other.Language && Delimiters == Other.Delimiters &&
4660 EnclosingFunctions == Other.EnclosingFunctions &&
4661 CanonicalDelimiter == Other.CanonicalDelimiter &&
4662 BasedOnStyle == Other.BasedOnStyle;
4663 }
4664 };
4665
4666 /// Defines hints for detecting supported languages code blocks in raw
4667 /// strings.
4668 ///
4669 /// A raw string with a matching delimiter or a matching enclosing function
4670 /// name will be reformatted assuming the specified language based on the
4671 /// style for that language defined in the .clang-format file. If no style has
4672 /// been defined in the .clang-format file for the specific language, a
4673 /// predefined style given by `BasedOnStyle` is used. If `BasedOnStyle` is
4674 /// not found, the formatting is based on `LLVM` style. A matching delimiter
4675 /// takes precedence over a matching enclosing function name for determining
4676 /// the language of the raw string contents.
4677 ///
4678 /// If a canonical delimiter is specified, occurrences of other delimiters for
4679 /// the same language will be updated to the canonical if possible.
4680 ///
4681 /// There should be at most one specification per language and each delimiter
4682 /// and enclosing function should not occur in multiple specifications.
4683 ///
4684 /// To configure this in the .clang-format file, use:
4685 /// \code{.yaml}
4686 /// RawStringFormats:
4687 /// - Language: TextProto
4688 /// Delimiters:
4689 /// - pb
4690 /// - proto
4691 /// EnclosingFunctions:
4692 /// - PARSE_TEXT_PROTO
4693 /// BasedOnStyle: google
4694 /// - Language: Cpp
4695 /// Delimiters:
4696 /// - cc
4697 /// - cpp
4698 /// BasedOnStyle: LLVM
4699 /// CanonicalDelimiter: cc
4700 /// \endcode
4701 /// \version 6
4702 std::vector<RawStringFormat> RawStringFormats;
4704 /// The `&` and `&&` alignment style.
4706 /// Align reference like `PointerAlignment`.
4708 /// Align reference to the left.
4709 /// \code
4710 /// int& a;
4711 /// \endcode
4712 RAS_Left,
4713 /// Align reference to the right.
4714 /// \code
4715 /// int &a;
4716 /// \endcode
4717 RAS_Right,
4718 /// Align reference in the middle.
4719 /// \code
4720 /// int & a;
4721 /// \endcode
4724
4725 /// Reference alignment style (overrides `PointerAlignment` for references).
4726 /// \version 13
4728
4729 // clang-format off
4730 /// Types of comment reflow style.
4732 /// Leave comments untouched.
4733 /// \code
4734 /// // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
4735 /// /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */
4736 /// /* third veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
4737 /// * and a misaligned second line */
4738 /// \endcode
4739 RCS_Never,
4740 /// Only apply indentation rules, moving comments left or right, without
4741 /// changing formatting inside the comments.
4742 /// \code
4743 /// // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
4744 /// /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */
4745 /// /* third veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
4746 /// * and a misaligned second line */
4747 /// \endcode
4749 /// Apply indentation rules and reflow long comments into new lines, trying
4750 /// to obey the `ColumnLimit`.
4751 /// \code
4752 /// // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
4753 /// // information
4754 /// /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
4755 /// * information */
4756 /// /* third veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
4757 /// * information and a misaligned second line */
4758 /// \endcode
4760 };
4761 // clang-format on
4762
4763 /// Comment reformatting style.
4764 /// \version 3.8
4766
4767 /// Remove optional braces of control statements (`if`, `else`, `for`,
4768 /// and `while`) in C++ according to the LLVM coding style.
4769 /// \warning
4770 /// This option will be renamed and expanded to support other styles.
4771 /// \endwarning
4772 /// \warning
4773 /// Setting this option to `true` could lead to incorrect code formatting
4774 /// due to clang-format's lack of complete semantic information. As such,
4775 /// extra care should be taken to review code changes made by this option.
4776 /// \endwarning
4777 /// \code
4778 /// false: true:
4779 ///
4780 /// if (isa<FunctionDecl>(D)) { vs. if (isa<FunctionDecl>(D))
4781 /// handleFunctionDecl(D); handleFunctionDecl(D);
4782 /// } else if (isa<VarDecl>(D)) { else if (isa<VarDecl>(D))
4783 /// handleVarDecl(D); handleVarDecl(D);
4784 /// }
4785 ///
4786 /// if (isa<VarDecl>(D)) { vs. if (isa<VarDecl>(D)) {
4787 /// for (auto *A : D.attrs()) { for (auto *A : D.attrs())
4788 /// if (shouldProcessAttr(A)) { if (shouldProcessAttr(A))
4789 /// handleAttr(A); handleAttr(A);
4790 /// } }
4791 /// }
4792 /// }
4793 ///
4794 /// if (isa<FunctionDecl>(D)) { vs. if (isa<FunctionDecl>(D))
4795 /// for (auto *A : D.attrs()) { for (auto *A : D.attrs())
4796 /// handleAttr(A); handleAttr(A);
4797 /// }
4798 /// }
4799 ///
4800 /// if (auto *D = (T)(D)) { vs. if (auto *D = (T)(D)) {
4801 /// if (shouldProcess(D)) { if (shouldProcess(D))
4802 /// handleVarDecl(D); handleVarDecl(D);
4803 /// } else { else
4804 /// markAsIgnored(D); markAsIgnored(D);
4805 /// } }
4806 /// }
4807 ///
4808 /// if (a) { vs. if (a)
4809 /// b(); b();
4810 /// } else { else if (c)
4811 /// if (c) { d();
4812 /// d(); else
4813 /// } else { e();
4814 /// e();
4815 /// }
4816 /// }
4817 /// \endcode
4818 /// \version 14
4819 bool RemoveBracesLLVM;
4820
4821 /// Remove empty lines within unwrapped lines.
4822 /// \code
4823 /// false: true:
4824 ///
4825 /// int c vs. int c = a + b;
4826 ///
4827 /// = a + b;
4828 ///
4829 /// enum : unsigned vs. enum : unsigned {
4830 /// AA = 0,
4831 /// { BB
4832 /// AA = 0, } myEnum;
4833 /// BB
4834 /// } myEnum;
4835 ///
4836 /// while ( vs. while (true) {
4837 /// }
4838 /// true) {
4839 /// }
4840 /// \endcode
4841 /// \version 20
4843
4844 /// Types of redundant parentheses to remove.
4846 /// Do not remove parentheses.
4847 /// \code
4848 /// class __declspec((dllimport)) X {};
4849 /// co_return (((0)));
4850 /// return ((a + b) - ((c + d)));
4851 /// \endcode
4852 RPS_Leave,
4853 /// Replace multiple parentheses with single parentheses.
4854 /// \code
4855 /// class __declspec(dllimport) X {};
4856 /// co_return (0);
4857 /// return ((a + b) - (c + d));
4858 /// \endcode
4860 /// Also remove parentheses enclosing the expression in a
4861 /// `return`/`co_return` statement.
4862 /// \code
4863 /// class __declspec(dllimport) X {};
4864 /// co_return 0;
4865 /// return (a + b) - (c + d);
4866 /// \endcode
4868 };
4869
4870 /// Remove redundant parentheses.
4871 /// \warning
4872 /// Setting this option to any value other than `Leave` could lead to
4873 /// incorrect code formatting due to clang-format's lack of complete semantic
4874 /// information. As such, extra care should be taken to review code changes
4875 /// made by this option.
4876 /// \endwarning
4877 /// \version 17
4879
4880 /// Remove semicolons after the closing braces of functions and
4881 /// constructors/destructors.
4882 /// \warning
4883 /// Setting this option to `true` could lead to incorrect code formatting
4884 /// due to clang-format's lack of complete semantic information. As such,
4885 /// extra care should be taken to review code changes made by this option.
4886 /// \endwarning
4887 /// \code
4888 /// false: true:
4889 ///
4890 /// int max(int a, int b) { int max(int a, int b) {
4891 /// return a > b ? a : b; return a > b ? a : b;
4892 /// }; }
4893 ///
4894 /// \endcode
4895 /// \version 16
4897
4898 /// The possible positions for the requires clause. The `IndentRequires`
4899 /// option is only used if the `requires` is put on the start of a line.
4901 /// Always put the `requires` clause on its own line (possibly followed by
4902 /// a semicolon).
4903 /// \code
4904 /// template <typename T>
4905 /// requires C<T>
4906 /// struct Foo {...
4907 ///
4908 /// template <typename T>
4909 /// void bar(T t)
4910 /// requires C<T>;
4911 ///
4912 /// template <typename T>
4913 /// requires C<T>
4914 /// void bar(T t) {...
4915 ///
4916 /// template <typename T>
4917 /// void baz(T t)
4918 /// requires C<T>
4919 /// {...
4920 /// \endcode
4922 /// As with `OwnLine`, except, unless otherwise prohibited, place a
4923 /// following open brace (of a function definition) to follow on the same
4924 /// line.
4925 /// \code
4926 /// void bar(T t)
4927 /// requires C<T> {
4928 /// return;
4929 /// }
4930 ///
4931 /// void bar(T t)
4932 /// requires C<T> {}
4933 ///
4934 /// template <typename T>
4935 /// requires C<T>
4936 /// void baz(T t) {
4937 /// ...
4938 /// \endcode
4940 /// Try to put the clause together with the preceding part of a declaration.
4941 /// For class templates: stick to the template declaration.
4942 /// For function templates: stick to the template declaration.
4943 /// For function declaration followed by a requires clause: stick to the
4944 /// parameter list.
4945 /// \code
4946 /// template <typename T> requires C<T>
4947 /// struct Foo {...
4948 ///
4949 /// template <typename T> requires C<T>
4950 /// void bar(T t) {...
4951 ///
4952 /// template <typename T>
4953 /// void baz(T t) requires C<T>
4954 /// {...
4955 /// \endcode
4957 /// Try to put the `requires` clause together with the class or function
4958 /// declaration.
4959 /// \code
4960 /// template <typename T>
4961 /// requires C<T> struct Foo {...
4962 ///
4963 /// template <typename T>
4964 /// requires C<T> void bar(T t) {...
4965 ///
4966 /// template <typename T>
4967 /// void baz(T t)
4968 /// requires C<T> {...
4969 /// \endcode
4971 /// Try to put everything in the same line if possible. Otherwise normal
4972 /// line breaking rules take over.
4973 /// \code
4974 /// // Fitting:
4975 /// template <typename T> requires C<T> struct Foo {...
4976 ///
4977 /// template <typename T> requires C<T> void bar(T t) {...
4978 ///
4979 /// template <typename T> void bar(T t) requires C<T> {...
4980 ///
4981 /// // Not fitting, one possible example:
4982 /// template <typename LongName>
4983 /// requires C<LongName>
4984 /// struct Foo {...
4985 ///
4986 /// template <typename LongName>
4987 /// requires C<LongName>
4988 /// void bar(LongName ln) {
4989 ///
4990 /// template <typename LongName>
4991 /// void bar(LongName ln)
4992 /// requires C<LongName> {
4993 /// \endcode
4996
4997 /// The position of the `requires` clause.
4998 /// \version 15
5000
5001 /// Indentation logic for requires expression bodies.
5003 /// Align requires expression body relative to the indentation level of the
5004 /// outer scope the requires expression resides in.
5005 /// This is the default.
5006 /// \code
5007 /// template <typename T>
5008 /// concept C = requires(T t) {
5009 /// ...
5010 /// }
5011 /// \endcode
5013 /// Align requires expression body relative to the `requires` keyword.
5014 /// \code
5015 /// template <typename T>
5016 /// concept C = requires(T t) {
5017 /// ...
5018 /// }
5019 /// \endcode
5022
5023 /// The indentation used for requires expression bodies.
5024 /// \version 16
5027 /// The style if definition blocks should be separated.
5029 /// Leave definition blocks as they are.
5031 /// Insert an empty line between definition blocks.
5032 SDS_Always,
5033 /// Remove any empty line between definition blocks.
5034 SDS_Never
5035 };
5036
5037 /// Specifies the use of empty lines to separate definition blocks, including
5038 /// classes, structs, enums, and functions.
5039 /// \code
5040 /// Never v.s. Always
5041 /// #include <cstring> #include <cstring>
5042 /// struct Foo {
5043 /// int a, b, c; struct Foo {
5044 /// }; int a, b, c;
5045 /// namespace Ns { };
5046 /// class Bar {
5047 /// public: namespace Ns {
5048 /// struct Foobar { class Bar {
5049 /// int a; public:
5050 /// int b; struct Foobar {
5051 /// }; int a;
5052 /// private: int b;
5053 /// int t; };
5054 /// int method1() {
5055 /// // ... private:
5056 /// } int t;
5057 /// enum List {
5058 /// ITEM1, int method1() {
5059 /// ITEM2 // ...
5060 /// }; }
5061 /// template<typename T>
5062 /// int method2(T x) { enum List {
5063 /// // ... ITEM1,
5064 /// } ITEM2
5065 /// int i, j, k; };
5066 /// int method3(int par) {
5067 /// // ... template<typename T>
5068 /// } int method2(T x) {
5069 /// }; // ...
5070 /// class C {}; }
5071 /// }
5072 /// int i, j, k;
5073 ///
5074 /// int method3(int par) {
5075 /// // ...
5076 /// }
5077 /// };
5078 ///
5079 /// class C {};
5080 /// }
5081 /// \endcode
5082 /// \version 14
5084
5085 /// The maximal number of unwrapped lines that a short namespace spans.
5086 /// Defaults to 1.
5087 ///
5088 /// This determines the maximum length of short namespaces by counting
5089 /// unwrapped lines (i.e. containing neither opening nor closing
5090 /// namespace brace) and makes `FixNamespaceComments` omit adding
5091 /// end comments for those.
5092 /// \code
5093 /// ShortNamespaceLines: 1 vs. ShortNamespaceLines: 0
5094 /// namespace a { namespace a {
5095 /// int foo; int foo;
5096 /// } } // namespace a
5097 ///
5098 /// ShortNamespaceLines: 1 vs. ShortNamespaceLines: 0
5099 /// namespace b { namespace b {
5100 /// int foo; int foo;
5101 /// int bar; int bar;
5102 /// } // namespace b } // namespace b
5103 /// \endcode
5104 /// \version 13
5106
5107 /// Do not format macro definition body.
5108 /// \version 18
5110
5111 /// Includes sorting options.
5112 struct SortIncludesOptions {
5113 /// If `true`, includes are sorted based on the other suboptions below.
5114 /// (`Never` is deprecated by `Enabled: false`.)
5115 bool Enabled;
5116 /// Whether or not includes are sorted in a case-insensitive fashion.
5117 /// (`CaseSensitive` and `CaseInsensitive` are deprecated by
5118 /// `IgnoreCase: false` and `IgnoreCase: true`, respectively.)
5119 /// \code
5120 /// true: false:
5121 /// #include "A/B.h" vs. #include "A/B.h"
5122 /// #include "A/b.h" #include "A/b.h"
5123 /// #include "a/b.h" #include "B/A.h"
5124 /// #include "B/A.h" #include "B/a.h"
5125 /// #include "B/a.h" #include "a/b.h"
5126 /// \endcode
5127 bool IgnoreCase;
5128 /// When sorting includes in each block, only take file extensions into
5129 /// account if two includes compare equal otherwise.
5130 /// \code
5131 /// true: false:
5132 /// # include "A.h" vs. # include "A-util.h"
5133 /// # include "A.inc" # include "A.h"
5134 /// # include "A-util.h" # include "A.inc"
5135 /// \endcode
5136 bool IgnoreExtension;
5137 /// Whether or not includes are sorted by natural ordering i.e., whether
5138 /// embedded runs of digits are compared as numbers rather than sequences of
5139 /// characters.
5140 /// \code
5141 /// true: false:
5142 /// #include "A2.h" vs. #include "A10.h"
5143 /// #include "A10.h" #include "A2.h"
5144 /// \endcode
5145 bool Natural;
5146 /// When `true`, sort includes so that files in a directory appear
5147 /// before subdirectories at each level, recursively. Within a level,
5148 /// files and folders are each sorted alphabetically.
5149 /// When `false` (default), sorts includes purely alphabetically.
5150 ///
5151 /// This option is a secondary sort key within each `Priority` group
5152 /// defined by `IncludeCategories`. Includes in different `Priority`
5153 /// groups are still separated by that primary ordering.
5154 /// \code
5155 /// true: false (default):
5156 /// #include "x.h" vs. #include "bar/alpha/e.h"
5157 /// #include "y.h" #include "bar/alpha/f.h"
5158 /// #include "z.h" #include "bar/beta/d.h"
5159 /// #include "bar/g.h" #include "bar/g.h"
5160 /// #include "bar/h.h" #include "bar/h.h"
5161 /// #include "bar/i.h" #include "bar/i.h"
5162 /// #include "bar/alpha/e.h" #include "foo/a.h"
5163 /// #include "bar/alpha/f.h" #include "x.h"
5164 /// #include "bar/beta/d.h" #include "y.h"
5165 /// #include "foo/a.h" #include "z.h"
5166 /// \endcode
5167 bool FilesBeforeFolders;
5168 bool operator==(const SortIncludesOptions &R) const {
5169 return Enabled == R.Enabled && IgnoreCase == R.IgnoreCase &&
5170 IgnoreExtension == R.IgnoreExtension && Natural == R.Natural &&
5171 FilesBeforeFolders == R.FilesBeforeFolders;
5172 }
5173 bool operator!=(const SortIncludesOptions &R) const {
5174 return !(*this == R);
5175 }
5177
5178 /// Controls if and how clang-format will sort `#includes`.
5179 /// \version 3.8
5181
5182 /// Position for Java Static imports.
5184 /// Static imports are placed before non-static imports.
5185 /// \code{.java}
5186 /// import static org.example.function1;
5187 ///
5188 /// import org.example.ClassA;
5189 /// \endcode
5191 /// Static imports are placed after non-static imports.
5192 /// \code{.java}
5193 /// import org.example.ClassA;
5194 ///
5195 /// import static org.example.function1;
5196 /// \endcode
5198 };
5199
5200 /// When sorting Java imports, by default static imports are placed before
5201 /// non-static imports. If `JavaStaticImportAfterImport` is `After`,
5202 /// static imports are placed after non-static imports.
5203 /// \version 12
5205
5206 /// Using declaration sorting options.
5208 /// Using declarations are never sorted.
5209 /// \code
5210 /// using std::chrono::duration_cast;
5211 /// using std::move;
5212 /// using boost::regex;
5213 /// using boost::regex_constants::icase;
5214 /// using std::string;
5215 /// \endcode
5216 SUD_Never,
5217 /// Using declarations are sorted in the order defined as follows:
5218 /// Split the strings by `::` and discard any initial empty strings. Sort
5219 /// the lists of names lexicographically, and within those groups, names are
5220 /// in case-insensitive lexicographic order.
5221 /// \code
5222 /// using boost::regex;
5223 /// using boost::regex_constants::icase;
5224 /// using std::chrono::duration_cast;
5225 /// using std::move;
5226 /// using std::string;
5227 /// \endcode
5229 /// Using declarations are sorted in the order defined as follows:
5230 /// Split the strings by `::` and discard any initial empty strings. The
5231 /// last element of each list is a non-namespace name; all others are
5232 /// namespace names. Sort the lists of names lexicographically, where the
5233 /// sort order of individual names is that all non-namespace names come
5234 /// before all namespace names, and within those groups, names are in
5235 /// case-insensitive lexicographic order.
5236 /// \code
5237 /// using boost::regex;
5238 /// using boost::regex_constants::icase;
5239 /// using std::move;
5240 /// using std::string;
5241 /// using std::chrono::duration_cast;
5242 /// \endcode
5245
5246 /// Controls if and how clang-format will sort using declarations.
5247 /// \version 5
5248 SortUsingDeclarationsOptions SortUsingDeclarations;
5249
5250 /// If `true`, a space is inserted after C style casts.
5251 /// \code
5252 /// true: false:
5253 /// (int) i; vs. (int)i;
5254 /// \endcode
5255 /// \version 3.5
5257
5258 /// If `true`, a space is inserted after the logical not operator (`!`).
5259 /// \code
5260 /// true: false:
5261 /// ! someExpression(); vs. !someExpression();
5262 /// \endcode
5263 /// \version 9
5265
5266 /// If `true`, a space will be inserted after the `operator` keyword.
5267 /// \code
5268 /// true: false:
5269 /// bool operator ==(int a); vs. bool operator==(int a);
5270 /// \endcode
5271 /// \version 21
5273
5274 /// If \c true, a space will be inserted after the `template` keyword.
5275 /// \code
5276 /// true: false:
5277 /// template <int> void foo(); vs. template<int> void foo();
5278 /// \endcode
5279 /// \version 4
5281
5282 /// Different ways to put a space before opening parentheses.
5284 /// Don't ensure spaces around pointer qualifiers and use PointerAlignment
5285 /// instead.
5286 /// \code
5287 /// PointerAlignment: Left PointerAlignment: Right
5288 /// void* const* x = NULL; vs. void *const *x = NULL;
5289 /// \endcode
5291 /// Ensure that there is a space before pointer qualifiers.
5292 /// \code
5293 /// PointerAlignment: Left PointerAlignment: Right
5294 /// void* const* x = NULL; vs. void * const *x = NULL;
5295 /// \endcode
5297 /// Ensure that there is a space after pointer qualifiers.
5298 /// \code
5299 /// PointerAlignment: Left PointerAlignment: Right
5300 /// void* const * x = NULL; vs. void *const *x = NULL;
5301 /// \endcode
5302 SAPQ_After,
5303 /// Ensure that there is a space both before and after pointer qualifiers.
5304 /// \code
5305 /// PointerAlignment: Left PointerAlignment: Right
5306 /// void* const * x = NULL; vs. void * const *x = NULL;
5307 /// \endcode
5308 SAPQ_Both,
5310
5311 /// Defines in which cases to put a space before or after pointer qualifiers
5312 /// \version 12
5313 SpaceAroundPointerQualifiersStyle SpaceAroundPointerQualifiers;
5314
5315 /// If `false`, spaces will be removed before assignment operators.
5316 /// \code
5317 /// true: false:
5318 /// int a = 5; vs. int a= 5;
5319 /// a += 42; a+= 42;
5320 /// \endcode
5321 /// \version 3.7
5323
5324 /// If `false`, spaces will be removed before case colon.
5325 /// \code
5326 /// true: false
5327 /// switch (x) { vs. switch (x) {
5328 /// case 1 : break; case 1: break;
5329 /// } }
5330 /// \endcode
5331 /// \version 12
5333
5334 /// If `true`, a space will be inserted before a C++11 braced list
5335 /// used to initialize an object (after the preceding identifier or type).
5336 /// \code
5337 /// true: false:
5338 /// Foo foo { bar }; vs. Foo foo{ bar };
5339 /// Foo {}; Foo{};
5340 /// vector<int> { 1, 2, 3 }; vector<int>{ 1, 2, 3 };
5341 /// new int[3] { 1, 2, 3 }; new int[3]{ 1, 2, 3 };
5342 /// \endcode
5343 /// \version 7
5345
5346 /// If `false`, spaces will be removed before constructor initializer
5347 /// colon.
5348 /// \code
5349 /// true: false:
5350 /// Foo::Foo() : a(a) {} Foo::Foo(): a(a) {}
5351 /// \endcode
5352 /// \version 7
5354
5355 /// If `false`, spaces will be removed before enum underlying type colon.
5356 /// \code
5357 /// true: false:
5358 /// enum E : int {} enum E: int {}
5359 /// \endcode
5360 /// \version 23
5362
5363 /// If `false`, spaces will be removed before inheritance colon.
5364 /// \code
5365 /// true: false:
5366 /// class Foo : Bar {} vs. class Foo: Bar {}
5367 /// \endcode
5368 /// \version 7
5370
5371 /// If `true`, a space will be added before a JSON colon. For other
5372 /// languages, e.g. JavaScript, use `SpacesInContainerLiterals` instead.
5373 /// \code
5374 /// true: false:
5375 /// { {
5376 /// "key" : "value" vs. "key": "value"
5377 /// } }
5378 /// \endcode
5379 /// \version 17
5381
5382 /// Different ways to put a space before opening parentheses.
5384 /// This is **deprecated** and replaced by `Custom` below, with all
5385 /// `SpaceBeforeParensOptions` but `AfterPlacementOperator` set to
5386 /// `false`.
5387 SBPO_Never,
5388 /// Put a space before opening parentheses only after control statement
5389 /// keywords (`for/if/while...`).
5390 /// \code
5391 /// void f() {
5392 /// if (true) {
5393 /// f();
5394 /// }
5395 /// }
5396 /// \endcode
5398 /// Same as `SBPO_ControlStatements` except this option doesn't apply to
5399 /// ForEach and If macros. This is useful in projects where ForEach/If
5400 /// macros are treated as function calls instead of control statements.
5401 /// `SBPO_ControlStatementsExceptForEachMacros` remains an alias for
5402 /// backward compatibility.
5403 /// \code
5404 /// void f() {
5405 /// Q_FOREACH(...) {
5406 /// f();
5407 /// }
5408 /// }
5409 /// \endcode
5411 /// Put a space before opening parentheses only if the parentheses are not
5412 /// empty.
5413 /// \code
5414 /// void() {
5415 /// if (true) {
5416 /// f();
5417 /// g (x, y, z);
5418 /// }
5419 /// }
5420 /// \endcode
5422 /// Always put a space before opening parentheses, except when it's
5423 /// prohibited by the syntax rules (in function-like macro definitions) or
5424 /// when determined by other style rules (after unary operators, opening
5425 /// parentheses, etc.)
5426 /// \code
5427 /// void f () {
5428 /// if (true) {
5429 /// f ();
5430 /// }
5431 /// }
5432 /// \endcode
5434 /// Configure each individual space before parentheses in
5435 /// `SpaceBeforeParensOptions`.
5438
5439 /// Defines in which cases to put a space before opening parentheses.
5440 /// \version 3.5
5441 SpaceBeforeParensStyle SpaceBeforeParens;
5442
5443 /// Precise control over the spacing before parentheses.
5444 /// \code{.yaml}
5445 /// # Should be declared this way:
5446 /// SpaceBeforeParens: Custom
5447 /// SpaceBeforeParensOptions:
5448 /// AfterControlStatements: true
5449 /// AfterFunctionDefinitionName: true
5450 /// \endcode
5452 /// If `true`, put space between control statement keywords
5453 /// (for/if/while...) and opening parentheses.
5454 /// \code
5455 /// true: false:
5456 /// if (...) {} vs. if(...) {}
5457 /// \endcode
5459 /// If `true`, put space between foreach macros and opening parentheses.
5460 /// \code
5461 /// true: false:
5462 /// FOREACH (...) vs. FOREACH(...)
5463 /// <loop-body> <loop-body>
5464 /// \endcode
5465 bool AfterForeachMacros;
5466 /// If `true`, put a space between function declaration name and opening
5467 /// parentheses.
5468 /// \code
5469 /// true: false:
5470 /// void f (); vs. void f();
5471 /// \endcode
5473 /// If `true`, put a space between function definition name and opening
5474 /// parentheses.
5475 /// \code
5476 /// true: false:
5477 /// void f () {} vs. void f() {}
5478 /// \endcode
5480 /// If `true`, put space between if macros and opening parentheses.
5481 /// \code
5482 /// true: false:
5483 /// IF (...) vs. IF(...)
5484 /// <conditional-body> <conditional-body>
5485 /// \endcode
5486 bool AfterIfMacros;
5487 /// If `true`, put a space between alternative operator `not` and the
5488 /// opening parenthesis.
5489 /// \code
5490 /// true: false:
5491 /// return not (a || b); vs. return not(a || b);
5492 /// \endcode
5493 bool AfterNot;
5494 /// If `true`, put a space between operator overloading and opening
5495 /// parentheses.
5496 /// \code
5497 /// true: false:
5498 /// void operator++ (int a); vs. void operator++(int a);
5499 /// object.operator++ (10); object.operator++(10);
5500 /// \endcode
5502 /// If `true`, put a space between operator `new`/`delete` and opening
5503 /// parenthesis.
5504 /// \code
5505 /// true: false:
5506 /// new (buf) T; vs. new(buf) T;
5507 /// delete (buf) T; delete(buf) T;
5508 /// \endcode
5510 /// If `true`, put space between requires keyword in a requires clause and
5511 /// opening parentheses, if there is one.
5512 /// \code
5513 /// true: false:
5514 /// template<typename T> vs. template<typename T>
5515 /// requires (A<T> && B<T>) requires(A<T> && B<T>)
5516 /// ... ...
5517 /// \endcode
5519 /// If `true`, put space between requires keyword in a requires expression
5520 /// and opening parentheses.
5521 /// \code
5522 /// true: false:
5523 /// template<typename T> vs. template<typename T>
5524 /// concept C = requires (T t) { concept C = requires(T t) {
5525 /// ... ...
5526 /// } }
5527 /// \endcode
5529 /// If `true`, put a space before opening parentheses only if the
5530 /// parentheses are not empty.
5531 /// \code
5532 /// true: false:
5533 /// void f (int a); vs. void f();
5545
5546 bool operator==(const SpaceBeforeParensCustom &Other) const {
5547 return AfterControlStatements == Other.AfterControlStatements &&
5548 AfterForeachMacros == Other.AfterForeachMacros &&
5550 Other.AfterFunctionDeclarationName &&
5551 AfterFunctionDefinitionName == Other.AfterFunctionDefinitionName &&
5552 AfterIfMacros == Other.AfterIfMacros &&
5553 AfterNot == Other.AfterNot &&
5554 AfterOverloadedOperator == Other.AfterOverloadedOperator &&
5555 AfterPlacementOperator == Other.AfterPlacementOperator &&
5556 AfterRequiresInClause == Other.AfterRequiresInClause &&
5557 AfterRequiresInExpression == Other.AfterRequiresInExpression &&
5558 BeforeNonEmptyParentheses == Other.BeforeNonEmptyParentheses;
5559 }
5560 };
5561
5562 /// Control of individual space before parentheses.
5563 ///
5564 /// If `SpaceBeforeParens` is set to `Custom`, use this to specify
5565 /// how each individual space before parentheses case should be handled.
5566 /// Otherwise, this is ignored.
5567 /// \code{.yaml}
5568 /// # Example of usage:
5569 /// SpaceBeforeParens: Custom
5570 /// SpaceBeforeParensOptions:
5571 /// AfterControlStatements: true
5572 /// AfterFunctionDefinitionName: true
5573 /// \endcode
5574 /// \version 14
5576
5577 /// If `true`, spaces will be before `[`.
5578 /// Lambdas will not be affected. Only the first `[` will get a space added.
5579 /// \code
5580 /// true: false:
5581 /// int a [5]; vs. int a[5];
5582 /// int a [5][5]; vs. int a[5][5];
5583 /// \endcode
5584 /// \version 10
5586
5587 /// If `false`, spaces will be removed before range-based for loop
5588 /// colon.
5589 /// \code
5590 /// true: false:
5591 /// for (auto v : values) {} vs. for(auto v: values) {}
5592 /// \endcode
5593 /// \version 7
5595
5596 /// This option is **deprecated**. See `Block` of `SpaceInEmptyBraces`.
5597 /// \version 10
5598 // bool SpaceInEmptyBlock;
5599
5600 /// Style of when to insert a space in empty braces.
5602 /// Always insert a space in empty braces.
5603 /// \code
5604 /// void f() { }
5605 /// class Unit { };
5606 /// auto a = [] { };
5607 /// int x{ };
5608 /// \endcode
5610 /// Only insert a space in empty blocks.
5611 /// \code
5612 /// void f() { }
5613 /// class Unit { };
5614 /// auto a = [] { };
5615 /// int x{};
5616 /// \endcode
5617 SIEB_Block,
5618 /// Never insert a space in empty braces.
5619 /// \code
5620 /// void f() {}
5621 /// class Unit {};
5622 /// auto a = [] {};
5623 /// int x{};
5624 /// \endcode
5626 };
5627
5628 /// Specifies when to insert a space in empty braces.
5629 /// \note
5630 /// This option doesn't apply to initializer braces if
5631 /// `Cpp11BracedListStyle` is not `Block`.
5632 /// \endnote
5633 /// \version 22
5635
5636 /// If `true`, spaces may be inserted into `()`.
5637 /// This option is **deprecated**. See `InEmptyParentheses` of
5638 /// `SpacesInParensOptions`.
5639 /// \version 3.7
5640 // bool SpaceInEmptyParentheses;
5641
5642 /// The number of spaces before trailing line comments
5643 /// (`//` - comments).
5644 ///
5645 /// This does not affect trailing block comments (`/*` - comments) as those
5646 /// commonly have different usage patterns and a number of special cases. In
5647 /// the case of Verilog, it doesn't affect a comment right after the opening
5648 /// parenthesis in the port or parameter list in a module header, because it
5649 /// is probably for the port on the following line instead of the parenthesis
5650 /// it follows.
5651 /// \code
5652 /// SpacesBeforeTrailingComments: 3
5653 /// void f() {
5654 /// if (true) { // foo1
5655 /// f(); // bar
5656 /// } // foo
5657 /// }
5658 /// \endcode
5659 /// \version 3.7
5661
5662 /// Styles for adding spacing after `<` and before `>`
5663 /// in template argument lists.
5665 /// Remove spaces after `<` and before `>`.
5666 /// \code
5667 /// static_cast<int>(arg);
5668 /// std::function<void(int)> fct;
5669 /// \endcode
5670 SIAS_Never,
5671 /// Add spaces after `<` and before `>`.
5672 /// \code
5673 /// static_cast< int >(arg);
5674 /// std::function< void(int) > fct;
5675 /// \endcode
5677 /// Keep a single space after `<` and before `>` if any spaces were
5678 /// present. Option `Standard: Cpp03` takes precedence.
5680 };
5681 /// The SpacesInAnglesStyle to use for template argument lists.
5682 /// \version 3.4
5684
5685 /// Styles for controlling spacing after `/*` and before `*/` in block
5686 /// comments.
5688 /// Remove spaces after `/*` and before `*/`.
5689 /// \code
5690 /// /*comment*/
5691 /// \endcode
5693 /// Add spaces after `/*` and before `*/`.
5694 /// \code
5695 /// /* comment */
5696 /// \endcode
5698 /// Leave existing spaces unchanged.
5701
5702 /// The SpacesInBlockCommentsStyle to use for ordinary block comments.
5703 /// Documentation comments such as `/** ... */` and `/*! ... */`
5704 /// and parameter comments ending with `=` before the closing `*/` are
5705 /// left unchanged.
5706 /// \version 24
5707 SpacesInBlockCommentsStyle SpacesInBlockComments;
5708
5709 /// If `true`, spaces will be inserted around if/for/switch/while
5710 /// conditions.
5711 /// This option is **deprecated**. See `InConditionalStatements` of
5712 /// `SpacesInParensOptions`.
5713 /// \version 10
5714 // bool SpacesInConditionalStatement;
5715
5716 /// If `true`, spaces are inserted inside container literals (e.g. ObjC and
5717 /// Javascript array and dict literals). For JSON, use
5718 /// `SpaceBeforeJsonColon` instead.
5719 /// \code{.js}
5720 /// true: false:
5721 /// var arr = [ 1, 2, 3 ]; vs. var arr = [1, 2, 3];
5722 /// f({a : 1, b : 2, c : 3}); f({a: 1, b: 2, c: 3});
5723 /// \endcode
5724 /// \version 3.7
5726
5727 /// If `true`, spaces may be inserted into C style casts.
5728 /// This option is **deprecated**. See `InCStyleCasts` of
5729 /// `SpacesInParensOptions`.
5730 /// \version 3.7
5731 // bool SpacesInCStyleCastParentheses;
5733 /// Control of spaces within a single line comment.
5735 /// The minimum number of spaces at the start of the comment.
5736 unsigned Minimum;
5737 /// The maximum number of spaces at the start of the comment.
5738 unsigned Maximum;
5739 };
5740
5741 /// How many spaces are allowed at the start of a line comment. To disable the
5742 /// maximum set it to `-1`, apart from that the maximum takes precedence
5743 /// over the minimum.
5744 /// \code
5745 /// Minimum = 1
5746 /// Maximum = -1
5747 /// // One space is forced
5748 ///
5749 /// // but more spaces are possible
5750 ///
5751 /// Minimum = 0
5752 /// Maximum = 0
5753 /// //Forces to start every comment directly after the slashes
5754 /// \endcode
5755 ///
5756 /// Note that in line comment sections the relative indent of the subsequent
5757 /// lines is kept, that means the following:
5758 /// \code
5759 /// before: after:
5760 /// Minimum: 1
5761 /// //if (b) { // if (b) {
5762 /// // return true; // return true;
5763 /// //} // }
5764 ///
5765 /// Maximum: 0
5766 /// /// List: ///List:
5767 /// /// - Foo /// - Foo
5768 /// /// - Bar /// - Bar
5769 /// \endcode
5770 ///
5771 /// This option has only effect if `ReflowComments` is set to `true`.
5772 /// \version 13
5774
5775 /// Different ways to put a space before opening and closing parentheses.
5777 /// Never put a space in parentheses.
5778 /// \code
5779 /// void f() {
5780 /// if(true) {
5781 /// f();
5782 /// }
5783 /// }
5784 /// \endcode
5785 SIPO_Never,
5786 /// Configure each individual space in parentheses in
5787 /// `SpacesInParensOptions`.
5789 };
5790
5791 /// If `true`, spaces will be inserted after `(` and before `)`.
5792 /// This option is **deprecated**. The previous behavior is preserved by using
5793 /// `SpacesInParens` with `Custom` and by setting all
5794 /// `SpacesInParensOptions` to `true` except for `InCStyleCasts` and
5795 /// `InEmptyParentheses`.
5796 /// \version 3.7
5797 // bool SpacesInParentheses;
5799 /// Defines in which cases spaces will be inserted after `(` and before
5800 /// `)`.
5801 /// \version 17
5803
5804 /// Precise control over the spacing in parentheses.
5805 /// \code{.yaml}
5806 /// # Should be declared this way:
5807 /// SpacesInParens: Custom
5808 /// SpacesInParensOptions:
5809 /// ExceptDoubleParentheses: false
5810 /// InConditionalStatements: true
5811 /// Other: true
5812 /// \endcode
5813 struct SpacesInParensCustom {
5814 /// Override any of the following options to prevent addition of space
5815 /// when both opening and closing parentheses use multiple parentheses.
5816 /// \code
5817 /// true:
5818 /// __attribute__(( noreturn ))
5819 /// __decltype__(( x ))
5820 /// if (( a = b ))
5821 /// \endcode
5822 /// false:
5823 /// Uses the applicable option.
5825 /// Put a space in parentheses only inside conditional statements
5826 /// (`for/if/while/switch...`).
5827 /// \code
5828 /// true: false:
5829 /// if ( a ) { ... } vs. if (a) { ... }
5830 /// while ( i < 5 ) { ... } while (i < 5) { ... }
5831 /// \endcode
5833 /// Put a space in C style casts.
5834 /// \code
5835 /// true: false:
5836 /// x = ( int32 )y vs. x = (int32)y
5837 /// y = (( int (*)(int) )foo)(x); y = ((int (*)(int))foo)(x);
5838 /// \endcode
5839 bool InCStyleCasts;
5840 /// Insert a space in empty parentheses, i.e. `()`.
5841 /// \code
5842 /// true: false:
5843 /// void f( ) { vs. void f() {
5844 /// int x[] = {foo( ), bar( )}; int x[] = {foo(), bar()};
5845 /// if (true) { if (true) {
5846 /// f( ); f();
5847 /// } }
5848 /// } }
5849 /// \endcode
5850 bool InEmptyParentheses;
5851 /// Put a space in parentheses not covered by preceding options.
5852 /// \code
5853 /// true: false:
5854 /// t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete;
5855 /// \endcode
5856 bool Other;
5857
5872 InConditionalStatements == R.InConditionalStatements &&
5873 InCStyleCasts == R.InCStyleCasts &&
5874 InEmptyParentheses == R.InEmptyParentheses && Other == R.Other;
5875 }
5876 bool operator!=(const SpacesInParensCustom &R) const {
5877 return !(*this == R);
5878 }
5879 };
5880
5881 /// Control of individual spaces in parentheses.
5882 ///
5883 /// If `SpacesInParens` is set to `Custom`, use this to specify
5884 /// how each individual space in parentheses case should be handled.
5885 /// Otherwise, this is ignored.
5886 /// \code{.yaml}
5887 /// # Example of usage:
5888 /// SpacesInParens: Custom
5889 /// SpacesInParensOptions:
5890 /// ExceptDoubleParentheses: false
5891 /// InConditionalStatements: true
5892 /// InEmptyParentheses: true
5893 /// \endcode
5894 /// \version 17
5896
5897 /// If `true`, spaces will be inserted after `[` and before `]`.
5898 /// Lambdas without arguments or unspecified size array declarations will not
5899 /// be affected.
5900 /// \code
5901 /// true: false:
5902 /// int a[ 5 ]; vs. int a[5];
5903 /// std::unique_ptr<int[]> foo() {} // Won't be affected
5904 /// \endcode
5905 /// \version 3.7
5907
5908 /// Supported language standards for parsing and formatting C++ constructs.
5909 /// \code
5910 /// Latest: vector<set<int>>
5911 /// c++03 vs. vector<set<int> >
5912 /// \endcode
5913 ///
5914 /// The correct way to spell a specific language version is e.g. `c++11`.
5915 /// The historical aliases `Cpp03` and `Cpp11` are deprecated.
5916 enum LanguageStandard : int8_t {
5917 /// Parse and format as C++03.
5918 /// `Cpp03` is a deprecated alias for `c++03`
5919 LS_Cpp03, // c++03
5920 /// Parse and format as C++11.
5921 LS_Cpp11, // c++11
5922 /// Parse and format as C++14.
5923 LS_Cpp14, // c++14
5924 /// Parse and format as C++17.
5925 LS_Cpp17, // c++17
5926 /// Parse and format as C++20.
5927 LS_Cpp20, // c++20
5928 /// Parse and format as C++23.
5929 LS_Cpp23, // c++23
5930 /// Parse and format as C++26.
5931 LS_Cpp26, // c++26
5932 /// Parse and format using the latest supported language version.
5933 /// `Cpp11` is a deprecated alias for `Latest`
5934 LS_Latest,
5935 /// Automatic detection based on the input.
5936 LS_Auto,
5937 };
5938
5939 /// Parse and format C++ constructs compatible with this standard.
5940 /// \code
5941 /// c++03: latest:
5942 /// vector<set<int> > x; vs. vector<set<int>> x;
5943 /// \endcode
5944 /// \version 3.7
5946
5947 /// Macros which are ignored in front of a statement, as if they were an
5948 /// attribute. So that they are not parsed as identifier, for example for Qts
5949 /// emit.
5950 /// \code
5951 /// AlignConsecutiveDeclarations: true
5952 /// StatementAttributeLikeMacros: []
5953 /// unsigned char data = 'x';
5954 /// emit signal(data); // This is parsed as variable declaration.
5955 ///
5956 /// AlignConsecutiveDeclarations: true
5957 /// StatementAttributeLikeMacros: [emit]
5958 /// unsigned char data = 'x';
5959 /// emit signal(data); // Now it's fine again.
5960 /// \endcode
5961 /// \version 12
5962 std::vector<std::string> StatementAttributeLikeMacros;
5963
5964 /// A vector of macros that should be interpreted as complete statements.
5965 ///
5966 /// Typical macros are expressions and require a semicolon to be added.
5967 /// Sometimes this is not the case, and this allows to make clang-format aware
5968 /// of such cases.
5969 ///
5970 /// For example: Q_UNUSED
5971 /// \version 8
5972 std::vector<std::string> StatementMacros;
5973
5974 /// Works only when TableGenBreakInsideDAGArg is not DontBreak.
5975 /// The string list needs to consist of identifiers in TableGen.
5976 /// If any identifier is specified, this limits the line breaks by
5977 /// TableGenBreakInsideDAGArg option only on DAGArg values beginning with
5978 /// the specified identifiers.
5979 ///
5980 /// For example the configuration,
5981 /// \code{.yaml}
5982 /// TableGenBreakInsideDAGArg: BreakAll
5983 /// TableGenBreakingDAGArgOperators: [ins, outs]
5984 /// \endcode
5985 ///
5986 /// makes the line break only occurs inside DAGArgs beginning with the
5987 /// specified identifiers `ins` and `outs`.
5988 ///
5989 /// \code
5990 /// let DAGArgIns = (ins
5991 /// i32:$src1,
5992 /// i32:$src2
5993 /// );
5994 /// let DAGArgOtherID = (other i32:$other1, i32:$other2);
5995 /// let DAGArgBang = (!cast<SomeType>("Some") i32:$src1, i32:$src2)
5996 /// \endcode
5997 /// \version 19
5998 std::vector<std::string> TableGenBreakingDAGArgOperators;
5999
6000 /// Different ways to control the format inside TableGen DAGArg.
6001 enum DAGArgStyle : int8_t {
6002 /// Never break inside DAGArg.
6003 /// \code
6004 /// let DAGArgIns = (ins i32:$src1, i32:$src2);
6005 /// \endcode
6007 /// Break inside DAGArg after each list element but for the last.
6008 /// This aligns to the first element.
6009 /// \code
6010 /// let DAGArgIns = (ins i32:$src1,
6011 /// i32:$src2);
6012 /// \endcode
6014 /// Break inside DAGArg after the operator and the all elements.
6015 /// \code
6016 /// let DAGArgIns = (ins
6017 /// i32:$src1,
6018 /// i32:$src2
6019 /// );
6020 /// \endcode
6023
6024 /// The styles of the line break inside the DAGArg in TableGen.
6025 /// \version 19
6027
6028 /// The number of columns used for tab stops.
6029 /// \version 3.7
6030 unsigned TabWidth;
6031
6032 /// A vector of non-keyword identifiers that should be interpreted as template
6033 /// names.
6034 ///
6035 /// A `<` after a template name is annotated as a template opener instead of
6036 /// a binary operator.
6037 ///
6038 /// \version 20
6039 std::vector<std::string> TemplateNames;
6040
6041 /// A vector of non-keyword identifiers that should be interpreted as type
6042 /// names.
6043 ///
6044 /// A `*`, `&`, or `&&` between a type name and another non-keyword
6045 /// identifier is annotated as a pointer or reference token instead of a
6046 /// binary operator.
6047 ///
6048 /// \version 17
6049 std::vector<std::string> TypeNames;
6050
6051 /// A vector of macros that should be interpreted as type declarations instead
6052 /// of as function calls.
6053 ///
6054 /// These are expected to be macros of the form:
6055 /// \code
6056 /// STACK_OF(...)
6057 /// \endcode
6058 ///
6059 /// In the .clang-format configuration file, this can be configured like:
6060 /// \code{.yaml}
6061 /// TypenameMacros: [STACK_OF, LIST]
6062 /// \endcode
6063 ///
6064 /// For example: OpenSSL STACK_OF, BSD LIST_ENTRY.
6065 /// \version 9
6066 std::vector<std::string> TypenameMacros;
6067
6068 /// This option is **deprecated**. See `LF` and `CRLF` of `LineEnding`.
6069 /// \version 10
6070 // bool UseCRLF;
6072 /// Different ways to use tab in formatting.
6074 /// Never use tab.
6075 UT_Never,
6076 /// Use tabs only for indentation.
6078 /// Fill all leading whitespace with tabs, and use spaces for alignment that
6079 /// appears within a line (e.g. consecutive assignments and declarations).
6081 /// Use tabs for line continuation and indentation, and spaces for
6082 /// alignment.
6084 /// Use tabs whenever we need to fill whitespace that spans at least from
6085 /// one tab stop to the next one.
6086 UT_Always
6088
6089 /// The way to use tab characters in the resulting file.
6090 /// \version 3.7
6091 UseTabStyle UseTab;
6092
6093 /// A vector of non-keyword identifiers that should be interpreted as variable
6094 /// template names.
6095 ///
6096 /// A `)` after a variable template instantiation is **not** annotated as
6097 /// the closing parenthesis of C-style cast operator.
6098 ///
6099 /// \version 20
6100 std::vector<std::string> VariableTemplates;
6101
6102 /// For Verilog, put each port on its own line in module instantiations.
6103 /// \code
6104 /// true:
6105 /// ffnand ff1(.q(),
6106 /// .qbar(out1),
6107 /// .clear(in1),
6108 /// .preset(in2));
6109 ///
6110 /// false:
6111 /// ffnand ff1(.q(), .qbar(out1), .clear(in1), .preset(in2));
6112 /// \endcode
6113 /// \version 17
6115
6116 /// A vector of macros which are whitespace-sensitive and should not
6117 /// be touched.
6118 ///
6119 /// These are expected to be macros of the form:
6120 /// \code
6121 /// STRINGIZE(...)
6122 /// \endcode
6123 ///
6124 /// In the .clang-format configuration file, this can be configured like:
6125 /// \code{.yaml}
6126 /// WhitespaceSensitiveMacros: [STRINGIZE, PP_STRINGIZE]
6127 /// \endcode
6128 ///
6129 /// For example: BOOST_PP_STRINGIZE
6130 /// \version 11
6131 std::vector<std::string> WhitespaceSensitiveMacros;
6132
6133 /// Different styles for wrapping namespace body with empty lines.
6135 /// Remove all empty lines at the beginning and the end of namespace body.
6136 /// \code
6137 /// namespace N1 {
6138 /// namespace N2 {
6139 /// function();
6140 /// }
6141 /// }
6142 /// \endcode
6144 /// Always have at least one empty line at the beginning and the end of
6145 /// namespace body except that the number of empty lines between consecutive
6146 /// nested namespace definitions is not increased.
6147 /// \code
6148 /// namespace N1 {
6149 /// namespace N2 {
6150 ///
6151 /// function();
6152 ///
6153 /// }
6154 /// }
6155 /// \endcode
6157 /// Keep existing newlines at the beginning and the end of namespace body.
6158 /// `MaxEmptyLinesToKeep` still applies.
6161
6162 /// Wrap namespace body with empty lines.
6163 /// \version 20
6165
6166 bool operator==(const FormatStyle &R) const {
6167 return AccessModifierOffset == R.AccessModifierOffset &&
6168 AlignAfterOpenBracket == R.AlignAfterOpenBracket &&
6169 AlignArrayOfStructures == R.AlignArrayOfStructures &&
6170 AlignConsecutiveAssignments == R.AlignConsecutiveAssignments &&
6171 AlignConsecutiveBitFields == R.AlignConsecutiveBitFields &&
6172 AlignConsecutiveDeclarations == R.AlignConsecutiveDeclarations &&
6173 AlignConsecutiveMacros == R.AlignConsecutiveMacros &&
6175 R.AlignConsecutiveShortCaseStatements &&
6177 R.AlignConsecutiveTableGenBreakingDAGArgColons &&
6179 R.AlignConsecutiveTableGenCondOperatorColons &&
6181 R.AlignConsecutiveTableGenDefinitionColons &&
6182 AlignEscapedNewlines == R.AlignEscapedNewlines &&
6183 AlignOperands == R.AlignOperands &&
6184 AlignTrailingComments == R.AlignTrailingComments &&
6185 AllowAllArgumentsOnNextLine == R.AllowAllArgumentsOnNextLine &&
6187 R.AllowAllParametersOfDeclarationOnNextLine &&
6189 R.AllowBreakBeforeNoexceptSpecifier &&
6190 AllowBreakBeforeQtProperty == R.AllowBreakBeforeQtProperty &&
6191 AllowShortBlocksOnASingleLine == R.AllowShortBlocksOnASingleLine &&
6193 R.AllowShortCaseExpressionOnASingleLine &&
6195 R.AllowShortCaseLabelsOnASingleLine &&
6197 R.AllowShortCompoundRequirementOnASingleLine &&
6198 AllowShortEnumsOnASingleLine == R.AllowShortEnumsOnASingleLine &&
6200 R.AllowShortFunctionsOnASingleLine &&
6202 R.AllowShortIfStatementsOnASingleLine &&
6203 AllowShortLambdasOnASingleLine == R.AllowShortLambdasOnASingleLine &&
6204 AllowShortLoopsOnASingleLine == R.AllowShortLoopsOnASingleLine &&
6206 R.AllowShortNamespacesOnASingleLine &&
6207 AllowShortRecordOnASingleLine == R.AllowShortRecordOnASingleLine &&
6209 R.AlwaysBreakBeforeMultilineStrings &&
6210 AttributeMacros == R.AttributeMacros &&
6211 BinPackLongBracedList == R.BinPackLongBracedList &&
6212 BitFieldColonSpacing == R.BitFieldColonSpacing &&
6213 BracedInitializerIndentWidth == R.BracedInitializerIndentWidth &&
6214 BreakAdjacentStringLiterals == R.BreakAdjacentStringLiterals &&
6215 BreakAfterAttributes == R.BreakAfterAttributes &&
6216 BreakAfterJavaFieldAnnotations == R.BreakAfterJavaFieldAnnotations &&
6218 R.BreakAfterOpenBracketBracedList &&
6219 BreakAfterOpenBracketFunction == R.BreakAfterOpenBracketFunction &&
6220 BreakAfterOpenBracketIf == R.BreakAfterOpenBracketIf &&
6221 BreakAfterOpenBracketLoop == R.BreakAfterOpenBracketLoop &&
6222 BreakAfterOpenBracketSwitch == R.BreakAfterOpenBracketSwitch &&
6223 BreakAfterReturnType == R.BreakAfterReturnType &&
6224 BreakArrays == R.BreakArrays &&
6225 BreakBeforeBinaryOperators == R.BreakBeforeBinaryOperators &&
6226 BreakBeforeBraces == R.BreakBeforeBraces &&
6228 R.BreakBeforeCloseBracketBracedList &&
6230 R.BreakBeforeCloseBracketFunction &&
6231 BreakBeforeCloseBracketIf == R.BreakBeforeCloseBracketIf &&
6232 BreakBeforeCloseBracketLoop == R.BreakBeforeCloseBracketLoop &&
6233 BreakBeforeCloseBracketSwitch == R.BreakBeforeCloseBracketSwitch &&
6234 BreakBeforeConceptDeclarations == R.BreakBeforeConceptDeclarations &&
6235 BreakBeforeInlineASMColon == R.BreakBeforeInlineASMColon &&
6236 BreakBeforeReturnType == R.BreakBeforeReturnType &&
6237 BreakBeforeTemplateCloser == R.BreakBeforeTemplateCloser &&
6238 BreakBeforeTernaryOperators == R.BreakBeforeTernaryOperators &&
6239 BreakBinaryOperations == R.BreakBinaryOperations &&
6240 BreakConstructorInitializers == R.BreakConstructorInitializers &&
6242 R.BreakFunctionDeclarationParameters &&
6244 R.BreakFunctionDefinitionParameters &&
6245 BreakInheritanceList == R.BreakInheritanceList &&
6246 BreakStringLiterals == R.BreakStringLiterals &&
6247 BreakTemplateDeclarations == R.BreakTemplateDeclarations &&
6248 ColumnLimit == R.ColumnLimit && CommentPragmas == R.CommentPragmas &&
6249 CompactNamespaces == R.CompactNamespaces &&
6251 R.ConstructorInitializerIndentWidth &&
6252 ContinuationIndentWidth == R.ContinuationIndentWidth &&
6253 Cpp11BracedListStyle == R.Cpp11BracedListStyle &&
6254 DerivePointerAlignment == R.DerivePointerAlignment &&
6255 DisableFormat == R.DisableFormat &&
6256 EmptyLineAfterAccessModifier == R.EmptyLineAfterAccessModifier &&
6257 EmptyLineBeforeAccessModifier == R.EmptyLineBeforeAccessModifier &&
6258 EnumTrailingComma == R.EnumTrailingComma &&
6260 R.ExperimentalAutoDetectBinPacking &&
6261 FixNamespaceComments == R.FixNamespaceComments &&
6262 ForEachMacros == R.ForEachMacros &&
6263 IncludeStyle.IncludeBlocks == R.IncludeStyle.IncludeBlocks &&
6264 IncludeStyle.IncludeCategories == R.IncludeStyle.IncludeCategories &&
6265 IncludeStyle.IncludeIsMainRegex ==
6266 R.IncludeStyle.IncludeIsMainRegex &&
6267 IncludeStyle.IncludeIsMainSourceRegex ==
6268 R.IncludeStyle.IncludeIsMainSourceRegex &&
6269 IncludeStyle.MainIncludeChar == R.IncludeStyle.MainIncludeChar &&
6270 IndentAccessModifiers == R.IndentAccessModifiers &&
6271 IndentCaseBlocks == R.IndentCaseBlocks &&
6272 IndentCaseLabels == R.IndentCaseLabels &&
6273 IndentExportBlock == R.IndentExportBlock &&
6274 IndentExternBlock == R.IndentExternBlock &&
6275 IndentGotoLabels == R.IndentGotoLabels &&
6276 IndentPPDirectives == R.IndentPPDirectives &&
6277 IndentRequiresClause == R.IndentRequiresClause &&
6278 IndentWidth == R.IndentWidth &&
6279 IndentWrappedFunctionNames == R.IndentWrappedFunctionNames &&
6280 InsertBraces == R.InsertBraces &&
6281 InsertNewlineAtEOF == R.InsertNewlineAtEOF &&
6282 IntegerLiteralSeparator == R.IntegerLiteralSeparator &&
6283 JavaImportGroups == R.JavaImportGroups &&
6284 JavaScriptQuotes == R.JavaScriptQuotes &&
6285 JavaScriptWrapImports == R.JavaScriptWrapImports &&
6286 KeepEmptyLines == R.KeepEmptyLines &&
6287 KeepFormFeed == R.KeepFormFeed && Language == R.Language &&
6288 LambdaBodyIndentation == R.LambdaBodyIndentation &&
6289 LineEnding == R.LineEnding && MacroBlockBegin == R.MacroBlockBegin &&
6290 MacroBlockEnd == R.MacroBlockEnd && Macros == R.Macros &&
6292 R.MacrosSkippedByRemoveParentheses &&
6293 MaxEmptyLinesToKeep == R.MaxEmptyLinesToKeep &&
6294 NamespaceIndentation == R.NamespaceIndentation &&
6295 NamespaceMacros == R.NamespaceMacros &&
6296 NumericLiteralCase == R.NumericLiteralCase &&
6297 ObjCBinPackProtocolList == R.ObjCBinPackProtocolList &&
6298 ObjCBlockIndentWidth == R.ObjCBlockIndentWidth &&
6300 R.ObjCBreakBeforeNestedBlockParam &&
6301 ObjCPropertyAttributeOrder == R.ObjCPropertyAttributeOrder &&
6303 R.ObjCSpaceAfterMethodDeclarationPrefix &&
6304 ObjCSpaceAfterProperty == R.ObjCSpaceAfterProperty &&
6305 ObjCSpaceBeforeProtocolList == R.ObjCSpaceBeforeProtocolList &&
6306 OneLineFormatOffRegex == R.OneLineFormatOffRegex &&
6307 PackArguments == R.PackArguments &&
6308 PackConstructorInitializers == R.PackConstructorInitializers &&
6309 PackParameters == R.PackParameters &&
6310 PenaltyBreakAssignment == R.PenaltyBreakAssignment &&
6312 R.PenaltyBreakBeforeFirstCallParameter &&
6313 PenaltyBreakBeforeMemberAccess == R.PenaltyBreakBeforeMemberAccess &&
6314 PenaltyBreakComment == R.PenaltyBreakComment &&
6315 PenaltyBreakFirstLessLess == R.PenaltyBreakFirstLessLess &&
6316 PenaltyBreakOpenParenthesis == R.PenaltyBreakOpenParenthesis &&
6317 PenaltyBreakScopeResolution == R.PenaltyBreakScopeResolution &&
6318 PenaltyBreakString == R.PenaltyBreakString &&
6320 R.PenaltyBreakTemplateDeclaration &&
6321 PenaltyExcessCharacter == R.PenaltyExcessCharacter &&
6322 PenaltyReturnTypeOnItsOwnLine == R.PenaltyReturnTypeOnItsOwnLine &&
6323 PointerAlignment == R.PointerAlignment &&
6324 QualifierAlignment == R.QualifierAlignment &&
6325 QualifierOrder == R.QualifierOrder &&
6326 RawStringFormats == R.RawStringFormats &&
6327 ReferenceAlignment == R.ReferenceAlignment &&
6328 RemoveBracesLLVM == R.RemoveBracesLLVM &&
6330 R.RemoveEmptyLinesInUnwrappedLines &&
6331 RemoveParentheses == R.RemoveParentheses &&
6332 RemoveSemicolon == R.RemoveSemicolon &&
6333 RequiresClausePosition == R.RequiresClausePosition &&
6334 RequiresExpressionIndentation == R.RequiresExpressionIndentation &&
6335 SeparateDefinitionBlocks == R.SeparateDefinitionBlocks &&
6336 ShortNamespaceLines == R.ShortNamespaceLines &&
6337 SkipMacroDefinitionBody == R.SkipMacroDefinitionBody &&
6338 SortIncludes == R.SortIncludes &&
6339 SortJavaStaticImport == R.SortJavaStaticImport &&
6340 SpaceAfterCStyleCast == R.SpaceAfterCStyleCast &&
6341 SpaceAfterLogicalNot == R.SpaceAfterLogicalNot &&
6342 SpaceAfterOperatorKeyword == R.SpaceAfterOperatorKeyword &&
6343 SpaceAfterTemplateKeyword == R.SpaceAfterTemplateKeyword &&
6344 SpaceBeforeAssignmentOperators == R.SpaceBeforeAssignmentOperators &&
6345 SpaceBeforeCaseColon == R.SpaceBeforeCaseColon &&
6346 SpaceBeforeCpp11BracedList == R.SpaceBeforeCpp11BracedList &&
6348 R.SpaceBeforeCtorInitializerColon &&
6349 SpaceBeforeInheritanceColon == R.SpaceBeforeInheritanceColon &&
6350 SpaceBeforeJsonColon == R.SpaceBeforeJsonColon &&
6351 SpaceBeforeParens == R.SpaceBeforeParens &&
6352 SpaceBeforeParensOptions == R.SpaceBeforeParensOptions &&
6353 SpaceAroundPointerQualifiers == R.SpaceAroundPointerQualifiers &&
6355 R.SpaceBeforeRangeBasedForLoopColon &&
6356 SpaceBeforeSquareBrackets == R.SpaceBeforeSquareBrackets &&
6357 SpaceInEmptyBraces == R.SpaceInEmptyBraces &&
6358 SpacesBeforeTrailingComments == R.SpacesBeforeTrailingComments &&
6359 SpacesInAngles == R.SpacesInAngles &&
6360 SpacesInBlockComments == R.SpacesInBlockComments &&
6361 SpacesInContainerLiterals == R.SpacesInContainerLiterals &&
6362 SpacesInLineCommentPrefix.Minimum ==
6363 R.SpacesInLineCommentPrefix.Minimum &&
6364 SpacesInLineCommentPrefix.Maximum ==
6365 R.SpacesInLineCommentPrefix.Maximum &&
6366 SpacesInParens == R.SpacesInParens &&
6367 SpacesInParensOptions == R.SpacesInParensOptions &&
6368 SpacesInSquareBrackets == R.SpacesInSquareBrackets &&
6369 Standard == R.Standard &&
6370 StatementAttributeLikeMacros == R.StatementAttributeLikeMacros &&
6371 StatementMacros == R.StatementMacros &&
6373 R.TableGenBreakingDAGArgOperators &&
6374 TableGenBreakInsideDAGArg == R.TableGenBreakInsideDAGArg &&
6375 TabWidth == R.TabWidth && TemplateNames == R.TemplateNames &&
6376 TypeNames == R.TypeNames && TypenameMacros == R.TypenameMacros &&
6377 UseTab == R.UseTab && VariableTemplates == R.VariableTemplates &&
6379 R.VerilogBreakBetweenInstancePorts &&
6380 WhitespaceSensitiveMacros == R.WhitespaceSensitiveMacros &&
6381 WrapNamespaceBodyWithEmptyLines == R.WrapNamespaceBodyWithEmptyLines;
6382 }
6383
6384 std::optional<FormatStyle> GetLanguageStyle(LanguageKind Language) const;
6385
6386 // Stores per-language styles. A FormatStyle instance inside has an empty
6387 // StyleSet. A FormatStyle instance returned by the Get method has its
6388 // StyleSet set to a copy of the originating StyleSet, effectively keeping the
6389 // internal representation of that StyleSet alive.
6391 // The memory management and ownership reminds of a birds nest: chicks
6392 // leaving the nest take photos of the nest with them.
6393 struct FormatStyleSet {
6394 typedef std::map<LanguageKind, FormatStyle> MapType;
6395
6396 std::optional<FormatStyle> Get(LanguageKind Language) const;
6397
6398 // Adds \p Style to this FormatStyleSet. Style must not have an associated
6399 // FormatStyleSet.
6400 // Style.Language should be different than LK_None. If this FormatStyleSet
6401 // already contains an entry for Style.Language, that gets replaced with the
6402 // passed Style.
6403 void Add(FormatStyle Style);
6404
6405 // Clears this FormatStyleSet.
6406 void Clear();
6407
6408 private:
6409 std::shared_ptr<MapType> Styles;
6410 };
6411
6412 static FormatStyleSet BuildStyleSetFromConfiguration(
6413 const FormatStyle &MainStyle,
6414 const std::vector<FormatStyle> &ConfigurationStyles);
6415
6416private:
6417 FormatStyleSet StyleSet;
6418
6419 friend std::error_code
6420 parseConfiguration(llvm::MemoryBufferRef Config, FormatStyle *Style,
6421 bool AllowUnknownOptions,
6422 llvm::SourceMgr::DiagHandlerTy DiagHandler,
6423 void *DiagHandlerCtxt, bool IsDotHFile);
6424};
6425
6426/// Returns a format style complying with the LLVM coding standards:
6427/// http://llvm.org/docs/CodingStandards.html.
6430
6431/// Returns a format style complying with one of Google's style guides:
6432/// http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml.
6433/// http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml.
6434/// https://developers.google.com/protocol-buffers/docs/style.
6436
6437/// Returns a format style complying with Chromium's style guide:
6438/// http://www.chromium.org/developers/coding-style.
6440
6441/// Returns a format style complying with Mozilla's style guide:
6442/// https://firefox-source-docs.mozilla.org/code-quality/coding-style/index.html.
6444
6445/// Returns a format style complying with Webkit's style guide:
6446/// http://www.webkit.org/coding/coding-style.html
6448
6449/// Returns a format style complying with GNU Coding Standards:
6450/// http://www.gnu.org/prep/standards/standards.html
6452
6453/// Returns a format style complying with Microsoft style guide:
6454/// https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017
6456
6458
6459/// Returns style indicating formatting should be not applied at all.
6461
6462/// Gets a predefined style for the specified language by name.
6463///
6464/// Currently supported names: LLVM, Google, Chromium, Mozilla. Names are
6465/// compared case-insensitively.
6466///
6467/// Returns `true` if the Style has been set.
6469 FormatStyle *Style);
6470
6471/// Parse configuration from YAML-formatted text.
6472///
6473/// Style->Language is used to get the base style, if the `BasedOnStyle`
6474/// option is present.
6475///
6476/// The FormatStyleSet of Style is reset.
6477///
6478/// When `BasedOnStyle` is not present, options not present in the YAML
6479/// document, are retained in \p Style.
6480///
6481/// If AllowUnknownOptions is true, no errors are emitted if unknown
6482/// format options are occurred.
6483///
6484/// If set all diagnostics are emitted through the DiagHandler.
6485std::error_code
6486parseConfiguration(llvm::MemoryBufferRef Config, FormatStyle *Style,
6487 bool AllowUnknownOptions = false,
6488 llvm::SourceMgr::DiagHandlerTy DiagHandler = nullptr,
6489 void *DiagHandlerCtx = nullptr, bool IsDotHFile = false);
6490
6491/// Like above but accepts an unnamed buffer.
6492inline std::error_code parseConfiguration(StringRef Config, FormatStyle *Style,
6493 bool AllowUnknownOptions = false,
6494 bool IsDotHFile = false) {
6495 return parseConfiguration(llvm::MemoryBufferRef(Config, "YAML"), Style,
6496 AllowUnknownOptions, /*DiagHandler=*/nullptr,
6497 /*DiagHandlerCtx=*/nullptr, IsDotHFile);
6498}
6499
6500/// Gets configuration in a YAML string.
6501std::string configurationAsText(const FormatStyle &Style);
6502
6503/// Returns the replacements necessary to sort all `#include` blocks
6504/// that are affected by `Ranges`.
6505tooling::Replacements sortIncludes(const FormatStyle &Style, StringRef Code,
6507 StringRef FileName,
6508 unsigned *Cursor = nullptr);
6509
6510/// Returns the replacements corresponding to applying and formatting
6511/// \p Replaces on success; otheriwse, return an llvm::Error carrying
6512/// llvm::StringError.
6514formatReplacements(StringRef Code, const tooling::Replacements &Replaces,
6515 const FormatStyle &Style);
6516
6517/// Returns the replacements corresponding to applying \p Replaces and
6518/// cleaning up the code after that on success; otherwise, return an llvm::Error
6519/// carrying llvm::StringError.
6520/// This also supports inserting/deleting C++ #include directives:
6521/// * If a replacement has offset UINT_MAX, length 0, and a replacement text
6522/// that is an #include directive, this will insert the #include into the
6523/// correct block in the \p Code.
6524/// * If a replacement has offset UINT_MAX, length 1, and a replacement text
6525/// that is the name of the header to be removed, the header will be removed
6526/// from \p Code if it exists.
6527/// The include manipulation is done via `tooling::HeaderInclude`, see its
6528/// documentation for more details on how include insertion points are found and
6529/// what edits are produced.
6531cleanupAroundReplacements(StringRef Code, const tooling::Replacements &Replaces,
6532 const FormatStyle &Style);
6533
6534/// Represents the status of a formatting attempt.
6536 /// A value of `false` means that any of the affected ranges were not
6537 /// formatted due to a non-recoverable syntax error.
6538 bool FormatComplete = true;
6539
6540 /// If `FormatComplete` is false, `Line` records a one-based
6541 /// original line number at which a syntax error might have occurred. This is
6542 /// based on a best-effort analysis and could be imprecise.
6543 unsigned Line = 0;
6544};
6545
6546/// Reformats the given \p Ranges in \p Code.
6547///
6548/// Each range is extended on either end to its next bigger logic unit, i.e.
6549/// everything that might influence its formatting or might be influenced by its
6550/// formatting.
6551///
6552/// Returns the `Replacements` necessary to make all \p Ranges comply with
6553/// \p Style.
6554///
6555/// If `Status` is non-null, its value will be populated with the status of
6556/// this formatting attempt. See \c FormattingAttemptStatus.
6557tooling::Replacements reformat(const FormatStyle &Style, StringRef Code,
6559 StringRef FileName = "<stdin>",
6560 FormattingAttemptStatus *Status = nullptr);
6561
6562/// Same as above, except if `IncompleteFormat` is non-null, its value
6563/// will be set to true if any of the affected ranges were not formatted due to
6564/// a non-recoverable syntax error.
6565tooling::Replacements reformat(const FormatStyle &Style, StringRef Code,
6567 StringRef FileName, bool *IncompleteFormat);
6568
6569/// Clean up any erroneous/redundant code in the given \p Ranges in \p
6570/// Code.
6571///
6572/// Returns the `Replacements` that clean up all \p Ranges in \p Code.
6573tooling::Replacements cleanup(const FormatStyle &Style, StringRef Code,
6575 StringRef FileName = "<stdin>");
6576
6577/// Fix namespace end comments in the given \p Ranges in \p Code.
6578///
6579/// Returns the `Replacements` that fix the namespace comments in all
6580/// \p Ranges in \p Code.
6582 StringRef Code,
6584 StringRef FileName = "<stdin>");
6585
6586/// Inserts or removes empty lines separating definition blocks including
6587/// classes, structs, functions, namespaces, and enums in the given \p Ranges in
6588/// \p Code.
6589///
6590/// Returns the `Replacements` that inserts or removes empty lines separating
6591/// definition blocks in all \p Ranges in \p Code.
6593 StringRef Code,
6595 StringRef FileName = "<stdin>");
6596
6597/// Sort consecutive using declarations in the given \p Ranges in
6598/// \p Code.
6599///
6600/// Returns the `Replacements` that sort the using declarations in all
6601/// \p Ranges in \p Code.
6603 StringRef Code,
6605 StringRef FileName = "<stdin>");
6606
6607/// Returns the `LangOpts` that the formatter expects you to set.
6608///
6609/// \param Style determines specific settings for lexing mode.
6611
6612/// Description to be used for help text for a `llvm::cl` option for
6613/// specifying format style. The description is closely related to the operation
6614/// of `getStyle()`.
6615extern const char *StyleOptionHelpDescription;
6616
6617/// The suggested format style to use by default. This allows tools using
6618/// `getStyle` to have a consistent default style.
6619/// Different builds can modify the value to the preferred styles.
6620extern const char *DefaultFormatStyle;
6621
6622/// The suggested predefined style to use as the fallback style in `getStyle`.
6623/// Different builds can modify the value to the preferred styles.
6624extern const char *DefaultFallbackStyle;
6625
6626/// Construct a FormatStyle based on `StyleName`.
6627///
6628/// `StyleName` can take several forms:
6629/// * "{<key>: <value>, ...}" - Set specic style parameters.
6630/// * "<style name>" - One of the style names supported by getPredefinedStyle().
6631/// * "file" - Load style configuration from a file called `.clang-format`
6632/// located in one of the parent directories of `FileName` or the current
6633/// directory if `FileName` is empty.
6634/// * "file:<format_file_path>" to explicitly specify the configuration file to
6635/// use.
6636///
6637/// \param[in] StyleName Style name to interpret according to the description
6638/// above.
6639/// \param[in] FileName Path to start search for .clang-format if `StyleName`
6640/// == "file".
6641/// \param[in] FallbackStyle The name of a predefined style used to fallback to
6642/// in case \p StyleName is "file" and no file can be found.
6643/// \param[in] Code The actual code to be formatted. Used to determine the
6644/// language if the filename isn't sufficient.
6645/// \param[in] FS The underlying file system, in which the file resides. By
6646/// default, the file system is the real file system.
6647/// \param[in] AllowUnknownOptions If true, unknown format options only
6648/// emit a warning. If false, errors are emitted on unknown format
6649/// options.
6650///
6651/// \returns FormatStyle as specified by `StyleName`. If `StyleName` is
6652/// "file" and no file is found, returns `FallbackStyle`. If no style could be
6653/// determined, returns an Error.
6655getStyle(StringRef StyleName, StringRef FileName, StringRef FallbackStyle,
6656 StringRef Code = "", llvm::vfs::FileSystem *FS = nullptr,
6657 bool AllowUnknownOptions = false,
6658 llvm::SourceMgr::DiagHandlerTy DiagHandler = nullptr);
6659
6660// Guesses the language from the `FileName` and `Code` to be formatted.
6661// Defaults to FormatStyle::LK_Cpp.
6662FormatStyle::LanguageKind guessLanguage(StringRef FileName, StringRef Code);
6663
6664// Returns a string representation of `Language`.
6666 switch (Language) {
6667 case FormatStyle::LK_C:
6668 return "C";
6670 return "C++";
6672 return "CSharp";
6674 return "Objective-C";
6676 return "Java";
6678 return "JavaScript";
6680 return "Json";
6682 return "Proto";
6684 return "TableGen";
6686 return "TextProto";
6688 return "Verilog";
6689 default:
6690 return "Unknown";
6691 }
6692}
6693
6694bool isClangFormatOn(StringRef Comment);
6695bool isClangFormatOff(StringRef Comment);
6696
6697} // end namespace format
6698} // end namespace clang
6699
6700template <>
6701struct std::is_error_code_enum<clang::format::ParseError> : std::true_type {};
6702
6703#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:1713
std::string message(int EV) const override
Definition Format.cpp:1717
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:4622
const char * DefaultFallbackStyle
The suggested predefined style to use as the fallback style in getStyle.
Definition Format.cpp:4743
FormatStyle getWebKitStyle()
Returns a format style complying with Webkit's style guide: http://www.webkit.org/coding/coding-style...
Definition Format.cpp:2372
std::error_code make_error_code(ParseError e)
Definition Format.cpp:1704
FormatStyle getClangFormatStyle()
Definition Format.cpp:2440
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:1879
FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language)
Returns a format style complying with one of Google's style guides: http://google-styleguide....
Definition Format.cpp:2133
std::string configurationAsText(const FormatStyle &Style)
Gets configuration in a YAML string.
Definition Format.cpp:2624
FormatStyle getMicrosoftStyle(FormatStyle::LanguageKind Language)
Returns a format style complying with Microsoft style guide: https://docs.microsoft....
Definition Format.cpp:2411
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:2527
const std::error_category & getParseCategory()
Definition Format.cpp:1700
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:4556
FormatStyle::LanguageKind guessLanguage(StringRef FileName, StringRef Code)
Definition Format.cpp:4718
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:4762
const char * DefaultFormatStyle
The suggested format style to use by default.
Definition Format.cpp:4741
FormatStyle getGNUStyle()
Returns a format style complying with GNU Coding Standards: http://www.gnu.org/prep/standards/standar...
Definition Format.cpp:2396
bool isClangFormatOff(StringRef Comment)
Definition Format.cpp:4982
LangOptions getFormattingLangOpts(const FormatStyle &Style=getLLVMStyle())
Returns the LangOpts that the formatter expects you to set.
Definition Format.cpp:4576
FormatStyle getMozillaStyle()
Returns a format style complying with Mozilla's style guide: https://firefox-source-docs....
Definition Format.cpp:2345
bool getPredefinedStyle(StringRef Name, FormatStyle::LanguageKind Language, FormatStyle *Style)
Gets a predefined style for the specified language by name.
Definition Format.cpp:2462
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:4301
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:4523
bool isClangFormatOn(StringRef Comment)
Definition Format.cpp:4978
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:4566
FormatStyle getChromiumStyle(FormatStyle::LanguageKind Language)
Returns a format style complying with Chromium's style guide: http://www.chromium....
Definition Format.cpp:2285
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:4534
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:4190
FormatStyle getNoStyle()
Returns style indicating formatting should be not applied at all.
Definition Format.cpp:2454
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:4149
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:6665
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.
int32_t uint32_t uint32_t 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:3859
@ LK_Cpp
Should be used for C++.
Definition Format.h:3865
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:6390
std::optional< FormatStyle > Get(LanguageKind Language) const
Definition Format.cpp:2640
Separator format of integer literals of different bases.
Definition Format.h:3574
int8_t DecimalMinDigitsInsert
Format separators in decimal literals with a minimum number of digits.
Definition Format.h:3617
int8_t BinaryMinDigitsInsert
Format separators in binary literals with a minimum number of digits.
Definition Format.h:3590
bool operator==(const IntegerLiteralSeparatorStyle &R) const
Definition Format.h:3659
int8_t Binary
Format separators in binary literals.
Definition Format.h:3582
int8_t HexMaxDigitsRemove
Remove separators in hexadecimal literals with a maximum number of digits.
Definition Format.h:3658
int8_t DecimalMaxDigitsRemove
Remove separators in decimal literals with a maximum number of digits.
Definition Format.h:3629
int8_t Decimal
Format separators in decimal literals.
Definition Format.h:3609
int8_t HexMinDigitsInsert
Format separators in hexadecimal literals with a minimum number of digits.
Definition Format.h:3645
int8_t BinaryMaxDigitsRemove
Remove separators in binary literals with a maximum number of digits.
Definition Format.h:3602
int8_t Hex
Format separators in hexadecimal literals.
Definition Format.h:3636
bool operator!=(const IntegerLiteralSeparatorStyle &R) const
Definition Format.h:3669
Options regarding which empty lines are kept.
Definition Format.h:3769
bool AtStartOfFile
Keep empty lines at start of file.
Definition Format.h:3791
bool AtEndOfBlock
Keep empty lines at end of a block.
Definition Format.h:3778
bool AtEndOfFile
Keep empty lines at end of file.
Definition Format.h:3780
bool operator==(const KeepEmptyLinesStyle &R) const
Definition Format.h:3792
bool AtStartOfBlock
Keep empty lines at start of a block.
Definition Format.h:3789
Separate control for each numeric literal component.
Definition Format.h:4087
NumericLiteralComponentStyle ExponentLetter
Format floating point exponent separator letter case.
Definition Format.h:4094
NumericLiteralComponentStyle Suffix
Format suffix case.
Definition Format.h:4116
bool operator==(const NumericLiteralCaseStyle &R) const
Definition Format.h:4118
NumericLiteralComponentStyle Prefix
Format integer prefix case.
Definition Format.h:4108
bool operator!=(const NumericLiteralCaseStyle &R) const
Definition Format.h:4123
NumericLiteralComponentStyle HexDigit
Format hexadecimal digit case.
Definition Format.h:4101
Options related to packing arguments of function calls.
Definition Format.h:4294
bool operator!=(const PackArgumentsStyle &R) const
Definition Format.h:4325
bool operator==(const PackArgumentsStyle &R) const
Definition Format.h:4322
unsigned BreakAfter
An argument list with more arguments than the specified number will be formatted with one argument pe...
Definition Format.h:4320
BinPackArgumentsStyle BinPack
The bin pack arguments style to use.
Definition Format.h:4298
Options related to packing parameters of function declarations and definitions.
Definition Format.h:4428
BinPackParametersStyle BinPack
The bin pack parameters style to use.
Definition Format.h:4432
bool operator!=(const PackParametersStyle &R) const
Definition Format.h:4457
bool operator==(const PackParametersStyle &R) const
Definition Format.h:4454
unsigned BreakAfter
A parameter list with more parameters than the specified number will be formatted with one parameter ...
Definition Format.h:4452
See documentation of RawStringFormats.
Definition Format.h:4641
std::string CanonicalDelimiter
The canonical delimiter for this language.
Definition Format.h:4649
LanguageKind Language
The language of this raw string.
Definition Format.h:4643
std::string BasedOnStyle
The style name on which this raw string format is based on.
Definition Format.h:4653
std::vector< std::string > EnclosingFunctions
A list of enclosing function names that match this language.
Definition Format.h:4647
bool operator==(const RawStringFormat &Other) const
Definition Format.h:4654
std::vector< std::string > Delimiters
A list of raw string delimiters that match this language.
Definition Format.h:4645
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:5141
bool operator==(const SortIncludesOptions &R) const
Definition Format.h:5164
bool operator!=(const SortIncludesOptions &R) const
Definition Format.h:5169
bool IgnoreCase
Whether or not includes are sorted in a case-insensitive fashion.
Definition Format.h:5123
bool IgnoreExtension
When sorting includes in each block, only take file extensions into account if two includes compare e...
Definition Format.h:5132
bool Enabled
If true, includes are sorted based on the other suboptions below.
Definition Format.h:5111
bool FilesBeforeFolders
When true, sort includes so that files in a directory appear before subdirectories at each level,...
Definition Format.h:5163
Precise control over the spacing before parentheses.
Definition Format.h:5447
bool AfterControlStatements
If true, put space between control statement keywords (for/if/while...) and opening parentheses.
Definition Format.h:5454
bool AfterOverloadedOperator
If true, put a space between operator overloading and opening parentheses.
Definition Format.h:5497
bool AfterRequiresInExpression
If true, put space between requires keyword in a requires expression and opening parentheses.
Definition Format.h:5524
bool AfterFunctionDeclarationName
If true, put a space between function declaration name and opening parentheses.
Definition Format.h:5468
bool AfterRequiresInClause
If true, put space between requires keyword in a requires clause and opening parentheses,...
Definition Format.h:5514
bool AfterForeachMacros
If true, put space between foreach macros and opening parentheses.
Definition Format.h:5461
bool AfterNot
If true, put a space between alternative operator not and the opening parenthesis.
Definition Format.h:5489
bool AfterFunctionDefinitionName
If true, put a space between function definition name and opening parentheses.
Definition Format.h:5475
bool BeforeNonEmptyParentheses
If true, put a space before opening parentheses only if the parentheses are not empty.
Definition Format.h:5532
bool operator==(const SpaceBeforeParensCustom &Other) const
Definition Format.h:5542
bool AfterIfMacros
If true, put space between if macros and opening parentheses.
Definition Format.h:5482
bool AfterPlacementOperator
If true, put a space between operator new/delete and opening parenthesis.
Definition Format.h:5505
If true, spaces may be inserted into C style casts.
Definition Format.h:5730
unsigned Maximum
The maximum number of spaces at the start of the comment.
Definition Format.h:5734
unsigned Minimum
The minimum number of spaces at the start of the comment.
Definition Format.h:5732
Precise control over the spacing in parentheses.
Definition Format.h:5809
bool operator==(const SpacesInParensCustom &R) const
Definition Format.h:5866
bool ExceptDoubleParentheses
Override any of the following options to prevent addition of space when both opening and closing pare...
Definition Format.h:5820
bool Other
Put a space in parentheses not covered by preceding options.
Definition Format.h:5852
bool InEmptyParentheses
Insert a space in empty parentheses, i.e.
Definition Format.h:5846
bool InCStyleCasts
Put a space in C style casts.
Definition Format.h:5835
bool operator!=(const SpacesInParensCustom &R) const
Definition Format.h:5872
bool InConditionalStatements
Put a space in parentheses only inside conditional statements (for/if/while/switch....
Definition Format.h:5828
SpacesInParensCustom(bool ExceptDoubleParentheses, bool InConditionalStatements, bool InCStyleCasts, bool InEmptyParentheses, bool Other)
Definition Format.h:5858
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:6069
@ UT_AlignWithSpaces
Use tabs for line continuation and indentation, and spaces for alignment.
Definition Format.h:6079
@ UT_ForContinuationAndIndentation
Fill all leading whitespace with tabs, and use spaces for alignment that appears within a line (e....
Definition Format.h:6076
@ UT_ForIndentation
Use tabs only for indentation.
Definition Format.h:6073
@ 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:6082
@ UT_Never
Never use tab.
Definition Format.h:6071
bool SpaceBeforeInheritanceColon
If false, spaces will be removed before inheritance colon.
Definition Format.h:5365
unsigned ContinuationIndentWidth
Indent width for line continuations.
Definition Format.h:2884
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:5941
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:3898
LanguageKind
Supported languages.
Definition Format.h:3859
@ LK_C
Should be used for C.
Definition Format.h:3863
@ LK_CSharp
Should be used for C#.
Definition Format.h:3867
@ LK_Java
Should be used for Java.
Definition Format.h:3869
@ LK_Cpp
Should be used for C++.
Definition Format.h:3865
@ LK_JavaScript
Should be used for JavaScript.
Definition Format.h:3871
@ LK_ObjC
Should be used for Objective-C, Objective-C++.
Definition Format.h:3875
@ LK_Verilog
Should be used for Verilog and SystemVerilog.
Definition Format.h:3886
@ LK_TableGen
Should be used for TableGen code.
Definition Format.h:3879
@ LK_Proto
Should be used for Protocol Buffers
Definition Format.h:3877
@ LK_Json
Should be used for JSON.
Definition Format.h:3873
@ LK_TextProto
Should be used for Protocol Buffer messages in text format.
Definition Format.h:3882
SortIncludesOptions SortIncludes
Controls if and how clang-format will sort #includes.
Definition Format.h:5176
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:4266
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:3462
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:5024
@ SDS_Never
Remove any empty line between definition blocks.
Definition Format.h:5030
@ SDS_Always
Insert an empty line between definition blocks.
Definition Format.h:5028
@ SDS_Leave
Leave definition blocks as they are.
Definition Format.h:5026
bool IndentRequiresClause
Indent the requires clause in a template.
Definition Format.h:3448
SpacesInAnglesStyle SpacesInAngles
The SpacesInAnglesStyle to use for template argument lists.
Definition Format.h:5679
bool KeepFormFeed
This option is deprecated.
Definition Format.h:3818
bool IndentCaseLabels
Indent case labels one level from the switch statement.
Definition Format.h:3267
std::vector< RawStringFormat > RawStringFormats
Defines hints for detecting supported languages code blocks in raw strings.
Definition Format.h:4698
std::vector< std::string > VariableTemplates
A vector of non-keyword identifiers that should be interpreted as variable template names.
Definition Format.h:6096
SortJavaStaticImportOptions
Position for Java Static imports.
Definition Format.h:5179
@ SJSIO_Before
Static imports are placed before non-static imports.
Definition Format.h:5186
@ SJSIO_After
Static imports are placed after non-static imports.
Definition Format.h:5193
PPDirectiveIndentStyle IndentPPDirectives
The preprocessor directive indenting style to use.
Definition Format.h:3425
bool RemoveSemicolon
Remove semicolons after the closing braces of functions and constructors/destructors.
Definition Format.h:4892
std::vector< std::string > Macros
A list of macros of the form <definition>=<expansion> .
Definition Format.h:3993
EnumTrailingCommaStyle
Styles for enum trailing commas.
Definition Format.h:3080
@ ETC_Remove
Remove trailing commas.
Definition Format.h:3098
@ ETC_Insert
Insert trailing commas.
Definition Format.h:3092
@ ETC_Leave
Don't insert or remove trailing commas.
Definition Format.h:3086
bool SpaceBeforeJsonColon
If true, a space will be added before a JSON colon.
Definition Format.h:5376
TrailingCommaStyle
The style of inserting trailing commas into container literals.
Definition Format.h:3515
@ TCS_Wrapped
Insert trailing commas in container literals that were wrapped over multiple lines.
Definition Format.h:3523
@ TCS_None
Do not insert trailing commas.
Definition Format.h:3517
unsigned PenaltyBreakBeforeFirstCallParameter
The penalty for breaking a function call after call(.
Definition Format.h:4473
bool SpaceBeforeCtorInitializerColon
If false, spaces will be removed before constructor initializer colon.
Definition Format.h:5349
BinPackParametersStyle
Different ways to try to fit all parameters on a line.
Definition Format.h:4397
@ BPPS_OnePerLine
Put all parameters on the current line if they fit.
Definition Format.h:4413
@ BPPS_UseBreakAfter
Use the BreakAfter option to handle parameter packing instead.
Definition Format.h:4423
@ BPPS_BinPack
Bin-pack parameters.
Definition Format.h:4403
@ BPPS_AlwaysOnePerLine
Always put each parameter on its own line.
Definition Format.h:4420
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:3280
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:4727
@ RCS_IndentOnly
Only apply indentation rules, moving comments left or right, without changing formatting inside the c...
Definition Format.h:4744
@ RCS_Never
Leave comments untouched.
Definition Format.h:4735
@ RCS_Always
Apply indentation rules and reflow long comments into new lines, trying to obey the ColumnLimit.
Definition Format.h:4755
EmptyLineBeforeAccessModifierStyle
Different styles for empty line before access modifiers.
Definition Format.h:3017
@ ELBAMS_LogicalBlock
Add empty line only when access modifier starts a new logical block.
Definition Format.h:3052
@ ELBAMS_Never
Remove all empty lines before access modifiers.
Definition Format.h:3032
@ ELBAMS_Always
Always add empty line before access modifiers unless access modifier is at the start of struct or cla...
Definition Format.h:3072
@ ELBAMS_Leave
Keep existing empty lines before access modifiers.
Definition Format.h:3034
unsigned SpacesBeforeTrailingComments
If true, spaces may be inserted into ().
Definition Format.h:5656
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:3283
@ IEBS_AfterExternBlock
Backwards compatible with AfterExternBlock's indenting.
Definition Format.h:3301
@ IEBS_Indent
Indents extern blocks.
Definition Format.h:3315
@ IEBS_NoIndent
Does not indent extern blocks.
Definition Format.h:3308
bool IndentCaseBlocks
Indent case label blocks one level from the case label.
Definition Format.h:3248
bool InsertBraces
Insert braces after control statements (if, else, for, do, and while) in C++ unless the control state...
Definition Format.h:3508
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:2959
std::vector< std::string > MacrosSkippedByRemoveParentheses
A vector of function-like macros whose invocations should be skipped by RemoveParentheses.
Definition Format.h:3998
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:3910
@ LE_DeriveLF
Use \n unless the input has more lines ending in \r\n.
Definition Format.h:3916
@ LE_DeriveCRLF
Use \r\n unless the input has more lines ending in \n.
Definition Format.h:3918
bool SpacesInSquareBrackets
If true, spaces will be inserted after [ and before ].
Definition Format.h:5902
bool IndentWrappedFunctionNames
Indent if a function definition or declaration is wrapped after the type.
Definition Format.h:3476
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:6160
bool FixNamespaceComments
If true, clang-format adds missing namespace end comments for namespaces and fixes invalid existing o...
Definition Format.h:3141
bool ObjCSpaceBeforeProtocolList
Add a space in front of an Objective-C protocol list, i.e.
Definition Format.h:4241
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:4874
std::string MacroBlockBegin
A regular expression matching macros that start a block.
Definition Format.h:3948
LanguageKind Language
The language that this format style targets.
Definition Format.h:3907
NumericLiteralComponentStyle
Control over each component in a numeric literal.
Definition Format.h:4066
@ NLCS_Lower
Format this component with lowercase characters.
Definition Format.h:4072
@ NLCS_Leave
Leave this component of the literal as is.
Definition Format.h:4068
@ NLCS_Upper
Format this component with uppercase characters.
Definition Format.h:4070
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:5772
@ SIPO_Custom
Configure each individual space in parentheses in SpacesInParensOptions.
Definition Format.h:5784
@ SIPO_Never
Never put a space in parentheses.
Definition Format.h:5781
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:4815
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:6110
unsigned TabWidth
The number of columns used for tab stops.
Definition Format.h:6026
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:3381
@ PPDIS_Leave
Leaves indentation of directives as-is.
Definition Format.h:3420
@ PPDIS_BeforeHash
Indents directives before the hash.
Definition Format.h:3408
@ PPDIS_None
Does not indent any directives.
Definition Format.h:3390
@ PPDIS_AfterHash
Indents directives after the hash.
Definition Format.h:3399
LambdaBodyIndentationKind
Indentation logic for lambda bodies.
Definition Format.h:3821
@ LBI_OuterScope
For statements within block scope, align lambda body relative to the indentation level of the outer s...
Definition Format.h:3843
@ LBI_Signature
Align lambda body relative to the lambda signature.
Definition Format.h:3829
std::vector< std::string > JavaImportGroups
A vector of prefixes ordered by the desired groups for Java imports.
Definition Format.h:3711
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:4485
std::vector< std::string > StatementAttributeLikeMacros
Macros which are ignored in front of a statement, as if they were an attribute.
Definition Format.h:5958
unsigned ObjCBlockIndentWidth
The number of characters to use for indentation of ObjC blocks.
Definition Format.h:4174
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:4638
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:2665
std::vector< std::string > IfMacros
A vector of macros that should be interpreted as conditionals instead of as function calls.
Definition Format.h:3182
bool SpaceBeforeEnumUnderlyingTypeColon
If false, spaces will be removed before enum underlying type colon.
Definition Format.h:5357
NamespaceIndentationKind NamespaceIndentation
The indentation used for namespaces.
Definition Format.h:4050
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:4221
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:3125
bool ObjCBreakBeforeNestedBlockParam
Break parameters list into lines when there is nested block parameters in a function call.
Definition Format.h:4198
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:4489
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:2527
unsigned PenaltyBreakBeforeMemberAccess
The penalty for breaking before a member access operator (.
Definition Format.h:4477
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:5798
SpacesInParensCustom SpacesInParensOptions
Control of individual spaces in parentheses.
Definition Format.h:5891
std::vector< std::string > ForEachMacros
A vector of macros that should be interpreted as foreach loops instead of as function calls.
Definition Format.h:3159
ReferenceAlignmentStyle ReferenceAlignment
Reference alignment style (overrides PointerAlignment for references).
Definition Format.h:4723
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:3542
unsigned PenaltyBreakTemplateDeclaration
The penalty for breaking after template declaration.
Definition Format.h:4501
SpaceBeforeParensCustom SpaceBeforeParensOptions
Control of individual space before parentheses.
Definition Format.h:5571
BreakConstructorInitializersStyle BreakConstructorInitializers
The break constructor initializers style to use.
Definition Format.h:2696
bool RemoveEmptyLinesInUnwrappedLines
Remove empty lines within unwrapped lines.
Definition Format.h:4838
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:5260
SpaceBeforeParensStyle
Different ways to put a space before opening parentheses.
Definition Format.h:5379
@ SBPO_Never
This is deprecated and replaced by Custom below, with all SpaceBeforeParensOptions but AfterPlacement...
Definition Format.h:5383
@ SBPO_Custom
Configure each individual space before parentheses in SpaceBeforeParensOptions.
Definition Format.h:5432
@ SBPO_NonEmptyParentheses
Put a space before opening parentheses only if the parentheses are not empty.
Definition Format.h:5417
@ SBPO_ControlStatementsExceptControlMacros
Same as SBPO_ControlStatements except this option doesn't apply to ForEach and If macros.
Definition Format.h:5406
@ SBPO_ControlStatements
Put a space before opening parentheses only after control statement keywords (for/if/while....
Definition Format.h:5393
@ SBPO_Always
Always put a space before opening parentheses, except when it's prohibited by the syntax rules (in fu...
Definition Format.h:5429
PackConstructorInitializersStyle
Different ways to try to fit all constructor initializers on a line.
Definition Format.h:4335
@ PCIS_NextLineOnly
Put all constructor initializers on the next line if they fit.
Definition Format.h:4389
@ PCIS_Never
Always put each constructor initializer on its own line.
Definition Format.h:4342
@ PCIS_CurrentLine
Put all constructor initializers on the current line if they fit.
Definition Format.h:4360
@ PCIS_BinPack
Bin-pack constructor initializers.
Definition Format.h:4349
@ PCIS_NextLine
Same as PCIS_CurrentLine except that if all constructor initializers do not fit on the current line,...
Definition Format.h:4374
std::vector< std::string > TypeNames
A vector of non-keyword identifiers that should be interpreted as type names.
Definition Format.h:6045
bool isTextProto() const
Definition Format.h:3896
bool ObjCSpaceAfterProperty
Add a space after @property in Objective-C, i.e.
Definition Format.h:4236
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:5683
@ SIBCS_Always
Add spaces after /* and before `.
Definition Format.h:5693
@ SIBCS_Leave
Leave existing spaces unchanged.
Definition Format.h:5695
@ SIBCS_Never
Remove spaces after /* and before `.
Definition Format.h:5688
unsigned PenaltyExcessCharacter
The penalty for each character outside of the column limit.
Definition Format.h:4505
std::vector< std::string > WhitespaceSensitiveMacros
A vector of macros which are whitespace-sensitive and should not be touched.
Definition Format.h:6127
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:6035
DAGArgStyle
Different ways to control the format inside TableGen DAGArg.
Definition Format.h:5997
@ DAS_BreakElements
Break inside DAGArg after each list element but for the last.
Definition Format.h:6009
@ DAS_DontBreak
Never break inside DAGArg.
Definition Format.h:6002
@ DAS_BreakAll
Break inside DAGArg after the operator and the all elements.
Definition Format.h:6017
unsigned ConstructorInitializerIndentWidth
This option is deprecated.
Definition Format.h:2873
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:2863
RequiresClausePositionStyle
The possible positions for the requires clause.
Definition Format.h:4896
@ RCPS_OwnLineWithBrace
As with OwnLine, except, unless otherwise prohibited, place a following open brace (of a function def...
Definition Format.h:4935
@ RCPS_OwnLine
Always put the requires clause on its own line (possibly followed by a semicolon).
Definition Format.h:4917
@ RCPS_WithPreceding
Try to put the clause together with the preceding part of a declaration.
Definition Format.h:4952
@ RCPS_SingleLine
Try to put everything in the same line if possible.
Definition Format.h:4990
@ RCPS_WithFollowing
Try to put the requires clause together with the class or function declaration.
Definition Format.h:4966
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:6162
LanguageStandard
Supported language standards for parsing and formatting C++ constructs.
Definition Format.h:5912
@ LS_Cpp17
Parse and format as C++17.
Definition Format.h:5921
@ LS_Cpp26
Parse and format as C++26.
Definition Format.h:5927
@ LS_Cpp23
Parse and format as C++23.
Definition Format.h:5925
@ LS_Latest
Parse and format using the latest supported language version.
Definition Format.h:5930
@ LS_Cpp11
Parse and format as C++11.
Definition Format.h:5917
@ LS_Auto
Automatic detection based on the input.
Definition Format.h:5932
@ LS_Cpp03
Parse and format as C++03.
Definition Format.h:5915
@ LS_Cpp14
Parse and format as C++14.
Definition Format.h:5919
@ LS_Cpp20
Parse and format as C++20.
Definition Format.h:5923
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:4995
JavaScriptQuoteStyle
Quotation styles for JavaScript strings.
Definition Format.h:3715
@ JSQS_Double
Always use double quotes.
Definition Format.h:3733
@ JSQS_Single
Always use single quotes.
Definition Format.h:3727
@ JSQS_Leave
Leave string quotes as they are.
Definition Format.h:3721
bool SpaceAfterCStyleCast
If true, a space is inserted after C style casts.
Definition Format.h:5252
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:4552
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:3677
SpaceAroundPointerQualifiersStyle SpaceAroundPointerQualifiers
Defines in which cases to put a space before or after pointer qualifiers.
Definition Format.h:5309
IndentAccessModifierStyle
Modes for indenting access modifiers and record members.
Definition Format.h:3185
@ IAMS_Never
Use AccessModifierOffset for access modifiers and indent members one level below the record.
Definition Format.h:3196
@ IAMS_AfterFirstAccessModifier
In C, C++, and Objective-C, indent members one level until the first explicit access modifier,...
Definition Format.h:3220
@ IAMS_Always
Give access modifiers their own indentation level and indent all members two levels below the record.
Definition Format.h:3208
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:5318
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:6130
@ 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:6152
@ WNBWELS_Leave
Keep existing newlines at the beginning and the end of namespace body.
Definition Format.h:6155
@ WNBWELS_Never
Remove all empty lines at the beginning and the end of namespace body.
Definition Format.h:6139
SpaceInEmptyBracesStyle SpaceInEmptyBraces
Specifies when to insert a space in empty braces.
Definition Format.h:5630
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:4231
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:4493
unsigned PenaltyReturnTypeOnItsOwnLine
Penalty for putting the return type of a function onto its own line.
Definition Format.h:4514
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:4537
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:4465
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:4998
@ REI_Keyword
Align requires expression body relative to the requires keyword.
Definition Format.h:5016
@ REI_OuterScope
Align requires expression body relative to the indentation level of the outer scope the requires expr...
Definition Format.h:5008
PackConstructorInitializersStyle PackConstructorInitializers
The pack constructor initializers style to use.
Definition Format.h:4394
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:4761
KeepEmptyLinesStyle KeepEmptyLines
Which empty lines are kept.
Definition Format.h:3801
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:2887
@ BLS_AlignFirstComment
Same as FunctionCall, except for the handling of a comment at the begin, it then aligns everything fo...
Definition Format.h:2941
@ BLS_FunctionCall
Best suited for C++11 braced lists.
Definition Format.h:2923
@ BLS_Block
Best suited for pre C++11 braced lists.
Definition Format.h:2903
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:4012
bool SpaceBeforeSquareBrackets
If true, spaces will be before [.
Definition Format.h:5581
BinPackStyle ObjCBinPackProtocolList
Controls bin-packing Objective-C protocol conformance list items into as few lines as possible when t...
Definition Format.h:4163
PackArgumentsStyle PackArguments
Options related to packing arguments of function calls.
Definition Format.h:4332
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:5769
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:3894
DAGArgStyle TableGenBreakInsideDAGArg
The styles of the line break inside the DAGArg in TableGen.
Definition Format.h:6022
JavaScriptQuoteStyle JavaScriptQuotes
The JavaScriptQuoteStyle to use for JavaScript strings.
Definition Format.h:3738
bool SpacesInContainerLiterals
If true, spaces will be inserted around if/for/switch/while conditions.
Definition Format.h:5721
SortJavaStaticImportOptions SortJavaStaticImport
When sorting Java imports, by default static imports are placed before non-static imports.
Definition Format.h:5200
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:5279
@ SAPQ_After
Ensure that there is a space after pointer qualifiers.
Definition Format.h:5298
@ SAPQ_Default
Don't ensure spaces around pointer qualifiers and use PointerAlignment instead.
Definition Format.h:5286
@ SAPQ_Both
Ensure that there is a space both before and after pointer qualifiers.
Definition Format.h:5304
@ SAPQ_Before
Ensure that there is a space before pointer qualifiers.
Definition Format.h:5292
bool SpaceBeforeRangeBasedForLoopColon
If false, spaces will be removed before range-based for loop colon.
Definition Format.h:5590
bool DisableFormat
Disables formatting completely.
Definition Format.h:2963
EmptyLineAfterAccessModifierStyle
Different styles for empty line after access modifiers.
Definition Format.h:2968
@ ELAAMS_Always
Always add empty line after access modifiers if there are none.
Definition Format.h:3007
@ ELAAMS_Never
Remove all empty lines after access modifiers.
Definition Format.h:2983
@ ELAAMS_Leave
Keep existing empty lines after access modifiers.
Definition Format.h:2986
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:4063
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:3852
QualifierAlignmentStyle QualifierAlignment
Different ways to arrange specifiers and qualifiers (e.g.
Definition Format.h:4598
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:3225
std::vector< std::string > StatementMacros
A vector of macros that should be interpreted as complete statements.
Definition Format.h:5968
SpacesInAnglesStyle
Styles for adding spacing after < and before > in template argument lists.
Definition Format.h:5660
@ SIAS_Never
Remove spaces after < and before >.
Definition Format.h:5666
@ SIAS_Always
Add spaces after < and before >.
Definition Format.h:5672
@ SIAS_Leave
Keep a single space after < and before > if any spaces were present.
Definition Format.h:5675
BinPackArgumentsStyle
Different ways to try to fit all arguments on a line.
Definition Format.h:4269
@ BPAS_OnePerLine
Put all arguments on the current line if they fit.
Definition Format.h:4287
@ BPAS_BinPack
Bin-pack arguments.
Definition Format.h:4277
@ BPAS_UseBreakAfter
Use the BreakAfter option to handle argument packing instead.
Definition Format.h:4290
SortUsingDeclarationsOptions
Using declaration sorting options.
Definition Format.h:5203
@ SUD_LexicographicNumeric
Using declarations are sorted in the order defined as follows: Split the strings by :: and discard an...
Definition Format.h:5239
@ SUD_Lexicographic
Using declarations are sorted in the order defined as follows: Split the strings by :: and discard an...
Definition Format.h:5224
@ SUD_Never
Using declarations are never sorted.
Definition Format.h:5212
AlignConsecutiveStyle AlignConsecutiveAssignments
Style of aligning consecutive assignments.
Definition Format.h:281
SpaceInEmptyBracesStyle
This option is deprecated.
Definition Format.h:5597
@ SIEB_Always
Always insert a space in empty braces.
Definition Format.h:5605
@ SIEB_Block
Only insert a space in empty blocks.
Definition Format.h:5613
@ SIEB_Never
Never insert a space in empty braces.
Definition Format.h:5621
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:4841
@ RPS_Leave
Do not remove parentheses.
Definition Format.h:4848
@ RPS_ReturnStatement
Also remove parentheses enclosing the expression in a return/co_return statement.
Definition Format.h:4863
@ RPS_MultipleParentheses
Replace multiple parentheses with single parentheses.
Definition Format.h:4855
std::vector< std::string > TableGenBreakingDAGArgOperators
Works only when TableGenBreakInsideDAGArg is not DontBreak.
Definition Format.h:5994
EmptyLineBeforeAccessModifierStyle EmptyLineBeforeAccessModifier
Defines in which cases to put empty line before access modifiers.
Definition Format.h:3077
EnumTrailingCommaStyle EnumTrailingComma
Insert a comma (if missing) or remove the comma at the end of an enum enumerator list.
Definition Format.h:3110
bool SpaceBeforeCaseColon
If false, spaces will be removed before case colon.
Definition Format.h:5328
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:3754
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:5105
unsigned PenaltyBreakAssignment
The penalty for breaking around an assignment operator.
Definition Format.h:4469
PointerAlignmentStyle
The &, && and * alignment style.
Definition Format.h:4517
@ PAS_Left
Align pointer to the left.
Definition Format.h:4522
@ PAS_Middle
Align pointer in the middle.
Definition Format.h:4532
@ PAS_Right
Align pointer to the right.
Definition Format.h:4527
unsigned PenaltyBreakString
The penalty for each line break introduced inside a string literal.
Definition Format.h:4497
RequiresExpressionIndentationKind RequiresExpressionIndentation
The indentation used for requires expression bodies.
Definition Format.h:5021
IndentGotoLabelStyle IndentGotoLabels
The goto label indenting style to use.
Definition Format.h:3378
bool SpaceAfterTemplateKeyword
If true, a space will be inserted after the template keyword.
Definition Format.h:5276
unsigned PenaltyIndentedWhitespace
Penalty for each character of whitespace indentation (counted relative to leading non-whitespace colu...
Definition Format.h:4510
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:4015
@ NI_None
Don't indent in namespaces.
Definition Format.h:4025
@ NI_All
Indent in all namespaces.
Definition Format.h:4045
@ NI_Inner
Indent only in inner namespaces (nested in other namespaces).
Definition Format.h:4035
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:3952
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:4481
bool SpaceAfterOperatorKeyword
If true, a space will be inserted after the operator keyword.
Definition Format.h:5268
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:4701
@ RAS_Right
Align reference to the right.
Definition Format.h:4713
@ RAS_Left
Align reference to the left.
Definition Format.h:4708
@ RAS_Pointer
Align reference like PointerAlignment.
Definition Format.h:4703
@ RAS_Middle
Align reference in the middle.
Definition Format.h:4718
EmptyLineAfterAccessModifierStyle EmptyLineAfterAccessModifier
Defines when to put an empty line after access modifiers.
Definition Format.h:3014
IndentGotoLabelStyle
Options for indenting goto labels.
Definition Format.h:3323
@ IGLS_InnerIndent
Indent goto labels to the surrounding statements (current indenting level).
Definition Format.h:3360
@ IGLS_OuterIndent
Indent goto labels to the enclosing block (previous indenting level).
Definition Format.h:3347
@ IGLS_HalfIndent
Indent goto labels to half the indentation of the surrounding code.
Definition Format.h:3373
@ IGLS_NoIndent
Do not indent goto labels.
Definition Format.h:3335
bool InsertNewlineAtEOF
Insert a newline at end of file if missing.
Definition Format.h:3512
SpaceBeforeParensStyle SpaceBeforeParens
Defines in which cases to put a space before opening parentheses.
Definition Format.h:5437
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:5340
NumericLiteralCaseStyle NumericLiteralCase
Capitalization style for numeric literals.
Definition Format.h:4130
UseTabStyle UseTab
The way to use tab characters in the resulting file.
Definition Format.h:6087
QualifierAlignmentStyle
Different specifiers and qualifiers alignment styles.
Definition Format.h:4555
@ QAS_Right
Change specifiers/qualifiers to be right-aligned.
Definition Format.h:4574
@ QAS_Custom
Change specifiers/qualifiers to be aligned based on QualifierOrder.
Definition Format.h:4586
@ QAS_Left
Change specifiers/qualifiers to be left-aligned.
Definition Format.h:4568
@ QAS_Leave
Don't change specifiers/qualifiers to either Left or Right alignment (default).
Definition Format.h:4562
std::vector< std::string > TypenameMacros
A vector of macros that should be interpreted as type declarations instead of as function calls.
Definition Format.h:6062
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:3923
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:2946
unsigned ShortNamespaceLines
The maximal number of unwrapped lines that a short namespace spans.
Definition Format.h:5101
SortUsingDeclarationsOptions SortUsingDeclarations
Controls if and how clang-format will sort using declarations.
Definition Format.h:5244
IndentExternBlockStyle IndentExternBlock
IndentExternBlockStyle is the type of indenting of extern blocks.
Definition Format.h:3320
SeparateDefinitionStyle SeparateDefinitionBlocks
Specifies the use of empty lines to separate definition blocks, including classes,...
Definition Format.h:5079
tooling::IncludeStyle IncludeStyle
Definition Format.h:3161
unsigned ColumnLimit
The column limit.
Definition Format.h:2785
Represents the status of a formatting attempt.
Definition Format.h:6535
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:6538
unsigned Line
If FormatComplete is false, Line records a one-based original line number at which a syntax error mig...
Definition Format.h:6543
Style for sorting and grouping C++ include directives.