From d33ee8b1cdb579dce83c43473b6eeec32c73b8af Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Thu, 24 Aug 2017 20:59:06 -0400 Subject: [PATCH] Merge #11112: [developer-notes] By default, declare single-argument constructors "explicit" f1708ef89 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 --- 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 550cfcba13e31..1c884d861223d 100644 --- a/doc/developer-notes.md +++ b/doc/developer-notes.md @@ -344,6 +344,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 8d8d03036664a..52f88b8a63453 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;