From fd319d579b97101894f826d866efa3440ecc1d65 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Thu, 4 Jun 2015 22:18:43 +1000 Subject: [PATCH] build: make single argument constructors explicit --- crypto/tea.hpp | 2 +- crypto/xtea.hpp | 2 +- crypto/xxtea.hpp | 2 +- debug.hpp | 2 +- endian.hpp | 2 +- fixed.hpp | 6 +++--- guid.hpp | 2 +- ip.hpp | 8 ++++---- json/except.hpp | 4 ++-- memory.hpp | 2 +- net/address.hpp | 2 +- net/except.hpp | 4 ++-- net/socket.cpp | 4 ++-- raii.hpp | 4 ++-- stream.hpp | 2 +- test/fixed.cpp | 4 ++-- uri.hpp | 4 ++-- version.hpp | 4 ++-- view.hpp | 2 +- zlib.hpp | 2 +- 20 files changed, 32 insertions(+), 32 deletions(-) diff --git a/crypto/tea.hpp b/crypto/tea.hpp index eda963fb..412dd744 100644 --- a/crypto/tea.hpp +++ b/crypto/tea.hpp @@ -27,7 +27,7 @@ namespace util { namespace crypto { public: using key_t = std::array; - TEA (key_t); + explicit TEA (key_t); void encrypt (uint32_t *restrict data, size_t count); void decrypt (uint32_t *restrict data, size_t count); diff --git a/crypto/xtea.hpp b/crypto/xtea.hpp index 7582213a..d636bed7 100644 --- a/crypto/xtea.hpp +++ b/crypto/xtea.hpp @@ -27,7 +27,7 @@ namespace util { namespace crypto { public: using key_t = std::array; - XTEA (key_t); + explicit XTEA (key_t); void encrypt (uint32_t *restrict data, size_t count); void decrypt (uint32_t *restrict data, size_t count); diff --git a/crypto/xxtea.hpp b/crypto/xxtea.hpp index 82f69eac..55ac8425 100644 --- a/crypto/xxtea.hpp +++ b/crypto/xxtea.hpp @@ -28,7 +28,7 @@ namespace util { namespace crypto { public: using key_t = std::array; - XXTEA (key_t); + explicit XXTEA (key_t); void encrypt (uint32_t *restrict data, size_t count); void decrypt (uint32_t *restrict data, size_t count); diff --git a/debug.hpp b/debug.hpp index cf17f60c..dc117bd5 100644 --- a/debug.hpp +++ b/debug.hpp @@ -282,7 +282,7 @@ class panic_error { std::string m_what; public: - panic_error (const std::string &_what): + explicit panic_error (const std::string &_what): m_what (_what) { ; } }; diff --git a/endian.hpp b/endian.hpp index c4644c25..4b0adc0e 100644 --- a/endian.hpp +++ b/endian.hpp @@ -76,7 +76,7 @@ template constexpr T ltoh (T v) { return v; } //----------------------------------------------------------------------------- struct from_endian { - from_endian (endian _endian): + explicit from_endian (endian _endian): src (_endian) { ; } diff --git a/fixed.hpp b/fixed.hpp index 18d05abe..9ce3b9c2 100644 --- a/fixed.hpp +++ b/fixed.hpp @@ -34,9 +34,9 @@ namespace util { typedef native_t integer_t; - fixed (double); - fixed (float); - fixed (native_t); + explicit fixed (double); + explicit fixed (float); + explicit fixed (native_t); double to_double (void) const; float to_float (void) const; diff --git a/guid.hpp b/guid.hpp index 1e542e1f..9993a706 100644 --- a/guid.hpp +++ b/guid.hpp @@ -34,7 +34,7 @@ class guid { public: guid (uint32_t, uint16_t, uint16_t, uint8_t[8]); - guid (const char *); + explicit guid (const char *); guid (const guid&); guid& operator= (const guid&); diff --git a/ip.hpp b/ip.hpp index e341814c..e7a1ab72 100644 --- a/ip.hpp +++ b/ip.hpp @@ -30,8 +30,8 @@ namespace ipv4 { uint32_t m_integer; }; - ip (const std::string &); - ip (uint32_t i); + explicit ip (const std::string &); + explicit ip (uint32_t i); ip (uint8_t a, uint8_t b, uint8_t c, uint8_t d); ip& operator = (const ip &); @@ -59,7 +59,7 @@ namespace ipv6 { struct ip { uint32_t m_quads[4]; - ip (const std::string&) { ; } + explicit ip (const std::string&) { ; } }; typedef uint16_t port; @@ -67,7 +67,7 @@ namespace ipv6 { struct mask { uint32_t m_quads[4]; - mask (uint32_t) { ; } + explicit mask (uint32_t) { ; } }; } diff --git a/json/except.hpp b/json/except.hpp index 8556cb26..d9004789 100644 --- a/json/except.hpp +++ b/json/except.hpp @@ -38,7 +38,7 @@ namespace json { struct parse_error : public error { using error::error; - parse_error (const std::string &_what, size_t _line = 0); + explicit parse_error (const std::string &_what, size_t _line = 0); size_t line; }; @@ -52,7 +52,7 @@ namespace json { /// Exception class for invalid object indexing struct key_error : public error { - key_error (std::string); + explicit key_error (std::string); }; } diff --git a/memory.hpp b/memory.hpp index 5878cf86..56b515f0 100644 --- a/memory.hpp +++ b/memory.hpp @@ -20,7 +20,7 @@ template class scoped_malloc { public: - scoped_malloc (T *_data): + explicit scoped_malloc (T *_data): m_data (_data) { ; } diff --git a/net/address.hpp b/net/address.hpp index 29dca0c4..10e307d6 100644 --- a/net/address.hpp +++ b/net/address.hpp @@ -71,7 +71,7 @@ namespace net { static const address LOOPBACK; static const address ANY; - address (const sockaddr_type &); + explicit address (const sockaddr_type &); address (const std::string &address, port_type); port_type port (void) const; diff --git a/net/except.hpp b/net/except.hpp index 0fe4e66b..a7d78695 100644 --- a/net/except.hpp +++ b/net/except.hpp @@ -32,8 +32,8 @@ namespace net { class error : public std::runtime_error { protected: - error (const std::string &); - error (int code); + explicit error (const std::string &); + explicit error (int code); static std::string code_to_string (int code); diff --git a/net/socket.cpp b/net/socket.cpp index 1558d364..db29ba2f 100644 --- a/net/socket.cpp +++ b/net/socket.cpp @@ -232,7 +232,7 @@ net::socket::get_peer (void) const { net::error::throw_code (); CHECK (addr_len == sizeof (addr)); - return addr; + return typename net::socket::address_type (addr); } @@ -288,7 +288,7 @@ net::socket::recv_addr (uint8_t *restrict data, if (recvd < 0) net::error::throw_code (); - return addr_in; + return net::socket::address_type (addr_in); } //----------------------------------------------------------------------------- diff --git a/raii.hpp b/raii.hpp index 52ad5903..b513b721 100644 --- a/raii.hpp +++ b/raii.hpp @@ -26,7 +26,7 @@ namespace util { /// Increments a counter for the lifetime of the object template struct scoped_counter { - scoped_counter (T &_counter): + explicit scoped_counter (T &_counter): counter (_counter) { ++counter; } @@ -40,7 +40,7 @@ namespace util { /// Executes a function upon object destruction template struct scoped_function { - scoped_function (T &&_func): + explicit scoped_function (T &&_func): func (std::move (_func)) { ; } diff --git a/stream.hpp b/stream.hpp index 89f42817..af2345ba 100644 --- a/stream.hpp +++ b/stream.hpp @@ -26,7 +26,7 @@ namespace util { template struct numeric { - numeric (T _val): val (_val) { ; } + explicit numeric (T _val): val (_val) { ; } T val; }; diff --git a/test/fixed.cpp b/test/fixed.cpp index fdde6972..5654b39e 100644 --- a/test/fixed.cpp +++ b/test/fixed.cpp @@ -9,8 +9,8 @@ test_simple (util::TAP::logger &tap) using fixed_t = util::fixed; using integer_t = typename fixed_t::integer_t; - const fixed_t lo = integer_t{0}; - const fixed_t hi = integer_t{1}; + const fixed_t lo {integer_t{0}}; + const fixed_t hi {integer_t{1}}; std::ostringstream os; os << "fixed<" << type_to_string () << ',' << I << ',' << E << '>'; diff --git a/uri.hpp b/uri.hpp index faad672d..2f772c2f 100644 --- a/uri.hpp +++ b/uri.hpp @@ -27,8 +27,8 @@ namespace util { class uri { public: - uri (std::string &&); - uri (const char *str); + explicit uri (std::string &&); + explicit uri (const char *str); uri (const char *first, const char *last); class parse_error : public std::runtime_error diff --git a/version.hpp b/version.hpp index ce49a037..a46b2922 100644 --- a/version.hpp +++ b/version.hpp @@ -33,8 +33,8 @@ namespace util { version (); version (unsigned int _major, unsigned int _minor); - version (const std::string& str); - version (const char *str); + explicit version (const std::string& str); + explicit version (const char *str); void sanity (void) const; diff --git a/view.hpp b/view.hpp index d4e533e6..86e33be9 100644 --- a/view.hpp +++ b/view.hpp @@ -25,7 +25,7 @@ namespace util { class view { public: view (); - view (const char *str); + explicit view (const char *str); view (const char *first, const char *last); const char *begin (void) const; diff --git a/zlib.hpp b/zlib.hpp index dfb18655..70c5d71c 100644 --- a/zlib.hpp +++ b/zlib.hpp @@ -55,7 +55,7 @@ namespace util { static void try_code (int code); static void throw_code (int code); - error(const std::string&); + explicit error(const std::string&); };