From f2f1843f0c2cfd06c2fcda1b8d1e70d2140488d5 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com> Date: Wed, 16 Jun 2021 13:31:16 +0530 Subject: [PATCH] merge bitcoin#20499: Remove obsolete NODISCARD ifdef forest. Use [[nodiscard]] (C++17) ------------- BEGIN SCRIPT --------------- gsed -i "s/NODISCARD/[[nodiscard]]/g" $(git grep -l "NODISCARD" ":(exclude)src/bench/nanobench.h" ":(exclude)src/attributes.h") ------------- END SCRIPT --------------- --- src/attributes.h | 13 ------------- src/base58.h | 8 ++++---- src/core_io.h | 4 ++-- src/evo/deterministicmns.h | 6 +++--- src/util/moneystr.h | 4 ++-- src/util/strencodings.cpp | 2 +- src/util/strencodings.h | 14 +++++++------- src/util/string.h | 6 +++--- 8 files changed, 22 insertions(+), 35 deletions(-) diff --git a/src/attributes.h b/src/attributes.h index 9d5c1d44a04c5..995c24e13f045 100644 --- a/src/attributes.h +++ b/src/attributes.h @@ -6,19 +6,6 @@ #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 - #if defined(__clang__) # if __has_attribute(lifetimebound) # define LIFETIMEBOUND [[clang::lifetimebound]] diff --git a/src/base58.h b/src/base58.h index 230e4392a3c87..038e3288cd3f8 100644 --- a/src/base58.h +++ b/src/base58.h @@ -35,13 +35,13 @@ std::string EncodeBase58(const std::vector& vch); * return true if decoding is successful. * psz cannot be nullptr. */ -NODISCARD 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. */ -NODISCARD 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 +52,12 @@ std::string EncodeBase58Check(const std::vector& vchIn); * Decode a base58-encoded string (psz) that includes a checksum into a byte * vector (vchRet), return true if decoding is successful */ -NODISCARD 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 */ -NODISCARD 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/core_io.h b/src/core_io.h index 9d3f5145d056c..7921c442fafa8 100644 --- a/src/core_io.h +++ b/src/core_io.h @@ -23,8 +23,8 @@ struct CSpentIndexTxInfo; // core_read.cpp CScript ParseScript(const std::string& s); std::string ScriptToAsmStr(const CScript& script, const bool fAttemptSighashDecode = false); -NODISCARD bool DecodeHexTx(CMutableTransaction& tx, const std::string& strHexTx); -NODISCARD bool DecodeHexBlk(CBlock&, const std::string& strHexBlk); +[[nodiscard]] bool DecodeHexTx(CMutableTransaction& tx, const std::string& strHexTx); +[[nodiscard]] bool DecodeHexBlk(CBlock&, const std::string& strHexBlk); uint256 ParseHashStr(const std::string&, const std::string& strName); std::vector ParseHexUV(const UniValue& v, const std::string& strName); diff --git a/src/evo/deterministicmns.h b/src/evo/deterministicmns.h index 2e554203a78df..0b3e8ae63e63d 100644 --- a/src/evo/deterministicmns.h +++ b/src/evo/deterministicmns.h @@ -508,7 +508,7 @@ class CDeterministicMNList private: template - NODISCARD bool AddUniqueProperty(const CDeterministicMNCPtr& dmn, const T& v) + [[nodiscard]] bool AddUniqueProperty(const CDeterministicMNCPtr& dmn, const T& v) { static const T nullValue; if (v == nullValue) { @@ -528,7 +528,7 @@ class CDeterministicMNList return true; } template - NODISCARD bool DeleteUniqueProperty(const CDeterministicMNCPtr& dmn, const T& oldValue) + [[nodiscard]] bool DeleteUniqueProperty(const CDeterministicMNCPtr& dmn, const T& oldValue) { static const T nullValue; if (oldValue == nullValue) { @@ -548,7 +548,7 @@ class CDeterministicMNList return true; } template - NODISCARD bool UpdateUniqueProperty(const CDeterministicMNCPtr& dmn, const T& oldValue, const T& newValue) + [[nodiscard]] bool UpdateUniqueProperty(const CDeterministicMNCPtr& dmn, const T& oldValue, const T& newValue) { if (oldValue == newValue) { return true; diff --git a/src/util/moneystr.h b/src/util/moneystr.h index 01dfd797f425c..ee78217baaed2 100644 --- a/src/util/moneystr.h +++ b/src/util/moneystr.h @@ -19,7 +19,7 @@ * JSON but use AmountFromValue and ValueFromAmount for that. */ std::string FormatMoney(const CAmount& n); -NODISCARD bool ParseMoney(const std::string& str, CAmount& nRet); -NODISCARD bool ParseMoney(const char* pszIn, CAmount& nRet); +[[nodiscard]] bool ParseMoney(const std::string& str, CAmount& nRet); +[[nodiscard]] bool ParseMoney(const char* pszIn, CAmount& nRet); #endif // BITCOIN_UTIL_MONEYSTR_H diff --git a/src/util/strencodings.cpp b/src/util/strencodings.cpp index ba702ce578113..e1d24fe54a941 100644 --- a/src/util/strencodings.cpp +++ b/src/util/strencodings.cpp @@ -266,7 +266,7 @@ std::string DecodeBase32(const std::string& str, bool* pf_invalid) return std::string((const char*)vchRet.data(), vchRet.size()); } -NODISCARD static bool ParsePrechecks(const std::string& str) +[[nodiscard]] static bool ParsePrechecks(const std::string& str) { if (str.empty()) // No empty string allowed return false; diff --git a/src/util/strencodings.h b/src/util/strencodings.h index 35cccdef25375..f683f245d1003 100644 --- a/src/util/strencodings.h +++ b/src/util/strencodings.h @@ -92,42 +92,42 @@ constexpr bool IsDigit(char c) * @returns true if the entire string could be parsed as valid integer, * false if not the entire string could be parsed or when overflow or underflow occurred. */ -NODISCARD bool ParseInt32(const std::string& str, int32_t *out); +[[nodiscard]] bool ParseInt32(const std::string& str, int32_t *out); /** * Convert string to signed 64-bit integer with strict parse error feedback. * @returns true if the entire string could be parsed as valid integer, * false if not the entire string could be parsed or when overflow or underflow occurred. */ -NODISCARD bool ParseInt64(const std::string& str, int64_t *out); +[[nodiscard]] bool ParseInt64(const std::string& str, int64_t *out); /** * Convert decimal string to unsigned 8-bit integer with strict parse error feedback. * @returns true if the entire string could be parsed as valid integer, * false if not the entire string could be parsed or when overflow or underflow occurred. */ -NODISCARD bool ParseUInt8(const std::string& str, uint8_t *out); +[[nodiscard]] bool ParseUInt8(const std::string& str, uint8_t *out); /** * Convert decimal string to unsigned 32-bit integer with strict parse error feedback. * @returns true if the entire string could be parsed as valid integer, * false if not the entire string could be parsed or when overflow or underflow occurred. */ -NODISCARD bool ParseUInt32(const std::string& str, uint32_t *out); +[[nodiscard]] bool ParseUInt32(const std::string& str, uint32_t *out); /** * Convert decimal string to unsigned 64-bit integer with strict parse error feedback. * @returns true if the entire string could be parsed as valid integer, * false if not the entire string could be parsed or when overflow or underflow occurred. */ -NODISCARD bool ParseUInt64(const std::string& str, uint64_t *out); +[[nodiscard]] bool ParseUInt64(const std::string& str, uint64_t *out); /** * Convert string to double with strict parse error feedback. * @returns true if the entire string could be parsed as valid double, * false if not the entire string could be parsed or when overflow or underflow occurred. */ -NODISCARD bool ParseDouble(const std::string& str, double *out); +[[nodiscard]] bool ParseDouble(const std::string& str, double *out); /** * Convert a span of bytes to a lower-case hexadecimal string. @@ -161,7 +161,7 @@ bool TimingResistantEqual(const T& a, const T& b) * @returns true on success, false on error. * @note The result must be in the range (-10^18,10^18), otherwise an overflow error will trigger. */ -NODISCARD bool ParseFixedPoint(const std::string &val, int decimals, int64_t *amount_out); +[[nodiscard]] bool ParseFixedPoint(const std::string &val, int decimals, int64_t *amount_out); /** Convert from one power-of-2 number base to another. */ template diff --git a/src/util/string.h b/src/util/string.h index 831b698c62097..223216b4cc1bd 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -15,7 +15,7 @@ #include #include -NODISCARD inline std::string TrimString(const std::string& str, const std::string& pattern = " \f\n\r\t\v") +[[nodiscard]] inline std::string TrimString(const std::string& str, const std::string& pattern = " \f\n\r\t\v") { std::string::size_type front = str.find_first_not_of(pattern); if (front == std::string::npos) { @@ -59,7 +59,7 @@ inline std::string Join(const std::vector& list, const std::string& /** * Check if a string does not contain any embedded NUL (\0) characters */ -NODISCARD inline bool ValidAsCString(const std::string& str) noexcept +[[nodiscard]] inline bool ValidAsCString(const std::string& str) noexcept { return str.size() == strlen(str.c_str()); } @@ -68,7 +68,7 @@ NODISCARD inline bool ValidAsCString(const std::string& str) noexcept * Check whether a container begins with the given prefix. */ template -NODISCARD inline bool HasPrefix(const T1& obj, +[[nodiscard]] inline bool HasPrefix(const T1& obj, const std::array& prefix) { return obj.size() >= PREFIX_LEN &&