From f1708ef89a38efe857daeb4252c6dfab5b7c258e Mon Sep 17 00:00:00 2001 From: practicalswift Date: Tue, 22 Aug 2017 22:50:03 +0200 Subject: [PATCH] Add recommendation: By default, declare single-argument constructors `explicit` --- doc/developer-notes.md | 6 ++++++ src/test/addrman_tests.cpp | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/doc/developer-notes.md b/doc/developer-notes.md index ad15aa662..2f04d6ee6 100644 --- a/doc/developer-notes.md +++ b/doc/developer-notes.md @@ -332,6 +332,12 @@ C++ data structures - *Rationale*: Ensure determinism by avoiding accidental use of uninitialized values. Also, static analyzers balk about this. +- 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. + - Use explicitly signed or unsigned `char`s, or even better `uint8_t` and `int8_t`. Do not use bare `char` unless it is to pass to a third-party API. This type can be signed or unsigned depending on the architecture, which can diff --git a/src/test/addrman_tests.cpp b/src/test/addrman_tests.cpp index 2ad22d34a..7be29c6d6 100644 --- a/src/test/addrman_tests.cpp +++ b/src/test/addrman_tests.cpp @@ -15,7 +15,7 @@ class CAddrManTest : public CAddrMan uint64_t state; public: - CAddrManTest(bool makeDeterministic = true) + explicit CAddrManTest(bool makeDeterministic = true) { state = 1;