Skip to content

Commit

Permalink
merge bitcoin#20499: Remove obsolete NODISCARD ifdef forest. Use [[no…
Browse files Browse the repository at this point in the history
…discard]] (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 ---------------
  • Loading branch information
kwvg committed Jun 27, 2021
1 parent ef4dfa8 commit f2f1843
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 35 deletions.
13 changes: 0 additions & 13 deletions src/attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down
8 changes: 4 additions & 4 deletions src/base58.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ std::string EncodeBase58(const std::vector<unsigned char>& vch);
* return true if decoding is successful.
* psz cannot be nullptr.
*/
NODISCARD bool DecodeBase58(const char* psz, std::vector<unsigned char>& vchRet);
[[nodiscard]] bool DecodeBase58(const char* psz, std::vector<unsigned char>& 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<unsigned char>& vchRet);
[[nodiscard]] bool DecodeBase58(const std::string& str, std::vector<unsigned char>& vchRet);

/**
* Encode a byte vector into a base58-encoded string, including checksum
Expand All @@ -52,12 +52,12 @@ std::string EncodeBase58Check(const std::vector<unsigned char>& 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<unsigned char>& vchRet);
[[nodiscard]] bool DecodeBase58Check(const char* psz, std::vector<unsigned char>& 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<unsigned char>& vchRet);
[[nodiscard]] bool DecodeBase58Check(const std::string& str, std::vector<unsigned char>& vchRet);

#endif // BITCOIN_BASE58_H
4 changes: 2 additions & 2 deletions src/core_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned char> ParseHexUV(const UniValue& v, const std::string& strName);

Expand Down
6 changes: 3 additions & 3 deletions src/evo/deterministicmns.h
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ class CDeterministicMNList

private:
template <typename T>
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) {
Expand All @@ -528,7 +528,7 @@ class CDeterministicMNList
return true;
}
template <typename T>
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) {
Expand All @@ -548,7 +548,7 @@ class CDeterministicMNList
return true;
}
template <typename T>
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;
Expand Down
4 changes: 2 additions & 2 deletions src/util/moneystr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/util/strencodings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions src/util/strencodings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<int frombits, int tobits, bool pad, typename O, typename I>
Expand Down
6 changes: 3 additions & 3 deletions src/util/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <string>
#include <vector>

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) {
Expand Down Expand Up @@ -59,7 +59,7 @@ inline std::string Join(const std::vector<std::string>& 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());
}
Expand All @@ -68,7 +68,7 @@ NODISCARD inline bool ValidAsCString(const std::string& str) noexcept
* Check whether a container begins with the given prefix.
*/
template <typename T1, size_t PREFIX_LEN>
NODISCARD inline bool HasPrefix(const T1& obj,
[[nodiscard]] inline bool HasPrefix(const T1& obj,
const std::array<uint8_t, PREFIX_LEN>& prefix)
{
return obj.size() >= PREFIX_LEN &&
Expand Down

0 comments on commit f2f1843

Please sign in to comment.