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