diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2018-04-07 16:42:22 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2018-04-07 16:44:28 +0200 |
commit | b15485eccacea8ad31908a3f8f34ba249e6632b3 (patch) | |
tree | a0c2eb71ffbeb01c8e39cf930a5439c0ef5f694b | |
parent | 215158a633c7feae6ebaadf4516aa5a2cd18f168 (diff) | |
parent | b119e7873304eb2f0bee3dd9e2f22c5c9001d899 (diff) |
Merge #12896: docs: Fix conflicting statements about initialization in developer notes
b119e78 docs: Fix conflicting statements about initialization in developer notes (practicalswift)
Pull request description:
Fix conflicting statements about initialization in developer notes.
Context: https://github.com/bitcoin/bitcoin/pull/12785#issuecomment-378941151
Tree-SHA512: 601b18cbeb963f99a4180e652d6c1b78210df89743fd3565c0bce95fd2dcc9784b6af212795a43d3a40a5858b1a03e0d2c7982295c92d6ea710db0e6ee69f0b4
-rw-r--r-- | doc/developer-notes.md | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/doc/developer-notes.md b/doc/developer-notes.md index b00cceb987..c9fe3a7ab4 100644 --- a/doc/developer-notes.md +++ b/doc/developer-notes.md @@ -450,12 +450,21 @@ C++ data structures - Vector bounds checking is only enabled in debug mode. Do not rely on it -- Make sure that constructors initialize all fields. If this is skipped for a - good reason (i.e., optimization on the critical path), add an explicit - comment about this +- Initialize all non-static class members where they are defined. + If this is skipped for a good reason (i.e., optimization on the critical + path), add an explicit comment about this - *Rationale*: Ensure determinism by avoiding accidental use of uninitialized values. Also, static analyzers balk about this. + Initializing the members in the declaration makes it easy to + spot uninitialized ones. + +```cpp +class A +{ + uint32_t m_count{0}; +} +``` - By default, declare single-argument constructors `explicit`. @@ -474,18 +483,6 @@ C++ data structures - *Rationale*: Easier to understand what is happening, thus easier to spot mistakes, even for those that are not language lawyers -- Initialize all non-static class members where they are defined - - - *Rationale*: Initializing the members in the declaration makes it easy to spot uninitialized ones, - and avoids accidentally reading uninitialized memory - -```cpp -class A -{ - uint32_t m_count{0}; -} -``` - Strings and formatting ------------------------ |