Skip to content

Commit a63b4e3

Browse files
author
MarcoFalke
committed
Merge #12982: Fix inconsistent namespace formatting guidelines
cd0e1e9 Fix inconsistent namespace formatting guidelines (Russell Yanofsky) Pull request description: Suggested formatting for namespaces in the developer guide is currently inconsistent. This commit updates the developer guide and clang-format configuration to consistently put "namespace" and opening/closing braces on the same line. Example: ```c++ namespace boost { namespace signals2 { class connection; } // namespace signals2 } // namespace boost ``` Currently the [Source code organization](https://github.com/bitcoin/bitcoin/blob/master/doc/developer-notes.md#source-code-organization) section has an example like the one above, but the [Coding style](https://github.com/bitcoin/bitcoin/blob/master/doc/developer-notes.md#coding-style) section example and description put a newline between the opening "namespace foo" and brace (but oddly no newline between closing namespace and brace). Avoiding newlines before namespace opening braces makes nested declarations less verbose and also avoids asymmetry with closing braces. It's also a common style used in our own and other codebases: * https://google.github.io/styleguide/cppguide.html#Namespaces * https://developer.mozilla.org/en-US/docs/Mozilla/Developer_guide/Coding_Style#Classes * https://llvm.org/docs/CodingStandards.html#namespace-indentation Tree-SHA512: 507259478e1a7f6f96db386dd04eb25aa04294f533503fdd82368cf809c3ceaa20204b2cb6ae65322eb27446e5934c1aa1ccb6240ead12aa06b314af76f68139
2 parents 58bbc55 + cd0e1e9 commit a63b4e3

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

doc/developer-notes.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Do not submit patches solely to modify the style of existing code.
5050
[src/.clang-format](/src/.clang-format). You can use the provided
5151
[clang-format-diff script](/contrib/devtools/README.md#clang-format-diffpy)
5252
tool to clean up patches automatically before submission.
53-
- Braces on new lines for namespaces, classes, functions, methods.
53+
- Braces on new lines for classes, functions, methods.
5454
- Braces on the same line for everything else.
5555
- 4 space indentation (no tabs) for every block except namespaces.
5656
- No indentation for `public`/`protected`/`private` or for `namespace`.
@@ -85,8 +85,7 @@ Block style example:
8585
```c++
8686
int g_count = 0;
8787

88-
namespace foo
89-
{
88+
namespace foo {
9089
class Class
9190
{
9291
std::string m_name;
@@ -585,11 +584,11 @@ Source code organization
585584
586585
```c++
587586
namespace mynamespace {
588-
...
587+
...
589588
} // namespace mynamespace
590589
591590
namespace {
592-
...
591+
...
593592
} // namespace
594593
```
595594

src/.clang-format

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ AlwaysBreakBeforeMultilineStrings: false
1212
AlwaysBreakTemplateDeclarations: true
1313
BinPackParameters: false
1414
BreakBeforeBinaryOperators: false
15-
BreakBeforeBraces: Linux
15+
BreakBeforeBraces: Custom
16+
BraceWrapping:
17+
AfterClass: true
18+
AfterFunction: true
1619
BreakBeforeTernaryOperators: false
1720
BreakConstructorInitializersBeforeComma: false
1821
ColumnLimit: 0

0 commit comments

Comments
 (0)