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