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