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 requires expression body.
1511 /// \code
1512 /// true:
1513 /// template <typename T>
1514 /// concept C = requires(T t)
1515 /// {
1516 /// foo(t);
1517 /// };
1518 ///
1519 /// false:
1520 /// template <typename T>
1521 /// concept C = requires(T t) {
1522 /// foo(t);
1523 /// };
1524 /// \endcode
1526 /// Wrap struct definitions.
1527 /// \code
1528 /// true:
1529 /// struct foo
1530 /// {
1531 /// int x;
1532 /// };
1533 ///
1534 /// false:
1535 /// struct foo {
1536 /// int x;
1537 /// };
1538 /// \endcode
1540 /// Wrap union definitions.
1541 /// \code
1542 /// true:
1543 /// union foo
1544 /// {
1545 /// int x;
1546 /// }
1547 ///
1548 /// false:
1549 /// union foo {
1550 /// int x;
1551 /// }
1552 /// \endcode
1554 /// Wrap export blocks.
1555 /// \code
1556 /// true: false:
1557 /// export vs. export {
1558 /// { int foo();
1559 /// int foo(); }
1560 /// }
1561 /// \endcode
1563 /// Wrap extern blocks.
1564 /// \code
1565 /// true:
1566 /// extern "C"
1567 /// {
1568 /// int foo();
1569 /// }
1570 ///
1571 /// false:
1572 /// extern "C" {
1573 /// int foo();
1574 /// }
1575 /// \endcode
1576 bool AfterExternBlock; // Partially superseded by IndentExternBlock
1577 /// Wrap before `catch`.
1578 /// \code
1579 /// true:
1580 /// try {
1581 /// foo();
1582 /// }
1583 /// catch () {
1584 /// }
1585 ///
1586 /// false:
1587 /// try {
1588 /// foo();
1589 /// } catch () {
1590 /// }
1591 /// \endcode
1593 /// Wrap before `else`.
1594 /// \code
1595 /// true:
1596 /// if (foo()) {
1597 /// }
1598 /// else {
1599 /// }
1600 ///
1601 /// false:
1602 /// if (foo()) {
1603 /// } else {
1604 /// }
1605 /// \endcode
1607 /// Wrap lambda block.
1608 /// \code
1609 /// true:
1610 /// connect(
1611 /// []()
1612 /// {
1613 /// foo();
1614 /// bar();
1615 /// });
1616 ///
1617 /// false:
1618 /// connect([]() {
1619 /// foo();
1620 /// bar();
1621 /// });
1622 /// \endcode
1624 /// Wrap before `while`.
1625 /// \code
1626 /// true:
1627 /// do {
1628 /// foo();
1629 /// }
1630 /// while (1);
1631 ///
1632 /// false:
1633 /// do {
1634 /// foo();
1635 /// } while (1);
1636 /// \endcode
1638 /// Indent the wrapped braces themselves.
1640 /// If `false`, empty function body can be put on a single line.
1641 /// This option is used only if the opening brace of the function has
1642 /// already been wrapped, i.e. the `AfterFunction` brace wrapping mode is
1643 /// set, and the function could/should not be put on a single line (as per
1644 /// `AllowShortFunctionsOnASingleLine` and constructor formatting
1645 /// options).
1646 /// \code
1647 /// false: true:
1648 /// int f() vs. int f()
1649 /// {} {
1650 /// }
1651 /// \endcode
1652 ///
1654 /// If `false`, empty record (e.g. class, struct or union) body
1655 /// can be put on a single line. This option is used only if the opening
1656 /// brace of the record has already been wrapped, i.e. the `AfterClass`
1657 /// (for classes) brace wrapping mode is set.
1658 /// \code
1659 /// false: true:
1660 /// class Foo vs. class Foo
1661 /// {} {
1662 /// }
1663 /// \endcode
1664 ///
1666 /// If `false`, empty namespace body can be put on a single line.
1667 /// This option is used only if the opening brace of the namespace has
1668 /// already been wrapped, i.e. the `AfterNamespace` brace wrapping mode is
1669 /// set.
1670 /// \code
1671 /// false: true:
1672 /// namespace Foo vs. namespace Foo
1673 /// {} {
1674 /// }
1675 /// \endcode
1676 ///
1678 };
1679
1680 /// Control of individual brace wrapping cases.
1681 ///
1682 /// If `BreakBeforeBraces` is set to `Custom`, use this to specify how
1683 /// each individual brace case should be handled. Otherwise, this is ignored.
1684 /// \code{.yaml}
1685 /// # Example of usage:
1686 /// BreakBeforeBraces: Custom
1687 /// BraceWrapping:
1688 /// AfterEnum: true
1689 /// AfterStruct: false
1690 /// SplitEmptyFunction: false
1691 /// \endcode
1692 /// \version 3.8
1694
1695 /// Break between adjacent string literals.
1696 /// \code
1697 /// true:
1698 /// return "Code"
1699 /// "\0\52\26\55\55\0"
1700 /// "x013"
1701 /// "\02\xBA";
1702 /// false:
1703 /// return "Code" "\0\52\26\55\55\0" "x013" "\02\xBA";
1704 /// \endcode
1705 /// \version 18
1707
1708 /// Different ways to break after the last attribute of a group before a
1709 /// declaration or control statement.
1711 /// Always break after the last attribute of the group.
1712 /// \code
1713 /// [[maybe_unused]]
1714 /// const int i;
1715 /// [[gnu::const]] [[maybe_unused]]
1716 /// int j;
1717 ///
1718 /// [[nodiscard]]
1719 /// inline int f();
1720 /// [[gnu::const]] [[nodiscard]]
1721 /// int g();
1722 ///
1723 /// [[likely]]
1724 /// if (a)
1725 /// f();
1726 /// else
1727 /// g();
1728 ///
1729 /// switch (b) {
1730 /// [[unlikely]]
1731 /// case 1:
1732 /// ++b;
1733 /// break;
1734 /// [[likely]]
1735 /// default:
1736 /// return;
1737 /// }
1738 /// \endcode
1740 /// Leave the line breaking after the last attribute of the group as is.
1741 /// \code
1742 /// [[maybe_unused]] const int i;
1743 /// [[gnu::const]] [[maybe_unused]]
1744 /// int j;
1745 ///
1746 /// [[nodiscard]] inline int f();
1747 /// [[gnu::const]] [[nodiscard]]
1748 /// int g();
1749 ///
1750 /// [[likely]] if (a)
1751 /// f();
1752 /// else
1753 /// g();
1754 ///
1755 /// switch (b) {
1756 /// [[unlikely]] case 1:
1757 /// ++b;
1758 /// break;
1759 /// [[likely]]
1760 /// default:
1761 /// return;
1762 /// }
1763 /// \endcode
1765 /// Same as `Leave` except that it applies to all attributes of the group.
1766 /// \code
1767 /// [[deprecated("Don't use this version")]]
1768 /// [[nodiscard]]
1769 /// bool foo() {
1770 /// return true;
1771 /// }
1772 ///
1773 /// [[deprecated("Don't use this version")]]
1774 /// [[nodiscard]] bool bar() {
1775 /// return true;
1776 /// }
1777 /// \endcode
1779 /// Never break after the last attribute of the group.
1780 /// \code
1781 /// [[maybe_unused]] const int i;
1782 /// [[gnu::const]] [[maybe_unused]] int j;
1783 ///
1784 /// [[nodiscard]] inline int f();
1785 /// [[gnu::const]] [[nodiscard]] int g();
1786 ///
1787 /// [[likely]] if (a)
1788 /// f();
1789 /// else
1790 /// g();
1791 ///
1792 /// switch (b) {
1793 /// [[unlikely]] case 1:
1794 /// ++b;
1795 /// break;
1796 /// [[likely]] default:
1797 /// return;
1798 /// }
1799 /// \endcode
1801 };
1802
1803 /// Break after a group of C++11 attributes before variable or function
1804 /// (including constructor/destructor) declaration/definition names or before
1805 /// control statements, i.e. `if`, `switch` (including `case` and
1806 /// `default` labels), `for`, and `while` statements.
1807 /// \version 16
1809
1810 /// Force break after the left bracket of a braced initializer list (when
1811 /// `Cpp11BracedListStyle` is `true`) when the list exceeds the column
1812 /// limit.
1813 /// \code
1814 /// true: false:
1815 /// vector<int> x { vs. vector<int> x {1,
1816 /// 1, 2, 3} 2, 3}
1817 /// \endcode
1818 /// \version 22
1820
1821 /// Force break after the left parenthesis of a function (declaration,
1822 /// definition, call) when the parameters exceed the column limit.
1823 /// \code
1824 /// true: false:
1825 /// foo ( vs. foo (a,
1826 /// a , b) b)
1827 /// \endcode
1828 /// \version 22
1830
1831 /// Force break after the left parenthesis of an if control statement
1832 /// when the expression exceeds the column limit.
1833 /// \code
1834 /// true: false:
1835 /// if constexpr ( vs. if constexpr (a ||
1836 /// a || b) b)
1837 /// \endcode
1838 /// \version 22
1840
1841 /// Force break after the left parenthesis of a loop control statement
1842 /// when the expression exceeds the column limit.
1843 /// \code
1844 /// true: false:
1845 /// while ( vs. while (a &&
1846 /// a && b) { b) {
1847 /// \endcode
1848 /// \version 22
1850
1851 /// Force break after the left parenthesis of a switch control statement
1852 /// when the expression exceeds the column limit.
1853 /// \code
1854 /// true: false:
1855 /// switch ( vs. switch (a +
1856 /// a + b) { b) {
1857 /// \endcode
1858 /// \version 22
1860
1861 /// The function declaration return type breaking style to use.
1862 /// \version 19
1864
1865 /// If `true`, clang-format will always break after a Json array `[`
1866 /// otherwise it will scan until the closing `]` to determine if it should
1867 /// add newlines between elements (prettier compatible).
1868 ///
1869 /// \note
1870 /// This is currently only for formatting JSON.
1871 /// \endnote
1872 /// \code
1873 /// true: false:
1874 /// [ vs. [1, 2, 3, 4]
1875 /// 1,
1876 /// 2,
1877 /// 3,
1878 /// 4
1879 /// ]
1880 /// \endcode
1881 /// \version 16
1883
1884 /// The style of wrapping parameters on the same line (bin-packed) or
1885 /// on one line each.
1887 /// Automatically determine parameter bin-packing behavior.
1889 /// Always bin-pack parameters.
1891 /// Never bin-pack parameters.
1893 };
1894
1895 /// The style of breaking before or after binary operators.
1897 /// Break after operators.
1898 /// \code
1899 /// LooooooooooongType loooooooooooooooooooooongVariable =
1900 /// someLooooooooooooooooongFunction();
1901 ///
1902 /// bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
1903 /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ==
1904 /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
1905 /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa >
1906 /// ccccccccccccccccccccccccccccccccccccccccc;
1907 /// \endcode
1909 /// Break before operators that aren't assignments.
1910 /// \code
1911 /// LooooooooooongType loooooooooooooooooooooongVariable =
1912 /// someLooooooooooooooooongFunction();
1913 ///
1914 /// bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1915 /// + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1916 /// == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1917 /// && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1918 /// > ccccccccccccccccccccccccccccccccccccccccc;
1919 /// \endcode
1921 /// Break before operators.
1922 /// \code
1923 /// LooooooooooongType loooooooooooooooooooooongVariable
1924 /// = someLooooooooooooooooongFunction();
1925 ///
1926 /// bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1927 /// + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1928 /// == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1929 /// && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1930 /// > ccccccccccccccccccccccccccccccccccccccccc;
1931 /// \endcode
1933 };
1934
1935 /// The way to wrap binary operators.
1936 /// \version 3.6
1938
1939 /// Different ways to attach braces to their surrounding context.
1941 /// Always attach braces to surrounding context.
1942 /// \code
1943 /// namespace N {
1944 /// enum E {
1945 /// E1,
1946 /// E2,
1947 /// };
1948 ///
1949 /// class C {
1950 /// public:
1951 /// C();
1952 /// };
1953 ///
1954 /// bool baz(int i) {
1955 /// try {
1956 /// do {
1957 /// switch (i) {
1958 /// case 1: {
1959 /// foobar();
1960 /// break;
1961 /// }
1962 /// default: {
1963 /// break;
1964 /// }
1965 /// }
1966 /// } while (--i);
1967 /// return true;
1968 /// } catch (...) {
1969 /// handleError();
1970 /// return false;
1971 /// }
1972 /// }
1973 ///
1974 /// void foo(bool b) {
1975 /// if (b) {
1976 /// baz(2);
1977 /// } else {
1978 /// baz(5);
1979 /// }
1980 /// }
1981 ///
1982 /// void bar() { foo(true); }
1983 /// } // namespace N
1984 /// \endcode
1986 /// Like `Attach`, but break before braces on function, namespace and
1987 /// class definitions.
1988 /// \code
1989 /// namespace N
1990 /// {
1991 /// enum E {
1992 /// E1,
1993 /// E2,
1994 /// };
1995 ///
1996 /// class C
1997 /// {
1998 /// public:
1999 /// C();
2000 /// };
2001 ///
2002 /// bool baz(int i)
2003 /// {
2004 /// try {
2005 /// do {
2006 /// switch (i) {
2007 /// case 1: {
2008 /// foobar();
2009 /// break;
2010 /// }
2011 /// default: {
2012 /// break;
2013 /// }
2014 /// }
2015 /// } while (--i);
2016 /// return true;
2017 /// } catch (...) {
2018 /// handleError();
2019 /// return false;
2020 /// }
2021 /// }
2022 ///
2023 /// void foo(bool b)
2024 /// {
2025 /// if (b) {
2026 /// baz(2);
2027 /// } else {
2028 /// baz(5);
2029 /// }
2030 /// }
2031 ///
2032 /// void bar() { foo(true); }
2033 /// } // namespace N
2034 /// \endcode
2036 /// Like `Attach`, but break before braces on enum, function, and record
2037 /// definitions.
2038 /// \code
2039 /// namespace N {
2040 /// enum E
2041 /// {
2042 /// E1,
2043 /// E2,
2044 /// };
2045 ///
2046 /// class C
2047 /// {
2048 /// public:
2049 /// C();
2050 /// };
2051 ///
2052 /// bool baz(int i)
2053 /// {
2054 /// try {
2055 /// do {
2056 /// switch (i) {
2057 /// case 1: {
2058 /// foobar();
2059 /// break;
2060 /// }
2061 /// default: {
2062 /// break;
2063 /// }
2064 /// }
2065 /// } while (--i);
2066 /// return true;
2067 /// } catch (...) {
2068 /// handleError();
2069 /// return false;
2070 /// }
2071 /// }
2072 ///
2073 /// void foo(bool b)
2074 /// {
2075 /// if (b) {
2076 /// baz(2);
2077 /// } else {
2078 /// baz(5);
2079 /// }
2080 /// }
2081 ///
2082 /// void bar() { foo(true); }
2083 /// } // namespace N
2084 /// \endcode
2086 /// Like `Attach`, but break before function definitions, `catch`, and
2087 /// `else`.
2088 /// \code
2089 /// namespace N {
2090 /// enum E {
2091 /// E1,
2092 /// E2,
2093 /// };
2094 ///
2095 /// class C {
2096 /// public:
2097 /// C();
2098 /// };
2099 ///
2100 /// bool baz(int i)
2101 /// {
2102 /// try {
2103 /// do {
2104 /// switch (i) {
2105 /// case 1: {
2106 /// foobar();
2107 /// break;
2108 /// }
2109 /// default: {
2110 /// break;
2111 /// }
2112 /// }
2113 /// } while (--i);
2114 /// return true;
2115 /// }
2116 /// catch (...) {
2117 /// handleError();
2118 /// return false;
2119 /// }
2120 /// }
2121 ///
2122 /// void foo(bool b)
2123 /// {
2124 /// if (b) {
2125 /// baz(2);
2126 /// }
2127 /// else {
2128 /// baz(5);
2129 /// }
2130 /// }
2131 ///
2132 /// void bar() { foo(true); }
2133 /// } // namespace N
2134 /// \endcode
2136 /// Always break before braces.
2137 /// \code
2138 /// namespace N
2139 /// {
2140 /// enum E
2141 /// {
2142 /// E1,
2143 /// E2,
2144 /// };
2145 ///
2146 /// class C
2147 /// {
2148 /// public:
2149 /// C();
2150 /// };
2151 ///
2152 /// bool baz(int i)
2153 /// {
2154 /// try
2155 /// {
2156 /// do
2157 /// {
2158 /// switch (i)
2159 /// {
2160 /// case 1:
2161 /// {
2162 /// foobar();
2163 /// break;
2164 /// }
2165 /// default:
2166 /// {
2167 /// break;
2168 /// }
2169 /// }
2170 /// } while (--i);
2171 /// return true;
2172 /// }
2173 /// catch (...)
2174 /// {
2175 /// handleError();
2176 /// return false;
2177 /// }
2178 /// }
2179 ///
2180 /// void foo(bool b)
2181 /// {
2182 /// if (b)
2183 /// {
2184 /// baz(2);
2185 /// }
2186 /// else
2187 /// {
2188 /// baz(5);
2189 /// }
2190 /// }
2191 ///
2192 /// void bar() { foo(true); }
2193 /// } // namespace N
2194 /// \endcode
2196 /// Like `Allman` but always indent braces and line up code with braces.
2197 /// \code
2198 /// namespace N
2199 /// {
2200 /// enum E
2201 /// {
2202 /// E1,
2203 /// E2,
2204 /// };
2205 ///
2206 /// class C
2207 /// {
2208 /// public:
2209 /// C();
2210 /// };
2211 ///
2212 /// bool baz(int i)
2213 /// {
2214 /// try
2215 /// {
2216 /// do
2217 /// {
2218 /// switch (i)
2219 /// {
2220 /// case 1:
2221 /// {
2222 /// foobar();
2223 /// break;
2224 /// }
2225 /// default:
2226 /// {
2227 /// break;
2228 /// }
2229 /// }
2230 /// } while (--i);
2231 /// return true;
2232 /// }
2233 /// catch (...)
2234 /// {
2235 /// handleError();
2236 /// return false;
2237 /// }
2238 /// }
2239 ///
2240 /// void foo(bool b)
2241 /// {
2242 /// if (b)
2243 /// {
2244 /// baz(2);
2245 /// }
2246 /// else
2247 /// {
2248 /// baz(5);
2249 /// }
2250 /// }
2251 ///
2252 /// void bar() { foo(true); }
2253 /// } // namespace N
2254 /// \endcode
2256 /// Always break before braces and add an extra level of indentation to
2257 /// braces of control statements, not to those of class, function
2258 /// or other definitions.
2259 /// \code
2260 /// namespace N
2261 /// {
2262 /// enum E
2263 /// {
2264 /// E1,
2265 /// E2,
2266 /// };
2267 ///
2268 /// class C
2269 /// {
2270 /// public:
2271 /// C();
2272 /// };
2273 ///
2274 /// bool baz(int i)
2275 /// {
2276 /// try
2277 /// {
2278 /// do
2279 /// {
2280 /// switch (i)
2281 /// {
2282 /// case 1:
2283 /// {
2284 /// foobar();
2285 /// break;
2286 /// }
2287 /// default:
2288 /// {
2289 /// break;
2290 /// }
2291 /// }
2292 /// }
2293 /// while (--i);
2294 /// return true;
2295 /// }
2296 /// catch (...)
2297 /// {
2298 /// handleError();
2299 /// return false;
2300 /// }
2301 /// }
2302 ///
2303 /// void foo(bool b)
2304 /// {
2305 /// if (b)
2306 /// {
2307 /// baz(2);
2308 /// }
2309 /// else
2310 /// {
2311 /// baz(5);
2312 /// }
2313 /// }
2314 ///
2315 /// void bar() { foo(true); }
2316 /// } // namespace N
2317 /// \endcode
2319 /// Like `Attach`, but break before functions.
2320 /// \code
2321 /// namespace N {
2322 /// enum E {
2323 /// E1,
2324 /// E2,
2325 /// };
2326 ///
2327 /// class C {
2328 /// public:
2329 /// C();
2330 /// };
2331 ///
2332 /// bool baz(int i)
2333 /// {
2334 /// try {
2335 /// do {
2336 /// switch (i) {
2337 /// case 1: {
2338 /// foobar();
2339 /// break;
2340 /// }
2341 /// default: {
2342 /// break;
2343 /// }
2344 /// }
2345 /// } while (--i);
2346 /// return true;
2347 /// } catch (...) {
2348 /// handleError();
2349 /// return false;
2350 /// }
2351 /// }
2352 ///
2353 /// void foo(bool b)
2354 /// {
2355 /// if (b) {
2356 /// baz(2);
2357 /// } else {
2358 /// baz(5);
2359 /// }
2360 /// }
2361 ///
2362 /// void bar() { foo(true); }
2363 /// } // namespace N
2364 /// \endcode
2366 /// Configure each individual brace in `BraceWrapping`.
2368 };
2369
2370 /// The brace breaking style to use.
2371 /// \version 3.7
2373
2374 /// Force break before the right bracket of a braced initializer list (when
2375 /// `Cpp11BracedListStyle` is `true`) when the list exceeds the column
2376 /// limit. The break before the right bracket is only made if there is a
2377 /// break after the opening bracket.
2378 /// \code
2379 /// true: false:
2380 /// vector<int> x { vs. vector<int> x {
2381 /// 1, 2, 3 1, 2, 3}
2382 /// }
2383 /// \endcode
2384 /// \version 22
2386
2387 /// Force break before the right parenthesis of a function (declaration,
2388 /// definition, call) when the parameters exceed the column limit.
2389 /// \code
2390 /// true: false:
2391 /// foo ( vs. foo (
2392 /// a , b a , b)
2393 /// )
2394 /// \endcode
2395 /// \version 22
2397
2398 /// Force break before the right parenthesis of an if control statement
2399 /// when the expression exceeds the column limit. The break before the
2400 /// closing parenthesis is only made if there is a break after the opening
2401 /// parenthesis.
2402 /// \code
2403 /// true: false:
2404 /// if constexpr ( vs. if constexpr (
2405 /// a || b a || b )
2406 /// )
2407 /// \endcode
2408 /// \version 22
2410
2411 /// Force break before the right parenthesis of a loop control statement
2412 /// when the expression exceeds the column limit. The break before the
2413 /// closing parenthesis is only made if there is a break after the opening
2414 /// parenthesis.
2415 /// \code
2416 /// true: false:
2417 /// while ( vs. while (
2418 /// a && b a && b) {
2419 /// ) {
2420 /// \endcode
2421 /// \version 22
2423
2424 /// Force break before the right parenthesis of a switch control statement
2425 /// when the expression exceeds the column limit. The break before the
2426 /// closing parenthesis is only made if there is a break after the opening
2427 /// parenthesis.
2428 /// \code
2429 /// true: false:
2430 /// switch ( vs. switch (
2431 /// a + b a + b) {
2432 /// ) {
2433 /// \endcode
2434 /// \version 22
2436
2437 /// Different ways to break before concept declarations.
2439 /// Keep the template declaration line together with `concept`.
2440 /// \code
2441 /// template <typename T> concept C = ...;
2442 /// \endcode
2444 /// Breaking between template declaration and `concept` is allowed. The
2445 /// actual behavior depends on the content and line breaking rules and
2446 /// penalties.
2448 /// Always break before `concept`, putting it in the line after the
2449 /// template declaration.
2450 /// \code
2451 /// template <typename T>
2452 /// concept C = ...;
2453 /// \endcode
2455 };
2456
2457 /// The concept declaration style to use.
2458 /// \version 12
2460
2461 /// Different ways to break ASM parameters.
2463 /// No break before inline ASM colon.
2464 /// \code
2465 /// asm volatile("string", : : val);
2466 /// \endcode
2468 /// Break before inline ASM colon if the line length is longer than column
2469 /// limit.
2470 /// \code
2471 /// asm volatile("string", : : val);
2472 /// asm("cmoveq %1, %2, %[result]"
2473 /// : [result] "=r"(result)
2474 /// : "r"(test), "r"(new), "[result]"(old));
2475 /// \endcode
2477 /// Always break before inline ASM colon.
2478 /// \code
2479 /// asm volatile("string",
2480 /// :
2481 /// : val);
2482 /// \endcode
2484 };
2485
2486 /// The inline ASM colon style to use.
2487 /// \version 16
2489
2490 /// Different ways to break before the function return type.
2492 /// Do not force a break before the return type.
2494 /// Always break before the return type.
2495 /// \code
2496 /// static inline
2497 /// void f();
2498 /// \endcode
2500 /// Break before the return type of top-level functions only.
2502 /// Break before the return type of function definitions only.
2504 /// Break before the return type of top-level definitions only.
2506 };
2507
2508 /// The function declaration/definition return type breaking style to use.
2509 /// Trailing return types (`auto f() -> T`) are not affected. To have
2510 /// identifier macros (e.g. `__always_inline`) treated as specifiers,
2511 /// add them to `AttributeMacros`.
2512 /// \version 23
2514
2515 /// If `true`, break before a template closing bracket (`>`) when there is
2516 /// a line break after the matching opening bracket (`<`).
2517 /// \code
2518 /// true:
2519 /// template <typename Foo, typename Bar>
2520 ///
2521 /// template <typename Foo,
2522 /// typename Bar>
2523 ///
2524 /// template <
2525 /// typename Foo,
2526 /// typename Bar
2527 /// >
2528 ///
2529 /// false:
2530 /// template <typename Foo, typename Bar>
2531 ///
2532 /// template <typename Foo,
2533 /// typename Bar>
2534 ///
2535 /// template <
2536 /// typename Foo,
2537 /// typename Bar>
2538 /// \endcode
2539 /// \version 21
2541
2542 /// If `true`, ternary operators will be placed after line breaks.
2543 /// \code
2544 /// true:
2545 /// veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription
2546 /// ? firstValue
2547 /// : SecondValueVeryVeryVeryVeryLong;
2548 ///
2549 /// false:
2550 /// veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ?
2551 /// firstValue :
2552 /// SecondValueVeryVeryVeryVeryLong;
2553 /// \endcode
2554 /// \version 3.7
2556
2557 /// Different ways to break binary operations.
2559 /// Don't break binary operations
2560 /// \code
2561 /// aaa + bbbb * ccccc - ddddd +
2562 /// eeeeeeeeeeeeeeee;
2563 /// \endcode
2565
2566 /// Binary operations will either be all on the same line, or each operation
2567 /// will have one line each.
2568 /// \code
2569 /// aaa +
2570 /// bbbb *
2571 /// ccccc -
2572 /// ddddd +
2573 /// eeeeeeeeeeeeeeee;
2574 /// \endcode
2576
2577 /// Binary operations of a particular precedence that exceed the column
2578 /// limit will have one line each.
2579 /// \code
2580 /// aaa +
2581 /// bbbb * ccccc -
2582 /// ddddd +
2583 /// eeeeeeeeeeeeeeee;
2584 /// \endcode
2586 };
2587
2588 /// A rule that specifies how to break a specific set of binary operators.
2589 /// \version 23
2591 /// The list of operators this rule applies to, e.g. `&&`, `||`, `|`.
2592 /// Alternative spellings (e.g. `and` for `&&`) are accepted.
2593 std::vector<tok::TokenKind> Operators;
2594 /// The break style for these operators (defaults to `OnePerLine`).
2596 /// Minimum number of operands in a chain before the rule triggers.
2597 /// For example, `a && b && c` is a chain of length 3.
2598 /// `0` means always break (when the line is too long).
2601 return Operators == R.Operators && Style == R.Style &&
2602 MinChainLength == R.MinChainLength;
2603 }
2605 return !(*this == R);
2606 }
2607 };
2608
2609 /// Options for `BreakBinaryOperations`.
2610 ///
2611 /// If specified as a simple string (e.g. `OnePerLine`), it behaves like
2612 /// the original enum and applies to all binary operators.
2613 ///
2614 /// If specified as a struct, allows per-operator configuration:
2615 /// \code{.yaml}
2616 /// BreakBinaryOperations:
2617 /// Default: Never
2618 /// PerOperator:
2619 /// - Operators: ['&&', '||']
2620 /// Style: OnePerLine
2621 /// MinChainLength: 3
2622 /// \endcode
2623 /// \version 23
2625 /// The default break style for operators not covered by `PerOperator`.
2627 /// Per-operator override rules.
2628 std::vector<BinaryOperationBreakRule> PerOperator;
2631 for (const auto &Rule : PerOperator) {
2632 if (llvm::find(Rule.Operators, Kind) != Rule.Operators.end())
2633 return &Rule;
2634 // clang-format splits ">>" into two ">" tokens for template parsing.
2635 // Match ">" against ">>" rules so that per-operator rules for ">>"
2636 // (stream extraction / right shift) work correctly.
2637 if (Kind == tok::greater &&
2638 llvm::find(Rule.Operators, tok::greatergreater) !=
2639 Rule.Operators.end()) {
2640 return &Rule;
2641 }
2642 }
2643 return nullptr;
2644 }
2646 if (const auto *Rule = findRuleForOperator(Kind))
2647 return Rule->Style;
2648 return Default;
2649 }
2651 if (const auto *Rule = findRuleForOperator(Kind))
2652 return Rule->MinChainLength;
2653 return 0;
2654 }
2656 return Default == R.Default && PerOperator == R.PerOperator;
2657 }
2659 return !(*this == R);
2660 }
2661 };
2662
2663 /// The break binary operations style to use.
2664 /// \version 20
2666
2667 /// Different ways to break initializers.
2669 /// Break constructor initializers before the colon and after the commas.
2670 /// \code
2671 /// Constructor()
2672 /// : initializer1(),
2673 /// initializer2()
2674 /// \endcode
2676 /// Break constructor initializers before the colon and commas, and align
2677 /// the commas with the colon.
2678 /// \code
2679 /// Constructor()
2680 /// : initializer1()
2681 /// , initializer2()
2682 /// \endcode
2684 /// Break constructor initializers after the colon and commas.
2685 /// \code
2686 /// Constructor() :
2687 /// initializer1(),
2688 /// initializer2()
2689 /// \endcode
2691 /// Break constructor initializers only after the commas.
2692 /// \code
2693 /// Constructor() : initializer1(),
2694 /// initializer2()
2695 /// \endcode
2697 };
2698
2699 /// The break constructor initializers style to use.
2700 /// \version 5
2702
2703 /// If `true`, clang-format will always break before function declaration
2704 /// parameters.
2705 /// \code
2706 /// true:
2707 /// void functionDeclaration(
2708 /// int A, int B);
2709 ///
2710 /// false:
2711 /// void functionDeclaration(int A, int B);
2712 ///
2713 /// \endcode
2714 /// \version 23
2716
2717 /// If `true`, clang-format will always break before function definition
2718 /// parameters.
2719 /// \code
2720 /// true:
2721 /// void functionDefinition(
2722 /// int A, int B) {}
2723 ///
2724 /// false:
2725 /// void functionDefinition(int A, int B) {}
2726 ///
2727 /// \endcode
2728 /// \version 19
2730
2731 /// Break after each annotation on a field in Java files.
2732 /// \code{.java}
2733 /// true: false:
2734 /// @Partial vs. @Partial @Mock DataLoad loader;
2735 /// @Mock
2736 /// DataLoad loader;
2737 /// \endcode
2738 /// \version 3.8
2740
2741 /// Allow breaking string literals when formatting.
2742 ///
2743 /// In C, C++, and Objective-C:
2744 /// \code
2745 /// true:
2746 /// const char* x = "veryVeryVeryVeryVeryVe"
2747 /// "ryVeryVeryVeryVeryVery"
2748 /// "VeryLongString";
2749 ///
2750 /// false:
2751 /// const char* x =
2752 /// "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
2753 /// \endcode
2754 ///
2755 /// In C# and Java:
2756 /// \code
2757 /// true:
2758 /// string x = "veryVeryVeryVeryVeryVe" +
2759 /// "ryVeryVeryVeryVeryVery" +
2760 /// "VeryLongString";
2761 ///
2762 /// false:
2763 /// string x =
2764 /// "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
2765 /// \endcode
2766 ///
2767 /// C# interpolated strings are not broken.
2768 ///
2769 /// In Verilog:
2770 /// \code
2771 /// true:
2772 /// string x = {"veryVeryVeryVeryVeryVe",
2773 /// "ryVeryVeryVeryVeryVery",
2774 /// "VeryLongString"};
2775 ///
2776 /// false:
2777 /// string x =
2778 /// "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
2779 /// \endcode
2780 ///
2781 /// \version 3.9
2783
2784 /// The column limit.
2785 ///
2786 /// A column limit of `0` means that there is no column limit. In this case,
2787 /// clang-format will respect the input's line breaking decisions within
2788 /// statements unless they contradict other rules.
2789 /// \version 3.7
2790 unsigned ColumnLimit;
2791
2792 /// A regular expression that describes comments with special meaning,
2793 /// which should not be split into lines or otherwise changed.
2794 /// \code
2795 /// // CommentPragmas: '^ FOOBAR pragma:'
2796 /// // Will leave the following line unaffected
2797 /// #include <vector> // FOOBAR pragma: keep
2798 /// \endcode
2799 /// \version 3.7
2800 std::string CommentPragmas;
2801
2802 /// Different ways to break inheritance list.
2804 /// Break inheritance list before the colon and after the commas.
2805 /// \code
2806 /// class Foo
2807 /// : Base1,
2808 /// Base2
2809 /// {};
2810 /// \endcode
2812 /// Break inheritance list before the colon and commas, and align
2813 /// the commas with the colon.
2814 /// \code
2815 /// class Foo
2816 /// : Base1
2817 /// , Base2
2818 /// {};
2819 /// \endcode
2821 /// Break inheritance list after the colon and commas.
2822 /// \code
2823 /// class Foo :
2824 /// Base1,
2825 /// Base2
2826 /// {};
2827 /// \endcode
2829 /// Break inheritance list only after the commas.
2830 /// \code
2831 /// class Foo : Base1,
2832 /// Base2
2833 /// {};
2834 /// \endcode
2836 };
2837
2838 /// The inheritance list style to use.
2839 /// \version 7
2841
2842 /// The template declaration breaking style to use.
2843 /// \version 19
2845
2846 /// If `true`, consecutive namespace declarations will be on the same
2847 /// line. If `false`, each namespace is declared on a new line.
2848 /// \code
2849 /// true:
2850 /// namespace Foo { namespace Bar {
2851 /// }}
2852 ///
2853 /// false:
2854 /// namespace Foo {
2855 /// namespace Bar {
2856 /// }
2857 /// }
2858 /// \endcode
2859 ///
2860 /// If it does not fit on a single line, the overflowing namespaces get
2861 /// wrapped:
2862 /// \code
2863 /// namespace Foo { namespace Bar {
2864 /// namespace Extra {
2865 /// }}}
2866 /// \endcode
2867 /// \version 5
2869
2870 /// This option is **deprecated**. See `CurrentLine` of
2871 /// `PackConstructorInitializers`.
2872 /// \version 3.7
2873 // bool ConstructorInitializerAllOnOneLineOrOnePerLine;
2874
2875 /// The number of characters to use for indentation of constructor
2876 /// initializer lists as well as inheritance lists.
2877 /// \version 3.7
2879
2880 /// Indent width for line continuations.
2881 /// \code
2882 /// ContinuationIndentWidth: 2
2883 ///
2884 /// int i = // VeryVeryVeryVeryVeryLongComment
2885 /// longFunction( // Again a long comment
2886 /// arg);
2887 /// \endcode
2888 /// \version 3.7
2890
2891 /// Different ways to handle braced lists.
2893 /// Best suited for pre C++11 braced lists.
2894 ///
2895 /// * Spaces inside the braced list.
2896 /// * Line break before the closing brace.
2897 /// * Indentation with the block indent.
2898 ///
2899 /// \code
2900 /// vector<int> x{ 1, 2, 3, 4 };
2901 /// vector<T> x{ {}, {}, {}, {} };
2902 /// f(MyMap[{ composite, key }]);
2903 /// new int[3]{ 1, 2, 3 };
2904 /// Type name{ // Comment
2905 /// value
2906 /// };
2907 /// \endcode
2909 /// Best suited for C++11 braced lists.
2910 ///
2911 /// * No spaces inside the braced list.
2912 /// * No line break before the closing brace.
2913 /// * Indentation with the continuation indent.
2914 ///
2915 /// Fundamentally, C++11 braced lists are formatted exactly like function
2916 /// calls would be formatted in their place. If the braced list follows a
2917 /// name (e.g. a type or variable name), clang-format formats as if the
2918 /// `{}` were the parentheses of a function call with that name. If there
2919 /// is no name, a zero-length name is assumed.
2920 /// \code
2921 /// vector<int> x{1, 2, 3, 4};
2922 /// vector<T> x{{}, {}, {}, {}};
2923 /// f(MyMap[{composite, key}]);
2924 /// new int[3]{1, 2, 3};
2925 /// Type name{ // Comment
2926 /// value};
2927 /// \endcode
2929 /// Same as `FunctionCall`, except for the handling of a comment at the
2930 /// begin, it then aligns everything following with the comment.
2931 ///
2932 /// * No spaces inside the braced list. (Even for a comment at the first
2933 /// position.)
2934 /// * No line break before the closing brace.
2935 /// * Indentation with the continuation indent, except when followed by a
2936 /// line comment, then it uses the block indent.
2937 ///
2938 /// \code
2939 /// vector<int> x{1, 2, 3, 4};
2940 /// vector<T> x{{}, {}, {}, {}};
2941 /// f(MyMap[{composite, key}]);
2942 /// new int[3]{1, 2, 3};
2943 /// Type name{// Comment
2944 /// value};
2945 /// \endcode
2947 };
2948
2949 /// The style to handle braced lists.
2950 /// \version 3.4
2952
2953 /// This option is **deprecated**. See `DeriveLF` and `DeriveCRLF` of
2954 /// `LineEnding`.
2955 /// \version 10
2956 // bool DeriveLineEnding;
2957
2958 /// If `true`, analyze the formatted file for the most common
2959 /// alignment of `&` and `*`.
2960 /// Pointer and reference alignment styles are going to be updated according
2961 /// to the preferences found in the file.
2962 /// `PointerAlignment` is then used only as fallback.
2963 /// \version 3.7
2965
2966 /// Disables formatting completely.
2967 /// \version 3.7
2969
2970 /// Different styles for empty line after access modifiers.
2971 /// `EmptyLineBeforeAccessModifier` configuration handles the number of
2972 /// empty lines between two access modifiers.
2974 /// Remove all empty lines after access modifiers.
2975 /// \code
2976 /// struct foo {
2977 /// private:
2978 /// int i;
2979 /// protected:
2980 /// int j;
2981 /// /* comment */
2982 /// public:
2983 /// foo() {}
2984 /// private:
2985 /// protected:
2986 /// };
2987 /// \endcode
2989 /// Keep existing empty lines after access modifiers.
2990 /// MaxEmptyLinesToKeep is applied instead.
2992 /// Always add empty line after access modifiers if there are none.
2993 /// MaxEmptyLinesToKeep is applied also.
2994 /// \code
2995 /// struct foo {
2996 /// private:
2997 ///
2998 /// int i;
2999 /// protected:
3000 ///
3001 /// int j;
3002 /// /* comment */
3003 /// public:
3004 ///
3005 /// foo() {}
3006 /// private:
3007 ///
3008 /// protected:
3009 ///
3010 /// };
3011 /// \endcode
3013 };
3014
3015 /// Defines when to put an empty line after access modifiers.
3016 /// `EmptyLineBeforeAccessModifier` configuration handles the number of
3017 /// empty lines between two access modifiers.
3018 /// \version 13
3020
3021 /// Different styles for empty line before access modifiers.
3023 /// Remove all empty lines before access modifiers.
3024 /// \code
3025 /// struct foo {
3026 /// private:
3027 /// int i;
3028 /// protected:
3029 /// int j;
3030 /// /* comment */
3031 /// public:
3032 /// foo() {}
3033 /// private:
3034 /// protected:
3035 /// };
3036 /// \endcode
3038 /// Keep existing empty lines before access modifiers.
3040 /// Add empty line only when access modifier starts a new logical block.
3041 /// Logical block is a group of one or more member fields or functions.
3042 /// \code
3043 /// struct foo {
3044 /// private:
3045 /// int i;
3046 ///
3047 /// protected:
3048 /// int j;
3049 /// /* comment */
3050 /// public:
3051 /// foo() {}
3052 ///
3053 /// private:
3054 /// protected:
3055 /// };
3056 /// \endcode
3058 /// Always add empty line before access modifiers unless access modifier
3059 /// is at the start of struct or class definition.
3060 /// \code
3061 /// struct foo {
3062 /// private:
3063 /// int i;
3064 ///
3065 /// protected:
3066 /// int j;
3067 /// /* comment */
3068 ///
3069 /// public:
3070 /// foo() {}
3071 ///
3072 /// private:
3073 ///
3074 /// protected:
3075 /// };
3076 /// \endcode
3078 };
3079
3080 /// Defines in which cases to put empty line before access modifiers.
3081 /// \version 12
3083
3084 /// Styles for `enum` trailing commas.
3086 /// Don't insert or remove trailing commas.
3087 /// \code
3088 /// enum { a, b, c, };
3089 /// enum Color { red, green, blue };
3090 /// \endcode
3092 /// Insert trailing commas.
3093 /// \code
3094 /// enum { a, b, c, };
3095 /// enum Color { red, green, blue, };
3096 /// \endcode
3098 /// Remove trailing commas.
3099 /// \code
3100 /// enum { a, b, c };
3101 /// enum Color { red, green, blue };
3102 /// \endcode
3104 };
3105
3106 /// Insert a comma (if missing) or remove the comma at the end of an `enum`
3107 /// enumerator list.
3108 /// \warning
3109 /// Setting this option to any value other than `Leave` could lead to
3110 /// incorrect code formatting due to clang-format's lack of complete semantic
3111 /// information. As such, extra care should be taken to review code changes
3112 /// made by this option.
3113 /// \endwarning
3114 /// \version 21
3116
3117 /// If `true`, clang-format detects whether function calls and
3118 /// definitions are formatted with one parameter per line.
3119 ///
3120 /// Each call can be bin-packed, one-per-line or inconclusive. If it is
3121 /// inconclusive, e.g. completely on one line, but a decision needs to be
3122 /// made, clang-format analyzes whether there are other bin-packed cases in
3123 /// the input file and act accordingly.
3124 ///
3125 /// \note
3126 /// This is an experimental flag, that might go away or be renamed. Do
3127 /// not use this in config files, etc. Use at your own risk.
3128 /// \endnote
3129 /// \version 3.7
3131
3132 /// If `true`, clang-format adds missing namespace end comments for
3133 /// namespaces and fixes invalid existing ones. This doesn't affect short
3134 /// namespaces, which are controlled by `ShortNamespaceLines`.
3135 /// \code
3136 /// true: false:
3137 /// namespace longNamespace { vs. namespace longNamespace {
3138 /// void foo(); void foo();
3139 /// void bar(); void bar();
3140 /// } // namespace a }
3141 /// namespace shortNamespace { namespace shortNamespace {
3142 /// void baz(); void baz();
3143 /// } }
3144 /// \endcode
3145 /// \version 5
3147
3148 /// A vector of macros that should be interpreted as foreach loops
3149 /// instead of as function calls.
3150 ///
3151 /// These are expected to be macros of the form:
3152 /// \code
3153 /// FOREACH(<variable-declaration>, ...)
3154 /// <loop-body>
3155 /// \endcode
3156 ///
3157 /// In the .clang-format configuration file, this can be configured like:
3158 /// \code{.yaml}
3159 /// ForEachMacros: [RANGES_FOR, FOREACH]
3160 /// \endcode
3161 ///
3162 /// For example: BOOST_FOREACH.
3163 /// \version 3.7
3164 std::vector<std::string> ForEachMacros;
3165
3167
3168 /// A vector of macros that should be interpreted as conditionals
3169 /// instead of as function calls.
3170 ///
3171 /// These are expected to be macros of the form:
3172 /// \code
3173 /// IF(...)
3174 /// <conditional-body>
3175 /// else IF(...)
3176 /// <conditional-body>
3177 /// \endcode
3178 ///
3179 /// In the .clang-format configuration file, this can be configured like:
3180 /// \code{.yaml}
3181 /// IfMacros: [IF]
3182 /// \endcode
3183 ///
3184 /// For example:
3185 /// [KJ_IF_MAYBE](https://github.com/capnproto/capnproto/blob/master/kjdoc/tour.md#maybes)
3186 /// \version 13
3187 std::vector<std::string> IfMacros;
3188
3189 /// Specify whether access modifiers should have their own indentation level.
3190 ///
3191 /// When `false`, access modifiers are indented (or outdented) relative to
3192 /// the record members, respecting the `AccessModifierOffset`. Record
3193 /// members are indented one level below the record.
3194 /// When `true`, access modifiers get their own indentation level. As a
3195 /// consequence, record members are always indented 2 levels below the record,
3196 /// regardless of the access modifier presence. Value of the
3197 /// `AccessModifierOffset` is ignored.
3198 /// \code
3199 /// false: true:
3200 /// class C { vs. class C {
3201 /// class D { class D {
3202 /// void bar(); void bar();
3203 /// protected: protected:
3204 /// D(); D();
3205 /// }; };
3206 /// public: public:
3207 /// C(); C();
3208 /// }; };
3209 /// void foo() { void foo() {
3210 /// return 1; return 1;
3211 /// } }
3212 /// \endcode
3213 /// \version 13
3215
3216 /// Indent case label blocks one level from the case label.
3217 ///
3218 /// When `false`, the block following the case label uses the same
3219 /// indentation level as for the case label, treating the case label the same
3220 /// as an if-statement.
3221 /// When `true`, the block gets indented as a scope block.
3222 /// \code
3223 /// false: true:
3224 /// switch (fool) { vs. switch (fool) {
3225 /// case 1: { case 1:
3226 /// bar(); {
3227 /// } break; bar();
3228 /// default: { }
3229 /// plop(); break;
3230 /// } default:
3231 /// } {
3232 /// plop();
3233 /// }
3234 /// }
3235 /// \endcode
3236 /// \version 11
3238
3239 /// Indent case labels one level from the switch statement.
3240 ///
3241 /// When `false`, use the same indentation level as for the switch
3242 /// statement. Switch statement body is always indented one level more than
3243 /// case labels (except the first block following the case label, which
3244 /// itself indents the code - unless IndentCaseBlocks is enabled).
3245 /// \code
3246 /// false: true:
3247 /// switch (fool) { vs. switch (fool) {
3248 /// case 1: case 1:
3249 /// bar(); bar();
3250 /// break; break;
3251 /// default: default:
3252 /// plop(); plop();
3253 /// } }
3254 /// \endcode
3255 /// \version 3.3
3257
3258 /// If `true`, clang-format will indent the body of an `export { ... }`
3259 /// block. This doesn't affect the formatting of anything else related to
3260 /// exported declarations.
3261 /// \code
3262 /// true: false:
3263 /// export { vs. export {
3264 /// void foo(); void foo();
3265 /// void bar(); void bar();
3266 /// } }
3267 /// \endcode
3268 /// \version 20
3270
3271 /// Indents extern blocks
3273 /// Backwards compatible with AfterExternBlock's indenting.
3274 /// \code
3275 /// IndentExternBlock: AfterExternBlock
3276 /// BraceWrapping.AfterExternBlock: true
3277 /// extern "C"
3278 /// {
3279 /// void foo();
3280 /// }
3281 /// \endcode
3282 ///
3283 /// \code
3284 /// IndentExternBlock: AfterExternBlock
3285 /// BraceWrapping.AfterExternBlock: false
3286 /// extern "C" {
3287 /// void foo();
3288 /// }
3289 /// \endcode
3291 /// Does not indent extern blocks.
3292 /// \code
3293 /// extern "C" {
3294 /// void foo();
3295 /// }
3296 /// \endcode
3298 /// Indents extern blocks.
3299 /// \code
3300 /// extern "C" {
3301 /// void foo();
3302 /// }
3303 /// \endcode
3305 };
3306
3307 /// IndentExternBlockStyle is the type of indenting of extern blocks.
3308 /// \version 11
3310
3311 /// Options for indenting goto labels.
3313 /// Do not indent goto labels.
3314 /// \code
3315 /// int f() {
3316 /// if (foo()) {
3317 /// label1:
3318 /// bar();
3319 /// }
3320 /// label2:
3321 /// return 1;
3322 /// }
3323 /// \endcode
3325 /// Indent goto labels to the enclosing block (previous indenting level).
3326 /// \code
3327 /// int f() {
3328 /// if (foo()) {
3329 /// label1:
3330 /// bar();
3331 /// }
3332 /// label2:
3333 /// return 1;
3334 /// }
3335 /// \endcode
3337 /// Indent goto labels to the surrounding statements (current indenting
3338 /// level).
3339 /// \code
3340 /// int f() {
3341 /// if (foo()) {
3342 /// label1:
3343 /// bar();
3344 /// }
3345 /// label2:
3346 /// return 1;
3347 /// }
3348 /// \endcode
3350 /// Indent goto labels to half the indentation of the surrounding code.
3351 /// If the indentation width is an odd number, it will round up.
3352 /// \code
3353 /// int f() {
3354 /// if (foo()) {
3355 /// label1:
3356 /// bar();
3357 /// }
3358 /// label2:
3359 /// return 1;
3360 /// }
3361 /// \endcode
3363 };
3364
3365 /// The goto label indenting style to use.
3366 /// \version 10
3368
3369 /// Options for indenting preprocessor directives.
3371 /// Does not indent any directives.
3372 /// \code
3373 /// #if FOO
3374 /// #if BAR
3375 /// #include <foo>
3376 /// #endif
3377 /// #endif
3378 /// \endcode
3380 /// Indents directives after the hash.
3381 /// \code
3382 /// #if FOO
3383 /// # if BAR
3384 /// # include <foo>
3385 /// # endif
3386 /// #endif
3387 /// \endcode
3389 /// Indents directives before the hash.
3390 /// \code
3391 /// #if FOO
3392 /// #if BAR
3393 /// #include <foo>
3394 /// #endif
3395 /// #endif
3396 /// \endcode
3398 /// Leaves indentation of directives as-is.
3399 /// \note
3400 /// Ignores `PPIndentWidth`.
3401 /// \endnote
3402 /// \code
3403 /// #if FOO
3404 /// #if BAR
3405 /// #include <foo>
3406 /// #endif
3407 /// #endif
3408 /// \endcode
3410 };
3411
3412 /// The preprocessor directive indenting style to use.
3413 /// \version 6
3415
3416 /// Indent the requires clause in a template. This only applies when
3417 /// `RequiresClausePosition` is `OwnLine`, `OwnLineWithBrace`,
3418 /// or `WithFollowing`.
3419 ///
3420 /// In clang-format 12, 13 and 14 it was named `IndentRequires`.
3421 /// \code
3422 /// true:
3423 /// template <typename It>
3424 /// requires Iterator<It>
3425 /// void sort(It begin, It end) {
3426 /// //....
3427 /// }
3428 ///
3429 /// false:
3430 /// template <typename It>
3431 /// requires Iterator<It>
3432 /// void sort(It begin, It end) {
3433 /// //....
3434 /// }
3435 /// \endcode
3436 /// \version 15
3438
3439 /// The number of columns to use for indentation.
3440 /// \code
3441 /// IndentWidth: 3
3442 ///
3443 /// void f() {
3444 /// someFunction();
3445 /// if (true, false) {
3446 /// f();
3447 /// }
3448 /// }
3449 /// \endcode
3450 /// \version 3.7
3451 unsigned IndentWidth;
3452
3453 /// Indent if a function definition or declaration is wrapped after the
3454 /// type.
3455 /// \code
3456 /// true:
3457 /// LoooooooooooooooooooooooooooooooooooooooongReturnType
3458 /// LoooooooooooooooooooooooooooooooongFunctionDeclaration();
3459 ///
3460 /// false:
3461 /// LoooooooooooooooooooooooooooooooooooooooongReturnType
3462 /// LoooooooooooooooooooooooooooooooongFunctionDeclaration();
3463 /// \endcode
3464 /// \version 3.7
3466
3467 /// Insert braces after control statements (`if`, `else`, `for`, `do`,
3468 /// and `while`) in C++ unless the control statements are inside macro
3469 /// definitions or the braces would enclose preprocessor directives.
3470 /// \warning
3471 /// Setting this option to `true` could lead to incorrect code formatting
3472 /// due to clang-format's lack of complete semantic information. As such,
3473 /// extra care should be taken to review code changes made by this option.
3474 /// \endwarning
3475 /// \code
3476 /// false: true:
3477 ///
3478 /// if (isa<FunctionDecl>(D)) vs. if (isa<FunctionDecl>(D)) {
3479 /// handleFunctionDecl(D); handleFunctionDecl(D);
3480 /// else if (isa<VarDecl>(D)) } else if (isa<VarDecl>(D)) {
3481 /// handleVarDecl(D); handleVarDecl(D);
3482 /// else } else {
3483 /// return; return;
3484 /// }
3485 ///
3486 /// while (i--) vs. while (i--) {
3487 /// for (auto *A : D.attrs()) for (auto *A : D.attrs()) {
3488 /// handleAttr(A); handleAttr(A);
3489 /// }
3490 /// }
3491 ///
3492 /// do vs. do {
3493 /// --i; --i;
3494 /// while (i); } while (i);
3495 /// \endcode
3496 /// \version 15
3498
3499 /// Insert a newline at end of file if missing.
3500 /// \version 16
3502
3503 /// The style of inserting trailing commas into container literals.
3505 /// Do not insert trailing commas.
3507 /// Insert trailing commas in container literals that were wrapped over
3508 /// multiple lines. Note that this is conceptually incompatible with
3509 /// bin-packing, because the trailing comma is used as an indicator
3510 /// that a container should be formatted one-per-line (i.e. not bin-packed).
3511 /// So inserting a trailing comma counteracts bin-packing.
3513 };
3514
3515 /// If set to `TCS_Wrapped` will insert trailing commas in container
3516 /// literals (arrays and objects) that wrap across multiple lines.
3517 /// It is currently only available for JavaScript
3518 /// and disabled by default `TCS_None`.
3519 /// `InsertTrailingCommas` cannot be used together with `BinPackArguments`
3520 /// as inserting the comma disables bin-packing.
3521 /// \code
3522 /// TSC_Wrapped:
3523 /// const someArray = [
3524 /// aaaaaaaaaaaaaaaaaaaaaaaaaa,
3525 /// aaaaaaaaaaaaaaaaaaaaaaaaaa,
3526 /// aaaaaaaaaaaaaaaaaaaaaaaaaa,
3527 /// // ^ inserted
3528 /// ]
3529 /// \endcode
3530 /// \version 11
3532
3533 /// Separator format of integer literals of different bases.
3534 ///
3535 /// If negative, remove separators. If `0`, leave the literal as is. If
3536 /// positive, insert separators between digits starting from the rightmost
3537 /// digit.
3538 ///
3539 /// For example, the config below will leave separators in binary literals
3540 /// alone, insert separators in decimal literals to separate the digits into
3541 /// groups of 3, and remove separators in hexadecimal literals.
3542 /// \code
3543 /// IntegerLiteralSeparator:
3544 /// Binary: 0
3545 /// Decimal: 3
3546 /// Hex: -1
3547 /// \endcode
3548 ///
3549 /// You can also specify a minimum number of digits
3550 /// (`BinaryMinDigitsInsert`, `DecimalMinDigitsInsert`, and
3551 /// `HexMinDigitsInsert`) the integer literal must have in order for the
3552 /// separators to be inserted, and a maximum number of digits
3553 /// (`BinaryMaxDigitsRemove`, `DecimalMaxDigitsRemove`, and
3554 /// `HexMaxDigitsRemove`) until the separators are removed. This divides the
3555 /// literals in 3 regions, always without separator (up until including
3556 /// `xxxMaxDigitsRemove`), maybe with, or without separators (up until
3557 /// excluding `xxxMinDigitsInsert`), and finally always with separators.
3558 /// \note
3559 /// `BinaryMinDigits`, `DecimalMinDigits`, and `HexMinDigits` are
3560 /// deprecated and renamed to `BinaryMinDigitsInsert`,
3561 /// `DecimalMinDigitsInsert`, and `HexMinDigitsInsert`, respectively.
3562 /// \endnote
3564 /// Format separators in binary literals.
3565 /// \code{.text}
3566 /// /* -1: */ b = 0b100111101101;
3567 /// /* 0: */ b = 0b10011'11'0110'1;
3568 /// /* 3: */ b = 0b100'111'101'101;
3569 /// /* 4: */ b = 0b1001'1110'1101;
3570 /// \endcode
3572 /// Format separators in binary literals with a minimum number of digits.
3573 /// \code{.text}
3574 /// // Binary: 3
3575 /// // BinaryMinDigitsInsert: 7
3576 /// b1 = 0b101101;
3577 /// b2 = 0b1'101'101;
3578 /// \endcode
3580 /// Remove separators in binary literals with a maximum number of digits.
3581 /// \code{.text}
3582 /// // Binary: 3
3583 /// // BinaryMinDigitsInsert: 7
3584 /// // BinaryMaxDigitsRemove: 4
3585 /// b0 = 0b1011; // Always removed.
3586 /// b1 = 0b101101; // Not added.
3587 /// b2 = 0b1'01'101; // Not removed, not corrected.
3588 /// b3 = 0b1'101'101; // Always added.
3589 /// b4 = 0b10'1101; // Corrected to 0b101'101.
3590 /// \endcode
3592 /// Format separators in decimal literals.
3593 /// \code{.text}
3594 /// /* -1: */ d = 18446744073709550592ull;
3595 /// /* 0: */ d = 184467'440737'0'95505'92ull;
3596 /// /* 3: */ d = 18'446'744'073'709'550'592ull;
3597 /// \endcode
3599 /// Format separators in decimal literals with a minimum number of digits.
3600 /// \code{.text}
3601 /// // Decimal: 3
3602 /// // DecimalMinDigitsInsert: 5
3603 /// d1 = 2023;
3604 /// d2 = 10'000;
3605 /// \endcode
3607 /// Remove separators in decimal literals with a maximum number of digits.
3608 /// \code{.text}
3609 /// // Decimal: 3
3610 /// // DecimalMinDigitsInsert: 7
3611 /// // DecimalMaxDigitsRemove: 4
3612 /// d0 = 2023; // Always removed.
3613 /// d1 = 123456; // Not added.
3614 /// d2 = 1'23'456; // Not removed, not corrected.
3615 /// d3 = 5'000'000; // Always added.
3616 /// d4 = 1'23'45; // Corrected to 12'345.
3617 /// \endcode
3619 /// Format separators in hexadecimal literals.
3620 /// \code{.text}
3621 /// /* -1: */ h = 0xDEADBEEFDEADBEEFuz;
3622 /// /* 0: */ h = 0xDEAD'BEEF'DE'AD'BEE'Fuz;
3623 /// /* 2: */ h = 0xDE'AD'BE'EF'DE'AD'BE'EFuz;
3624 /// \endcode
3626 /// Format separators in hexadecimal literals with a minimum number of
3627 /// digits.
3628 /// \code{.text}
3629 /// // Hex: 2
3630 /// // HexMinDigitsInsert: 6
3631 /// h1 = 0xABCDE;
3632 /// h2 = 0xAB'CD'EF;
3633 /// \endcode
3635 /// Remove separators in hexadecimal literals with a maximum number of
3636 /// digits.
3637 /// \code{.text}
3638 /// // Hex: 2
3639 /// // HexMinDigitsInsert: 6
3640 /// // HexMaxDigitsRemove: 4
3641 /// h0 = 0xAFFE; // Always removed.
3642 /// h1 = 0xABCDE; // Not added.
3643 /// h2 = 0xABC'DE; // Not removed, not corrected.
3644 /// h3 = 0xAB'CD'EF; // Always added.
3645 /// h4 = 0xABCD'E; // Corrected to 0xA'BC'DE.
3646 /// \endcode
3649 return Binary == R.Binary &&
3650 BinaryMinDigitsInsert == R.BinaryMinDigitsInsert &&
3651 BinaryMaxDigitsRemove == R.BinaryMaxDigitsRemove &&
3652 Decimal == R.Decimal &&
3653 DecimalMinDigitsInsert == R.DecimalMinDigitsInsert &&
3654 DecimalMaxDigitsRemove == R.DecimalMaxDigitsRemove &&
3655 Hex == R.Hex && HexMinDigitsInsert == R.HexMinDigitsInsert &&
3656 HexMaxDigitsRemove == R.HexMaxDigitsRemove;
3657 }
3659 return !operator==(R);
3660 }
3661 };
3662
3663 /// Format integer literal separators (`'` for C/C++ and `_` for C#, Java,
3664 /// and JavaScript).
3665 /// \version 16
3667
3668 /// A vector of prefixes ordered by the desired groups for Java imports.
3669 ///
3670 /// One group's prefix can be a subset of another - the longest prefix is
3671 /// always matched. Within a group, the imports are ordered lexicographically.
3672 /// Static imports are grouped separately and follow the same group rules.
3673 /// By default, static imports are placed before non-static imports,
3674 /// but this behavior is changed by another option,
3675 /// `SortJavaStaticImport`.
3676 ///
3677 /// In the .clang-format configuration file, this can be configured like
3678 /// in the following yaml example. This will result in imports being
3679 /// formatted as in the Java example below.
3680 /// \code{.yaml}
3681 /// JavaImportGroups: [com.example, com, org]
3682 /// \endcode
3683 ///
3684 /// \code{.java}
3685 /// import static com.example.function1;
3686 ///
3687 /// import static com.test.function2;
3688 ///
3689 /// import static org.example.function3;
3690 ///
3691 /// import com.example.ClassA;
3692 /// import com.example.Test;
3693 /// import com.example.a.ClassB;
3694 ///
3695 /// import com.test.ClassC;
3696 ///
3697 /// import org.example.ClassD;
3698 /// \endcode
3699 /// \version 8
3700 std::vector<std::string> JavaImportGroups;
3701
3702 /// Quotation styles for JavaScript strings. Does not affect template
3703 /// strings.
3705 /// Leave string quotes as they are.
3706 /// \code{.js}
3707 /// string1 = "foo";
3708 /// string2 = 'bar';
3709 /// \endcode
3711 /// Always use single quotes.
3712 /// \code{.js}
3713 /// string1 = 'foo';
3714 /// string2 = 'bar';
3715 /// \endcode
3717 /// Always use double quotes.
3718 /// \code{.js}
3719 /// string1 = "foo";
3720 /// string2 = "bar";
3721 /// \endcode
3723 };
3724
3725 /// The JavaScriptQuoteStyle to use for JavaScript strings.
3726 /// \version 3.9
3728
3729 // clang-format off
3730 /// Whether to wrap JavaScript import/export statements.
3731 /// \code{.js}
3732 /// true:
3733 /// import {
3734 /// VeryLongImportsAreAnnoying,
3735 /// VeryLongImportsAreAnnoying,
3736 /// VeryLongImportsAreAnnoying,
3737 /// } from "some/module.js"
3738 ///
3739 /// false:
3740 /// import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js"
3741 /// \endcode
3742 /// \version 3.9
3744 // clang-format on
3745
3746 /// Options regarding which empty lines are kept.
3747 ///
3748 /// For example, the config below will remove empty lines at start of the
3749 /// file, end of the file, and start of blocks.
3750 ///
3751 /// \code
3752 /// KeepEmptyLines:
3753 /// AtEndOfFile: false
3754 /// AtStartOfBlock: false
3755 /// AtStartOfFile: false
3756 /// \endcode
3758 /// Keep empty lines at end of file.
3760 /// Keep empty lines at start of a block.
3761 /// \code
3762 /// true: false:
3763 /// if (foo) { vs. if (foo) {
3764 /// bar();
3765 /// bar(); }
3766 /// }
3767 /// \endcode
3769 /// Keep empty lines at start of file.
3771 bool operator==(const KeepEmptyLinesStyle &R) const {
3772 return AtEndOfFile == R.AtEndOfFile &&
3773 AtStartOfBlock == R.AtStartOfBlock &&
3774 AtStartOfFile == R.AtStartOfFile;
3775 }
3776 };
3777 /// Which empty lines are kept. See `MaxEmptyLinesToKeep` for how many
3778 /// consecutive empty lines are kept.
3779 /// \version 19
3781
3782 /// This option is **deprecated**. See `AtEndOfFile` of `KeepEmptyLines`.
3783 /// \version 17
3784 // bool KeepEmptyLinesAtEOF;
3785
3786 /// This option is **deprecated**. See `AtStartOfBlock` of
3787 /// `KeepEmptyLines`.
3788 /// \version 3.7
3789 // bool KeepEmptyLinesAtTheStartOfBlocks;
3790
3791 /// Keep the form feed character if it's immediately preceded and followed by
3792 /// a newline. Multiple form feeds and newlines within a whitespace range are
3793 /// replaced with a single newline and form feed followed by the remaining
3794 /// newlines. (See
3795 /// www.gnu.org/prep/standards/html_node/Formatting.html#:~:text=formfeed.)
3796 /// \version 20
3798
3799 /// Indentation logic for lambda bodies.
3801 /// Align lambda body relative to the lambda signature. This is the default.
3802 /// \code
3803 /// someMethod(
3804 /// [](SomeReallyLongLambdaSignatureArgument foo) {
3805 /// return;
3806 /// });
3807 /// \endcode
3809 /// For statements within block scope, align lambda body relative to the
3810 /// indentation level of the outer scope the lambda signature resides in.
3811 /// \code
3812 /// someMethod(
3813 /// [](SomeReallyLongLambdaSignatureArgument foo) {
3814 /// return;
3815 /// });
3816 ///
3817 /// someMethod(someOtherMethod(
3818 /// [](SomeReallyLongLambdaSignatureArgument foo) {
3819 /// return;
3820 /// }));
3821 /// \endcode
3823 };
3824
3825 /// The indentation style of lambda bodies. `Signature` (the default)
3826 /// causes the lambda body to be indented one additional level relative to
3827 /// the indentation level of the signature. `OuterScope` forces the lambda
3828 /// body to be indented one additional level relative to the parent scope
3829 /// containing the lambda signature.
3830 /// \version 13
3832
3833 /// Supported languages.
3834 ///
3835 /// When stored in a configuration file, specifies the language, that the
3836 /// configuration targets. When passed to the `reformat()` function, enables
3837 /// syntax features specific to the language.
3839 /// Do not use.
3841 /// Should be used for C.
3843 /// Should be used for C++.
3845 /// Should be used for C#.
3847 /// Should be used for Java.
3849 /// Should be used for JavaScript.
3851 /// Should be used for JSON.
3853 /// Should be used for Objective-C, Objective-C++.
3855 /// Should be used for [Protocol Buffers](https://protobuf.dev/)
3857 /// Should be used for TableGen code.
3859 /// Should be used for [Protocol Buffer](https://protobuf.dev/) messages in
3860 /// text format
3862 /// Should be used for Verilog and SystemVerilog.
3863 /// https://standards.ieee.org/ieee/1800/6700/
3864 /// https://sci-hub.st/10.1109/IEEESTD.2018.8299595
3866 };
3867 bool isCpp() const {
3868 return Language == LK_Cpp || Language == LK_C || Language == LK_ObjC;
3869 }
3870 bool isCSharp() const { return Language == LK_CSharp; }
3871 bool isJson() const { return Language == LK_Json; }
3872 bool isJava() const { return Language == LK_Java; }
3873 bool isJavaScript() const { return Language == LK_JavaScript; }
3874 bool isVerilog() const { return Language == LK_Verilog; }
3875 bool isTextProto() const { return Language == LK_TextProto; }
3876 bool isProto() const { return Language == LK_Proto || isTextProto(); }
3877 bool isTableGen() const { return Language == LK_TableGen; }
3878
3879 /// The language that this format style targets.
3880 /// \note
3881 /// You can specify the language (`C`, `Cpp`, or `ObjC`) for `.h`
3882 /// files by adding a `// clang-format Language:` line before the first
3883 /// non-comment (and non-empty) line, e.g. `// clang-format Language: Cpp`.
3884 /// \endnote
3885 /// \version 3.5
3887
3888 /// Line ending style.
3890 /// Use `\n`.
3892 /// Use `\r\n`.
3894 /// Use `\n` unless the input has more lines ending in `\r\n`.
3896 /// Use `\r\n` unless the input has more lines ending in `\n`.
3898 };
3899
3900 /// Line ending style (`\n` or `\r\n`) to use.
3901 /// \version 16
3903
3904 /// A regular expression matching macros that start a block.
3905 /// \code
3906 /// # With:
3907 /// MacroBlockBegin: "^NS_MAP_BEGIN|\
3908 /// NS_TABLE_HEAD$"
3909 /// MacroBlockEnd: "^\
3910 /// NS_MAP_END|\
3911 /// NS_TABLE_.*_END$"
3912 ///
3913 /// NS_MAP_BEGIN
3914 /// foo();
3915 /// NS_MAP_END
3916 ///
3917 /// NS_TABLE_HEAD
3918 /// bar();
3919 /// NS_TABLE_FOO_END
3920 ///
3921 /// # Without:
3922 /// NS_MAP_BEGIN
3923 /// foo();
3924 /// NS_MAP_END
3925 ///
3926 /// NS_TABLE_HEAD
3927 /// bar();
3928 /// NS_TABLE_FOO_END
3929 /// \endcode
3930 /// \version 3.7
3931 std::string MacroBlockBegin;
3932
3933 /// A regular expression matching macros that end a block.
3934 /// \version 3.7
3935 std::string MacroBlockEnd;
3936
3937 /// A list of macros of the form \c <definition>=<expansion> .
3938 ///
3939 /// Code will be parsed with macros expanded, in order to determine how to
3940 /// interpret and format the macro arguments.
3941 ///
3942 /// For example, the code:
3943 /// \code
3944 /// A(a*b);
3945 /// \endcode
3946 ///
3947 /// will usually be interpreted as a call to a function A, and the
3948 /// multiplication expression will be formatted as `a * b`.
3949 ///
3950 /// If we specify the macro definition:
3951 /// \code{.yaml}
3952 /// Macros:
3953 /// - A(x)=x
3954 /// \endcode
3955 ///
3956 /// the code will now be parsed as a declaration of the variable b of type a*,
3957 /// and formatted as `a* b` (depending on pointer-binding rules).
3958 ///
3959 /// Features and restrictions:
3960 ///
3961 /// - Both function-like macros and object-like macros are supported.
3962 /// - Macro arguments must be used exactly once in the expansion.
3963 /// - No recursive expansion; macros referencing other macros will be
3964 /// ignored.
3965 /// - Overloading by arity is supported: for example, given the macro
3966 /// definitions A=x, A()=y, A(a)=a
3967 ///
3968 /// \code
3969 /// A; -> x;
3970 /// A(); -> y;
3971 /// A(z); -> z;
3972 /// A(a, b); // will not be expanded.
3973 /// \endcode
3974 ///
3975 /// \version 17
3976 std::vector<std::string> Macros;
3978 /// A vector of function-like macros whose invocations should be skipped by
3979 /// `RemoveParentheses`.
3980 /// \version 21
3981 std::vector<std::string> MacrosSkippedByRemoveParentheses;
3982
3983 /// The maximum number of consecutive empty lines to keep.
3984 /// \code
3985 /// MaxEmptyLinesToKeep: 1 vs. MaxEmptyLinesToKeep: 0
3986 /// int f() { int f() {
3987 /// int = 1; int i = 1;
3988 /// i = foo();
3989 /// i = foo(); return i;
3990 /// }
3991 /// return i;
3992 /// }
3993 /// \endcode
3994 /// \version 3.7
3995 unsigned MaxEmptyLinesToKeep;
3996
3997 /// Different ways to indent namespace contents.
3999 /// Don't indent in namespaces.
4000 /// \code
4001 /// namespace out {
4002 /// int i;
4003 /// namespace in {
4004 /// int i;
4005 /// }
4006 /// }
4007 /// \endcode
4008 NI_None,
4009 /// Indent only in inner namespaces (nested in other namespaces).
4010 /// \code
4011 /// namespace out {
4012 /// int i;
4013 /// namespace in {
4014 /// int i;
4015 /// }
4016 /// }
4017 /// \endcode
4018 NI_Inner,
4019 /// Indent in all namespaces.
4020 /// \code
4021 /// namespace out {
4022 /// int i;
4023 /// namespace in {
4024 /// int i;
4025 /// }
4026 /// }
4027 /// \endcode
4028 NI_All
4030
4031 /// The indentation used for namespaces.
4032 /// \version 3.7
4033 NamespaceIndentationKind NamespaceIndentation;
4034
4035 /// A vector of macros which are used to open namespace blocks.
4036 ///
4037 /// These are expected to be macros of the form:
4038 /// \code
4039 /// NAMESPACE(<namespace-name>, ...) {
4040 /// <namespace-content>
4041 /// }
4042 /// \endcode
4043 ///
4044 /// For example: TESTSUITE
4045 /// \version 9
4046 std::vector<std::string> NamespaceMacros;
4048 /// Control over each component in a numeric literal.
4050 /// Leave this component of the literal as is.
4052 /// Format this component with uppercase characters.
4053 NLCS_Upper,
4054 /// Format this component with lowercase characters.
4055 NLCS_Lower,
4056 };
4057
4058 /// Separate control for each numeric literal component.
4059 ///
4060 /// For example, the config below will leave exponent letters alone, reformat
4061 /// hexadecimal digits in lowercase, reformat numeric literal prefixes in
4062 /// uppercase, and reformat suffixes in lowercase.
4063 /// \code
4064 /// NumericLiteralCase:
4065 /// ExponentLetter: Leave
4066 /// HexDigit: Lower
4067 /// Prefix: Upper
4068 /// Suffix: Lower
4069 /// \endcode
4071 /// Format floating point exponent separator letter case.
4072 /// \code
4073 /// float a = 6.02e23 + 1.0E10; // Leave
4074 /// float a = 6.02E23 + 1.0E10; // Upper
4075 /// float a = 6.02e23 + 1.0e10; // Lower
4076 /// \endcode
4078 /// Format hexadecimal digit case.
4079 /// \code
4080 /// a = 0xaBcDeF; // Leave
4081 /// a = 0xABCDEF; // Upper
4082 /// a = 0xabcdef; // Lower
4083 /// \endcode
4085 /// Format integer prefix case.
4086 /// \code
4087 /// a = 0XF0 | 0b1; // Leave
4088 /// a = 0XF0 | 0B1; // Upper
4089 /// a = 0xF0 | 0b1; // Lower
4090 /// \endcode
4092 /// Format suffix case. This option excludes case-sensitive reserved
4093 /// suffixes, such as `min` in C++.
4094 /// \code
4095 /// a = 1uLL; // Leave
4096 /// a = 1ULL; // Upper
4097 /// a = 1ull; // Lower
4098 /// \endcode
4100
4101 bool operator==(const NumericLiteralCaseStyle &R) const {
4102 return ExponentLetter == R.ExponentLetter && HexDigit == R.HexDigit &&
4103 Prefix == R.Prefix && Suffix == R.Suffix;
4104 }
4105
4106 bool operator!=(const NumericLiteralCaseStyle &R) const {
4107 return !(*this == R);
4108 }
4110
4111 /// Capitalization style for numeric literals.
4112 /// \version 22
4113 NumericLiteralCaseStyle NumericLiteralCase;
4114
4115 /// Controls bin-packing Objective-C protocol conformance list
4116 /// items into as few lines as possible when they go over `ColumnLimit`.
4117 ///
4118 /// If `Auto` (the default), delegates to the value in
4119 /// `BinPackParameters`. If that is `BinPack`, bin-packs Objective-C
4120 /// protocol conformance list items into as few lines as possible
4121 /// whenever they go over `ColumnLimit`.
4122 ///
4123 /// If `Always`, always bin-packs Objective-C protocol conformance
4124 /// list items into as few lines as possible whenever they go over
4125 /// `ColumnLimit`.
4126 ///
4127 /// If `Never`, lays out Objective-C protocol conformance list items
4128 /// onto individual lines whenever they go over `ColumnLimit`.
4129 ///
4130 /// \code{.objc}
4131 /// Always (or Auto, if BinPackParameters==BinPack):
4132 /// @interface ccccccccccccc () <
4133 /// ccccccccccccc, ccccccccccccc,
4134 /// ccccccccccccc, ccccccccccccc> {
4135 /// }
4136 ///
4137 /// Never (or Auto, if BinPackParameters!=BinPack):
4138 /// @interface ddddddddddddd () <
4139 /// ddddddddddddd,
4140 /// ddddddddddddd,
4141 /// ddddddddddddd,
4142 /// ddddddddddddd> {
4143 /// }
4144 /// \endcode
4145 /// \version 7
4147
4148 /// The number of characters to use for indentation of ObjC blocks.
4149 /// \code{.objc}
4150 /// ObjCBlockIndentWidth: 4
4151 ///
4152 /// [operation setCompletionBlock:^{
4153 /// [self onOperationDone];
4154 /// }];
4155 /// \endcode
4156 /// \version 3.7
4157 unsigned ObjCBlockIndentWidth;
4158
4159 /// Break parameters list into lines when there is nested block
4160 /// parameters in a function call.
4161 /// \code
4162 /// false:
4163 /// - (void)_aMethod
4164 /// {
4165 /// [self.test1 t:self w:self callback:^(typeof(self) self, NSNumber
4166 /// *u, NSNumber *v) {
4167 /// u = c;
4168 /// }]
4169 /// }
4170 /// true:
4171 /// - (void)_aMethod
4172 /// {
4173 /// [self.test1 t:self
4174 /// w:self
4175 /// callback:^(typeof(self) self, NSNumber *u, NSNumber *v) {
4176 /// u = c;
4177 /// }]
4178 /// }
4179 /// \endcode
4180 /// \version 11
4182
4183 /// The order in which ObjC property attributes should appear.
4184 ///
4185 /// Attributes in code will be sorted in the order specified. Any attributes
4186 /// encountered that are not mentioned in this array will be sorted last, in
4187 /// stable order. Comments between attributes will leave the attributes
4188 /// untouched.
4189 /// \warning
4190 /// Using this option could lead to incorrect code formatting due to
4191 /// clang-format's lack of complete semantic information. As such, extra
4192 /// care should be taken to review code changes made by this option.
4193 /// \endwarning
4194 /// \code{.yaml}
4195 /// ObjCPropertyAttributeOrder: [
4196 /// class, direct,
4197 /// atomic, nonatomic,
4198 /// assign, retain, strong, copy, weak, unsafe_unretained,
4199 /// readonly, readwrite, getter, setter,
4200 /// nullable, nonnull, null_resettable, null_unspecified
4201 /// ]
4202 /// \endcode
4203 /// \version 18
4204 std::vector<std::string> ObjCPropertyAttributeOrder;
4205
4206 /// Add or remove a space between the '-'/'+' and the return type in
4207 /// Objective-C method declarations. i.e
4208 /// \code{.objc}
4209 /// false: true:
4210 ///
4211 /// -(void)method vs. - (void)method
4212 /// \endcode
4213 /// \version 23
4216 /// Add a space after `@property` in Objective-C, i.e. use
4217 /// `@property (readonly)` instead of `@property(readonly)`.
4218 /// \version 3.7
4221 /// Add a space in front of an Objective-C protocol list, i.e. use
4222 /// `Foo <Protocol>` instead of `Foo<Protocol>`.
4223 /// \version 3.7
4225
4226 /// A regular expression that describes markers for turning formatting off for
4227 /// one line. If it matches a comment that is the only token of a line,
4228 /// clang-format skips the comment and the next line. Otherwise, clang-format
4229 /// skips lines containing a matched token.
4230 /// \note
4231 /// This option does not apply to `IntegerLiteralSeparator` and
4232 /// `NumericLiteralCase`.
4233 /// \endnote
4234 /// \code
4235 /// // OneLineFormatOffRegex: ^(// NOLINT|logger$)
4236 /// // results in the output below:
4237 /// int a;
4238 /// int b ; // NOLINT
4239 /// int c;
4240 /// // NOLINTNEXTLINE
4241 /// int d ;
4242 /// int e;
4243 /// s = "// NOLINT";
4244 /// logger() ;
4245 /// logger2();
4246 /// my_logger();
4247 /// \endcode
4248 /// \version 21
4249 std::string OneLineFormatOffRegex;
4250
4251 /// Different ways to try to fit all arguments on a line.
4253 /// Bin-pack arguments.
4254 /// \code
4255 /// void f() {
4256 /// f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa,
4257 /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
4258 /// }
4259 /// \endcode
4261 /// Put all arguments on the current line if they fit.
4262 /// Otherwise, put each one on its own line.
4263 /// \code
4264 /// void f() {
4265 /// f(aaaaaaaaaaaaaaaaaaaa,
4266 /// aaaaaaaaaaaaaaaaaaaa,
4267 /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
4268 /// }
4269 /// \endcode
4271 /// Use the `BreakAfter` option to handle argument packing instead.
4272 /// If the `BreakAfter` limit is not exceeded, behave like `BinPack`.
4274 };
4275
4276 /// Options related to packing arguments of function calls.
4278
4279 /// The bin pack arguments style to use.
4280 /// \version 3.7
4282
4283 /// An argument list with more arguments than the specified number will be
4284 /// formatted with one argument per line. This option must be used with
4285 /// `BinPack: UseBreakAfter`.
4286 /// \code
4287 /// PackArguments:
4288 /// BinPack: UseBreakAfter
4289 /// BreakAfter: 3
4290 ///
4291 /// void f() {
4292 /// foo(1);
4293 ///
4294 /// bar(1, 2, 3);
4295 ///
4296 /// baz(1,
4297 /// 2,
4298 /// 3,
4299 /// 4);
4300 /// }
4301 /// \endcode
4302 /// \version 23
4303 unsigned BreakAfter;
4305 bool operator==(const PackArgumentsStyle &R) const {
4306 return BinPack == R.BinPack && BreakAfter == R.BreakAfter;
4307 }
4308 bool operator!=(const PackArgumentsStyle &R) const {
4309 return !operator==(R);
4310 }
4312
4313 /// Options related to packing arguments of function calls.
4314 /// \version 23
4316
4317 /// Different ways to try to fit all constructor initializers on a line.
4319 /// Always put each constructor initializer on its own line.
4320 /// \code
4321 /// Constructor()
4322 /// : a(),
4323 /// b()
4324 /// \endcode
4325 PCIS_Never,
4326 /// Bin-pack constructor initializers.
4327 /// \code
4328 /// Constructor()
4329 /// : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(),
4330 /// cccccccccccccccccccc()
4331 /// \endcode
4333 /// Put all constructor initializers on the current line if they fit.
4334 /// Otherwise, put each one on its own line.
4335 /// \code
4336 /// Constructor() : a(), b()
4337 ///
4338 /// Constructor()
4339 /// : aaaaaaaaaaaaaaaaaaaa(),
4340 /// bbbbbbbbbbbbbbbbbbbb(),
4341 /// ddddddddddddd()
4342 /// \endcode
4344 /// Same as `PCIS_CurrentLine` except that if all constructor initializers
4345 /// do not fit on the current line, try to fit them on the next line.
4346 /// \code
4347 /// Constructor() : a(), b()
4348 ///
4349 /// Constructor()
4350 /// : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), ddddddddddddd()
4351 ///
4352 /// Constructor()
4353 /// : aaaaaaaaaaaaaaaaaaaa(),
4354 /// bbbbbbbbbbbbbbbbbbbb(),
4355 /// cccccccccccccccccccc()
4356 /// \endcode
4358 /// Put all constructor initializers on the next line if they fit.
4359 /// Otherwise, put each one on its own line.
4360 /// \code
4361 /// Constructor()
4362 /// : a(), b()
4363 ///
4364 /// Constructor()
4365 /// : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), ddddddddddddd()
4366 ///
4367 /// Constructor()
4368 /// : aaaaaaaaaaaaaaaaaaaa(),
4369 /// bbbbbbbbbbbbbbbbbbbb(),
4370 /// cccccccccccccccccccc()
4371 /// \endcode
4374
4375 /// The pack constructor initializers style to use.
4376 /// \version 14
4378
4379 /// Different ways to try to fit all parameters on a line.
4381 /// Bin-pack parameters.
4382 /// \code
4383 /// void f(int a, int bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
4384 /// int ccccccccccccccccccccccccccccccccccccccccccc);
4385 /// \endcode
4387 /// Put all parameters on the current line if they fit.
4388 /// Otherwise, put each one on its own line.
4389 /// \code
4390 /// void f(int a, int b, int c);
4391 ///
4392 /// void f(int a,
4393 /// int b,
4394 /// int ccccccccccccccccccccccccccccccccccccc);
4395 /// \endcode
4397 /// Always put each parameter on its own line.
4398 /// \code
4399 /// void f(int a,
4400 /// int b,
4401 /// int c);
4402 /// \endcode
4404 /// Use the `BreakAfter` option to handle parameter packing instead.
4405 /// If the `BreakAfter` limit is not exceeded, behave like `BinPack`.
4408
4409 /// Options related to packing parameters of function declarations and
4410 /// definitions.
4412
4413 /// The bin pack parameters style to use.
4414 /// \version 3.7
4416
4417 /// A parameter list with more parameters than the specified number will be
4418 /// formatted with one parameter per line. This option must be used with
4419 /// `BinPack: UseBreakAfter`.
4420 /// \code
4421 /// PackParameters:
4422 /// BinPack: UseBreakAfter
4423 /// BreakAfter: 3
4424 ///
4425 /// void foo(int a);
4426 ///
4427 /// void bar(int a, int b, int c);
4428 ///
4429 /// void baz(int a,
4430 /// int b,
4431 /// int c,
4432 /// int d);
4433 /// \endcode
4434 /// \version 23
4435 unsigned BreakAfter;
4437 bool operator==(const PackParametersStyle &R) const {
4438 return BinPack == R.BinPack && BreakAfter == R.BreakAfter;
4439 }
4440 bool operator!=(const PackParametersStyle &R) const {
4441 return !operator==(R);
4442 }
4443 };
4445 /// Options related to packing parameters of function declarations and
4446 /// definitions.
4447 /// \version 23
4449
4450 /// The penalty for breaking around an assignment operator.
4451 /// \version 5
4453
4454 /// The penalty for breaking a function call after `call(`.
4455 /// \version 3.7
4457
4458 /// The penalty for breaking before a member access operator (`.`, `->`).
4459 /// \version 20
4461
4462 /// The penalty for each line break introduced inside a comment.
4463 /// \version 3.7
4465
4466 /// The penalty for breaking before the first `<<`.
4467 /// \version 3.7
4469
4470 /// The penalty for breaking after `(`.
4471 /// \version 14
4473
4474 /// The penalty for breaking after `::`.
4475 /// \version 18
4477
4478 /// The penalty for each line break introduced inside a string literal.
4479 /// \version 3.7
4481
4482 /// The penalty for breaking after template declaration.
4483 /// \version 7
4485
4486 /// The penalty for each character outside of the column limit.
4487 /// \version 3.7
4488 unsigned PenaltyExcessCharacter;
4490 /// Penalty for each character of whitespace indentation
4491 /// (counted relative to leading non-whitespace column).
4492 /// \version 12
4494
4495 /// Penalty for putting the return type of a function onto its own line.
4496 /// \version 3.7
4498
4499 /// The `&`, `&&` and `*` alignment style.
4501 /// Align pointer to the left.
4502 /// \code
4503 /// int* a;
4504 /// \endcode
4505 PAS_Left,
4506 /// Align pointer to the right.
4507 /// \code
4508 /// int *a;
4509 /// \endcode
4510 PAS_Right,
4511 /// Align pointer in the middle.
4512 /// \code
4513 /// int * a;
4514 /// \endcode
4517
4518 /// Pointer and reference alignment style.
4519 /// \version 3.7
4520 PointerAlignmentStyle PointerAlignment;
4521
4522 /// The number of columns to use for indentation of preprocessor statements.
4523 /// When set to -1 (default) `IndentWidth` is used also for preprocessor
4524 /// statements.
4525 /// \code
4526 /// PPIndentWidth: 1
4527 ///
4528 /// #ifdef __linux__
4529 /// # define FOO
4530 /// #else
4531 /// # define BAR
4532 /// #endif
4533 /// \endcode
4534 /// \version 13
4535 int PPIndentWidth;
4536
4537 /// Different specifiers and qualifiers alignment styles.
4539 /// Don't change specifiers/qualifiers to either Left or Right alignment
4540 /// (default).
4541 /// \code
4542 /// int const a;
4543 /// const int *a;
4544 /// \endcode
4545 QAS_Leave,
4546 /// Change specifiers/qualifiers to be left-aligned.
4547 /// \code
4548 /// const int a;
4549 /// const int *a;
4550 /// \endcode
4551 QAS_Left,
4552 /// Change specifiers/qualifiers to be right-aligned.
4553 /// \code
4554 /// int const a;
4555 /// int const *a;
4556 /// \endcode
4557 QAS_Right,
4558 /// Change specifiers/qualifiers to be aligned based on `QualifierOrder`.
4559 /// With:
4560 /// \code{.yaml}
4561 /// QualifierOrder: [inline, static, type, const]
4562 /// \endcode
4563 ///
4564 /// \code
4565 ///
4566 /// int const a;
4567 /// int const *a;
4568 /// \endcode
4570 };
4571
4572 /// Different ways to arrange specifiers and qualifiers (e.g. const/volatile).
4573 /// \warning
4574 /// Setting `QualifierAlignment` to something other than `Leave`, COULD
4575 /// lead to incorrect code formatting due to incorrect decisions made due to
4576 /// clang-formats lack of complete semantic information.
4577 /// As such extra care should be taken to review code changes made by the use
4578 /// of this option.
4579 /// \endwarning
4580 /// \version 14
4582
4583 /// The order in which the qualifiers appear.
4584 /// The order is an array that can contain any of the following:
4585 ///
4586 /// * `const`
4587 /// * `inline`
4588 /// * `static`
4589 /// * `friend`
4590 /// * `constexpr`
4591 /// * `volatile`
4592 /// * `restrict`
4593 /// * `typedef`
4594 /// * `consteval`
4595 /// * `constinit`
4596 /// * `thread_local`
4597 /// * `extern`
4598 /// * `mutable`
4599 /// * `signed`
4600 /// * `unsigned`
4601 /// * `long`
4602 /// * `short`
4603 /// * `explicit`
4604 /// * `type`
4605 ///
4606 /// \note
4607 /// It must contain `type`.
4608 /// \endnote
4609 ///
4610 /// Items to the left of `type` will be placed to the left of the type and
4611 /// aligned in the order supplied. Items to the right of `type` will be
4612 /// placed to the right of the type and aligned in the order supplied.
4613 /// If only one of `signed` and `unsigned` is specified, both are placed at
4614 /// that position. The same applies to `long` and `short`. Specifying both
4615 /// members of a pair allows them to be placed independently.
4616 ///
4617 /// \code{.yaml}
4618 /// QualifierOrder: [inline, static, type, const, volatile]
4619 /// \endcode
4620 /// \version 14
4621 std::vector<std::string> QualifierOrder;
4623 /// See documentation of `RawStringFormats`.
4625 /// The language of this raw string.
4627 /// A list of raw string delimiters that match this language.
4628 std::vector<std::string> Delimiters;
4629 /// A list of enclosing function names that match this language.
4630 std::vector<std::string> EnclosingFunctions;
4631 /// The canonical delimiter for this language.
4633 /// The style name on which this raw string format is based on.
4634 /// If not specified, the raw string format is based on the style that this
4635 /// format is based on.
4636 std::string BasedOnStyle;
4637 bool operator==(const RawStringFormat &Other) const {
4638 return Language == Other.Language && Delimiters == Other.Delimiters &&
4639 EnclosingFunctions == Other.EnclosingFunctions &&
4640 CanonicalDelimiter == Other.CanonicalDelimiter &&
4641 BasedOnStyle == Other.BasedOnStyle;
4642 }
4643 };
4644
4645 /// Defines hints for detecting supported languages code blocks in raw
4646 /// strings.
4647 ///
4648 /// A raw string with a matching delimiter or a matching enclosing function
4649 /// name will be reformatted assuming the specified language based on the
4650 /// style for that language defined in the .clang-format file. If no style has
4651 /// been defined in the .clang-format file for the specific language, a
4652 /// predefined style given by `BasedOnStyle` is used. If `BasedOnStyle` is
4653 /// not found, the formatting is based on `LLVM` style. A matching delimiter
4654 /// takes precedence over a matching enclosing function name for determining
4655 /// the language of the raw string contents.
4656 ///
4657 /// If a canonical delimiter is specified, occurrences of other delimiters for
4658 /// the same language will be updated to the canonical if possible.
4659 ///
4660 /// There should be at most one specification per language and each delimiter
4661 /// and enclosing function should not occur in multiple specifications.
4662 ///
4663 /// To configure this in the .clang-format file, use:
4664 /// \code{.yaml}
4665 /// RawStringFormats:
4666 /// - Language: TextProto
4667 /// Delimiters:
4668 /// - pb
4669 /// - proto
4670 /// EnclosingFunctions:
4671 /// - PARSE_TEXT_PROTO
4672 /// BasedOnStyle: google
4673 /// - Language: Cpp
4674 /// Delimiters:
4675 /// - cc
4676 /// - cpp
4677 /// BasedOnStyle: LLVM
4678 /// CanonicalDelimiter: cc
4679 /// \endcode
4680 /// \version 6
4681 std::vector<RawStringFormat> RawStringFormats;
4683 /// The `&` and `&&` alignment style.
4685 /// Align reference like `PointerAlignment`.
4687 /// Align reference to the left.
4688 /// \code
4689 /// int& a;
4690 /// \endcode
4691 RAS_Left,
4692 /// Align reference to the right.
4693 /// \code
4694 /// int &a;
4695 /// \endcode
4696 RAS_Right,
4697 /// Align reference in the middle.
4698 /// \code
4699 /// int & a;
4700 /// \endcode
4703
4704 /// Reference alignment style (overrides `PointerAlignment` for references).
4705 /// \version 13
4707
4708 // clang-format off
4709 /// Types of comment reflow style.
4711 /// Leave comments untouched.
4712 /// \code
4713 /// // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
4714 /// /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */
4715 /// /* third veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
4716 /// * and a misaligned second line */
4717 /// \endcode
4718 RCS_Never,
4719 /// Only apply indentation rules, moving comments left or right, without
4720 /// changing formatting inside the comments.
4721 /// \code
4722 /// // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
4723 /// /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */
4724 /// /* third veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
4725 /// * and a misaligned second line */
4726 /// \endcode
4728 /// Apply indentation rules and reflow long comments into new lines, trying
4729 /// to obey the `ColumnLimit`.
4730 /// \code
4731 /// // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
4732 /// // information
4733 /// /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
4734 /// * information */
4735 /// /* third veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
4736 /// * information and a misaligned second line */
4737 /// \endcode
4739 };
4740 // clang-format on
4741
4742 /// Comment reformatting style.
4743 /// \version 3.8
4745
4746 /// Remove optional braces of control statements (`if`, `else`, `for`,
4747 /// and `while`) in C++ according to the LLVM coding style.
4748 /// \warning
4749 /// This option will be renamed and expanded to support other styles.
4750 /// \endwarning
4751 /// \warning
4752 /// Setting this option to `true` could lead to incorrect code formatting
4753 /// due to clang-format's lack of complete semantic information. As such,
4754 /// extra care should be taken to review code changes made by this option.
4755 /// \endwarning
4756 /// \code
4757 /// false: true:
4758 ///
4759 /// if (isa<FunctionDecl>(D)) { vs. if (isa<FunctionDecl>(D))
4760 /// handleFunctionDecl(D); handleFunctionDecl(D);
4761 /// } else if (isa<VarDecl>(D)) { else if (isa<VarDecl>(D))
4762 /// handleVarDecl(D); handleVarDecl(D);
4763 /// }
4764 ///
4765 /// if (isa<VarDecl>(D)) { vs. if (isa<VarDecl>(D)) {
4766 /// for (auto *A : D.attrs()) { for (auto *A : D.attrs())
4767 /// if (shouldProcessAttr(A)) { if (shouldProcessAttr(A))
4768 /// handleAttr(A); handleAttr(A);
4769 /// } }
4770 /// }
4771 /// }
4772 ///
4773 /// if (isa<FunctionDecl>(D)) { vs. if (isa<FunctionDecl>(D))
4774 /// for (auto *A : D.attrs()) { for (auto *A : D.attrs())
4775 /// handleAttr(A); handleAttr(A);
4776 /// }
4777 /// }
4778 ///
4779 /// if (auto *D = (T)(D)) { vs. if (auto *D = (T)(D)) {
4780 /// if (shouldProcess(D)) { if (shouldProcess(D))
4781 /// handleVarDecl(D); handleVarDecl(D);
4782 /// } else { else
4783 /// markAsIgnored(D); markAsIgnored(D);
4784 /// } }
4785 /// }
4786 ///
4787 /// if (a) { vs. if (a)
4788 /// b(); b();
4789 /// } else { else if (c)
4790 /// if (c) { d();
4791 /// d(); else
4792 /// } else { e();
4793 /// e();
4794 /// }
4795 /// }
4796 /// \endcode
4797 /// \version 14
4798 bool RemoveBracesLLVM;
4799
4800 /// Remove empty lines within unwrapped lines.
4801 /// \code
4802 /// false: true:
4803 ///
4804 /// int c vs. int c = a + b;
4805 ///
4806 /// = a + b;
4807 ///
4808 /// enum : unsigned vs. enum : unsigned {
4809 /// AA = 0,
4810 /// { BB
4811 /// AA = 0, } myEnum;
4812 /// BB
4813 /// } myEnum;
4814 ///
4815 /// while ( vs. while (true) {
4816 /// }
4817 /// true) {
4818 /// }
4819 /// \endcode
4820 /// \version 20
4822
4823 /// Types of redundant parentheses to remove.
4825 /// Do not remove parentheses.
4826 /// \code
4827 /// class __declspec((dllimport)) X {};
4828 /// co_return (((0)));
4829 /// return ((a + b) - ((c + d)));
4830 /// \endcode
4831 RPS_Leave,
4832 /// Replace multiple parentheses with single parentheses.
4833 /// \code
4834 /// class __declspec(dllimport) X {};
4835 /// co_return (0);
4836 /// return ((a + b) - (c + d));
4837 /// \endcode
4839 /// Also remove parentheses enclosing the expression in a
4840 /// `return`/`co_return` statement.
4841 /// \code
4842 /// class __declspec(dllimport) X {};
4843 /// co_return 0;
4844 /// return (a + b) - (c + d);
4845 /// \endcode
4847 };
4848
4849 /// Remove redundant parentheses.
4850 /// \warning
4851 /// Setting this option to any value other than `Leave` could lead to
4852 /// incorrect code formatting due to clang-format's lack of complete semantic
4853 /// information. As such, extra care should be taken to review code changes
4854 /// made by this option.
4855 /// \endwarning
4856 /// \version 17
4858
4859 /// Remove semicolons after the closing braces of functions and
4860 /// constructors/destructors.
4861 /// \warning
4862 /// Setting this option to `true` could lead to incorrect code formatting
4863 /// due to clang-format's lack of complete semantic information. As such,
4864 /// extra care should be taken to review code changes made by this option.
4865 /// \endwarning
4866 /// \code
4867 /// false: true:
4868 ///
4869 /// int max(int a, int b) { int max(int a, int b) {
4870 /// return a > b ? a : b; return a > b ? a : b;
4871 /// }; }
4872 ///
4873 /// \endcode
4874 /// \version 16
4876
4877 /// The possible positions for the requires clause. The `IndentRequires`
4878 /// option is only used if the `requires` is put on the start of a line.
4880 /// Always put the `requires` clause on its own line (possibly followed by
4881 /// a semicolon).
4882 /// \code
4883 /// template <typename T>
4884 /// requires C<T>
4885 /// struct Foo {...
4886 ///
4887 /// template <typename T>
4888 /// void bar(T t)
4889 /// requires C<T>;
4890 ///
4891 /// template <typename T>
4892 /// requires C<T>
4893 /// void bar(T t) {...
4894 ///
4895 /// template <typename T>
4896 /// void baz(T t)
4897 /// requires C<T>
4898 /// {...
4899 /// \endcode
4901 /// As with `OwnLine`, except, unless otherwise prohibited, place a
4902 /// following open brace (of a function definition) to follow on the same
4903 /// line.
4904 /// \code
4905 /// void bar(T t)
4906 /// requires C<T> {
4907 /// return;
4908 /// }
4909 ///
4910 /// void bar(T t)
4911 /// requires C<T> {}
4912 ///
4913 /// template <typename T>
4914 /// requires C<T>
4915 /// void baz(T t) {
4916 /// ...
4917 /// \endcode
4919 /// Try to put the clause together with the preceding part of a declaration.
4920 /// For class templates: stick to the template declaration.
4921 /// For function templates: stick to the template declaration.
4922 /// For function declaration followed by a requires clause: stick to the
4923 /// parameter list.
4924 /// \code
4925 /// template <typename T> requires C<T>
4926 /// struct Foo {...
4927 ///
4928 /// template <typename T> requires C<T>
4929 /// void bar(T t) {...
4930 ///
4931 /// template <typename T>
4932 /// void baz(T t) requires C<T>
4933 /// {...
4934 /// \endcode
4936 /// Try to put the `requires` clause together with the class or function
4937 /// declaration.
4938 /// \code
4939 /// template <typename T>
4940 /// requires C<T> struct Foo {...
4941 ///
4942 /// template <typename T>
4943 /// requires C<T> void bar(T t) {...
4944 ///
4945 /// template <typename T>
4946 /// void baz(T t)
4947 /// requires C<T> {...
4948 /// \endcode
4950 /// Try to put everything in the same line if possible. Otherwise normal
4951 /// line breaking rules take over.
4952 /// \code
4953 /// // Fitting:
4954 /// template <typename T> requires C<T> struct Foo {...
4955 ///
4956 /// template <typename T> requires C<T> void bar(T t) {...
4957 ///
4958 /// template <typename T> void bar(T t) requires C<T> {...
4959 ///
4960 /// // Not fitting, one possible example:
4961 /// template <typename LongName>
4962 /// requires C<LongName>
4963 /// struct Foo {...
4964 ///
4965 /// template <typename LongName>
4966 /// requires C<LongName>
4967 /// void bar(LongName ln) {
4968 ///
4969 /// template <typename LongName>
4970 /// void bar(LongName ln)
4971 /// requires C<LongName> {
4972 /// \endcode
4975
4976 /// The position of the `requires` clause.
4977 /// \version 15
4979
4980 /// Indentation logic for requires expression bodies.
4982 /// Align requires expression body relative to the indentation level of the
4983 /// outer scope the requires expression resides in.
4984 /// This is the default.
4985 /// \code
4986 /// template <typename T>
4987 /// concept C = requires(T t) {
4988 /// ...
4989 /// }
4990 /// \endcode
4992 /// Align requires expression body relative to the `requires` keyword.
4993 /// \code
4994 /// template <typename T>
4995 /// concept C = requires(T t) {
4996 /// ...
4997 /// }
4998 /// \endcode
5001
5002 /// The indentation used for requires expression bodies.
5003 /// \version 16
5006 /// The style if definition blocks should be separated.
5008 /// Leave definition blocks as they are.
5010 /// Insert an empty line between definition blocks.
5011 SDS_Always,
5012 /// Remove any empty line between definition blocks.
5013 SDS_Never
5014 };
5015
5016 /// Specifies the use of empty lines to separate definition blocks, including
5017 /// classes, structs, enums, and functions.
5018 /// \code
5019 /// Never v.s. Always
5020 /// #include <cstring> #include <cstring>
5021 /// struct Foo {
5022 /// int a, b, c; struct Foo {
5023 /// }; int a, b, c;
5024 /// namespace Ns { };
5025 /// class Bar {
5026 /// public: namespace Ns {
5027 /// struct Foobar { class Bar {
5028 /// int a; public:
5029 /// int b; struct Foobar {
5030 /// }; int a;
5031 /// private: int b;
5032 /// int t; };
5033 /// int method1() {
5034 /// // ... private:
5035 /// } int t;
5036 /// enum List {
5037 /// ITEM1, int method1() {
5038 /// ITEM2 // ...
5039 /// }; }
5040 /// template<typename T>
5041 /// int method2(T x) { enum List {
5042 /// // ... ITEM1,
5043 /// } ITEM2
5044 /// int i, j, k; };
5045 /// int method3(int par) {
5046 /// // ... template<typename T>
5047 /// } int method2(T x) {
5048 /// }; // ...
5049 /// class C {}; }
5050 /// }
5051 /// int i, j, k;
5052 ///
5053 /// int method3(int par) {
5054 /// // ...
5055 /// }
5056 /// };
5057 ///
5058 /// class C {};
5059 /// }
5060 /// \endcode
5061 /// \version 14
5063
5064 /// The maximal number of unwrapped lines that a short namespace spans.
5065 /// Defaults to 1.
5066 ///
5067 /// This determines the maximum length of short namespaces by counting
5068 /// unwrapped lines (i.e. containing neither opening nor closing
5069 /// namespace brace) and makes `FixNamespaceComments` omit adding
5070 /// end comments for those.
5071 /// \code
5072 /// ShortNamespaceLines: 1 vs. ShortNamespaceLines: 0
5073 /// namespace a { namespace a {
5074 /// int foo; int foo;
5075 /// } } // namespace a
5076 ///
5077 /// ShortNamespaceLines: 1 vs. ShortNamespaceLines: 0
5078 /// namespace b { namespace b {
5079 /// int foo; int foo;
5080 /// int bar; int bar;
5081 /// } // namespace b } // namespace b
5082 /// \endcode
5083 /// \version 13
5085
5086 /// Do not format macro definition body.
5087 /// \version 18
5089
5090 /// Includes sorting options.
5091 struct SortIncludesOptions {
5092 /// If `true`, includes are sorted based on the other suboptions below.
5093 /// (`Never` is deprecated by `Enabled: false`.)
5094 bool Enabled;
5095 /// Whether or not includes are sorted in a case-insensitive fashion.
5096 /// (`CaseSensitive` and `CaseInsensitive` are deprecated by
5097 /// `IgnoreCase: false` and `IgnoreCase: true`, respectively.)
5098 /// \code
5099 /// true: false:
5100 /// #include "A/B.h" vs. #include "A/B.h"
5101 /// #include "A/b.h" #include "A/b.h"
5102 /// #include "a/b.h" #include "B/A.h"
5103 /// #include "B/A.h" #include "B/a.h"
5104 /// #include "B/a.h" #include "a/b.h"
5105 /// \endcode
5106 bool IgnoreCase;
5107 /// When sorting includes in each block, only take file extensions into
5108 /// account if two includes compare equal otherwise.
5109 /// \code
5110 /// true: false:
5111 /// # include "A.h" vs. # include "A-util.h"
5112 /// # include "A.inc" # include "A.h"
5113 /// # include "A-util.h" # include "A.inc"
5114 /// \endcode
5115 bool IgnoreExtension;
5116 /// Whether or not includes are sorted by natural ordering i.e., whether
5117 /// embedded runs of digits are compared as numbers rather than sequences of
5118 /// characters.
5119 /// \code
5120 /// true: false:
5121 /// #include "A2.h" vs. #include "A10.h"
5122 /// #include "A10.h" #include "A2.h"
5123 /// \endcode
5124 bool Natural;
5125 /// When `true`, sort includes so that files in a directory appear
5126 /// before subdirectories at each level, recursively. Within a level,
5127 /// files and folders are each sorted alphabetically.
5128 /// When `false` (default), sorts includes purely alphabetically.
5129 ///
5130 /// This option is a secondary sort key within each `Priority` group
5131 /// defined by `IncludeCategories`. Includes in different `Priority`
5132 /// groups are still separated by that primary ordering.
5133 /// \code
5134 /// true: false (default):
5135 /// #include "x.h" vs. #include "bar/alpha/e.h"
5136 /// #include "y.h" #include "bar/alpha/f.h"
5137 /// #include "z.h" #include "bar/beta/d.h"
5138 /// #include "bar/g.h" #include "bar/g.h"
5139 /// #include "bar/h.h" #include "bar/h.h"
5140 /// #include "bar/i.h" #include "bar/i.h"
5141 /// #include "bar/alpha/e.h" #include "foo/a.h"
5142 /// #include "bar/alpha/f.h" #include "x.h"
5143 /// #include "bar/beta/d.h" #include "y.h"
5144 /// #include "foo/a.h" #include "z.h"
5145 /// \endcode
5146 bool FilesBeforeFolders;
5147 bool operator==(const SortIncludesOptions &R) const {
5148 return Enabled == R.Enabled && IgnoreCase == R.IgnoreCase &&
5149 IgnoreExtension == R.IgnoreExtension && Natural == R.Natural &&
5150 FilesBeforeFolders == R.FilesBeforeFolders;
5151 }
5152 bool operator!=(const SortIncludesOptions &R) const {
5153 return !(*this == R);
5154 }
5156
5157 /// Controls if and how clang-format will sort `#includes`.
5158 /// \version 3.8
5160
5161 /// Position for Java Static imports.
5163 /// Static imports are placed before non-static imports.
5164 /// \code{.java}
5165 /// import static org.example.function1;
5166 ///
5167 /// import org.example.ClassA;
5168 /// \endcode
5170 /// Static imports are placed after non-static imports.
5171 /// \code{.java}
5172 /// import org.example.ClassA;
5173 ///
5174 /// import static org.example.function1;
5175 /// \endcode
5177 };
5178
5179 /// When sorting Java imports, by default static imports are placed before
5180 /// non-static imports. If `JavaStaticImportAfterImport` is `After`,
5181 /// static imports are placed after non-static imports.
5182 /// \version 12
5184
5185 /// Using declaration sorting options.
5187 /// Using declarations are never sorted.
5188 /// \code
5189 /// using std::chrono::duration_cast;
5190 /// using std::move;
5191 /// using boost::regex;
5192 /// using boost::regex_constants::icase;
5193 /// using std::string;
5194 /// \endcode
5195 SUD_Never,
5196 /// Using declarations are sorted in the order defined as follows:
5197 /// Split the strings by `::` and discard any initial empty strings. Sort
5198 /// the lists of names lexicographically, and within those groups, names are
5199 /// in case-insensitive lexicographic order.
5200 /// \code
5201 /// using boost::regex;
5202 /// using boost::regex_constants::icase;
5203 /// using std::chrono::duration_cast;
5204 /// using std::move;
5205 /// using std::string;
5206 /// \endcode
5208 /// Using declarations are sorted in the order defined as follows:
5209 /// Split the strings by `::` and discard any initial empty strings. The
5210 /// last element of each list is a non-namespace name; all others are
5211 /// namespace names. Sort the lists of names lexicographically, where the
5212 /// sort order of individual names is that all non-namespace names come
5213 /// before all namespace names, and within those groups, names are in
5214 /// case-insensitive lexicographic order.
5215 /// \code
5216 /// using boost::regex;
5217 /// using boost::regex_constants::icase;
5218 /// using std::move;
5219 /// using std::string;
5220 /// using std::chrono::duration_cast;
5221 /// \endcode
5224
5225 /// Controls if and how clang-format will sort using declarations.
5226 /// \version 5
5227 SortUsingDeclarationsOptions SortUsingDeclarations;
5228
5229 /// If `true`, a space is inserted after C style casts.
5230 /// \code
5231 /// true: false:
5232 /// (int) i; vs. (int)i;
5233 /// \endcode
5234 /// \version 3.5
5236
5237 /// If `true`, a space is inserted after the logical not operator (`!`).
5238 /// \code
5239 /// true: false:
5240 /// ! someExpression(); vs. !someExpression();
5241 /// \endcode
5242 /// \version 9
5244
5245 /// If `true`, a space will be inserted after the `operator` keyword.
5246 /// \code
5247 /// true: false:
5248 /// bool operator ==(int a); vs. bool operator==(int a);
5249 /// \endcode
5250 /// \version 21
5252
5253 /// If \c true, a space will be inserted after the `template` keyword.
5254 /// \code
5255 /// true: false:
5256 /// template <int> void foo(); vs. template<int> void foo();
5257 /// \endcode
5258 /// \version 4
5260
5261 /// Different ways to put a space before opening parentheses.
5263 /// Don't ensure spaces around pointer qualifiers and use PointerAlignment
5264 /// instead.
5265 /// \code
5266 /// PointerAlignment: Left PointerAlignment: Right
5267 /// void* const* x = NULL; vs. void *const *x = NULL;
5268 /// \endcode
5270 /// Ensure that there is a space before pointer qualifiers.
5271 /// \code
5272 /// PointerAlignment: Left PointerAlignment: Right
5273 /// void* const* x = NULL; vs. void * const *x = NULL;
5274 /// \endcode
5276 /// Ensure that there is a space after pointer qualifiers.
5277 /// \code
5278 /// PointerAlignment: Left PointerAlignment: Right
5279 /// void* const * x = NULL; vs. void *const *x = NULL;
5280 /// \endcode
5281 SAPQ_After,
5282 /// Ensure that there is a space both before and after pointer qualifiers.
5283 /// \code
5284 /// PointerAlignment: Left PointerAlignment: Right
5285 /// void* const * x = NULL; vs. void * const *x = NULL;
5286 /// \endcode
5287 SAPQ_Both,
5289
5290 /// Defines in which cases to put a space before or after pointer qualifiers
5291 /// \version 12
5292 SpaceAroundPointerQualifiersStyle SpaceAroundPointerQualifiers;
5293
5294 /// If `false`, spaces will be removed before assignment operators.
5295 /// \code
5296 /// true: false:
5297 /// int a = 5; vs. int a= 5;
5298 /// a += 42; a+= 42;
5299 /// \endcode
5300 /// \version 3.7
5302
5303 /// If `false`, spaces will be removed before case colon.
5304 /// \code
5305 /// true: false
5306 /// switch (x) { vs. switch (x) {
5307 /// case 1 : break; case 1: break;
5308 /// } }
5309 /// \endcode
5310 /// \version 12
5312
5313 /// If `true`, a space will be inserted before a C++11 braced list
5314 /// used to initialize an object (after the preceding identifier or type).
5315 /// \code
5316 /// true: false:
5317 /// Foo foo { bar }; vs. Foo foo{ bar };
5318 /// Foo {}; Foo{};
5319 /// vector<int> { 1, 2, 3 }; vector<int>{ 1, 2, 3 };
5320 /// new int[3] { 1, 2, 3 }; new int[3]{ 1, 2, 3 };
5321 /// \endcode
5322 /// \version 7
5324
5325 /// If `false`, spaces will be removed before constructor initializer
5326 /// colon.
5327 /// \code
5328 /// true: false:
5329 /// Foo::Foo() : a(a) {} Foo::Foo(): a(a) {}
5330 /// \endcode
5331 /// \version 7
5333
5334 /// If `false`, spaces will be removed before enum underlying type colon.
5335 /// \code
5336 /// true: false:
5337 /// enum E : int {} enum E: int {}
5338 /// \endcode
5339 /// \version 23
5341
5342 /// If `false`, spaces will be removed before inheritance colon.
5343 /// \code
5344 /// true: false:
5345 /// class Foo : Bar {} vs. class Foo: Bar {}
5346 /// \endcode
5347 /// \version 7
5349
5350 /// If `true`, a space will be added before a JSON colon. For other
5351 /// languages, e.g. JavaScript, use `SpacesInContainerLiterals` instead.
5352 /// \code
5353 /// true: false:
5354 /// { {
5355 /// "key" : "value" vs. "key": "value"
5356 /// } }
5357 /// \endcode
5358 /// \version 17
5360
5361 /// Different ways to put a space before opening parentheses.
5363 /// This is **deprecated** and replaced by `Custom` below, with all
5364 /// `SpaceBeforeParensOptions` but `AfterPlacementOperator` set to
5365 /// `false`.
5366 SBPO_Never,
5367 /// Put a space before opening parentheses only after control statement
5368 /// keywords (`for/if/while...`).
5369 /// \code
5370 /// void f() {
5371 /// if (true) {
5372 /// f();
5373 /// }
5374 /// }
5375 /// \endcode
5377 /// Same as `SBPO_ControlStatements` except this option doesn't apply to
5378 /// ForEach and If macros. This is useful in projects where ForEach/If
5379 /// macros are treated as function calls instead of control statements.
5380 /// `SBPO_ControlStatementsExceptForEachMacros` remains an alias for
5381 /// backward compatibility.
5382 /// \code
5383 /// void f() {
5384 /// Q_FOREACH(...) {
5385 /// f();
5386 /// }
5387 /// }
5388 /// \endcode
5390 /// Put a space before opening parentheses only if the parentheses are not
5391 /// empty.
5392 /// \code
5393 /// void() {
5394 /// if (true) {
5395 /// f();
5396 /// g (x, y, z);
5397 /// }
5398 /// }
5399 /// \endcode
5401 /// Always put a space before opening parentheses, except when it's
5402 /// prohibited by the syntax rules (in function-like macro definitions) or
5403 /// when determined by other style rules (after unary operators, opening
5404 /// parentheses, etc.)
5405 /// \code
5406 /// void f () {
5407 /// if (true) {
5408 /// f ();
5409 /// }
5410 /// }
5411 /// \endcode
5413 /// Configure each individual space before parentheses in
5414 /// `SpaceBeforeParensOptions`.
5417
5418 /// Defines in which cases to put a space before opening parentheses.
5419 /// \version 3.5
5420 SpaceBeforeParensStyle SpaceBeforeParens;
5421
5422 /// Precise control over the spacing before parentheses.
5423 /// \code{.yaml}
5424 /// # Should be declared this way:
5425 /// SpaceBeforeParens: Custom
5426 /// SpaceBeforeParensOptions:
5427 /// AfterControlStatements: true
5428 /// AfterFunctionDefinitionName: true
5429 /// \endcode
5431 /// If `true`, put space between control statement keywords
5432 /// (for/if/while...) and opening parentheses.
5433 /// \code
5434 /// true: false:
5435 /// if (...) {} vs. if(...) {}
5436 /// \endcode
5438 /// If `true`, put space between foreach macros and opening parentheses.
5439 /// \code
5440 /// true: false:
5441 /// FOREACH (...) vs. FOREACH(...)
5442 /// <loop-body> <loop-body>
5443 /// \endcode
5444 bool AfterForeachMacros;
5445 /// If `true`, put a space between function declaration name and opening
5446 /// parentheses.
5447 /// \code
5448 /// true: false:
5449 /// void f (); vs. void f();
5450 /// \endcode
5452 /// If `true`, put a space between function definition name and opening
5453 /// parentheses.
5454 /// \code
5455 /// true: false:
5456 /// void f () {} vs. void f() {}
5457 /// \endcode
5459 /// If `true`, put space between if macros and opening parentheses.
5460 /// \code
5461 /// true: false:
5462 /// IF (...) vs. IF(...)
5463 /// <conditional-body> <conditional-body>
5464 /// \endcode
5465 bool AfterIfMacros;
5466 /// If `true`, put a space between alternative operator `not` and the
5467 /// opening parenthesis.
5468 /// \code
5469 /// true: false:
5470 /// return not (a || b); vs. return not(a || b);
5471 /// \endcode
5472 bool AfterNot;
5473 /// If `true`, put a space between operator overloading and opening
5474 /// parentheses.
5475 /// \code
5476 /// true: false:
5477 /// void operator++ (int a); vs. void operator++(int a);
5478 /// object.operator++ (10); object.operator++(10);
5479 /// \endcode
5481 /// If `true`, put a space between operator `new`/`delete` and opening
5482 /// parenthesis.
5483 /// \code
5484 /// true: false:
5485 /// new (buf) T; vs. new(buf) T;
5486 /// delete (buf) T; delete(buf) T;
5487 /// \endcode
5489 /// If `true`, put space between requires keyword in a requires clause and
5490 /// opening parentheses, if there is one.
5491 /// \code
5492 /// true: false:
5493 /// template<typename T> vs. template<typename T>
5494 /// requires (A<T> && B<T>) requires(A<T> && B<T>)
5495 /// ... ...
5496 /// \endcode
5498 /// If `true`, put space between requires keyword in a requires expression
5499 /// and opening parentheses.
5500 /// \code
5501 /// true: false:
5502 /// template<typename T> vs. template<typename T>
5503 /// concept C = requires (T t) { concept C = requires(T t) {
5504 /// ... ...
5505 /// } }
5506 /// \endcode
5508 /// If `true`, put a space before opening parentheses only if the
5509 /// parentheses are not empty.
5510 /// \code
5511 /// true: false:
5512 /// void f (int a); vs. void f();
5524
5525 bool operator==(const SpaceBeforeParensCustom &Other) const {
5526 return AfterControlStatements == Other.AfterControlStatements &&
5527 AfterForeachMacros == Other.AfterForeachMacros &&
5529 Other.AfterFunctionDeclarationName &&
5530 AfterFunctionDefinitionName == Other.AfterFunctionDefinitionName &&
5531 AfterIfMacros == Other.AfterIfMacros &&
5532 AfterNot == Other.AfterNot &&
5533 AfterOverloadedOperator == Other.AfterOverloadedOperator &&
5534 AfterPlacementOperator == Other.AfterPlacementOperator &&
5535 AfterRequiresInClause == Other.AfterRequiresInClause &&
5536 AfterRequiresInExpression == Other.AfterRequiresInExpression &&
5537 BeforeNonEmptyParentheses == Other.BeforeNonEmptyParentheses;
5538 }
5539 };
5540
5541 /// Control of individual space before parentheses.
5542 ///
5543 /// If `SpaceBeforeParens` is set to `Custom`, use this to specify
5544 /// how each individual space before parentheses case should be handled.
5545 /// Otherwise, this is ignored.
5546 /// \code{.yaml}
5547 /// # Example of usage:
5548 /// SpaceBeforeParens: Custom
5549 /// SpaceBeforeParensOptions:
5550 /// AfterControlStatements: true
5551 /// AfterFunctionDefinitionName: true
5552 /// \endcode
5553 /// \version 14
5555
5556 /// If `true`, spaces will be before `[`.
5557 /// Lambdas will not be affected. Only the first `[` will get a space added.
5558 /// \code
5559 /// true: false:
5560 /// int a [5]; vs. int a[5];
5561 /// int a [5][5]; vs. int a[5][5];
5562 /// \endcode
5563 /// \version 10
5565
5566 /// If `false`, spaces will be removed before range-based for loop
5567 /// colon.
5568 /// \code
5569 /// true: false:
5570 /// for (auto v : values) {} vs. for(auto v: values) {}
5571 /// \endcode
5572 /// \version 7
5574
5575 /// This option is **deprecated**. See `Block` of `SpaceInEmptyBraces`.
5576 /// \version 10
5577 // bool SpaceInEmptyBlock;
5578
5579 /// Style of when to insert a space in empty braces.
5581 /// Always insert a space in empty braces.
5582 /// \code
5583 /// void f() { }
5584 /// class Unit { };
5585 /// auto a = [] { };
5586 /// int x{ };
5587 /// \endcode
5589 /// Only insert a space in empty blocks.
5590 /// \code
5591 /// void f() { }
5592 /// class Unit { };
5593 /// auto a = [] { };
5594 /// int x{};
5595 /// \endcode
5596 SIEB_Block,
5597 /// Never insert a space in empty braces.
5598 /// \code
5599 /// void f() {}
5600 /// class Unit {};
5601 /// auto a = [] {};
5602 /// int x{};
5603 /// \endcode
5605 };
5606
5607 /// Specifies when to insert a space in empty braces.
5608 /// \note
5609 /// This option doesn't apply to initializer braces if
5610 /// `Cpp11BracedListStyle` is not `Block`.
5611 /// \endnote
5612 /// \version 22
5614
5615 /// If `true`, spaces may be inserted into `()`.
5616 /// This option is **deprecated**. See `InEmptyParentheses` of
5617 /// `SpacesInParensOptions`.
5618 /// \version 3.7
5619 // bool SpaceInEmptyParentheses;
5620
5621 /// The number of spaces before trailing line comments
5622 /// (`//` - comments).
5623 ///
5624 /// This does not affect trailing block comments (`/*` - comments) as those
5625 /// commonly have different usage patterns and a number of special cases. In
5626 /// the case of Verilog, it doesn't affect a comment right after the opening
5627 /// parenthesis in the port or parameter list in a module header, because it
5628 /// is probably for the port on the following line instead of the parenthesis
5629 /// it follows.
5630 /// \code
5631 /// SpacesBeforeTrailingComments: 3
5632 /// void f() {
5633 /// if (true) { // foo1
5634 /// f(); // bar
5635 /// } // foo
5636 /// }
5637 /// \endcode
5638 /// \version 3.7
5640
5641 /// Styles for adding spacing after `<` and before `>`
5642 /// in template argument lists.
5644 /// Remove spaces after `<` and before `>`.
5645 /// \code
5646 /// static_cast<int>(arg);
5647 /// std::function<void(int)> fct;
5648 /// \endcode
5649 SIAS_Never,
5650 /// Add spaces after `<` and before `>`.
5651 /// \code
5652 /// static_cast< int >(arg);
5653 /// std::function< void(int) > fct;
5654 /// \endcode
5656 /// Keep a single space after `<` and before `>` if any spaces were
5657 /// present. Option `Standard: Cpp03` takes precedence.
5659 };
5660 /// The SpacesInAnglesStyle to use for template argument lists.
5661 /// \version 3.4
5663
5664 /// Styles for controlling spacing after `/*` and before `*/` in block
5665 /// comments.
5667 /// Remove spaces after `/*` and before `*/`.
5668 /// \code
5669 /// /*comment*/
5670 /// \endcode
5672 /// Add spaces after `/*` and before `*/`.
5673 /// \code
5674 /// /* comment */
5675 /// \endcode
5677 /// Leave existing spaces unchanged.
5680
5681 /// The SpacesInBlockCommentsStyle to use for ordinary block comments.
5682 /// Documentation comments such as `/** ... */` and `/*! ... */`
5683 /// and parameter comments ending with `=` before the closing `*/` are
5684 /// left unchanged.
5685 /// \version 24
5686 SpacesInBlockCommentsStyle SpacesInBlockComments;
5687
5688 /// If `true`, spaces will be inserted around if/for/switch/while
5689 /// conditions.
5690 /// This option is **deprecated**. See `InConditionalStatements` of
5691 /// `SpacesInParensOptions`.
5692 /// \version 10
5693 // bool SpacesInConditionalStatement;
5694
5695 /// If `true`, spaces are inserted inside container literals (e.g. ObjC and
5696 /// Javascript array and dict literals). For JSON, use
5697 /// `SpaceBeforeJsonColon` instead.
5698 /// \code{.js}
5699 /// true: false:
5700 /// var arr = [ 1, 2, 3 ]; vs. var arr = [1, 2, 3];
5701 /// f({a : 1, b : 2, c : 3}); f({a: 1, b: 2, c: 3});
5702 /// \endcode
5703 /// \version 3.7
5705
5706 /// If `true`, spaces may be inserted into C style casts.
5707 /// This option is **deprecated**. See `InCStyleCasts` of
5708 /// `SpacesInParensOptions`.
5709 /// \version 3.7
5710 // bool SpacesInCStyleCastParentheses;
5712 /// Control of spaces within a single line comment.
5714 /// The minimum number of spaces at the start of the comment.
5715 unsigned Minimum;
5716 /// The maximum number of spaces at the start of the comment.
5717 unsigned Maximum;
5718 };
5719
5720 /// How many spaces are allowed at the start of a line comment. To disable the
5721 /// maximum set it to `-1`, apart from that the maximum takes precedence
5722 /// over the minimum.
5723 /// \code
5724 /// Minimum = 1
5725 /// Maximum = -1
5726 /// // One space is forced
5727 ///
5728 /// // but more spaces are possible
5729 ///
5730 /// Minimum = 0
5731 /// Maximum = 0
5732 /// //Forces to start every comment directly after the slashes
5733 /// \endcode
5734 ///
5735 /// Note that in line comment sections the relative indent of the subsequent
5736 /// lines is kept, that means the following:
5737 /// \code
5738 /// before: after:
5739 /// Minimum: 1
5740 /// //if (b) { // if (b) {
5741 /// // return true; // return true;
5742 /// //} // }
5743 ///
5744 /// Maximum: 0
5745 /// /// List: ///List:
5746 /// /// - Foo /// - Foo
5747 /// /// - Bar /// - Bar
5748 /// \endcode
5749 ///
5750 /// This option has only effect if `ReflowComments` is set to `true`.
5751 /// \version 13
5753
5754 /// Different ways to put a space before opening and closing parentheses.
5756 /// Never put a space in parentheses.
5757 /// \code
5758 /// void f() {
5759 /// if(true) {
5760 /// f();
5761 /// }
5762 /// }
5763 /// \endcode
5764 SIPO_Never,
5765 /// Configure each individual space in parentheses in
5766 /// `SpacesInParensOptions`.
5768 };
5769
5770 /// If `true`, spaces will be inserted after `(` and before `)`.
5771 /// This option is **deprecated**. The previous behavior is preserved by using
5772 /// `SpacesInParens` with `Custom` and by setting all
5773 /// `SpacesInParensOptions` to `true` except for `InCStyleCasts` and
5774 /// `InEmptyParentheses`.
5775 /// \version 3.7
5776 // bool SpacesInParentheses;
5778 /// Defines in which cases spaces will be inserted after `(` and before
5779 /// `)`.
5780 /// \version 17
5782
5783 /// Precise control over the spacing in parentheses.
5784 /// \code{.yaml}
5785 /// # Should be declared this way:
5786 /// SpacesInParens: Custom
5787 /// SpacesInParensOptions:
5788 /// ExceptDoubleParentheses: false
5789 /// InConditionalStatements: true
5790 /// Other: true
5791 /// \endcode
5792 struct SpacesInParensCustom {
5793 /// Override any of the following options to prevent addition of space
5794 /// when both opening and closing parentheses use multiple parentheses.
5795 /// \code
5796 /// true:
5797 /// __attribute__(( noreturn ))
5798 /// __decltype__(( x ))
5799 /// if (( a = b ))
5800 /// \endcode
5801 /// false:
5802 /// Uses the applicable option.
5804 /// Put a space in parentheses only inside conditional statements
5805 /// (`for/if/while/switch...`).
5806 /// \code
5807 /// true: false:
5808 /// if ( a ) { ... } vs. if (a) { ... }
5809 /// while ( i < 5 ) { ... } while (i < 5) { ... }
5810 /// \endcode
5812 /// Put a space in C style casts.
5813 /// \code
5814 /// true: false:
5815 /// x = ( int32 )y vs. x = (int32)y
5816 /// y = (( int (*)(int) )foo)(x); y = ((int (*)(int))foo)(x);
5817 /// \endcode
5818 bool InCStyleCasts;
5819 /// Insert a space in empty parentheses, i.e. `()`.
5820 /// \code
5821 /// true: false:
5822 /// void f( ) { vs. void f() {
5823 /// int x[] = {foo( ), bar( )}; int x[] = {foo(), bar()};
5824 /// if (true) { if (true) {
5825 /// f( ); f();
5826 /// } }
5827 /// } }
5828 /// \endcode
5829 bool InEmptyParentheses;
5830 /// Put a space in parentheses not covered by preceding options.
5831 /// \code
5832 /// true: false:
5833 /// t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete;
5834 /// \endcode
5835 bool Other;
5836
5851 InConditionalStatements == R.InConditionalStatements &&
5852 InCStyleCasts == R.InCStyleCasts &&
5853 InEmptyParentheses == R.InEmptyParentheses && Other == R.Other;
5854 }
5855 bool operator!=(const SpacesInParensCustom &R) const {
5856 return !(*this == R);
5857 }
5858 };
5859
5860 /// Control of individual spaces in parentheses.
5861 ///
5862 /// If `SpacesInParens` is set to `Custom`, use this to specify
5863 /// how each individual space in parentheses case should be handled.
5864 /// Otherwise, this is ignored.
5865 /// \code{.yaml}
5866 /// # Example of usage:
5867 /// SpacesInParens: Custom
5868 /// SpacesInParensOptions:
5869 /// ExceptDoubleParentheses: false
5870 /// InConditionalStatements: true
5871 /// InEmptyParentheses: true
5872 /// \endcode
5873 /// \version 17
5875
5876 /// If `true`, spaces will be inserted after `[` and before `]`.
5877 /// Lambdas without arguments or unspecified size array declarations will not
5878 /// be affected.
5879 /// \code
5880 /// true: false:
5881 /// int a[ 5 ]; vs. int a[5];
5882 /// std::unique_ptr<int[]> foo() {} // Won't be affected
5883 /// \endcode
5884 /// \version 3.7
5886
5887 /// Supported language standards for parsing and formatting C++ constructs.
5888 /// \code
5889 /// Latest: vector<set<int>>
5890 /// c++03 vs. vector<set<int> >
5891 /// \endcode
5892 ///
5893 /// The correct way to spell a specific language version is e.g. `c++11`.
5894 /// The historical aliases `Cpp03` and `Cpp11` are deprecated.
5895 enum LanguageStandard : int8_t {
5896 /// Parse and format as C++03.
5897 /// `Cpp03` is a deprecated alias for `c++03`
5898 LS_Cpp03, // c++03
5899 /// Parse and format as C++11.
5900 LS_Cpp11, // c++11
5901 /// Parse and format as C++14.
5902 LS_Cpp14, // c++14
5903 /// Parse and format as C++17.
5904 LS_Cpp17, // c++17
5905 /// Parse and format as C++20.
5906 LS_Cpp20, // c++20
5907 /// Parse and format as C++23.
5908 LS_Cpp23, // c++23
5909 /// Parse and format as C++26.
5910 LS_Cpp26, // c++26
5911 /// Parse and format using the latest supported language version.
5912 /// `Cpp11` is a deprecated alias for `Latest`
5913 LS_Latest,
5914 /// Automatic detection based on the input.
5915 LS_Auto,
5916 };
5917
5918 /// Parse and format C++ constructs compatible with this standard.
5919 /// \code
5920 /// c++03: latest:
5921 /// vector<set<int> > x; vs. vector<set<int>> x;
5922 /// \endcode
5923 /// \version 3.7
5925
5926 /// Macros which are ignored in front of a statement, as if they were an
5927 /// attribute. So that they are not parsed as identifier, for example for Qts
5928 /// emit.
5929 /// \code
5930 /// AlignConsecutiveDeclarations: true
5931 /// StatementAttributeLikeMacros: []
5932 /// unsigned char data = 'x';
5933 /// emit signal(data); // This is parsed as variable declaration.
5934 ///
5935 /// AlignConsecutiveDeclarations: true
5936 /// StatementAttributeLikeMacros: [emit]
5937 /// unsigned char data = 'x';
5938 /// emit signal(data); // Now it's fine again.
5939 /// \endcode
5940 /// \version 12
5941 std::vector<std::string> StatementAttributeLikeMacros;
5942
5943 /// A vector of macros that should be interpreted as complete statements.
5944 ///
5945 /// Typical macros are expressions and require a semicolon to be added.
5946 /// Sometimes this is not the case, and this allows to make clang-format aware
5947 /// of such cases.
5948 ///
5949 /// For example: Q_UNUSED
5950 /// \version 8
5951 std::vector<std::string> StatementMacros;
5952
5953 /// Works only when TableGenBreakInsideDAGArg is not DontBreak.
5954 /// The string list needs to consist of identifiers in TableGen.
5955 /// If any identifier is specified, this limits the line breaks by
5956 /// TableGenBreakInsideDAGArg option only on DAGArg values beginning with
5957 /// the specified identifiers.
5958 ///
5959 /// For example the configuration,
5960 /// \code{.yaml}
5961 /// TableGenBreakInsideDAGArg: BreakAll
5962 /// TableGenBreakingDAGArgOperators: [ins, outs]
5963 /// \endcode
5964 ///
5965 /// makes the line break only occurs inside DAGArgs beginning with the
5966 /// specified identifiers `ins` and `outs`.
5967 ///
5968 /// \code
5969 /// let DAGArgIns = (ins
5970 /// i32:$src1,
5971 /// i32:$src2
5972 /// );
5973 /// let DAGArgOtherID = (other i32:$other1, i32:$other2);
5974 /// let DAGArgBang = (!cast<SomeType>("Some") i32:$src1, i32:$src2)
5975 /// \endcode
5976 /// \version 19
5977 std::vector<std::string> TableGenBreakingDAGArgOperators;
5978
5979 /// Different ways to control the format inside TableGen DAGArg.
5980 enum DAGArgStyle : int8_t {
5981 /// Never break inside DAGArg.
5982 /// \code
5983 /// let DAGArgIns = (ins i32:$src1, i32:$src2);
5984 /// \endcode
5986 /// Break inside DAGArg after each list element but for the last.
5987 /// This aligns to the first element.
5988 /// \code
5989 /// let DAGArgIns = (ins i32:$src1,
5990 /// i32:$src2);
5991 /// \endcode
5993 /// Break inside DAGArg after the operator and the all elements.
5994 /// \code
5995 /// let DAGArgIns = (ins
5996 /// i32:$src1,
5997 /// i32:$src2
5998 /// );
5999 /// \endcode
6002
6003 /// The styles of the line break inside the DAGArg in TableGen.
6004 /// \version 19
6006
6007 /// The number of columns used for tab stops.
6008 /// \version 3.7
6009 unsigned TabWidth;
6010
6011 /// A vector of non-keyword identifiers that should be interpreted as template
6012 /// names.
6013 ///
6014 /// A `<` after a template name is annotated as a template opener instead of
6015 /// a binary operator.
6016 ///
6017 /// \version 20
6018 std::vector<std::string> TemplateNames;
6019
6020 /// A vector of non-keyword identifiers that should be interpreted as type
6021 /// names.
6022 ///
6023 /// A `*`, `&`, or `&&` between a type name and another non-keyword
6024 /// identifier is annotated as a pointer or reference token instead of a
6025 /// binary operator.
6026 ///
6027 /// \version 17
6028 std::vector<std::string> TypeNames;
6029
6030 /// A vector of macros that should be interpreted as type declarations instead
6031 /// of as function calls.
6032 ///
6033 /// These are expected to be macros of the form:
6034 /// \code
6035 /// STACK_OF(...)
6036 /// \endcode
6037 ///
6038 /// In the .clang-format configuration file, this can be configured like:
6039 /// \code{.yaml}
6040 /// TypenameMacros: [STACK_OF, LIST]
6041 /// \endcode
6042 ///
6043 /// For example: OpenSSL STACK_OF, BSD LIST_ENTRY.
6044 /// \version 9
6045 std::vector<std::string> TypenameMacros;
6046
6047 /// This option is **deprecated**. See `LF` and `CRLF` of `LineEnding`.
6048 /// \version 10
6049 // bool UseCRLF;
6051 /// Different ways to use tab in formatting.
6053 /// Never use tab.
6054 UT_Never,
6055 /// Use tabs only for indentation.
6057 /// Fill all leading whitespace with tabs, and use spaces for alignment that
6058 /// appears within a line (e.g. consecutive assignments and declarations).
6060 /// Use tabs for line continuation and indentation, and spaces for
6061 /// alignment.
6063 /// Use tabs whenever we need to fill whitespace that spans at least from
6064 /// one tab stop to the next one.
6065 UT_Always
6067
6068 /// The way to use tab characters in the resulting file.
6069 /// \version 3.7
6070 UseTabStyle UseTab;
6071
6072 /// A vector of non-keyword identifiers that should be interpreted as variable
6073 /// template names.
6074 ///
6075 /// A `)` after a variable template instantiation is **not** annotated as
6076 /// the closing parenthesis of C-style cast operator.
6077 ///
6078 /// \version 20
6079 std::vector<std::string> VariableTemplates;
6080
6081 /// For Verilog, put each port on its own line in module instantiations.
6082 /// \code
6083 /// true:
6084 /// ffnand ff1(.q(),
6085 /// .qbar(out1),
6086 /// .clear(in1),
6087 /// .preset(in2));
6088 ///
6089 /// false:
6090 /// ffnand ff1(.q(), .qbar(out1), .clear(in1), .preset(in2));
6091 /// \endcode
6092 /// \version 17
6094
6095 /// A vector of macros which are whitespace-sensitive and should not
6096 /// be touched.
6097 ///
6098 /// These are expected to be macros of the form:
6099 /// \code
6100 /// STRINGIZE(...)
6101 /// \endcode
6102 ///
6103 /// In the .clang-format configuration file, this can be configured like:
6104 /// \code{.yaml}
6105 /// WhitespaceSensitiveMacros: [STRINGIZE, PP_STRINGIZE]
6106 /// \endcode
6107 ///
6108 /// For example: BOOST_PP_STRINGIZE
6109 /// \version 11
6110 std::vector<std::string> WhitespaceSensitiveMacros;
6111
6112 /// Different styles for wrapping namespace body with empty lines.
6114 /// Remove all empty lines at the beginning and the end of namespace body.
6115 /// \code
6116 /// namespace N1 {
6117 /// namespace N2 {
6118 /// function();
6119 /// }
6120 /// }
6121 /// \endcode
6123 /// Always have at least one empty line at the beginning and the end of
6124 /// namespace body except that the number of empty lines between consecutive
6125 /// nested namespace definitions is not increased.
6126 /// \code
6127 /// namespace N1 {
6128 /// namespace N2 {
6129 ///
6130 /// function();
6131 ///
6132 /// }
6133 /// }
6134 /// \endcode
6136 /// Keep existing newlines at the beginning and the end of namespace body.
6137 /// `MaxEmptyLinesToKeep` still applies.
6140
6141 /// Wrap namespace body with empty lines.
6142 /// \version 20
6144
6145 bool operator==(const FormatStyle &R) const {
6146 return AccessModifierOffset == R.AccessModifierOffset &&
6147 AlignAfterOpenBracket == R.AlignAfterOpenBracket &&
6148 AlignArrayOfStructures == R.AlignArrayOfStructures &&
6149 AlignConsecutiveAssignments == R.AlignConsecutiveAssignments &&
6150 AlignConsecutiveBitFields == R.AlignConsecutiveBitFields &&
6151 AlignConsecutiveDeclarations == R.AlignConsecutiveDeclarations &&
6152 AlignConsecutiveMacros == R.AlignConsecutiveMacros &&
6154 R.AlignConsecutiveShortCaseStatements &&
6156 R.AlignConsecutiveTableGenBreakingDAGArgColons &&
6158 R.AlignConsecutiveTableGenCondOperatorColons &&
6160 R.AlignConsecutiveTableGenDefinitionColons &&
6161 AlignEscapedNewlines == R.AlignEscapedNewlines &&
6162 AlignOperands == R.AlignOperands &&
6163 AlignTrailingComments == R.AlignTrailingComments &&
6164 AllowAllArgumentsOnNextLine == R.AllowAllArgumentsOnNextLine &&
6166 R.AllowAllParametersOfDeclarationOnNextLine &&
6168 R.AllowBreakBeforeNoexceptSpecifier &&
6169 AllowBreakBeforeQtProperty == R.AllowBreakBeforeQtProperty &&
6170 AllowShortBlocksOnASingleLine == R.AllowShortBlocksOnASingleLine &&
6172 R.AllowShortCaseExpressionOnASingleLine &&
6174 R.AllowShortCaseLabelsOnASingleLine &&
6176 R.AllowShortCompoundRequirementOnASingleLine &&
6177 AllowShortEnumsOnASingleLine == R.AllowShortEnumsOnASingleLine &&
6179 R.AllowShortFunctionsOnASingleLine &&
6181 R.AllowShortIfStatementsOnASingleLine &&
6182 AllowShortLambdasOnASingleLine == R.AllowShortLambdasOnASingleLine &&
6183 AllowShortLoopsOnASingleLine == R.AllowShortLoopsOnASingleLine &&
6185 R.AllowShortNamespacesOnASingleLine &&
6186 AllowShortRecordOnASingleLine == R.AllowShortRecordOnASingleLine &&
6188 R.AlwaysBreakBeforeMultilineStrings &&
6189 AttributeMacros == R.AttributeMacros &&
6190 BinPackLongBracedList == R.BinPackLongBracedList &&
6191 BitFieldColonSpacing == R.BitFieldColonSpacing &&
6192 BracedInitializerIndentWidth == R.BracedInitializerIndentWidth &&
6193 BreakAdjacentStringLiterals == R.BreakAdjacentStringLiterals &&
6194 BreakAfterAttributes == R.BreakAfterAttributes &&
6195 BreakAfterJavaFieldAnnotations == R.BreakAfterJavaFieldAnnotations &&
6197 R.BreakAfterOpenBracketBracedList &&
6198 BreakAfterOpenBracketFunction == R.BreakAfterOpenBracketFunction &&
6199 BreakAfterOpenBracketIf == R.BreakAfterOpenBracketIf &&
6200 BreakAfterOpenBracketLoop == R.BreakAfterOpenBracketLoop &&
6201 BreakAfterOpenBracketSwitch == R.BreakAfterOpenBracketSwitch &&
6202 BreakAfterReturnType == R.BreakAfterReturnType &&
6203 BreakArrays == R.BreakArrays &&
6204 BreakBeforeBinaryOperators == R.BreakBeforeBinaryOperators &&
6205 BreakBeforeBraces == R.BreakBeforeBraces &&
6207 R.BreakBeforeCloseBracketBracedList &&
6209 R.BreakBeforeCloseBracketFunction &&
6210 BreakBeforeCloseBracketIf == R.BreakBeforeCloseBracketIf &&
6211 BreakBeforeCloseBracketLoop == R.BreakBeforeCloseBracketLoop &&
6212 BreakBeforeCloseBracketSwitch == R.BreakBeforeCloseBracketSwitch &&
6213 BreakBeforeConceptDeclarations == R.BreakBeforeConceptDeclarations &&
6214 BreakBeforeInlineASMColon == R.BreakBeforeInlineASMColon &&
6215 BreakBeforeReturnType == R.BreakBeforeReturnType &&
6216 BreakBeforeTemplateCloser == R.BreakBeforeTemplateCloser &&
6217 BreakBeforeTernaryOperators == R.BreakBeforeTernaryOperators &&
6218 BreakBinaryOperations == R.BreakBinaryOperations &&
6219 BreakConstructorInitializers == R.BreakConstructorInitializers &&
6221 R.BreakFunctionDeclarationParameters &&
6223 R.BreakFunctionDefinitionParameters &&
6224 BreakInheritanceList == R.BreakInheritanceList &&
6225 BreakStringLiterals == R.BreakStringLiterals &&
6226 BreakTemplateDeclarations == R.BreakTemplateDeclarations &&
6227 ColumnLimit == R.ColumnLimit && CommentPragmas == R.CommentPragmas &&
6228 CompactNamespaces == R.CompactNamespaces &&
6230 R.ConstructorInitializerIndentWidth &&
6231 ContinuationIndentWidth == R.ContinuationIndentWidth &&
6232 Cpp11BracedListStyle == R.Cpp11BracedListStyle &&
6233 DerivePointerAlignment == R.DerivePointerAlignment &&
6234 DisableFormat == R.DisableFormat &&
6235 EmptyLineAfterAccessModifier == R.EmptyLineAfterAccessModifier &&
6236 EmptyLineBeforeAccessModifier == R.EmptyLineBeforeAccessModifier &&
6237 EnumTrailingComma == R.EnumTrailingComma &&
6239 R.ExperimentalAutoDetectBinPacking &&
6240 FixNamespaceComments == R.FixNamespaceComments &&
6241 ForEachMacros == R.ForEachMacros &&
6242 IncludeStyle.IncludeBlocks == R.IncludeStyle.IncludeBlocks &&
6243 IncludeStyle.IncludeCategories == R.IncludeStyle.IncludeCategories &&
6244 IncludeStyle.IncludeIsMainRegex ==
6245 R.IncludeStyle.IncludeIsMainRegex &&
6246 IncludeStyle.IncludeIsMainSourceRegex ==
6247 R.IncludeStyle.IncludeIsMainSourceRegex &&
6248 IncludeStyle.MainIncludeChar == R.IncludeStyle.MainIncludeChar &&
6249 IndentAccessModifiers == R.IndentAccessModifiers &&
6250 IndentCaseBlocks == R.IndentCaseBlocks &&
6251 IndentCaseLabels == R.IndentCaseLabels &&
6252 IndentExportBlock == R.IndentExportBlock &&
6253 IndentExternBlock == R.IndentExternBlock &&
6254 IndentGotoLabels == R.IndentGotoLabels &&
6255 IndentPPDirectives == R.IndentPPDirectives &&
6256 IndentRequiresClause == R.IndentRequiresClause &&
6257 IndentWidth == R.IndentWidth &&
6258 IndentWrappedFunctionNames == R.IndentWrappedFunctionNames &&
6259 InsertBraces == R.InsertBraces &&
6260 InsertNewlineAtEOF == R.InsertNewlineAtEOF &&
6261 IntegerLiteralSeparator == R.IntegerLiteralSeparator &&
6262 JavaImportGroups == R.JavaImportGroups &&
6263 JavaScriptQuotes == R.JavaScriptQuotes &&
6264 JavaScriptWrapImports == R.JavaScriptWrapImports &&
6265 KeepEmptyLines == R.KeepEmptyLines &&
6266 KeepFormFeed == R.KeepFormFeed && Language == R.Language &&
6267 LambdaBodyIndentation == R.LambdaBodyIndentation &&
6268 LineEnding == R.LineEnding && MacroBlockBegin == R.MacroBlockBegin &&
6269 MacroBlockEnd == R.MacroBlockEnd && Macros == R.Macros &&
6271 R.MacrosSkippedByRemoveParentheses &&
6272 MaxEmptyLinesToKeep == R.MaxEmptyLinesToKeep &&
6273 NamespaceIndentation == R.NamespaceIndentation &&
6274 NamespaceMacros == R.NamespaceMacros &&
6275 NumericLiteralCase == R.NumericLiteralCase &&
6276 ObjCBinPackProtocolList == R.ObjCBinPackProtocolList &&
6277 ObjCBlockIndentWidth == R.ObjCBlockIndentWidth &&
6279 R.ObjCBreakBeforeNestedBlockParam &&
6280 ObjCPropertyAttributeOrder == R.ObjCPropertyAttributeOrder &&
6282 R.ObjCSpaceAfterMethodDeclarationPrefix &&
6283 ObjCSpaceAfterProperty == R.ObjCSpaceAfterProperty &&
6284 ObjCSpaceBeforeProtocolList == R.ObjCSpaceBeforeProtocolList &&
6285 OneLineFormatOffRegex == R.OneLineFormatOffRegex &&
6286 PackArguments == R.PackArguments &&
6287 PackConstructorInitializers == R.PackConstructorInitializers &&
6288 PackParameters == R.PackParameters &&
6289 PenaltyBreakAssignment == R.PenaltyBreakAssignment &&
6291 R.PenaltyBreakBeforeFirstCallParameter &&
6292 PenaltyBreakBeforeMemberAccess == R.PenaltyBreakBeforeMemberAccess &&
6293 PenaltyBreakComment == R.PenaltyBreakComment &&
6294 PenaltyBreakFirstLessLess == R.PenaltyBreakFirstLessLess &&
6295 PenaltyBreakOpenParenthesis == R.PenaltyBreakOpenParenthesis &&
6296 PenaltyBreakScopeResolution == R.PenaltyBreakScopeResolution &&
6297 PenaltyBreakString == R.PenaltyBreakString &&
6299 R.PenaltyBreakTemplateDeclaration &&
6300 PenaltyExcessCharacter == R.PenaltyExcessCharacter &&
6301 PenaltyReturnTypeOnItsOwnLine == R.PenaltyReturnTypeOnItsOwnLine &&
6302 PointerAlignment == R.PointerAlignment &&
6303 QualifierAlignment == R.QualifierAlignment &&
6304 QualifierOrder == R.QualifierOrder &&
6305 RawStringFormats == R.RawStringFormats &&
6306 ReferenceAlignment == R.ReferenceAlignment &&
6307 RemoveBracesLLVM == R.RemoveBracesLLVM &&
6309 R.RemoveEmptyLinesInUnwrappedLines &&
6310 RemoveParentheses == R.RemoveParentheses &&
6311 RemoveSemicolon == R.RemoveSemicolon &&
6312 RequiresClausePosition == R.RequiresClausePosition &&
6313 RequiresExpressionIndentation == R.RequiresExpressionIndentation &&
6314 SeparateDefinitionBlocks == R.SeparateDefinitionBlocks &&
6315 ShortNamespaceLines == R.ShortNamespaceLines &&
6316 SkipMacroDefinitionBody == R.SkipMacroDefinitionBody &&
6317 SortIncludes == R.SortIncludes &&
6318 SortJavaStaticImport == R.SortJavaStaticImport &&
6319 SpaceAfterCStyleCast == R.SpaceAfterCStyleCast &&
6320 SpaceAfterLogicalNot == R.SpaceAfterLogicalNot &&
6321 SpaceAfterOperatorKeyword == R.SpaceAfterOperatorKeyword &&
6322 SpaceAfterTemplateKeyword == R.SpaceAfterTemplateKeyword &&
6323 SpaceBeforeAssignmentOperators == R.SpaceBeforeAssignmentOperators &&
6324 SpaceBeforeCaseColon == R.SpaceBeforeCaseColon &&
6325 SpaceBeforeCpp11BracedList == R.SpaceBeforeCpp11BracedList &&
6327 R.SpaceBeforeCtorInitializerColon &&
6328 SpaceBeforeInheritanceColon == R.SpaceBeforeInheritanceColon &&
6329 SpaceBeforeJsonColon == R.SpaceBeforeJsonColon &&
6330 SpaceBeforeParens == R.SpaceBeforeParens &&
6331 SpaceBeforeParensOptions == R.SpaceBeforeParensOptions &&
6332 SpaceAroundPointerQualifiers == R.SpaceAroundPointerQualifiers &&
6334 R.SpaceBeforeRangeBasedForLoopColon &&
6335 SpaceBeforeSquareBrackets == R.SpaceBeforeSquareBrackets &&
6336 SpaceInEmptyBraces == R.SpaceInEmptyBraces &&
6337 SpacesBeforeTrailingComments == R.SpacesBeforeTrailingComments &&
6338 SpacesInAngles == R.SpacesInAngles &&
6339 SpacesInBlockComments == R.SpacesInBlockComments &&
6340 SpacesInContainerLiterals == R.SpacesInContainerLiterals &&
6341 SpacesInLineCommentPrefix.Minimum ==
6342 R.SpacesInLineCommentPrefix.Minimum &&
6343 SpacesInLineCommentPrefix.Maximum ==
6344 R.SpacesInLineCommentPrefix.Maximum &&
6345 SpacesInParens == R.SpacesInParens &&
6346 SpacesInParensOptions == R.SpacesInParensOptions &&
6347 SpacesInSquareBrackets == R.SpacesInSquareBrackets &&
6348 Standard == R.Standard &&
6349 StatementAttributeLikeMacros == R.StatementAttributeLikeMacros &&
6350 StatementMacros == R.StatementMacros &&
6352 R.TableGenBreakingDAGArgOperators &&
6353 TableGenBreakInsideDAGArg == R.TableGenBreakInsideDAGArg &&
6354 TabWidth == R.TabWidth && TemplateNames == R.TemplateNames &&
6355 TypeNames == R.TypeNames && TypenameMacros == R.TypenameMacros &&
6356 UseTab == R.UseTab && VariableTemplates == R.VariableTemplates &&
6358 R.VerilogBreakBetweenInstancePorts &&
6359 WhitespaceSensitiveMacros == R.WhitespaceSensitiveMacros &&
6360 WrapNamespaceBodyWithEmptyLines == R.WrapNamespaceBodyWithEmptyLines;
6361 }
6362
6363 std::optional<FormatStyle> GetLanguageStyle(LanguageKind Language) const;
6364
6365 // Stores per-language styles. A FormatStyle instance inside has an empty
6366 // StyleSet. A FormatStyle instance returned by the Get method has its
6367 // StyleSet set to a copy of the originating StyleSet, effectively keeping the
6368 // internal representation of that StyleSet alive.
6370 // The memory management and ownership reminds of a birds nest: chicks
6371 // leaving the nest take photos of the nest with them.
6372 struct FormatStyleSet {
6373 typedef std::map<LanguageKind, FormatStyle> MapType;
6374
6375 std::optional<FormatStyle> Get(LanguageKind Language) const;
6376
6377 // Adds \p Style to this FormatStyleSet. Style must not have an associated
6378 // FormatStyleSet.
6379 // Style.Language should be different than LK_None. If this FormatStyleSet
6380 // already contains an entry for Style.Language, that gets replaced with the
6381 // passed Style.
6382 void Add(FormatStyle Style);
6383
6384 // Clears this FormatStyleSet.
6385 void Clear();
6386
6387 private:
6388 std::shared_ptr<MapType> Styles;
6389 };
6390
6391 static FormatStyleSet BuildStyleSetFromConfiguration(
6392 const FormatStyle &MainStyle,
6393 const std::vector<FormatStyle> &ConfigurationStyles);
6394
6395private:
6396 FormatStyleSet StyleSet;
6397
6398 friend std::error_code
6399 parseConfiguration(llvm::MemoryBufferRef Config, FormatStyle *Style,
6400 bool AllowUnknownOptions,
6401 llvm::SourceMgr::DiagHandlerTy DiagHandler,
6402 void *DiagHandlerCtxt, bool IsDotHFile);
6403};
6404
6405/// Returns a format style complying with the LLVM coding standards:
6406/// http://llvm.org/docs/CodingStandards.html.
6409
6410/// Returns a format style complying with one of Google's style guides:
6411/// http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml.
6412/// http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml.
6413/// https://developers.google.com/protocol-buffers/docs/style.
6415
6416/// Returns a format style complying with Chromium's style guide:
6417/// http://www.chromium.org/developers/coding-style.
6419
6420/// Returns a format style complying with Mozilla's style guide:
6421/// https://firefox-source-docs.mozilla.org/code-quality/coding-style/index.html.
6423
6424/// Returns a format style complying with Webkit's style guide:
6425/// http://www.webkit.org/coding/coding-style.html
6427
6428/// Returns a format style complying with GNU Coding Standards:
6429/// http://www.gnu.org/prep/standards/standards.html
6431
6432/// Returns a format style complying with Microsoft style guide:
6433/// https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017
6435
6437
6438/// Returns style indicating formatting should be not applied at all.
6440
6441/// Gets a predefined style for the specified language by name.
6442///
6443/// Currently supported names: LLVM, Google, Chromium, Mozilla. Names are
6444/// compared case-insensitively.
6445///
6446/// Returns `true` if the Style has been set.
6448 FormatStyle *Style);
6449
6450/// Parse configuration from YAML-formatted text.
6451///
6452/// Style->Language is used to get the base style, if the `BasedOnStyle`
6453/// option is present.
6454///
6455/// The FormatStyleSet of Style is reset.
6456///
6457/// When `BasedOnStyle` is not present, options not present in the YAML
6458/// document, are retained in \p Style.
6459///
6460/// If AllowUnknownOptions is true, no errors are emitted if unknown
6461/// format options are occurred.
6462///
6463/// If set all diagnostics are emitted through the DiagHandler.
6464std::error_code
6465parseConfiguration(llvm::MemoryBufferRef Config, FormatStyle *Style,
6466 bool AllowUnknownOptions = false,
6467 llvm::SourceMgr::DiagHandlerTy DiagHandler = nullptr,
6468 void *DiagHandlerCtx = nullptr, bool IsDotHFile = false);
6469
6470/// Like above but accepts an unnamed buffer.
6471inline std::error_code parseConfiguration(StringRef Config, FormatStyle *Style,
6472 bool AllowUnknownOptions = false,
6473 bool IsDotHFile = false) {
6474 return parseConfiguration(llvm::MemoryBufferRef(Config, "YAML"), Style,
6475 AllowUnknownOptions, /*DiagHandler=*/nullptr,
6476 /*DiagHandlerCtx=*/nullptr, IsDotHFile);
6477}
6478
6479/// Gets configuration in a YAML string.
6480std::string configurationAsText(const FormatStyle &Style);
6481
6482/// Returns the replacements necessary to sort all `#include` blocks
6483/// that are affected by `Ranges`.
6484tooling::Replacements sortIncludes(const FormatStyle &Style, StringRef Code,
6486 StringRef FileName,
6487 unsigned *Cursor = nullptr);
6488
6489/// Returns the replacements corresponding to applying and formatting
6490/// \p Replaces on success; otheriwse, return an llvm::Error carrying
6491/// llvm::StringError.
6493formatReplacements(StringRef Code, const tooling::Replacements &Replaces,
6494 const FormatStyle &Style);
6495
6496/// Returns the replacements corresponding to applying \p Replaces and
6497/// cleaning up the code after that on success; otherwise, return an llvm::Error
6498/// carrying llvm::StringError.
6499/// This also supports inserting/deleting C++ #include directives:
6500/// * If a replacement has offset UINT_MAX, length 0, and a replacement text
6501/// that is an #include directive, this will insert the #include into the
6502/// correct block in the \p Code.
6503/// * If a replacement has offset UINT_MAX, length 1, and a replacement text
6504/// that is the name of the header to be removed, the header will be removed
6505/// from \p Code if it exists.
6506/// The include manipulation is done via `tooling::HeaderInclude`, see its
6507/// documentation for more details on how include insertion points are found and
6508/// what edits are produced.
6510cleanupAroundReplacements(StringRef Code, const tooling::Replacements &Replaces,
6511 const FormatStyle &Style);
6512
6513/// Represents the status of a formatting attempt.
6515 /// A value of `false` means that any of the affected ranges were not
6516 /// formatted due to a non-recoverable syntax error.
6517 bool FormatComplete = true;
6518
6519 /// If `FormatComplete` is false, `Line` records a one-based
6520 /// original line number at which a syntax error might have occurred. This is
6521 /// based on a best-effort analysis and could be imprecise.
6522 unsigned Line = 0;
6523};
6524
6525/// Reformats the given \p Ranges in \p Code.
6526///
6527/// Each range is extended on either end to its next bigger logic unit, i.e.
6528/// everything that might influence its formatting or might be influenced by its
6529/// formatting.
6530///
6531/// Returns the `Replacements` necessary to make all \p Ranges comply with
6532/// \p Style.
6533///
6534/// If `Status` is non-null, its value will be populated with the status of
6535/// this formatting attempt. See \c FormattingAttemptStatus.
6536tooling::Replacements reformat(const FormatStyle &Style, StringRef Code,
6538 StringRef FileName = "<stdin>",
6539 FormattingAttemptStatus *Status = nullptr);
6540
6541/// Same as above, except if `IncompleteFormat` is non-null, its value
6542/// will be set to true if any of the affected ranges were not formatted due to
6543/// a non-recoverable syntax error.
6544tooling::Replacements reformat(const FormatStyle &Style, StringRef Code,
6546 StringRef FileName, bool *IncompleteFormat);
6547
6548/// Clean up any erroneous/redundant code in the given \p Ranges in \p
6549/// Code.
6550///
6551/// Returns the `Replacements` that clean up all \p Ranges in \p Code.
6552tooling::Replacements cleanup(const FormatStyle &Style, StringRef Code,
6554 StringRef FileName = "<stdin>");
6555
6556/// Fix namespace end comments in the given \p Ranges in \p Code.
6557///
6558/// Returns the `Replacements` that fix the namespace comments in all
6559/// \p Ranges in \p Code.
6561 StringRef Code,
6563 StringRef FileName = "<stdin>");
6564
6565/// Inserts or removes empty lines separating definition blocks including
6566/// classes, structs, functions, namespaces, and enums in the given \p Ranges in
6567/// \p Code.
6568///
6569/// Returns the `Replacements` that inserts or removes empty lines separating
6570/// definition blocks in all \p Ranges in \p Code.
6572 StringRef Code,
6574 StringRef FileName = "<stdin>");
6575
6576/// Sort consecutive using declarations in the given \p Ranges in
6577/// \p Code.
6578///
6579/// Returns the `Replacements` that sort the using declarations in all
6580/// \p Ranges in \p Code.
6582 StringRef Code,
6584 StringRef FileName = "<stdin>");
6585
6586/// Returns the `LangOpts` that the formatter expects you to set.
6587///
6588/// \param Style determines specific settings for lexing mode.
6590
6591/// Description to be used for help text for a `llvm::cl` option for
6592/// specifying format style. The description is closely related to the operation
6593/// of `getStyle()`.
6594extern const char *StyleOptionHelpDescription;
6595
6596/// The suggested format style to use by default. This allows tools using
6597/// `getStyle` to have a consistent default style.
6598/// Different builds can modify the value to the preferred styles.
6599extern const char *DefaultFormatStyle;
6600
6601/// The suggested predefined style to use as the fallback style in `getStyle`.
6602/// Different builds can modify the value to the preferred styles.
6603extern const char *DefaultFallbackStyle;
6604
6605/// Construct a FormatStyle based on `StyleName`.
6606///
6607/// `StyleName` can take several forms:
6608/// * "{<key>: <value>, ...}" - Set specic style parameters.
6609/// * "<style name>" - One of the style names supported by getPredefinedStyle().
6610/// * "file" - Load style configuration from a file called `.clang-format`
6611/// located in one of the parent directories of `FileName` or the current
6612/// directory if `FileName` is empty.
6613/// * "file:<format_file_path>" to explicitly specify the configuration file to
6614/// use.
6615///
6616/// \param[in] StyleName Style name to interpret according to the description
6617/// above.
6618/// \param[in] FileName Path to start search for .clang-format if `StyleName`
6619/// == "file".
6620/// \param[in] FallbackStyle The name of a predefined style used to fallback to
6621/// in case \p StyleName is "file" and no file can be found.
6622/// \param[in] Code The actual code to be formatted. Used to determine the
6623/// language if the filename isn't sufficient.
6624/// \param[in] FS The underlying file system, in which the file resides. By
6625/// default, the file system is the real file system.
6626/// \param[in] AllowUnknownOptions If true, unknown format options only
6627/// emit a warning. If false, errors are emitted on unknown format
6628/// options.
6629///
6630/// \returns FormatStyle as specified by `StyleName`. If `StyleName` is
6631/// "file" and no file is found, returns `FallbackStyle`. If no style could be
6632/// determined, returns an Error.
6634getStyle(StringRef StyleName, StringRef FileName, StringRef FallbackStyle,
6635 StringRef Code = "", llvm::vfs::FileSystem *FS = nullptr,
6636 bool AllowUnknownOptions = false,
6637 llvm::SourceMgr::DiagHandlerTy DiagHandler = nullptr);
6638
6639// Guesses the language from the `FileName` and `Code` to be formatted.
6640// Defaults to FormatStyle::LK_Cpp.
6641FormatStyle::LanguageKind guessLanguage(StringRef FileName, StringRef Code);
6642
6643// Returns a string representation of `Language`.
6645 switch (Language) {
6646 case FormatStyle::LK_C:
6647 return "C";
6649 return "C++";
6651 return "CSharp";
6653 return "Objective-C";
6655 return "Java";
6657 return "JavaScript";
6659 return "Json";
6661 return "Proto";
6663 return "TableGen";
6665 return "TextProto";
6667 return "Verilog";
6668 default:
6669 return "Unknown";
6670 }
6671}
6672
6673bool isClangFormatOn(StringRef Comment);
6674bool isClangFormatOff(StringRef Comment);
6675
6676} // end namespace format
6677} // end namespace clang
6678
6679template <>
6680struct std::is_error_code_enum<clang::format::ParseError> : std::true_type {};
6681
6682#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:1697
std::string message(int EV) const override
Definition Format.cpp:1701
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:4605
const char * DefaultFallbackStyle
The suggested predefined style to use as the fallback style in getStyle.
Definition Format.cpp:4726
FormatStyle getWebKitStyle()
Returns a format style complying with Webkit's style guide: http://www.webkit.org/coding/coding-style...
Definition Format.cpp:2355
std::error_code make_error_code(ParseError e)
Definition Format.cpp:1688
FormatStyle getClangFormatStyle()
Definition Format.cpp:2423
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:1863
FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language)
Returns a format style complying with one of Google's style guides: http://google-styleguide....
Definition Format.cpp:2116
std::string configurationAsText(const FormatStyle &Style)
Gets configuration in a YAML string.
Definition Format.cpp:2607
FormatStyle getMicrosoftStyle(FormatStyle::LanguageKind Language)
Returns a format style complying with Microsoft style guide: https://docs.microsoft....
Definition Format.cpp:2394
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:2510
const std::error_category & getParseCategory()
Definition Format.cpp:1684
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:4539
FormatStyle::LanguageKind guessLanguage(StringRef FileName, StringRef Code)
Definition Format.cpp:4701
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:4745
const char * DefaultFormatStyle
The suggested format style to use by default.
Definition Format.cpp:4724
FormatStyle getGNUStyle()
Returns a format style complying with GNU Coding Standards: http://www.gnu.org/prep/standards/standar...
Definition Format.cpp:2379
bool isClangFormatOff(StringRef Comment)
Definition Format.cpp:4965
LangOptions getFormattingLangOpts(const FormatStyle &Style=getLLVMStyle())
Returns the LangOpts that the formatter expects you to set.
Definition Format.cpp:4559
FormatStyle getMozillaStyle()
Returns a format style complying with Mozilla's style guide: https://firefox-source-docs....
Definition Format.cpp:2328
bool getPredefinedStyle(StringRef Name, FormatStyle::LanguageKind Language, FormatStyle *Style)
Gets a predefined style for the specified language by name.
Definition Format.cpp:2445
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:4284
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:4506
bool isClangFormatOn(StringRef Comment)
Definition Format.cpp:4961
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:4549
FormatStyle getChromiumStyle(FormatStyle::LanguageKind Language)
Returns a format style complying with Chromium's style guide: http://www.chromium....
Definition Format.cpp:2268
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:4517
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:4173
FormatStyle getNoStyle()
Returns style indicating formatting should be not applied at all.
Definition Format.cpp:2437
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:4132
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:6644
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:3838
@ LK_Cpp
Should be used for C++.
Definition Format.h:3844
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:2590
unsigned MinChainLength
Minimum number of operands in a chain before the rule triggers.
Definition Format.h:2599
BreakBinaryOperationsStyle Style
The break style for these operators (defaults to OnePerLine).
Definition Format.h:2595
std::vector< tok::TokenKind > Operators
The list of operators this rule applies to, e.g.
Definition Format.h:2593
bool operator!=(const BinaryOperationBreakRule &R) const
Definition Format.h:2604
bool operator==(const BinaryOperationBreakRule &R) const
Definition Format.h:2600
Precise control over the wrapping of braces.
Definition Format.h:1430
bool SplitEmptyRecord
If false, empty record (e.g.
Definition Format.h:1665
bool AfterClass
Wrap class definitions.
Definition Format.h:1456
bool AfterStruct
Wrap struct definitions.
Definition Format.h:1539
bool AfterRequiresExpression
Wrap requires expression body.
Definition Format.h:1525
bool AfterUnion
Wrap union definitions.
Definition Format.h:1553
bool AfterEnum
Wrap enum definitions.
Definition Format.h:1471
bool IndentBraces
Indent the wrapped braces themselves.
Definition Format.h:1639
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:1677
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:1653
BreakBinaryOperationsStyle getStyleForOperator(tok::TokenKind Kind) const
Definition Format.h:2645
unsigned getMinChainLengthForOperator(tok::TokenKind Kind) const
Definition Format.h:2650
bool operator==(const BreakBinaryOperationsOptions &R) const
Definition Format.h:2655
BreakBinaryOperationsStyle Default
The default break style for operators not covered by PerOperator.
Definition Format.h:2626
const BinaryOperationBreakRule * findRuleForOperator(tok::TokenKind Kind) const
Definition Format.h:2630
std::vector< BinaryOperationBreakRule > PerOperator
Per-operator override rules.
Definition Format.h:2628
bool operator!=(const BreakBinaryOperationsOptions &R) const
Definition Format.h:2658
std::map< LanguageKind, FormatStyle > MapType
Definition Format.h:6369
std::optional< FormatStyle > Get(LanguageKind Language) const
Definition Format.cpp:2623
Separator format of integer literals of different bases.
Definition Format.h:3563
int8_t DecimalMinDigitsInsert
Format separators in decimal literals with a minimum number of digits.
Definition Format.h:3606
int8_t BinaryMinDigitsInsert
Format separators in binary literals with a minimum number of digits.
Definition Format.h:3579
bool operator==(const IntegerLiteralSeparatorStyle &R) const
Definition Format.h:3648
int8_t Binary
Format separators in binary literals.
Definition Format.h:3571
int8_t HexMaxDigitsRemove
Remove separators in hexadecimal literals with a maximum number of digits.
Definition Format.h:3647
int8_t DecimalMaxDigitsRemove
Remove separators in decimal literals with a maximum number of digits.
Definition Format.h:3618
int8_t Decimal
Format separators in decimal literals.
Definition Format.h:3598
int8_t HexMinDigitsInsert
Format separators in hexadecimal literals with a minimum number of digits.
Definition Format.h:3634
int8_t BinaryMaxDigitsRemove
Remove separators in binary literals with a maximum number of digits.
Definition Format.h:3591
int8_t Hex
Format separators in hexadecimal literals.
Definition Format.h:3625
bool operator!=(const IntegerLiteralSeparatorStyle &R) const
Definition Format.h:3658
Options regarding which empty lines are kept.
Definition Format.h:3757
bool AtStartOfFile
Keep empty lines at start of file.
Definition Format.h:3770
bool AtEndOfFile
Keep empty lines at end of file.
Definition Format.h:3759
bool operator==(const KeepEmptyLinesStyle &R) const
Definition Format.h:3771
bool AtStartOfBlock
Keep empty lines at start of a block.
Definition Format.h:3768
Separate control for each numeric literal component.
Definition Format.h:4066
NumericLiteralComponentStyle ExponentLetter
Format floating point exponent separator letter case.
Definition Format.h:4073
NumericLiteralComponentStyle Suffix
Format suffix case.
Definition Format.h:4095
bool operator==(const NumericLiteralCaseStyle &R) const
Definition Format.h:4097
NumericLiteralComponentStyle Prefix
Format integer prefix case.
Definition Format.h:4087
bool operator!=(const NumericLiteralCaseStyle &R) const
Definition Format.h:4102
NumericLiteralComponentStyle HexDigit
Format hexadecimal digit case.
Definition Format.h:4080
Options related to packing arguments of function calls.
Definition Format.h:4273
bool operator!=(const PackArgumentsStyle &R) const
Definition Format.h:4304
bool operator==(const PackArgumentsStyle &R) const
Definition Format.h:4301
unsigned BreakAfter
An argument list with more arguments than the specified number will be formatted with one argument pe...
Definition Format.h:4299
BinPackArgumentsStyle BinPack
The bin pack arguments style to use.
Definition Format.h:4277
Options related to packing parameters of function declarations and definitions.
Definition Format.h:4407
BinPackParametersStyle BinPack
The bin pack parameters style to use.
Definition Format.h:4411
bool operator!=(const PackParametersStyle &R) const
Definition Format.h:4436
bool operator==(const PackParametersStyle &R) const
Definition Format.h:4433
unsigned BreakAfter
A parameter list with more parameters than the specified number will be formatted with one parameter ...
Definition Format.h:4431
See documentation of RawStringFormats.
Definition Format.h:4620
std::string CanonicalDelimiter
The canonical delimiter for this language.
Definition Format.h:4628
LanguageKind Language
The language of this raw string.
Definition Format.h:4622
std::string BasedOnStyle
The style name on which this raw string format is based on.
Definition Format.h:4632
std::vector< std::string > EnclosingFunctions
A list of enclosing function names that match this language.
Definition Format.h:4626
bool operator==(const RawStringFormat &Other) const
Definition Format.h:4633
std::vector< std::string > Delimiters
A list of raw string delimiters that match this language.
Definition Format.h:4624
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:5120
bool operator==(const SortIncludesOptions &R) const
Definition Format.h:5143
bool operator!=(const SortIncludesOptions &R) const
Definition Format.h:5148
bool IgnoreCase
Whether or not includes are sorted in a case-insensitive fashion.
Definition Format.h:5102
bool IgnoreExtension
When sorting includes in each block, only take file extensions into account if two includes compare e...
Definition Format.h:5111
bool Enabled
If true, includes are sorted based on the other suboptions below.
Definition Format.h:5090
bool FilesBeforeFolders
When true, sort includes so that files in a directory appear before subdirectories at each level,...
Definition Format.h:5142
Precise control over the spacing before parentheses.
Definition Format.h:5426
bool AfterControlStatements
If true, put space between control statement keywords (for/if/while...) and opening parentheses.
Definition Format.h:5433
bool AfterOverloadedOperator
If true, put a space between operator overloading and opening parentheses.
Definition Format.h:5476
bool AfterRequiresInExpression
If true, put space between requires keyword in a requires expression and opening parentheses.
Definition Format.h:5503
bool AfterFunctionDeclarationName
If true, put a space between function declaration name and opening parentheses.
Definition Format.h:5447
bool AfterRequiresInClause
If true, put space between requires keyword in a requires clause and opening parentheses,...
Definition Format.h:5493
bool AfterForeachMacros
If true, put space between foreach macros and opening parentheses.
Definition Format.h:5440
bool AfterNot
If true, put a space between alternative operator not and the opening parenthesis.
Definition Format.h:5468
bool AfterFunctionDefinitionName
If true, put a space between function definition name and opening parentheses.
Definition Format.h:5454
bool BeforeNonEmptyParentheses
If true, put a space before opening parentheses only if the parentheses are not empty.
Definition Format.h:5511
bool operator==(const SpaceBeforeParensCustom &Other) const
Definition Format.h:5521
bool AfterIfMacros
If true, put space between if macros and opening parentheses.
Definition Format.h:5461
bool AfterPlacementOperator
If true, put a space between operator new/delete and opening parenthesis.
Definition Format.h:5484
If true, spaces may be inserted into C style casts.
Definition Format.h:5709
unsigned Maximum
The maximum number of spaces at the start of the comment.
Definition Format.h:5713
unsigned Minimum
The minimum number of spaces at the start of the comment.
Definition Format.h:5711
Precise control over the spacing in parentheses.
Definition Format.h:5788
bool operator==(const SpacesInParensCustom &R) const
Definition Format.h:5845
bool ExceptDoubleParentheses
Override any of the following options to prevent addition of space when both opening and closing pare...
Definition Format.h:5799
bool Other
Put a space in parentheses not covered by preceding options.
Definition Format.h:5831
bool InEmptyParentheses
Insert a space in empty parentheses, i.e.
Definition Format.h:5825
bool InCStyleCasts
Put a space in C style casts.
Definition Format.h:5814
bool operator!=(const SpacesInParensCustom &R) const
Definition Format.h:5851
bool InConditionalStatements
Put a space in parentheses only inside conditional statements (for/if/while/switch....
Definition Format.h:5807
SpacesInParensCustom(bool ExceptDoubleParentheses, bool InConditionalStatements, bool InCStyleCasts, bool InEmptyParentheses, bool Other)
Definition Format.h:5837
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:6048
@ UT_AlignWithSpaces
Use tabs for line continuation and indentation, and spaces for alignment.
Definition Format.h:6058
@ UT_ForContinuationAndIndentation
Fill all leading whitespace with tabs, and use spaces for alignment that appears within a line (e....
Definition Format.h:6055
@ UT_ForIndentation
Use tabs only for indentation.
Definition Format.h:6052
@ 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:6061
@ UT_Never
Never use tab.
Definition Format.h:6050
bool SpaceBeforeInheritanceColon
If false, spaces will be removed before inheritance colon.
Definition Format.h:5344
unsigned ContinuationIndentWidth
Indent width for line continuations.
Definition Format.h:2889
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:5920
bool BreakAdjacentStringLiterals
Break between adjacent string literals.
Definition Format.h:1706
ReturnTypeBreakingStyle BreakAfterReturnType
The function declaration return type breaking style to use.
Definition Format.h:1863
bool isTableGen() const
Definition Format.h:3877
LanguageKind
Supported languages.
Definition Format.h:3838
@ LK_C
Should be used for C.
Definition Format.h:3842
@ LK_CSharp
Should be used for C#.
Definition Format.h:3846
@ LK_Java
Should be used for Java.
Definition Format.h:3848
@ LK_Cpp
Should be used for C++.
Definition Format.h:3844
@ LK_JavaScript
Should be used for JavaScript.
Definition Format.h:3850
@ LK_ObjC
Should be used for Objective-C, Objective-C++.
Definition Format.h:3854
@ LK_Verilog
Should be used for Verilog and SystemVerilog.
Definition Format.h:3865
@ LK_TableGen
Should be used for TableGen code.
Definition Format.h:3858
@ LK_Proto
Should be used for Protocol Buffers
Definition Format.h:3856
@ LK_Json
Should be used for JSON.
Definition Format.h:3852
@ LK_TextProto
Should be used for Protocol Buffer messages in text format.
Definition Format.h:3861
SortIncludesOptions SortIncludes
Controls if and how clang-format will sort #includes.
Definition Format.h:5155
BreakInheritanceListStyle BreakInheritanceList
The inheritance list style to use.
Definition Format.h:2840
std::string OneLineFormatOffRegex
A regular expression that describes markers for turning formatting off for one line.
Definition Format.h:4245
bool BreakAfterOpenBracketIf
Force break after the left parenthesis of an if control statement when the expression exceeds the col...
Definition Format.h:1839
unsigned IndentWidth
The number of columns to use for indentation.
Definition Format.h:3451
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:5003
@ SDS_Never
Remove any empty line between definition blocks.
Definition Format.h:5009
@ SDS_Always
Insert an empty line between definition blocks.
Definition Format.h:5007
@ SDS_Leave
Leave definition blocks as they are.
Definition Format.h:5005
bool IndentRequiresClause
Indent the requires clause in a template.
Definition Format.h:3437
SpacesInAnglesStyle SpacesInAngles
The SpacesInAnglesStyle to use for template argument lists.
Definition Format.h:5658
bool KeepFormFeed
This option is deprecated.
Definition Format.h:3797
bool IndentCaseLabels
Indent case labels one level from the switch statement.
Definition Format.h:3256
std::vector< RawStringFormat > RawStringFormats
Defines hints for detecting supported languages code blocks in raw strings.
Definition Format.h:4677
std::vector< std::string > VariableTemplates
A vector of non-keyword identifiers that should be interpreted as variable template names.
Definition Format.h:6075
SortJavaStaticImportOptions
Position for Java Static imports.
Definition Format.h:5158
@ SJSIO_Before
Static imports are placed before non-static imports.
Definition Format.h:5165
@ SJSIO_After
Static imports are placed after non-static imports.
Definition Format.h:5172
PPDirectiveIndentStyle IndentPPDirectives
The preprocessor directive indenting style to use.
Definition Format.h:3414
bool RemoveSemicolon
Remove semicolons after the closing braces of functions and constructors/destructors.
Definition Format.h:4871
std::vector< std::string > Macros
A list of macros of the form <definition>=<expansion> .
Definition Format.h:3972
EnumTrailingCommaStyle
Styles for enum trailing commas.
Definition Format.h:3085
@ ETC_Remove
Remove trailing commas.
Definition Format.h:3103
@ ETC_Insert
Insert trailing commas.
Definition Format.h:3097
@ ETC_Leave
Don't insert or remove trailing commas.
Definition Format.h:3091
bool SpaceBeforeJsonColon
If true, a space will be added before a JSON colon.
Definition Format.h:5355
TrailingCommaStyle
The style of inserting trailing commas into container literals.
Definition Format.h:3504
@ TCS_Wrapped
Insert trailing commas in container literals that were wrapped over multiple lines.
Definition Format.h:3512
@ TCS_None
Do not insert trailing commas.
Definition Format.h:3506
unsigned PenaltyBreakBeforeFirstCallParameter
The penalty for breaking a function call after call(.
Definition Format.h:4452
bool SpaceBeforeCtorInitializerColon
If false, spaces will be removed before constructor initializer colon.
Definition Format.h:5328
BinPackParametersStyle
Different ways to try to fit all parameters on a line.
Definition Format.h:4376
@ BPPS_OnePerLine
Put all parameters on the current line if they fit.
Definition Format.h:4392
@ BPPS_UseBreakAfter
Use the BreakAfter option to handle parameter packing instead.
Definition Format.h:4402
@ BPPS_BinPack
Bin-pack parameters.
Definition Format.h:4382
@ BPPS_AlwaysOnePerLine
Always put each parameter on its own line.
Definition Format.h:4399
BinaryOperatorStyle BreakBeforeBinaryOperators
The way to wrap binary operators.
Definition Format.h:1937
bool IndentExportBlock
If true, clang-format will indent the body of an export { ... } block.
Definition Format.h:3269
BinPackStyle
The style of wrapping parameters on the same line (bin-packed) or on one line each.
Definition Format.h:1886
@ BPS_Never
Never bin-pack parameters.
Definition Format.h:1892
@ BPS_Auto
Automatically determine parameter bin-packing behavior.
Definition Format.h:1888
@ BPS_Always
Always bin-pack parameters.
Definition Format.h:1890
BitFieldColonSpacingStyle BitFieldColonSpacing
The BitFieldColonSpacingStyle to use for bitfields.
Definition Format.h:1354
ReflowCommentsStyle
Types of comment reflow style.
Definition Format.h:4706
@ RCS_IndentOnly
Only apply indentation rules, moving comments left or right, without changing formatting inside the c...
Definition Format.h:4723
@ RCS_Never
Leave comments untouched.
Definition Format.h:4714
@ RCS_Always
Apply indentation rules and reflow long comments into new lines, trying to obey the ColumnLimit.
Definition Format.h:4734
EmptyLineBeforeAccessModifierStyle
Different styles for empty line before access modifiers.
Definition Format.h:3022
@ ELBAMS_LogicalBlock
Add empty line only when access modifier starts a new logical block.
Definition Format.h:3057
@ ELBAMS_Never
Remove all empty lines before access modifiers.
Definition Format.h:3037
@ ELBAMS_Always
Always add empty line before access modifiers unless access modifier is at the start of struct or cla...
Definition Format.h:3077
@ ELBAMS_Leave
Keep existing empty lines before access modifiers.
Definition Format.h:3039
unsigned SpacesBeforeTrailingComments
If true, spaces may be inserted into ().
Definition Format.h:5635
BreakConstructorInitializersStyle
Different ways to break initializers.
Definition Format.h:2668
@ BCIS_AfterColon
Break constructor initializers after the colon and commas.
Definition Format.h:2690
@ BCIS_AfterComma
Break constructor initializers only after the commas.
Definition Format.h:2696
@ BCIS_BeforeColon
Break constructor initializers before the colon and after the commas.
Definition Format.h:2675
@ BCIS_BeforeComma
Break constructor initializers before the colon and commas, and align the commas with the colon.
Definition Format.h:2683
IndentExternBlockStyle
Indents extern blocks.
Definition Format.h:3272
@ IEBS_AfterExternBlock
Backwards compatible with AfterExternBlock's indenting.
Definition Format.h:3290
@ IEBS_Indent
Indents extern blocks.
Definition Format.h:3304
@ IEBS_NoIndent
Does not indent extern blocks.
Definition Format.h:3297
bool IndentCaseBlocks
Indent case label blocks one level from the case label.
Definition Format.h:3237
bool InsertBraces
Insert braces after control statements (if, else, for, do, and while) in C++ unless the control state...
Definition Format.h:3497
BreakBeforeConceptDeclarationsStyle BreakBeforeConceptDeclarations
The concept declaration style to use.
Definition Format.h:2459
BreakTemplateDeclarationsStyle BreakTemplateDeclarations
The template declaration breaking style to use.
Definition Format.h:2844
bool DerivePointerAlignment
This option is deprecated.
Definition Format.h:2964
std::vector< std::string > MacrosSkippedByRemoveParentheses
A vector of function-like macros whose invocations should be skipped by RemoveParentheses.
Definition Format.h:3977
BinaryOperatorStyle
The style of breaking before or after binary operators.
Definition Format.h:1896
@ BOS_All
Break before operators.
Definition Format.h:1932
@ BOS_None
Break after operators.
Definition Format.h:1908
@ BOS_NonAssignment
Break before operators that aren't assignments.
Definition Format.h:1920
LineEndingStyle
Line ending style.
Definition Format.h:3889
@ LE_DeriveLF
Use \n unless the input has more lines ending in \r\n.
Definition Format.h:3895
@ LE_DeriveCRLF
Use \r\n unless the input has more lines ending in \n.
Definition Format.h:3897
bool SpacesInSquareBrackets
If true, spaces will be inserted after [ and before ].
Definition Format.h:5881
bool IndentWrappedFunctionNames
Indent if a function definition or declaration is wrapped after the type.
Definition Format.h:3465
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:6139
bool FixNamespaceComments
If true, clang-format adds missing namespace end comments for namespaces and fixes invalid existing o...
Definition Format.h:3146
bool ObjCSpaceBeforeProtocolList
Add a space in front of an Objective-C protocol list, i.e.
Definition Format.h:4220
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:4853
std::string MacroBlockBegin
A regular expression matching macros that start a block.
Definition Format.h:3927
LanguageKind Language
The language that this format style targets.
Definition Format.h:3886
NumericLiteralComponentStyle
Control over each component in a numeric literal.
Definition Format.h:4045
@ NLCS_Lower
Format this component with lowercase characters.
Definition Format.h:4051
@ NLCS_Leave
Leave this component of the literal as is.
Definition Format.h:4047
@ NLCS_Upper
Format this component with uppercase characters.
Definition Format.h:4049
bool BreakBeforeCloseBracketFunction
Force break before the right parenthesis of a function (declaration, definition, call) when the param...
Definition Format.h:2396
SpacesInParensStyle
Different ways to put a space before opening and closing parentheses.
Definition Format.h:5751
@ SIPO_Custom
Configure each individual space in parentheses in SpacesInParensOptions.
Definition Format.h:5763
@ SIPO_Never
Never put a space in parentheses.
Definition Format.h:5760
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:4794
static FormatStyleSet BuildStyleSetFromConfiguration(const FormatStyle &MainStyle, const std::vector< FormatStyle > &ConfigurationStyles)
BreakBeforeInlineASMColonStyle
Different ways to break ASM parameters.
Definition Format.h:2462
@ BBIAS_Always
Always break before inline ASM colon.
Definition Format.h:2483
@ BBIAS_OnlyMultiline
Break before inline ASM colon if the line length is longer than column limit.
Definition Format.h:2476
@ BBIAS_Never
No break before inline ASM colon.
Definition Format.h:2467
bool VerilogBreakBetweenInstancePorts
For Verilog, put each port on its own line in module instantiations.
Definition Format.h:6089
unsigned TabWidth
The number of columns used for tab stops.
Definition Format.h:6005
BreakBeforeReturnTypeStyle BreakBeforeReturnType
The function declaration/definition return type breaking style to use.
Definition Format.h:2513
PPDirectiveIndentStyle
Options for indenting preprocessor directives.
Definition Format.h:3370
@ PPDIS_Leave
Leaves indentation of directives as-is.
Definition Format.h:3409
@ PPDIS_BeforeHash
Indents directives before the hash.
Definition Format.h:3397
@ PPDIS_None
Does not indent any directives.
Definition Format.h:3379
@ PPDIS_AfterHash
Indents directives after the hash.
Definition Format.h:3388
LambdaBodyIndentationKind
Indentation logic for lambda bodies.
Definition Format.h:3800
@ LBI_OuterScope
For statements within block scope, align lambda body relative to the indentation level of the outer s...
Definition Format.h:3822
@ LBI_Signature
Align lambda body relative to the lambda signature.
Definition Format.h:3808
std::vector< std::string > JavaImportGroups
A vector of prefixes ordered by the desired groups for Java imports.
Definition Format.h:3700
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:4464
std::vector< std::string > StatementAttributeLikeMacros
Macros which are ignored in front of a statement, as if they were an attribute.
Definition Format.h:5937
unsigned ObjCBlockIndentWidth
The number of characters to use for indentation of ObjC blocks.
Definition Format.h:4153
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:4617
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:2648
std::vector< std::string > IfMacros
A vector of macros that should be interpreted as conditionals instead of as function calls.
Definition Format.h:3187
bool SpaceBeforeEnumUnderlyingTypeColon
If false, spaces will be removed before enum underlying type colon.
Definition Format.h:5336
NamespaceIndentationKind NamespaceIndentation
The indentation used for namespaces.
Definition Format.h:4029
bool BreakArrays
If true, clang-format will always break after a Json array [ otherwise it will scan until the closing...
Definition Format.h:1882
bool BreakAfterJavaFieldAnnotations
Break after each annotation on a field in Java files.
Definition Format.h:2739
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:4200
bool BreakBeforeCloseBracketBracedList
Force break before the right bracket of a braced initializer list (when Cpp11BracedListStyle is true)...
Definition Format.h:2385
bool ExperimentalAutoDetectBinPacking
If true, clang-format detects whether function calls and definitions are formatted with one parameter...
Definition Format.h:3130
bool ObjCBreakBeforeNestedBlockParam
Break parameters list into lines when there is nested block parameters in a function call.
Definition Format.h:4177
bool BreakFunctionDeclarationParameters
If true, clang-format will always break before function declaration parameters.
Definition Format.h:2715
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:4468
bool BreakAfterOpenBracketLoop
Force break after the left parenthesis of a loop control statement when the expression exceeds the co...
Definition Format.h:1849
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:2510
unsigned PenaltyBreakBeforeMemberAccess
The penalty for breaking before a member access operator (.
Definition Format.h:4456
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:5777
SpacesInParensCustom SpacesInParensOptions
Control of individual spaces in parentheses.
Definition Format.h:5870
std::vector< std::string > ForEachMacros
A vector of macros that should be interpreted as foreach loops instead of as function calls.
Definition Format.h:3164
ReferenceAlignmentStyle ReferenceAlignment
Reference alignment style (overrides PointerAlignment for references).
Definition Format.h:4702
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:3531
unsigned PenaltyBreakTemplateDeclaration
The penalty for breaking after template declaration.
Definition Format.h:4480
SpaceBeforeParensCustom SpaceBeforeParensOptions
Control of individual space before parentheses.
Definition Format.h:5550
BreakConstructorInitializersStyle BreakConstructorInitializers
The break constructor initializers style to use.
Definition Format.h:2701
bool RemoveEmptyLinesInUnwrappedLines
Remove empty lines within unwrapped lines.
Definition Format.h:4817
bool BreakStringLiterals
Allow breaking string literals when formatting.
Definition Format.h:2782
bool SpaceAfterLogicalNot
If true, a space is inserted after the logical not operator (!).
Definition Format.h:5239
SpaceBeforeParensStyle
Different ways to put a space before opening parentheses.
Definition Format.h:5358
@ SBPO_Never
This is deprecated and replaced by Custom below, with all SpaceBeforeParensOptions but AfterPlacement...
Definition Format.h:5362
@ SBPO_Custom
Configure each individual space before parentheses in SpaceBeforeParensOptions.
Definition Format.h:5411
@ SBPO_NonEmptyParentheses
Put a space before opening parentheses only if the parentheses are not empty.
Definition Format.h:5396
@ SBPO_ControlStatementsExceptControlMacros
Same as SBPO_ControlStatements except this option doesn't apply to ForEach and If macros.
Definition Format.h:5385
@ SBPO_ControlStatements
Put a space before opening parentheses only after control statement keywords (for/if/while....
Definition Format.h:5372
@ SBPO_Always
Always put a space before opening parentheses, except when it's prohibited by the syntax rules (in fu...
Definition Format.h:5408
PackConstructorInitializersStyle
Different ways to try to fit all constructor initializers on a line.
Definition Format.h:4314
@ PCIS_NextLineOnly
Put all constructor initializers on the next line if they fit.
Definition Format.h:4368
@ PCIS_Never
Always put each constructor initializer on its own line.
Definition Format.h:4321
@ PCIS_CurrentLine
Put all constructor initializers on the current line if they fit.
Definition Format.h:4339
@ PCIS_BinPack
Bin-pack constructor initializers.
Definition Format.h:4328
@ PCIS_NextLine
Same as PCIS_CurrentLine except that if all constructor initializers do not fit on the current line,...
Definition Format.h:4353
std::vector< std::string > TypeNames
A vector of non-keyword identifiers that should be interpreted as type names.
Definition Format.h:6024
bool isTextProto() const
Definition Format.h:3875
bool ObjCSpaceAfterProperty
Add a space after @property in Objective-C, i.e.
Definition Format.h:4215
BreakBeforeReturnTypeStyle
Different ways to break before the function return type.
Definition Format.h:2491
@ BBRTS_None
Do not force a break before the return type.
Definition Format.h:2493
@ BBRTS_TopLevelDefinitions
Break before the return type of top-level definitions only.
Definition Format.h:2505
@ BBRTS_TopLevel
Break before the return type of top-level functions only.
Definition Format.h:2501
@ BBRTS_All
Always break before the return type.
Definition Format.h:2499
@ BBRTS_AllDefinitions
Break before the return type of function definitions only.
Definition Format.h:2503
bool BreakAfterOpenBracketSwitch
Force break after the left parenthesis of a switch control statement when the expression exceeds the ...
Definition Format.h:1859
BraceBreakingStyle BreakBeforeBraces
The brace breaking style to use.
Definition Format.h:2372
BreakInheritanceListStyle
Different ways to break inheritance list.
Definition Format.h:2803
@ BILS_AfterColon
Break inheritance list after the colon and commas.
Definition Format.h:2828
@ BILS_AfterComma
Break inheritance list only after the commas.
Definition Format.h:2835
@ BILS_BeforeColon
Break inheritance list before the colon and after the commas.
Definition Format.h:2811
@ BILS_BeforeComma
Break inheritance list before the colon and commas, and align the commas with the colon.
Definition Format.h:2820
SpacesInBlockCommentsStyle
Styles for controlling spacing after /* and before `.
Definition Format.h:5662
@ SIBCS_Always
Add spaces after /* and before `.
Definition Format.h:5672
@ SIBCS_Leave
Leave existing spaces unchanged.
Definition Format.h:5674
@ SIBCS_Never
Remove spaces after /* and before `.
Definition Format.h:5667
unsigned PenaltyExcessCharacter
The penalty for each character outside of the column limit.
Definition Format.h:4484
std::vector< std::string > WhitespaceSensitiveMacros
A vector of macros which are whitespace-sensitive and should not be touched.
Definition Format.h:6106
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:6014
DAGArgStyle
Different ways to control the format inside TableGen DAGArg.
Definition Format.h:5976
@ DAS_BreakElements
Break inside DAGArg after each list element but for the last.
Definition Format.h:5988
@ DAS_DontBreak
Never break inside DAGArg.
Definition Format.h:5981
@ DAS_BreakAll
Break inside DAGArg after the operator and the all elements.
Definition Format.h:5996
unsigned ConstructorInitializerIndentWidth
This option is deprecated.
Definition Format.h:2878
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:2868
RequiresClausePositionStyle
The possible positions for the requires clause.
Definition Format.h:4875
@ RCPS_OwnLineWithBrace
As with OwnLine, except, unless otherwise prohibited, place a following open brace (of a function def...
Definition Format.h:4914
@ RCPS_OwnLine
Always put the requires clause on its own line (possibly followed by a semicolon).
Definition Format.h:4896
@ RCPS_WithPreceding
Try to put the clause together with the preceding part of a declaration.
Definition Format.h:4931
@ RCPS_SingleLine
Try to put everything in the same line if possible.
Definition Format.h:4969
@ RCPS_WithFollowing
Try to put the requires clause together with the class or function declaration.
Definition Format.h:4945
bool BreakBeforeCloseBracketSwitch
Force break before the right parenthesis of a switch control statement when the expression exceeds th...
Definition Format.h:2435
bool operator==(const FormatStyle &R) const
Definition Format.h:6141
LanguageStandard
Supported language standards for parsing and formatting C++ constructs.
Definition Format.h:5891
@ LS_Cpp17
Parse and format as C++17.
Definition Format.h:5900
@ LS_Cpp26
Parse and format as C++26.
Definition Format.h:5906
@ LS_Cpp23
Parse and format as C++23.
Definition Format.h:5904
@ LS_Latest
Parse and format using the latest supported language version.
Definition Format.h:5909
@ LS_Cpp11
Parse and format as C++11.
Definition Format.h:5896
@ LS_Auto
Automatic detection based on the input.
Definition Format.h:5911
@ LS_Cpp03
Parse and format as C++03.
Definition Format.h:5894
@ LS_Cpp14
Parse and format as C++14.
Definition Format.h:5898
@ LS_Cpp20
Parse and format as C++20.
Definition Format.h:5902
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:4974
JavaScriptQuoteStyle
Quotation styles for JavaScript strings.
Definition Format.h:3704
@ JSQS_Double
Always use double quotes.
Definition Format.h:3722
@ JSQS_Single
Always use single quotes.
Definition Format.h:3716
@ JSQS_Leave
Leave string quotes as they are.
Definition Format.h:3710
bool SpaceAfterCStyleCast
If true, a space is inserted after C style casts.
Definition Format.h:5231
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:4531
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:3666
SpaceAroundPointerQualifiersStyle SpaceAroundPointerQualifiers
Defines in which cases to put a space before or after pointer qualifiers.
Definition Format.h:5288
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:5297
BreakBeforeInlineASMColonStyle BreakBeforeInlineASMColon
The inline ASM colon style to use.
Definition Format.h:2488
WrapNamespaceBodyWithEmptyLinesStyle
Different styles for wrapping namespace body with empty lines.
Definition Format.h:6109
@ 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:6131
@ WNBWELS_Leave
Keep existing newlines at the beginning and the end of namespace body.
Definition Format.h:6134
@ WNBWELS_Never
Remove all empty lines at the beginning and the end of namespace body.
Definition Format.h:6118
SpaceInEmptyBracesStyle SpaceInEmptyBraces
Specifies when to insert a space in empty braces.
Definition Format.h:5609
BraceBreakingStyle
Different ways to attach braces to their surrounding context.
Definition Format.h:1940
@ BS_Mozilla
Like Attach, but break before braces on enum, function, and record definitions.
Definition Format.h:2085
@ BS_Whitesmiths
Like Allman but always indent braces and line up code with braces.
Definition Format.h:2255
@ BS_Allman
Always break before braces.
Definition Format.h:2195
@ BS_Stroustrup
Like Attach, but break before function definitions, catch, and else.
Definition Format.h:2135
@ BS_Linux
Like Attach, but break before braces on function, namespace and class definitions.
Definition Format.h:2035
@ BS_WebKit
Like Attach, but break before functions.
Definition Format.h:2365
@ BS_Custom
Configure each individual brace in BraceWrapping.
Definition Format.h:2367
@ BS_GNU
Always break before braces and add an extra level of indentation to braces of control statements,...
Definition Format.h:2318
@ BS_Attach
Always attach braces to surrounding context.
Definition Format.h:1985
bool ObjCSpaceAfterMethodDeclarationPrefix
Add or remove a space between the '-'/'+' and the return type in Objective-C method declarations.
Definition Format.h:4210
AttributeBreakingStyle
Different ways to break after the last attribute of a group before a declaration or control statement...
Definition Format.h:1710
@ ABS_Leave
Leave the line breaking after the last attribute of the group as is.
Definition Format.h:1764
@ ABS_Never
Never break after the last attribute of the group.
Definition Format.h:1800
@ ABS_Always
Always break after the last attribute of the group.
Definition Format.h:1739
@ ABS_LeaveAll
Same as Leave except that it applies to all attributes of the group.
Definition Format.h:1778
bool BreakBeforeCloseBracketLoop
Force break before the right parenthesis of a loop control statement when the expression exceeds the ...
Definition Format.h:2422
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:4472
unsigned PenaltyReturnTypeOnItsOwnLine
Penalty for putting the return type of a function onto its own line.
Definition Format.h:4493
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:4516
bool BreakBeforeTemplateCloser
If true, break before a template closing bracket (>) when there is a line break after the matching op...
Definition Format.h:2540
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:4444
bool BreakFunctionDefinitionParameters
If true, clang-format will always break before function definition parameters.
Definition Format.h:2729
RequiresExpressionIndentationKind
Indentation logic for requires expression bodies.
Definition Format.h:4977
@ REI_Keyword
Align requires expression body relative to the requires keyword.
Definition Format.h:4995
@ REI_OuterScope
Align requires expression body relative to the indentation level of the outer scope the requires expr...
Definition Format.h:4987
PackConstructorInitializersStyle PackConstructorInitializers
The pack constructor initializers style to use.
Definition Format.h:4373
BreakBeforeConceptDeclarationsStyle
Different ways to break before concept declarations.
Definition Format.h:2438
@ BBCDS_Allowed
Breaking between template declaration and concept is allowed.
Definition Format.h:2447
@ BBCDS_Never
Keep the template declaration line together with concept.
Definition Format.h:2443
@ BBCDS_Always
Always break before concept, putting it in the line after the template declaration.
Definition Format.h:2454
ReflowCommentsStyle ReflowComments
Comment reformatting style.
Definition Format.h:4740
KeepEmptyLinesStyle KeepEmptyLines
Which empty lines are kept.
Definition Format.h:3780
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:2892
@ BLS_AlignFirstComment
Same as FunctionCall, except for the handling of a comment at the begin, it then aligns everything fo...
Definition Format.h:2946
@ BLS_FunctionCall
Best suited for C++11 braced lists.
Definition Format.h:2928
@ BLS_Block
Best suited for pre C++11 braced lists.
Definition Format.h:2908
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:2409
unsigned MaxEmptyLinesToKeep
The maximum number of consecutive empty lines to keep.
Definition Format.h:3991
bool SpaceBeforeSquareBrackets
If true, spaces will be before [.
Definition Format.h:5560
BinPackStyle ObjCBinPackProtocolList
Controls bin-packing Objective-C protocol conformance list items into as few lines as possible when t...
Definition Format.h:4142
PackArgumentsStyle PackArguments
Options related to packing arguments of function calls.
Definition Format.h:4311
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:5748
std::string CommentPragmas
A regular expression that describes comments with special meaning, which should not be split into lin...
Definition Format.h:2800
bool isJavaScript() const
Definition Format.h:3873
DAGArgStyle TableGenBreakInsideDAGArg
The styles of the line break inside the DAGArg in TableGen.
Definition Format.h:6001
JavaScriptQuoteStyle JavaScriptQuotes
The JavaScriptQuoteStyle to use for JavaScript strings.
Definition Format.h:3727
bool SpacesInContainerLiterals
If true, spaces will be inserted around if/for/switch/while conditions.
Definition Format.h:5700
SortJavaStaticImportOptions SortJavaStaticImport
When sorting Java imports, by default static imports are placed before non-static imports.
Definition Format.h:5179
BreakBinaryOperationsOptions BreakBinaryOperations
The break binary operations style to use.
Definition Format.h:2665
SpaceAroundPointerQualifiersStyle
Different ways to put a space before opening parentheses.
Definition Format.h:5258
@ SAPQ_After
Ensure that there is a space after pointer qualifiers.
Definition Format.h:5277
@ SAPQ_Default
Don't ensure spaces around pointer qualifiers and use PointerAlignment instead.
Definition Format.h:5265
@ SAPQ_Both
Ensure that there is a space both before and after pointer qualifiers.
Definition Format.h:5283
@ SAPQ_Before
Ensure that there is a space before pointer qualifiers.
Definition Format.h:5271
bool SpaceBeforeRangeBasedForLoopColon
If false, spaces will be removed before range-based for loop colon.
Definition Format.h:5569
bool DisableFormat
Disables formatting completely.
Definition Format.h:2968
EmptyLineAfterAccessModifierStyle
Different styles for empty line after access modifiers.
Definition Format.h:2973
@ ELAAMS_Always
Always add empty line after access modifiers if there are none.
Definition Format.h:3012
@ ELAAMS_Never
Remove all empty lines after access modifiers.
Definition Format.h:2988
@ ELAAMS_Leave
Keep existing empty lines after access modifiers.
Definition Format.h:2991
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:4042
AttributeBreakingStyle BreakAfterAttributes
Break after a group of C++11 attributes before variable or function (including constructor/destructor...
Definition Format.h:1808
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:3831
QualifierAlignmentStyle QualifierAlignment
Different ways to arrange specifiers and qualifiers (e.g.
Definition Format.h:4577
BreakBinaryOperationsStyle
Different ways to break binary operations.
Definition Format.h:2558
@ BBO_OnePerLine
Binary operations will either be all on the same line, or each operation will have one line each.
Definition Format.h:2575
@ BBO_Never
Don't break binary operations.
Definition Format.h:2564
@ BBO_RespectPrecedence
Binary operations of a particular precedence that exceed the column limit will have one line each.
Definition Format.h:2585
BraceWrappingFlags BraceWrapping
Control of individual brace wrapping cases.
Definition Format.h:1693
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:5947
SpacesInAnglesStyle
Styles for adding spacing after < and before > in template argument lists.
Definition Format.h:5639
@ SIAS_Never
Remove spaces after < and before >.
Definition Format.h:5645
@ SIAS_Always
Add spaces after < and before >.
Definition Format.h:5651
@ SIAS_Leave
Keep a single space after < and before > if any spaces were present.
Definition Format.h:5654
BinPackArgumentsStyle
Different ways to try to fit all arguments on a line.
Definition Format.h:4248
@ BPAS_OnePerLine
Put all arguments on the current line if they fit.
Definition Format.h:4266
@ BPAS_BinPack
Bin-pack arguments.
Definition Format.h:4256
@ BPAS_UseBreakAfter
Use the BreakAfter option to handle argument packing instead.
Definition Format.h:4269
SortUsingDeclarationsOptions
Using declaration sorting options.
Definition Format.h:5182
@ SUD_LexicographicNumeric
Using declarations are sorted in the order defined as follows: Split the strings by :: and discard an...
Definition Format.h:5218
@ SUD_Lexicographic
Using declarations are sorted in the order defined as follows: Split the strings by :: and discard an...
Definition Format.h:5203
@ SUD_Never
Using declarations are never sorted.
Definition Format.h:5191
AlignConsecutiveStyle AlignConsecutiveAssignments
Style of aligning consecutive assignments.
Definition Format.h:286
SpaceInEmptyBracesStyle
This option is deprecated.
Definition Format.h:5576
@ SIEB_Always
Always insert a space in empty braces.
Definition Format.h:5584
@ SIEB_Block
Only insert a space in empty blocks.
Definition Format.h:5592
@ SIEB_Never
Never insert a space in empty braces.
Definition Format.h:5600
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:4820
@ RPS_Leave
Do not remove parentheses.
Definition Format.h:4827
@ RPS_ReturnStatement
Also remove parentheses enclosing the expression in a return/co_return statement.
Definition Format.h:4842
@ RPS_MultipleParentheses
Replace multiple parentheses with single parentheses.
Definition Format.h:4834
std::vector< std::string > TableGenBreakingDAGArgOperators
Works only when TableGenBreakInsideDAGArg is not DontBreak.
Definition Format.h:5973
EmptyLineBeforeAccessModifierStyle EmptyLineBeforeAccessModifier
Defines in which cases to put empty line before access modifiers.
Definition Format.h:3082
EnumTrailingCommaStyle EnumTrailingComma
Insert a comma (if missing) or remove the comma at the end of an enum enumerator list.
Definition Format.h:3115
bool SpaceBeforeCaseColon
If false, spaces will be removed before case colon.
Definition Format.h:5307
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:3743
bool BreakAfterOpenBracketFunction
Force break after the left parenthesis of a function (declaration, definition, call) when the paramet...
Definition Format.h:1829
bool SkipMacroDefinitionBody
Do not format macro definition body.
Definition Format.h:5084
unsigned PenaltyBreakAssignment
The penalty for breaking around an assignment operator.
Definition Format.h:4448
PointerAlignmentStyle
The &, && and * alignment style.
Definition Format.h:4496
@ PAS_Left
Align pointer to the left.
Definition Format.h:4501
@ PAS_Middle
Align pointer in the middle.
Definition Format.h:4511
@ PAS_Right
Align pointer to the right.
Definition Format.h:4506
unsigned PenaltyBreakString
The penalty for each line break introduced inside a string literal.
Definition Format.h:4476
RequiresExpressionIndentationKind RequiresExpressionIndentation
The indentation used for requires expression bodies.
Definition Format.h:5000
IndentGotoLabelStyle IndentGotoLabels
The goto label indenting style to use.
Definition Format.h:3367
bool SpaceAfterTemplateKeyword
If true, a space will be inserted after the template keyword.
Definition Format.h:5255
unsigned PenaltyIndentedWhitespace
Penalty for each character of whitespace indentation (counted relative to leading non-whitespace colu...
Definition Format.h:4489
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:3994
@ NI_None
Don't indent in namespaces.
Definition Format.h:4004
@ NI_All
Indent in all namespaces.
Definition Format.h:4024
@ NI_Inner
Indent only in inner namespaces (nested in other namespaces).
Definition Format.h:4014
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:3931
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:4460
bool SpaceAfterOperatorKeyword
If true, a space will be inserted after the operator keyword.
Definition Format.h:5247
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:4680
@ RAS_Right
Align reference to the right.
Definition Format.h:4692
@ RAS_Left
Align reference to the left.
Definition Format.h:4687
@ RAS_Pointer
Align reference like PointerAlignment.
Definition Format.h:4682
@ RAS_Middle
Align reference in the middle.
Definition Format.h:4697
EmptyLineAfterAccessModifierStyle EmptyLineAfterAccessModifier
Defines when to put an empty line after access modifiers.
Definition Format.h:3019
IndentGotoLabelStyle
Options for indenting goto labels.
Definition Format.h:3312
@ IGLS_InnerIndent
Indent goto labels to the surrounding statements (current indenting level).
Definition Format.h:3349
@ IGLS_OuterIndent
Indent goto labels to the enclosing block (previous indenting level).
Definition Format.h:3336
@ IGLS_HalfIndent
Indent goto labels to half the indentation of the surrounding code.
Definition Format.h:3362
@ IGLS_NoIndent
Do not indent goto labels.
Definition Format.h:3324
bool IndentAccessModifiers
Specify whether access modifiers should have their own indentation level.
Definition Format.h:3214
bool InsertNewlineAtEOF
Insert a newline at end of file if missing.
Definition Format.h:3501
SpaceBeforeParensStyle SpaceBeforeParens
Defines in which cases to put a space before opening parentheses.
Definition Format.h:5416
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:5319
NumericLiteralCaseStyle NumericLiteralCase
Capitalization style for numeric literals.
Definition Format.h:4109
UseTabStyle UseTab
The way to use tab characters in the resulting file.
Definition Format.h:6066
QualifierAlignmentStyle
Different specifiers and qualifiers alignment styles.
Definition Format.h:4534
@ QAS_Right
Change specifiers/qualifiers to be right-aligned.
Definition Format.h:4553
@ QAS_Custom
Change specifiers/qualifiers to be aligned based on QualifierOrder.
Definition Format.h:4565
@ QAS_Left
Change specifiers/qualifiers to be left-aligned.
Definition Format.h:4547
@ QAS_Leave
Don't change specifiers/qualifiers to either Left or Right alignment (default).
Definition Format.h:4541
std::vector< std::string > TypenameMacros
A vector of macros that should be interpreted as type declarations instead of as function calls.
Definition Format.h:6041
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:3902
bool BreakAfterOpenBracketBracedList
Force break after the left bracket of a braced initializer list (when Cpp11BracedListStyle is true) w...
Definition Format.h:1819
bool BreakBeforeTernaryOperators
If true, ternary operators will be placed after line breaks.
Definition Format.h:2555
BracedListStyle Cpp11BracedListStyle
The style to handle braced lists.
Definition Format.h:2951
unsigned ShortNamespaceLines
The maximal number of unwrapped lines that a short namespace spans.
Definition Format.h:5080
SortUsingDeclarationsOptions SortUsingDeclarations
Controls if and how clang-format will sort using declarations.
Definition Format.h:5223
IndentExternBlockStyle IndentExternBlock
IndentExternBlockStyle is the type of indenting of extern blocks.
Definition Format.h:3309
SeparateDefinitionStyle SeparateDefinitionBlocks
Specifies the use of empty lines to separate definition blocks, including classes,...
Definition Format.h:5058
tooling::IncludeStyle IncludeStyle
Definition Format.h:3166
unsigned ColumnLimit
The column limit.
Definition Format.h:2790
Represents the status of a formatting attempt.
Definition Format.h:6514
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:6517
unsigned Line
If FormatComplete is false, Line records a one-based original line number at which a syntax error mig...
Definition Format.h:6522
Style for sorting and grouping C++ include directives.