Skip to content

Commit 3f726c9

Browse files
author
MarcoFalke
committed
Merge #11112: [developer-notes] By default, declare single-argument constructors "explicit"
f1708ef Add recommendation: By default, declare single-argument constructors `explicit` (practicalswift) Pull request description: This is a follow-up to the now merged #10969. Add recommendation: > By default, declare single-argument constructors `explicit`. > > - *Rationale*: This is a precaution to avoid unintended conversions that might arise when single-argument constructors are used as implicit conversion functions. > Tree-SHA512: 1ceb1008a7863ebd0f09ba9c06b4e28b3b03265d7381f9d0c8bd4be1663d5d0392de0ecd811027aa27c0d962723674b245b3c165a437942a776f3525db39d36b
2 parents 77fc469 + f1708ef commit 3f726c9

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

doc/developer-notes.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,12 @@ C++ data structures
332332
- *Rationale*: Ensure determinism by avoiding accidental use of uninitialized
333333
values. Also, static analyzers balk about this.
334334

335+
- By default, declare single-argument constructors `explicit`.
336+
337+
- *Rationale*: This is a precaution to avoid unintended conversions that might
338+
arise when single-argument constructors are used as implicit conversion
339+
functions.
340+
335341
- Use explicitly signed or unsigned `char`s, or even better `uint8_t` and
336342
`int8_t`. Do not use bare `char` unless it is to pass to a third-party API.
337343
This type can be signed or unsigned depending on the architecture, which can

src/test/addrman_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class CAddrManTest : public CAddrMan
1515
uint64_t state;
1616

1717
public:
18-
CAddrManTest(bool makeDeterministic = true)
18+
explicit CAddrManTest(bool makeDeterministic = true)
1919
{
2020
state = 1;
2121

0 commit comments

Comments
 (0)