Skip to content

Commit

Permalink
Merge #2504: [Refactor] Clang-tidy and fix compiler error in HasReaso…
Browse files Browse the repository at this point in the history
…n class

03525ea [Refactor] Clang-tidy and fix compiler error in HasReason class (Fuzzbawls)

Pull request description:

  Came across this compiler error when updating the [code coverage report](https://www.fuzzbawls.pw/pivx/regression-test-coverage/index.html). The server runs on CentOS 7 currently, which uses a fairly old (but still supported) version of gcc. Indeed, upstream also ran into this error (Ref: bitcoin#20033)

  Some older (but still supported) versions of gcc will throw an error
  when trying to convert from `std::ios_base::failure` to `std::runtime_error`.
  Use `std::exception` base type instead.

  Also apply clang-format to the class and remove the `cout`.

ACKs for top commit:
  random-zebra:
    utACK 03525ea
  furszy:
    utACK 03525ea and merging..

Tree-SHA512: 46a92f96d30c5f0f29babc30841b0b8b694fabe9ee0e8a5ed79ebc1e405c8718515b718ef12384973b0b003adb907378b27c1fca7f00581e7c3a742d59e9f9ba
  • Loading branch information
furszy committed Aug 12, 2021
2 parents 34ef597 + 03525ea commit 51055cb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/netaddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* should be serialized in (unserialized from) v2 format (BIP155).
* Make sure that this does not collide with any of the values in `version.h`
*/
static const int ADDRV2_FORMAT = 0x20000000;
static constexpr int ADDRV2_FORMAT = 0x20000000;

/**
* A network type.
Expand Down
23 changes: 14 additions & 9 deletions src/test/test_pivx.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "scheduler.h"
#include "txdb.h"

#include <stdexcept>

#include <boost/thread.hpp>

extern FastRandomContext insecure_rand_ctx;
Expand Down Expand Up @@ -144,17 +146,20 @@ struct TestMemPoolEntryHelper
// define an implicit conversion here so that uint256 may be used directly in BOOST_CHECK_*
std::ostream& operator<<(std::ostream& os, const uint256& num);

// BOOST_CHECK_EXCEPTION predicates to check the specific validation error
class HasReason {
/**
* BOOST_CHECK_EXCEPTION predicates to check the specific validation error.
* Use as
* BOOST_CHECK_EXCEPTION(code that throws, exception type, HasReason("foo"));
*/
class HasReason
{
public:
HasReason(const std::string& reason) : m_reason(reason) {}
bool operator() (const std::runtime_error& e) const {
bool ret = std::string(e.what()).find(m_reason) != std::string::npos;
if (!ret) {
std::cout << "error: " << e.what() << std::endl;
}
return ret;
explicit HasReason(const std::string& reason) : m_reason(reason) {}
bool operator()(const std::exception& e) const
{
return std::string(e.what()).find(m_reason) != std::string::npos;
};

private:
const std::string m_reason;
};
Expand Down

0 comments on commit 51055cb

Please sign in to comment.