Skip to content

Commit 8864382

Browse files
committed
[clang-format] Update style documentation, NFC
Summary: Style documentation is generated automatically by `docs/tools/dump_format_style.py`. This hasn't been ran for a while. Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D34457 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306089 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 742c4c8 commit 8864382

File tree

2 files changed

+101
-19
lines changed

2 files changed

+101
-19
lines changed

docs/ClangFormatStyleOptions.rst

+96-13
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,28 @@ the configuration (without a prefix: ``Auto``).
309309
* ``SFS_None`` (in configuration: ``None``)
310310
Never merge functions into a single line.
311311

312+
* ``SFS_InlineOnly`` (in configuration: ``InlineOnly``)
313+
Only merge functions defined inside a class. Same as "inline",
314+
except it does not implies "empty": i.e. top level empty functions
315+
are not merged either.
316+
317+
.. code-block:: c++
318+
319+
class Foo {
320+
void f() { foo(); }
321+
};
322+
void f() {
323+
foo();
324+
}
325+
void f() {
326+
}
327+
312328
* ``SFS_Empty`` (in configuration: ``Empty``)
313329
Only merge empty functions.
314330

315331
.. code-block:: c++
316332

317-
void f() { bar(); }
333+
void f() {}
318334
void f2() {
319335
bar2();
320336
}
@@ -327,6 +343,10 @@ the configuration (without a prefix: ``Auto``).
327343
class Foo {
328344
void f() { foo(); }
329345
};
346+
void f() {
347+
foo();
348+
}
349+
void f() {}
330350

331351
* ``SFS_All`` (in configuration: ``All``)
332352
Merge all functions fitting on a single line.
@@ -521,11 +541,11 @@ the configuration (without a prefix: ``Auto``).
521541
.. code-block:: c++
522542

523543
true:
524-
class foo
525-
{};
544+
class foo {};
526545

527546
false:
528-
class foo {};
547+
class foo
548+
{};
529549

530550
* ``bool AfterControlStatement`` Wrap control statements (``if``/``for``/``while``/``switch``/..).
531551

@@ -659,6 +679,18 @@ the configuration (without a prefix: ``Auto``).
659679

660680
* ``bool IndentBraces`` Indent the wrapped braces themselves.
661681

682+
* ``bool SplitEmptyFunctionBody`` If ``false``, empty function body can be put on a single line.
683+
This option is used only if the opening brace of the function has
684+
already been wrapped, i.e. the `AfterFunction` brace wrapping mode is
685+
set, and the function could/should not be put on a single line (as per
686+
`AllowShortFunctionsOnASingleLine` and constructor formatting options).
687+
688+
.. code-block:: c++
689+
690+
int f() vs. inf f()
691+
{} {
692+
}
693+
662694

663695
**BreakAfterJavaFieldAnnotations** (``bool``)
664696
Break after each annotation on a field in Java files.
@@ -899,17 +931,40 @@ the configuration (without a prefix: ``Auto``).
899931
firstValue :
900932
SecondValueVeryVeryVeryVeryLong;
901933

902-
**BreakConstructorInitializersBeforeComma** (``bool``)
903-
Always break constructor initializers before commas and align
904-
the commas with the colon.
934+
**BreakConstructorInitializers** (``BreakConstructorInitializersStyle``)
935+
The constructor initializers style to use.
936+
937+
Possible values:
938+
939+
* ``BCIS_BeforeColon`` (in configuration: ``BeforeColon``)
940+
Break constructor initializers before the colon and after the commas.
941+
942+
.. code-block:: c++
943+
944+
Constructor()
945+
: initializer1(),
946+
initializer2()
947+
948+
* ``BCIS_BeforeComma`` (in configuration: ``BeforeComma``)
949+
Break constructor initializers before the colon and commas, and align
950+
the commas with the colon.
951+
952+
.. code-block:: c++
953+
954+
Constructor()
955+
: initializer1()
956+
, initializer2()
957+
958+
* ``BCIS_AfterColon`` (in configuration: ``AfterColon``)
959+
Break constructor initializers after the colon and commas.
960+
961+
.. code-block:: c++
962+
963+
Constructor() :
964+
initializer1(),
965+
initializer2()
905966

906-
.. code-block:: c++
907967

908-
true: false:
909-
SomeClass::Constructor() vs. SomeClass::Constructor() : a(a),
910-
: a(a) b(b),
911-
, b(b) c(c) {}
912-
, c(c) {}
913968

914969
**BreakStringLiterals** (``bool``)
915970
Allow breaking string literals when formatting.
@@ -931,6 +986,31 @@ the configuration (without a prefix: ``Auto``).
931986
// Will leave the following line unaffected
932987
#include <vector> // FOOBAR pragma: keep
933988

989+
**CompactNamespaces** (``bool``)
990+
If ``true``, consecutive namespace declarations will be on the same
991+
line. If ``false``, each namespace is declared on a new line.
992+
993+
.. code-block:: c++
994+
995+
true:
996+
namespace Foo { namespace Bar {
997+
}}
998+
999+
false:
1000+
namespace Foo {
1001+
namespace Bar {
1002+
}
1003+
}
1004+
1005+
If it does not fit on a single line, the overflowing namespaces get
1006+
wrapped:
1007+
1008+
.. code-block:: c++
1009+
1010+
namespace Foo { namespace Bar {
1011+
namespace Extra {
1012+
}}}
1013+
9341014
**ConstructorInitializerAllOnOneLineOrOnePerLine** (``bool``)
9351015
If the constructor initializers don't fit on a line, put each
9361016
initializer on its own line.
@@ -1321,6 +1401,9 @@ the configuration (without a prefix: ``Auto``).
13211401
Add a space in front of an Objective-C protocol list, i.e. use
13221402
``Foo <Protocol>`` instead of ``Foo<Protocol>``.
13231403

1404+
**PenaltyBreakAssignment** (``unsigned``)
1405+
The penalty for breaking around an assignment operator.
1406+
13241407
**PenaltyBreakBeforeFirstCallParameter** (``unsigned``)
13251408
The penalty for breaking a function call after ``call(``.
13261409

include/clang/Format/Format.h

+5-6
Original file line numberDiff line numberDiff line change
@@ -652,12 +652,12 @@ struct FormatStyle {
652652
/// struct foo
653653
/// {
654654
/// int x;
655-
/// }
655+
/// };
656656
///
657657
/// false:
658658
/// struct foo {
659659
/// int x;
660-
/// }
660+
/// };
661661
/// \endcode
662662
bool AfterStruct;
663663
/// \brief Wrap union definitions.
@@ -733,16 +733,15 @@ struct FormatStyle {
733733
/// ? firstValue
734734
/// : SecondValueVeryVeryVeryVeryLong;
735735
///
736-
/// true:
736+
/// false:
737737
/// veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ?
738738
/// firstValue :
739739
/// SecondValueVeryVeryVeryVeryLong;
740740
/// \endcode
741741
bool BreakBeforeTernaryOperators;
742742

743743
/// \brief Different ways to break initializers.
744-
enum BreakConstructorInitializersStyle
745-
{
744+
enum BreakConstructorInitializersStyle {
746745
/// Break constructor initializers before the colon and after the commas.
747746
/// \code
748747
/// Constructor()
@@ -767,7 +766,7 @@ struct FormatStyle {
767766
BCIS_AfterColon
768767
};
769768

770-
/// \brief The constructor initializers style to use..
769+
/// \brief The constructor initializers style to use.
771770
BreakConstructorInitializersStyle BreakConstructorInitializers;
772771

773772
/// \brief Break after each annotation on a field in Java files.

0 commit comments

Comments
 (0)