Skip to content

Commit

Permalink
Use noexcept instead of exception specifications
Browse files Browse the repository at this point in the history
  • Loading branch information
p12tic committed May 30, 2020
1 parent 5d0f6e6 commit 5eac13a
Show file tree
Hide file tree
Showing 19 changed files with 73 additions and 87 deletions.
4 changes: 2 additions & 2 deletions src/lib/arch/XArch.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ string for that error code.
class XArchEval {
public:
XArchEval() { }
virtual ~XArchEval() _NOEXCEPT { }
virtual ~XArchEval() noexcept { }

virtual std::string eval() const = 0;
};
Expand All @@ -66,7 +66,7 @@ class XArch : public std::runtime_error {
public:
XArch(XArchEval* adopted) : std::runtime_error(adopted->eval()) { delete adopted; }
XArch(const std::string& msg) : std::runtime_error(msg) { }
virtual ~XArch() _NOEXCEPT { }
virtual ~XArch() noexcept { }
};

// Macro to declare XArch derived types
Expand Down
2 changes: 1 addition & 1 deletion src/lib/arch/unix/XArchUnix.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
class XArchEvalUnix : public XArchEval {
public:
XArchEvalUnix(int error) : m_error(error) { }
virtual ~XArchEvalUnix() _NOEXCEPT { }
virtual ~XArchEvalUnix() noexcept { }

virtual std::string eval() const;

Expand Down
4 changes: 2 additions & 2 deletions src/lib/arch/win32/XArchWindows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
//

std::string
XArchEvalWindows::eval() const throw()
XArchEvalWindows::eval() const noexcept
{
char* cmsg;
if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
Expand All @@ -50,7 +50,7 @@ XArchEvalWindows::eval() const throw()
//

std::string
XArchEvalWinsock::eval() const throw()
XArchEvalWinsock::eval() const noexcept
{
// built-in windows function for looking up error message strings
// may not look up network error messages correctly. we'll have
Expand Down
2 changes: 1 addition & 1 deletion src/lib/barrier/ProtocolUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ ProtocolUtil::read(barrier::IStream* stream, void* vbuffer, UInt32 count)
//

String
XIOReadMismatch::getWhat() const throw()
XIOReadMismatch::getWhat() const noexcept
{
return format("XIOReadMismatch", "ProtocolUtil::readf() mismatch");
}
2 changes: 1 addition & 1 deletion src/lib/barrier/ProtocolUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,5 @@ match the format.
class XIOReadMismatch : public XIO {
public:
// XBase overrides
virtual std::string getWhat() const throw();
virtual std::string getWhat() const noexcept;
};
30 changes: 10 additions & 20 deletions src/lib/barrier/XBarrier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
// XBadClient
//

String
XBadClient::getWhat() const throw()
String XBadClient::getWhat() const noexcept
{
return "XBadClient";
}
Expand All @@ -41,20 +40,17 @@ XIncompatibleClient::XIncompatibleClient(int major, int minor) :
// do nothing
}

int
XIncompatibleClient::getMajor() const throw()
int XIncompatibleClient::getMajor() const noexcept
{
return m_major;
}

int
XIncompatibleClient::getMinor() const throw()
int XIncompatibleClient::getMinor() const noexcept
{
return m_minor;
}

String
XIncompatibleClient::getWhat() const throw()
String XIncompatibleClient::getWhat() const noexcept
{
return format("XIncompatibleClient", "incompatible client %{1}.%{2}",
barrier::string::sprintf("%d", m_major).c_str(),
Expand All @@ -72,14 +68,12 @@ XDuplicateClient::XDuplicateClient(const String& name) :
// do nothing
}

const String&
XDuplicateClient::getName() const throw()
const String& XDuplicateClient::getName() const noexcept
{
return m_name;
}

String
XDuplicateClient::getWhat() const throw()
String XDuplicateClient::getWhat() const noexcept
{
return format("XDuplicateClient", "duplicate client %{1}", m_name.c_str());
}
Expand All @@ -95,14 +89,12 @@ XUnknownClient::XUnknownClient(const String& name) :
// do nothing
}

const String&
XUnknownClient::getName() const throw()
const String& XUnknownClient::getName() const noexcept
{
return m_name;
}

String
XUnknownClient::getWhat() const throw()
String XUnknownClient::getWhat() const noexcept
{
return format("XUnknownClient", "unknown client %{1}", m_name.c_str());
}
Expand All @@ -118,14 +110,12 @@ XExitApp::XExitApp(int code) :
// do nothing
}

int
XExitApp::getCode() const throw()
int XExitApp::getCode() const noexcept
{
return m_code;
}

String
XExitApp::getWhat() const throw()
String XExitApp::getWhat() const noexcept
{
return format(
"XExitApp", "exiting with code %{1}",
Expand Down
24 changes: 12 additions & 12 deletions src/lib/barrier/XBarrier.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ class XIncompatibleClient : public XBarrier {
//@{

//! Get client's major version number
int getMajor() const throw();
int getMajor() const noexcept;
//! Get client's minor version number
int getMinor() const throw();
int getMinor() const noexcept;

//@}

protected:
virtual std::string getWhat() const throw();
virtual std::string getWhat() const noexcept;

private:
int m_major;
Expand All @@ -69,18 +69,18 @@ a client that is already connected.
class XDuplicateClient : public XBarrier {
public:
XDuplicateClient(const std::string& name);
virtual ~XDuplicateClient() _NOEXCEPT { }
virtual ~XDuplicateClient() noexcept { }

//! @name accessors
//@{

//! Get client's name
virtual const std::string& getName() const throw();
virtual const std::string& getName() const noexcept;

//@}

protected:
virtual std::string getWhat() const throw();
virtual std::string getWhat() const noexcept;

private:
std::string m_name;
Expand All @@ -94,18 +94,18 @@ unknown to the server.
class XUnknownClient : public XBarrier {
public:
XUnknownClient(const std::string& name);
virtual ~XUnknownClient() _NOEXCEPT { }
virtual ~XUnknownClient() noexcept { }

//! @name accessors
//@{

//! Get the client's name
virtual const std::string& getName() const throw();
virtual const std::string& getName() const noexcept;

//@}

protected:
virtual std::string getWhat() const throw();
virtual std::string getWhat() const noexcept;

private:
std::string m_name;
Expand All @@ -120,13 +120,13 @@ exit(int).
class XExitApp : public XBarrier {
public:
XExitApp(int code);
virtual ~XExitApp() _NOEXCEPT { }
virtual ~XExitApp() noexcept { }

//! Get the exit code
int getCode() const throw();
int getCode() const noexcept;

protected:
virtual std::string getWhat() const throw();
virtual std::string getWhat() const noexcept;

private:
int m_code;
Expand Down
8 changes: 4 additions & 4 deletions src/lib/barrier/XScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
// XScreenOpenFailure
//

std::string XScreenOpenFailure::getWhat() const throw()
std::string XScreenOpenFailure::getWhat() const noexcept
{
return format("XScreenOpenFailure", "unable to open screen");
}
Expand All @@ -32,7 +32,7 @@ std::string XScreenOpenFailure::getWhat() const throw()
// XScreenXInputFailure
//

std::string XScreenXInputFailure::getWhat() const throw()
std::string XScreenXInputFailure::getWhat() const noexcept
{
return "";
}
Expand All @@ -48,7 +48,7 @@ XScreenUnavailable::XScreenUnavailable(double timeUntilRetry) :
// do nothing
}

XScreenUnavailable::~XScreenUnavailable() _NOEXCEPT
XScreenUnavailable::~XScreenUnavailable() noexcept
{
// do nothing
}
Expand All @@ -59,7 +59,7 @@ XScreenUnavailable::getRetryTime() const
return m_timeUntilRetry;
}

std::string XScreenUnavailable::getWhat() const throw()
std::string XScreenUnavailable::getWhat() const noexcept
{
return format("XScreenUnavailable", "unable to open screen");
}
4 changes: 2 additions & 2 deletions src/lib/barrier/XScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class XScreenUnavailable : public XScreenOpenFailure {
trying to open the screen again.
*/
XScreenUnavailable(double timeUntilRetry);
virtual ~XScreenUnavailable() _NOEXCEPT;
virtual ~XScreenUnavailable() noexcept;

//! @name manipulators
//@{
Expand All @@ -61,7 +61,7 @@ class XScreenUnavailable : public XScreenOpenFailure {
//@}

protected:
virtual std::string getWhat() const throw();
virtual std::string getWhat() const noexcept;

private:
double m_timeUntilRetry;
Expand Down
7 changes: 3 additions & 4 deletions src/lib/base/XBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ XBase::XBase(const std::string& msg) :
// do nothing
}

XBase::~XBase() _NOEXCEPT
XBase::~XBase() noexcept
{
// do nothing
}

const char*
XBase::what() const _NOEXCEPT
XBase::what() const noexcept
{
const char* what = std::runtime_error::what();
if (strlen(what) == 0) {
Expand All @@ -54,8 +54,7 @@ XBase::what() const _NOEXCEPT
return what;
}

std::string
XBase::format(const char* /*id*/, const char* fmt, ...) const throw()
std::string XBase::format(const char* /*id*/, const char* fmt, ...) const noexcept
{
// FIXME -- lookup message string using id as an index. set
// fmt to that string if it exists.
Expand Down
20 changes: 10 additions & 10 deletions src/lib/base/XBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,22 @@ class XBase : public std::runtime_error {
XBase();
//! Use \c msg as the result of what()
XBase(const std::string& msg);
virtual ~XBase() _NOEXCEPT;
virtual ~XBase() noexcept;

//! Reason for exception
virtual const char* what() const _NOEXCEPT;
virtual const char* what() const noexcept;

protected:
//! Get a human readable string describing the exception
virtual std::string getWhat() const throw() { return ""; }
virtual std::string getWhat() const noexcept { return ""; }

//! Format a string
/*!
Looks up a message format using \c id, using \c defaultFormat if
no format can be found, then replaces positional parameters in
the format string and returns the result.
*/
virtual std::string format(const char* id, const char* defaultFormat, ...) const throw();
virtual std::string format(const char* id, const char* defaultFormat, ...) const noexcept;
private:
mutable std::string m_what;
};
Expand All @@ -62,7 +62,7 @@ class name_ : public super_ { \
public: \
name_() : super_() { } \
name_(const std::string& msg) : super_(msg) { } \
virtual ~name_() _NOEXCEPT { } \
virtual ~name_() noexcept { } \
}

/*!
Expand All @@ -76,10 +76,10 @@ class name_ : public super_ { \
public: \
name_() : super_() { } \
name_(const std::string& msg) : super_(msg) { } \
virtual ~name_() _NOEXCEPT { } \
virtual ~name_() noexcept { } \
\
protected: \
virtual std::string getWhat() const throw(); \
virtual std::string getWhat() const noexcept; \
}

/*!
Expand All @@ -98,9 +98,9 @@ private: \
public: \
name_() : super_(), m_state(kDone) { } \
name_(const std::string& msg) : super_(msg), m_state(kFirst) { } \
virtual ~name_() _NOEXCEPT { } \
virtual ~name_() noexcept { } \
\
virtual const char* what() const _NOEXCEPT \
virtual const char* what() const noexcept \
{ \
if (m_state == kFirst) { \
m_state = kFormat; \
Expand All @@ -116,7 +116,7 @@ public: \
} \
\
protected: \
virtual std::string getWhat() const throw(); \
virtual std::string getWhat() const noexcept; \
\
private: \
mutable EState m_state; \
Expand Down
2 changes: 1 addition & 1 deletion src/lib/common/stdexcept.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@

// apple declares _NOEXCEPT
#ifndef _NOEXCEPT
# define _NOEXCEPT throw()
# define _NOEXCEPT noexcept
#endif
Loading

0 comments on commit 5eac13a

Please sign in to comment.