Skip to content

Commit f1708ef

Browse files
Add recommendation: By default, declare single-argument constructors explicit
1 parent 3e55f13 commit f1708ef

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)