aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorphunkyfish <phunkyfish@gmail.com>2019-10-02 17:02:17 +0100
committerphunkyfish <phunkyfish@gmail.com>2019-10-06 09:10:20 +0100
commitd0dd36c61ed2613af812e1b6b40480c83927442f (patch)
treebb273aa43b96a61b25ba28300ea5fae521294dde
parentd1628d4bf5f0a377186960a273e930831b4953ed (diff)
[clang-format] change constructor init list to colon on newline, break after comma for longer lines
-rw-r--r--.clang-format5
-rw-r--r--docs/CODE_GUIDELINES.md29
2 files changed, 32 insertions, 2 deletions
diff --git a/.clang-format b/.clang-format
index c0ec891d43..02f730e6d6 100644
--- a/.clang-format
+++ b/.clang-format
@@ -22,12 +22,13 @@ BinPackParameters: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Allman
BreakBeforeTernaryOperators: true
-BreakConstructorInitializersBeforeComma: true
+BreakConstructorInitializersBeforeComma: false
+BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 100
CommentPragmas: '^ IWYU pragma:'
-ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
diff --git a/docs/CODE_GUIDELINES.md b/docs/CODE_GUIDELINES.md
index 63f1a5195a..07c12991fe 100644
--- a/docs/CODE_GUIDELINES.md
+++ b/docs/CODE_GUIDELINES.md
@@ -44,6 +44,7 @@
* [11.3. Overriding virtual functions](#113-overriding-virtual-functions)
* [11.4. Default member initialization](#114-default-member-initialization)
* [11.5. Destructors in interfaces](#115-destructors-in-interfaces)
+ * [11.6. Constructor Initialzation Lists](#116-constructor-initialzation-lists)
* [12. Other conventions](#12-other-conventions)
* [12.1. Output parameters](#121-output-parameters)
* [12.2. Casts](#122-casts)
@@ -73,6 +74,9 @@ We currently target the C++11 language standard. Do use C++11 features when poss
## 3. Formatting
+### Line length
+The `ColumnLimit` in `.clang-format` is set to `100` which defines line length (in general where lines should be broken) that allows two editors side by side on a 1080p screen for diffs.
+
### 3.1. Braces
Curly braces always go on a new line.
@@ -632,6 +636,31 @@ class Foo
A class with any virtual functions should have a destructor that is either public and virtual or else protected and nonvirtual (cf. [ISO C++ guidelines](http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-dtor-virtual)).
+### 11.6. Constructor Initialzation Lists
+
+For lines up to [line length](#line-length) everything stays on one line, excluding the braces which must be on the following lines.
+
+```cpp
+MyClass::CMyClass(bool bBoolArg, int iIntegerArg) : m_bArg(bBoolArg), m_iArg(iIntegerArg)
+{
+}
+```
+
+For longer lines, break before colon and after comma.
+
+```cpp
+MyClass::CMyClass(bool bBoolArg,
+ int iIntegerArg,
+ const std::string& strSomeText,
+ const std::shared_ptr<CMyOtherClass>& myOtherClass)
+ : m_bBoolArg(bBoolArg),
+ m_iIntegerArg(iIntegerArg),
+ m_strSomeText(strSomeText),
+ m_myOtherClass(myOtherClass)
+{
+}
+```
+
## 12. Other conventions
### 12.1. Output parameters