Skip to content

Commit

Permalink
Remove obsolete NODISCARD ifdef forest. Use [[nodiscard]] C++17 (bitc…
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkLTZ committed Feb 16, 2021
1 parent 39550b9 commit 78c81d9
Show file tree
Hide file tree
Showing 17 changed files with 31 additions and 44 deletions.
13 changes: 0 additions & 13 deletions src/attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,4 @@
#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
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 @@ class UniValue;
// 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& hex_tx, bool try_no_witness = false, bool try_witness = true);
NODISCARD bool DecodeHexBlk(CBlock&, const std::string& strHexBlk);
[[nodiscard]] bool DecodeHexTx(CMutableTransaction& tx, const std::string& hex_tx, bool try_no_witness = false, bool try_witness = true);
[[nodiscard]] bool DecodeHexBlk(CBlock&, const std::string& strHexBlk);
bool DecodeHexBlockHeader(CBlockHeader&, const std::string& hex_header);

/**
Expand Down
2 changes: 1 addition & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ static fs::path GetPidFile()
return AbsPathForConfigVal(fs::path(gArgs.GetArg("-pid", BITCOIN_PID_FILENAME)));
}

NODISCARD static bool CreatePidFile()
[[nodiscard]] static bool CreatePidFile()
{
fsbridge::ofstream file{GetPidFile()};
if (file) {
Expand Down
2 changes: 1 addition & 1 deletion src/node/transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
* @param[in] wait_callback wait until callbacks have been processed to avoid stale result due to a sequentially RPC.
* return error
*/
NODISCARD TransactionError BroadcastTransaction(CTransactionRef tx, std::string& err_string, const CAmount& max_tx_fee, bool relay, bool wait_callback);
[[nodiscard]] TransactionError BroadcastTransaction(CTransactionRef tx, std::string& err_string, const CAmount& max_tx_fee, bool relay, bool wait_callback);

#endif // BITCOIN_NODE_TRANSACTION_H
2 changes: 1 addition & 1 deletion src/outputtype.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ enum class OutputType {
CHANGE_AUTO,
};

NODISCARD bool ParseOutputType(const std::string& str, OutputType& output_type);
[[nodiscard]] bool ParseOutputType(const std::string& str, OutputType& output_type);
const std::string& FormatOutputType(OutputType type);

/**
Expand Down
8 changes: 4 additions & 4 deletions src/psbt.h
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ struct PartiallySignedTransaction

/** Merge psbt into this. The two psbts must have the same underlying CTransaction (i.e. the
* same actual Bitcoin transaction.) Returns true if the merge succeeded, false otherwise. */
NODISCARD bool Merge(const PartiallySignedTransaction& psbt);
[[nodiscard]] bool Merge(const PartiallySignedTransaction& psbt);
bool IsSane() const;
bool AddInput(const CTxIn& txin, PSBTInput& psbtin);
bool AddOutput(const CTxOut& txout, const PSBTOutput& psbtout);
Expand Down Expand Up @@ -606,11 +606,11 @@ bool FinalizeAndExtractPSBT(PartiallySignedTransaction& psbtx, CMutableTransacti
* @param[in] psbtxs the PSBTs to combine
* @return error (OK if we successfully combined the transactions, other error if they were not compatible)
*/
NODISCARD TransactionError CombinePSBTs(PartiallySignedTransaction& out, const std::vector<PartiallySignedTransaction>& psbtxs);
[[nodiscard]] TransactionError CombinePSBTs(PartiallySignedTransaction& out, const std::vector<PartiallySignedTransaction>& psbtxs);

//! Decode a base64ed PSBT into a PartiallySignedTransaction
NODISCARD bool DecodeBase64PSBT(PartiallySignedTransaction& decoded_psbt, const std::string& base64_psbt, std::string& error);
[[nodiscard]] bool DecodeBase64PSBT(PartiallySignedTransaction& decoded_psbt, const std::string& base64_psbt, std::string& error);
//! Decode a raw (binary blob) PSBT into a PartiallySignedTransaction
NODISCARD bool DecodeRawPSBT(PartiallySignedTransaction& decoded_psbt, const std::string& raw_psbt, std::string& error);
[[nodiscard]] bool DecodeRawPSBT(PartiallySignedTransaction& decoded_psbt, const std::string& raw_psbt, std::string& error);

#endif // BITCOIN_PSBT_H
2 changes: 1 addition & 1 deletion src/script/descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ std::vector<Span<const char>> Split(const Span<const char>& sp, char sep)
}

/** Parse a key path, being passed a split list of elements (the first element is ignored). */
NODISCARD bool ParseKeyPath(const std::vector<Span<const char>>& split, KeyPath& out, std::string& error)
[[nodiscard]] bool ParseKeyPath(const std::vector<Span<const char>>& split, KeyPath& out, std::string& error)
{
for (size_t i = 1; i < split.size(); ++i) {
Span<const char> elem = split[i];
Expand Down
2 changes: 1 addition & 1 deletion src/test/coins_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CCoinsViewTest : public CCoinsView
std::map<COutPoint, Coin> map_;

public:
NODISCARD bool GetCoin(const COutPoint& outpoint, Coin& coin) const override
[[nodiscard]] bool GetCoin(const COutPoint& outpoint, Coin& coin) const override
{
std::map<COutPoint, Coin>::const_iterator it = map_.find(outpoint);
if (it == map_.end()) {
Expand Down
2 changes: 1 addition & 1 deletion src/util/bip32.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <vector>

/** Parse an HD keypaths like "m/7/0'/2000". */
NODISCARD bool ParseHDKeypath(const std::string& keypath_str, std::vector<uint32_t>& keypath);
[[nodiscard]] bool ParseHDKeypath(const std::string& keypath_str, std::vector<uint32_t>& keypath);

/** Write HD keypaths as strings */
std::string WriteHDKeypath(const std::vector<uint32_t>& keypath);
Expand Down
2 changes: 1 addition & 1 deletion src/util/moneystr.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
*/
std::string FormatMoney(const CAmount& n);
/** Parse an amount denoted in full coins. E.g. "0.0034" supplied on the command line. **/
NODISCARD bool ParseMoney(const std::string& str, CAmount& nRet);
[[nodiscard]] bool ParseMoney(const std::string& str, 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 @@ -292,7 +292,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
12 changes: 6 additions & 6 deletions src/util/strencodings.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,35 +94,35 @@ constexpr inline bool IsSpace(char c) noexcept {
* @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 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);

template<typename T>
std::string HexStr(const T itbegin, const T itend)
Expand Down Expand Up @@ -172,7 +172,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
4 changes: 2 additions & 2 deletions src/util/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,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 @@ -48,7 +48,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 Down
2 changes: 1 addition & 1 deletion src/util/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ class ArgsManagerHelper {
* that debug log output is not sent to any file at all).
*/

NODISCARD static bool InterpretOption(std::string key, std::string val, unsigned int flags,
[[nodiscard]] static bool InterpretOption(std::string key, std::string val, unsigned int flags,
std::map<std::string, std::vector<std::string>>& args,
std::string& error)
{
Expand Down
6 changes: 3 additions & 3 deletions src/util/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class ArgsManager
std::map<OptionsCategory, std::map<std::string, Arg>> m_available_args GUARDED_BY(cs_args);
std::list<SectionInfo> m_config_sections GUARDED_BY(cs_args);

NODISCARD bool ReadConfigStream(std::istream& stream, const std::string& filepath, std::string& error, bool ignore_invalid_keys = false);
[[nodiscard]] bool ReadConfigStream(std::istream& stream, const std::string& filepath, std::string& error, bool ignore_invalid_keys = false);

public:
ArgsManager();
Expand All @@ -176,8 +176,8 @@ class ArgsManager
*/
void SelectConfigNetwork(const std::string& network);

NODISCARD bool ParseParameters(int argc, const char* const argv[], std::string& error);
NODISCARD bool ReadConfigFiles(std::string& error, bool ignore_invalid_keys = false);
[[nodiscard]] bool ParseParameters(int argc, const char* const argv[], std::string& error);
[[nodiscard]] bool ReadConfigFiles(std::string& error, bool ignore_invalid_keys = false);

/**
* Log warnings for options in m_section_only_args when
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/psbtwallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* @param[in] bip32derivs whether to fill in bip32 derivation information if available
* return error
*/
NODISCARD TransactionError FillPSBT(const CWallet* pwallet,
[[nodiscard]] TransactionError FillPSBT(const CWallet* pwallet,
PartiallySignedTransaction& psbtx,
bool& complete,
int sighash_type = 1 /* SIGHASH_ALL */,
Expand Down

0 comments on commit 78c81d9

Please sign in to comment.