Skip to content

Commit

Permalink
Merge #14214: convert C-style (void) parameter lists to C++ style ()
Browse files Browse the repository at this point in the history
3ccfa34 convert C-style (void) parameter lists to C++ style () (Arvid Norberg)

Pull request description:

  In C, an empty parameter list, `()`, means the function takes any arguments, and `(void)` means the function does not take any parameters.
  In C++, an empty parameter list means the function does not take any parameters.

  So, C++ still supports `(void)` parameter lists with the same semantics, why change to `()`?

  1. removing the redundant `void` improves signal-to-noise ratio of the code
  2. using `(void)` exposes a rare inconsistency in that a template taking a template `(T)` parameter list, cannot be instantiated with `T=void`

Tree-SHA512: be2897b6c5e474873aa878ed6bac098382cd21866aec33752fe40b089a6331aa6263cae749aba1b4a41e8467f1a47086d32eb74abaf09927fd5a2f44a4b2109a
  • Loading branch information
MarcoFalke committed Sep 20, 2018
2 parents 9a3a984 + 3ccfa34 commit 2796c6e
Show file tree
Hide file tree
Showing 16 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/httprpc.cpp
Expand Up @@ -31,7 +31,7 @@ static const char* WWW_AUTH_HEADER_DATA = "Basic realm=\"jsonrpc\"";
class HTTPRPCTimer : public RPCTimerBase
{
public:
HTTPRPCTimer(struct event_base* eventBase, std::function<void(void)>& func, int64_t millis) :
HTTPRPCTimer(struct event_base* eventBase, std::function<void()>& func, int64_t millis) :
ev(eventBase, false, func)
{
struct timeval tv;
Expand All @@ -53,7 +53,7 @@ class HTTPRPCTimerInterface : public RPCTimerInterface
{
return "HTTP";
}
RPCTimerBase* NewTimer(std::function<void(void)>& func, int64_t millis) override
RPCTimerBase* NewTimer(std::function<void()>& func, int64_t millis) override
{
return new HTTPRPCTimer(base, func, millis);
}
Expand Down
2 changes: 1 addition & 1 deletion src/httpserver.cpp
Expand Up @@ -498,7 +498,7 @@ static void httpevent_callback_fn(evutil_socket_t, short, void* data)
delete self;
}

HTTPEvent::HTTPEvent(struct event_base* base, bool _deleteWhenTriggered, const std::function<void(void)>& _handler):
HTTPEvent::HTTPEvent(struct event_base* base, bool _deleteWhenTriggered, const std::function<void()>& _handler):
deleteWhenTriggered(_deleteWhenTriggered), handler(_handler)
{
ev = event_new(base, -1, 0, httpevent_callback_fn, this);
Expand Down
4 changes: 2 additions & 2 deletions src/httpserver.h
Expand Up @@ -134,7 +134,7 @@ class HTTPEvent
* deleteWhenTriggered deletes this event object after the event is triggered (and the handler called)
* handler is the handler to call when the event is triggered.
*/
HTTPEvent(struct event_base* base, bool deleteWhenTriggered, const std::function<void(void)>& handler);
HTTPEvent(struct event_base* base, bool deleteWhenTriggered, const std::function<void()>& handler);
~HTTPEvent();

/** Trigger the event. If tv is 0, trigger it immediately. Otherwise trigger it after
Expand All @@ -143,7 +143,7 @@ class HTTPEvent
void trigger(struct timeval* tv);

bool deleteWhenTriggered;
std::function<void(void)> handler;
std::function<void()> handler;
private:
struct event* ev;
};
Expand Down
2 changes: 1 addition & 1 deletion src/init.cpp
Expand Up @@ -691,7 +691,7 @@ static void ThreadImport(std::vector<fs::path> vImportFiles)
* Ensure that Bitcoin is running in a usable environment with all
* necessary library support.
*/
static bool InitSanityCheck(void)
static bool InitSanityCheck()
{
if(!ECC_InitSanityCheck()) {
InitError("Elliptic curve cryptography sanity check failure. Aborting.");
Expand Down
6 changes: 3 additions & 3 deletions src/key.h
Expand Up @@ -181,12 +181,12 @@ struct CExtKey {
};

/** Initialize the elliptic curve support. May not be called twice without calling ECC_Stop first. */
void ECC_Start(void);
void ECC_Start();

/** Deinitialize the elliptic curve support. No-op if ECC_Start wasn't called first. */
void ECC_Stop(void);
void ECC_Stop();

/** Check that required EC support is available at runtime. */
bool ECC_InitSanityCheck(void);
bool ECC_InitSanityCheck();

#endif // BITCOIN_KEY_H
2 changes: 1 addition & 1 deletion src/qt/bitcoin.cpp
Expand Up @@ -586,7 +586,7 @@ int main(int argc, char *argv[])
// Need to pass name here as CAmount is a typedef (see http://qt-project.org/doc/qt-5/qmetatype.html#qRegisterMetaType)
// IMPORTANT if it is no longer a typedef use the normal variant above
qRegisterMetaType< CAmount >("CAmount");
qRegisterMetaType< std::function<void(void)> >("std::function<void(void)>");
qRegisterMetaType< std::function<void()> >("std::function<void()>");
#ifdef ENABLE_WALLET
qRegisterMetaType<WalletModel*>("WalletModel*");
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/qt/macnotificationhandler.h
Expand Up @@ -19,7 +19,7 @@ class MacNotificationHandler : public QObject
void showNotification(const QString &title, const QString &text);

/** check if OS can handle UserNotifications */
bool hasUserNotificationCenterSupport(void);
bool hasUserNotificationCenterSupport();
static MacNotificationHandler *instance();
};

Expand Down
6 changes: 3 additions & 3 deletions src/qt/rpcconsole.cpp
Expand Up @@ -101,7 +101,7 @@ class QtRPCTimerBase: public QObject, public RPCTimerBase
{
Q_OBJECT
public:
QtRPCTimerBase(std::function<void(void)>& _func, int64_t millis):
QtRPCTimerBase(std::function<void()>& _func, int64_t millis):
func(_func)
{
timer.setSingleShot(true);
Expand All @@ -111,15 +111,15 @@ class QtRPCTimerBase: public QObject, public RPCTimerBase
~QtRPCTimerBase() {}
private:
QTimer timer;
std::function<void(void)> func;
std::function<void()> func;
};

class QtRPCTimerInterface: public RPCTimerInterface
{
public:
~QtRPCTimerInterface() {}
const char *Name() { return "Qt"; }
RPCTimerBase* NewTimer(std::function<void(void)>& func, int64_t millis)
RPCTimerBase* NewTimer(std::function<void()>& func, int64_t millis)
{
return new QtRPCTimerBase(func, millis);
}
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/server.cpp
Expand Up @@ -540,7 +540,7 @@ void RPCUnsetTimerInterface(RPCTimerInterface *iface)
timerInterface = nullptr;
}

void RPCRunLater(const std::string& name, std::function<void(void)> func, int64_t nSeconds)
void RPCRunLater(const std::string& name, std::function<void()> func, int64_t nSeconds)
{
if (!timerInterface)
throw JSONRPCError(RPC_INTERNAL_ERROR, "No timer handler registered for RPC");
Expand Down
4 changes: 2 additions & 2 deletions src/rpc/server.h
Expand Up @@ -110,7 +110,7 @@ class RPCTimerInterface
* This is needed to cope with the case in which there is no HTTP server, but
* only GUI RPC console, and to break the dependency of pcserver on httprpc.
*/
virtual RPCTimerBase* NewTimer(std::function<void(void)>& func, int64_t millis) = 0;
virtual RPCTimerBase* NewTimer(std::function<void()>& func, int64_t millis) = 0;
};

/** Set the factory function for timers */
Expand All @@ -124,7 +124,7 @@ void RPCUnsetTimerInterface(RPCTimerInterface *iface);
* Run func nSeconds from now.
* Overrides previous timer <name> (if any).
*/
void RPCRunLater(const std::string& name, std::function<void(void)> func, int64_t nSeconds);
void RPCRunLater(const std::string& name, std::function<void()> func, int64_t nSeconds);

typedef UniValue(*rpcfn_type)(const JSONRPCRequest& jsonRequest);

Expand Down
4 changes: 2 additions & 2 deletions src/scheduler.cpp
Expand Up @@ -159,7 +159,7 @@ void SingleThreadedSchedulerClient::MaybeScheduleProcessQueue() {
}

void SingleThreadedSchedulerClient::ProcessQueue() {
std::function<void (void)> callback;
std::function<void ()> callback;
{
LOCK(m_cs_callbacks_pending);
if (m_are_callbacks_running) return;
Expand Down Expand Up @@ -187,7 +187,7 @@ void SingleThreadedSchedulerClient::ProcessQueue() {
callback();
}

void SingleThreadedSchedulerClient::AddToProcessQueue(std::function<void (void)> func) {
void SingleThreadedSchedulerClient::AddToProcessQueue(std::function<void ()> func) {
assert(m_pscheduler);

{
Expand Down
6 changes: 3 additions & 3 deletions src/scheduler.h
Expand Up @@ -40,7 +40,7 @@ class CScheduler
CScheduler();
~CScheduler();

typedef std::function<void(void)> Function;
typedef std::function<void()> Function;

// Call func at/after time t
void schedule(Function f, boost::chrono::system_clock::time_point t=boost::chrono::system_clock::now());
Expand Down Expand Up @@ -99,7 +99,7 @@ class SingleThreadedSchedulerClient {
CScheduler *m_pscheduler;

CCriticalSection m_cs_callbacks_pending;
std::list<std::function<void (void)>> m_callbacks_pending GUARDED_BY(m_cs_callbacks_pending);
std::list<std::function<void ()>> m_callbacks_pending GUARDED_BY(m_cs_callbacks_pending);
bool m_are_callbacks_running GUARDED_BY(m_cs_callbacks_pending) = false;

void MaybeScheduleProcessQueue();
Expand All @@ -114,7 +114,7 @@ class SingleThreadedSchedulerClient {
* Practically, this means that callbacks can behave as if they are executed
* in order by a single thread.
*/
void AddToProcessQueue(std::function<void (void)> func);
void AddToProcessQueue(std::function<void ()> func);

// Processes all remaining queue members on the calling thread, blocking until queue is empty
// Must be called after the CScheduler has no remaining processing threads!
Expand Down
2 changes: 1 addition & 1 deletion src/test/crypto_tests.cpp
Expand Up @@ -200,7 +200,7 @@ static void TestChaCha20(const std::string &hexkey, uint64_t nonce, uint64_t see
BOOST_CHECK(out == outres);
}

static std::string LongTestString(void) {
static std::string LongTestString() {
std::string ret;
for (int i=0; i<200000; i++) {
ret += (unsigned char)(i);
Expand Down
2 changes: 1 addition & 1 deletion src/util.cpp
Expand Up @@ -1248,7 +1248,7 @@ fs::path AbsPathForConfigVal(const fs::path& path, bool net_specific)
return fs::absolute(path, GetDataDir(net_specific));
}

int ScheduleBatchPriority(void)
int ScheduleBatchPriority()
{
#ifdef SCHED_BATCH
const static sched_param param{0};
Expand Down
2 changes: 1 addition & 1 deletion src/util.h
Expand Up @@ -347,7 +347,7 @@ std::string CopyrightHolders(const std::string& strPrefix);
* @return The return value of sched_setschedule(), or 1 on systems without
* sched_setschedule().
*/
int ScheduleBatchPriority(void);
int ScheduleBatchPriority();

namespace util {

Expand Down
4 changes: 2 additions & 2 deletions src/validation.cpp
Expand Up @@ -4682,7 +4682,7 @@ int VersionBitsTipStateSinceHeight(const Consensus::Params& params, Consensus::D

static const uint64_t MEMPOOL_DUMP_VERSION = 1;

bool LoadMempool(void)
bool LoadMempool()
{
const CChainParams& chainparams = Params();
int64_t nExpiryTimeout = gArgs.GetArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY) * 60 * 60;
Expand Down Expand Up @@ -4759,7 +4759,7 @@ bool LoadMempool(void)
return true;
}

bool DumpMempool(void)
bool DumpMempool()
{
int64_t start = GetTimeMicros();

Expand Down

0 comments on commit 2796c6e

Please sign in to comment.