diff --git a/src/Makefile.am b/src/Makefile.am --- a/src/Makefile.am +++ b/src/Makefile.am @@ -103,6 +103,7 @@ BITCOIN_CORE_H = \ addrdb.h \ addrman.h \ + attributes.h \ avalanche.h \ banman.h \ base58.h \ diff --git a/src/attributes.h b/src/attributes.h new file mode 100644 --- /dev/null +++ b/src/attributes.h @@ -0,0 +1,22 @@ +// Copyright (c) 2009-2010 Satoshi Nakamoto +// Copyright (c) 2009-2018 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_ATTRIBUTES_H +#define BITCOIN_ATTRIBUTES_H + +#if defined(__has_cpp_attribute) +#if __has_cpp_attribute(nodiscard) +#define NODISCARD [[nodiscard]] +#endif +#endif +#ifndef NODISCARD +#if defined(_MSC_VER) && _MSC_VER >= 1700 +#define NODISCARD _Check_return_ +#else +#define NODISCARD __attribute__((warn_unused_result)) +#endif +#endif + +#endif // BITCOIN_ATTRIBUTES_H diff --git a/src/base58.h b/src/base58.h --- a/src/base58.h +++ b/src/base58.h @@ -16,6 +16,8 @@ #ifndef BITCOIN_BASE58_H #define BITCOIN_BASE58_H +#include + #include #include @@ -35,13 +37,14 @@ * return true if decoding is successful. * psz cannot be nullptr. */ -bool DecodeBase58(const char *psz, std::vector &vchRet); +NODISCARD bool DecodeBase58(const char *psz, std::vector &vchRet); /** * Decode a base58-encoded string (str) into a byte vector (vchRet). * return true if decoding is successful. */ -bool DecodeBase58(const std::string &str, std::vector &vchRet); +NODISCARD bool DecodeBase58(const std::string &str, + std::vector &vchRet); /** * Encode a byte vector into a base58-encoded string, including checksum @@ -52,12 +55,13 @@ * Decode a base58-encoded string (psz) that includes a checksum into a byte * vector (vchRet), return true if decoding is successful */ -bool DecodeBase58Check(const char *psz, std::vector &vchRet); +NODISCARD bool DecodeBase58Check(const char *psz, std::vector &vchRet); /** * Decode a base58-encoded string (str) that includes a checksum into a byte * vector (vchRet), return true if decoding is successful */ -bool DecodeBase58Check(const std::string &str, std::vector &vchRet); +NODISCARD bool DecodeBase58Check(const std::string &str, + std::vector &vchRet); #endif // BITCOIN_BASE58_H diff --git a/src/bench/base58.cpp b/src/bench/base58.cpp --- a/src/bench/base58.cpp +++ b/src/bench/base58.cpp @@ -35,7 +35,7 @@ const char *addr = "17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhem"; std::vector vch; while (state.KeepRunning()) { - DecodeBase58(addr, vch); + (void)DecodeBase58(addr, vch); } } diff --git a/src/core_io.h b/src/core_io.h --- a/src/core_io.h +++ b/src/core_io.h @@ -5,6 +5,7 @@ #ifndef BITCOIN_CORE_IO_H #define BITCOIN_CORE_IO_H +#include #include