Merge pull request #718 from p12tic/use-noexcept

Use noexcept instead of dynamic exception specifications
This commit is contained in:
Dom Rodriguez 2020-05-30 21:39:12 +01:00 committed by GitHub
commit 8891364258
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 79 additions and 118 deletions

View File

@ -20,7 +20,7 @@
#include "common/common.h" #include "common/common.h"
#include "common/stdstring.h" #include "common/stdstring.h"
#include "common/stdexcept.h" #include <stdexcept>
//! Generic thread exception //! Generic thread exception
/*! /*!
@ -56,7 +56,7 @@ string for that error code.
class XArchEval { class XArchEval {
public: public:
XArchEval() { } XArchEval() { }
virtual ~XArchEval() _NOEXCEPT { } virtual ~XArchEval() noexcept { }
virtual std::string eval() const = 0; virtual std::string eval() const = 0;
}; };
@ -66,7 +66,7 @@ class XArch : public std::runtime_error {
public: public:
XArch(XArchEval* adopted) : std::runtime_error(adopted->eval()) { delete adopted; } XArch(XArchEval* adopted) : std::runtime_error(adopted->eval()) { delete adopted; }
XArch(const std::string& msg) : std::runtime_error(msg) { } XArch(const std::string& msg) : std::runtime_error(msg) { }
virtual ~XArch() _NOEXCEPT { } virtual ~XArch() noexcept { }
}; };
// Macro to declare XArch derived types // Macro to declare XArch derived types

View File

@ -24,7 +24,7 @@
class XArchEvalUnix : public XArchEval { class XArchEvalUnix : public XArchEval {
public: public:
XArchEvalUnix(int error) : m_error(error) { } XArchEvalUnix(int error) : m_error(error) { }
virtual ~XArchEvalUnix() _NOEXCEPT { } virtual ~XArchEvalUnix() noexcept { }
virtual std::string eval() const; virtual std::string eval() const;

View File

@ -24,7 +24,7 @@
// //
std::string std::string
XArchEvalWindows::eval() const throw() XArchEvalWindows::eval() const noexcept
{ {
char* cmsg; char* cmsg;
if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
@ -50,7 +50,7 @@ XArchEvalWindows::eval() const throw()
// //
std::string std::string
XArchEvalWinsock::eval() const throw() XArchEvalWinsock::eval() const noexcept
{ {
// built-in windows function for looking up error message strings // built-in windows function for looking up error message strings
// may not look up network error messages correctly. we'll have // may not look up network error messages correctly. we'll have

View File

@ -20,7 +20,6 @@
#include "barrier/IPlatformScreen.h" #include "barrier/IPlatformScreen.h"
#include "barrier/DragInformation.h" #include "barrier/DragInformation.h"
#include "common/stdexcept.h"
//! Base screen implementation //! Base screen implementation
/*! /*!

View File

@ -539,7 +539,7 @@ ProtocolUtil::read(barrier::IStream* stream, void* vbuffer, UInt32 count)
// //
String String
XIOReadMismatch::getWhat() const throw() XIOReadMismatch::getWhat() const noexcept
{ {
return format("XIOReadMismatch", "ProtocolUtil::readf() mismatch"); return format("XIOReadMismatch", "ProtocolUtil::readf() mismatch");
} }

View File

@ -92,5 +92,5 @@ match the format.
class XIOReadMismatch : public XIO { class XIOReadMismatch : public XIO {
public: public:
// XBase overrides // XBase overrides
virtual std::string getWhat() const throw(); virtual std::string getWhat() const noexcept;
}; };

View File

@ -29,9 +29,9 @@
#include "base/Log.h" #include "base/Log.h"
#include "base/Stopwatch.h" #include "base/Stopwatch.h"
#include "base/String.h" #include "base/String.h"
#include "common/stdexcept.h"
#include <fstream> #include <fstream>
#include <stdexcept>
using namespace std; using namespace std;

View File

@ -23,8 +23,7 @@
// XBadClient // XBadClient
// //
String String XBadClient::getWhat() const noexcept
XBadClient::getWhat() const throw()
{ {
return "XBadClient"; return "XBadClient";
} }
@ -41,20 +40,17 @@ XIncompatibleClient::XIncompatibleClient(int major, int minor) :
// do nothing // do nothing
} }
int int XIncompatibleClient::getMajor() const noexcept
XIncompatibleClient::getMajor() const throw()
{ {
return m_major; return m_major;
} }
int int XIncompatibleClient::getMinor() const noexcept
XIncompatibleClient::getMinor() const throw()
{ {
return m_minor; return m_minor;
} }
String String XIncompatibleClient::getWhat() const noexcept
XIncompatibleClient::getWhat() const throw()
{ {
return format("XIncompatibleClient", "incompatible client %{1}.%{2}", return format("XIncompatibleClient", "incompatible client %{1}.%{2}",
barrier::string::sprintf("%d", m_major).c_str(), barrier::string::sprintf("%d", m_major).c_str(),
@ -72,14 +68,12 @@ XDuplicateClient::XDuplicateClient(const String& name) :
// do nothing // do nothing
} }
const String& const String& XDuplicateClient::getName() const noexcept
XDuplicateClient::getName() const throw()
{ {
return m_name; return m_name;
} }
String String XDuplicateClient::getWhat() const noexcept
XDuplicateClient::getWhat() const throw()
{ {
return format("XDuplicateClient", "duplicate client %{1}", m_name.c_str()); return format("XDuplicateClient", "duplicate client %{1}", m_name.c_str());
} }
@ -95,14 +89,12 @@ XUnknownClient::XUnknownClient(const String& name) :
// do nothing // do nothing
} }
const String& const String& XUnknownClient::getName() const noexcept
XUnknownClient::getName() const throw()
{ {
return m_name; return m_name;
} }
String String XUnknownClient::getWhat() const noexcept
XUnknownClient::getWhat() const throw()
{ {
return format("XUnknownClient", "unknown client %{1}", m_name.c_str()); return format("XUnknownClient", "unknown client %{1}", m_name.c_str());
} }
@ -118,14 +110,12 @@ XExitApp::XExitApp(int code) :
// do nothing // do nothing
} }
int int XExitApp::getCode() const noexcept
XExitApp::getCode() const throw()
{ {
return m_code; return m_code;
} }
String String XExitApp::getWhat() const noexcept
XExitApp::getWhat() const throw()
{ {
return format( return format(
"XExitApp", "exiting with code %{1}", "XExitApp", "exiting with code %{1}",

View File

@ -47,14 +47,14 @@ public:
//@{ //@{
//! Get client's major version number //! Get client's major version number
int getMajor() const throw(); int getMajor() const noexcept;
//! Get client's minor version number //! Get client's minor version number
int getMinor() const throw(); int getMinor() const noexcept;
//@} //@}
protected: protected:
virtual std::string getWhat() const throw(); virtual std::string getWhat() const noexcept;
private: private:
int m_major; int m_major;
@ -69,18 +69,18 @@ a client that is already connected.
class XDuplicateClient : public XBarrier { class XDuplicateClient : public XBarrier {
public: public:
XDuplicateClient(const std::string& name); XDuplicateClient(const std::string& name);
virtual ~XDuplicateClient() _NOEXCEPT { } virtual ~XDuplicateClient() noexcept { }
//! @name accessors //! @name accessors
//@{ //@{
//! Get client's name //! Get client's name
virtual const std::string& getName() const throw(); virtual const std::string& getName() const noexcept;
//@} //@}
protected: protected:
virtual std::string getWhat() const throw(); virtual std::string getWhat() const noexcept;
private: private:
std::string m_name; std::string m_name;
@ -94,18 +94,18 @@ unknown to the server.
class XUnknownClient : public XBarrier { class XUnknownClient : public XBarrier {
public: public:
XUnknownClient(const std::string& name); XUnknownClient(const std::string& name);
virtual ~XUnknownClient() _NOEXCEPT { } virtual ~XUnknownClient() noexcept { }
//! @name accessors //! @name accessors
//@{ //@{
//! Get the client's name //! Get the client's name
virtual const std::string& getName() const throw(); virtual const std::string& getName() const noexcept;
//@} //@}
protected: protected:
virtual std::string getWhat() const throw(); virtual std::string getWhat() const noexcept;
private: private:
std::string m_name; std::string m_name;
@ -120,13 +120,13 @@ exit(int).
class XExitApp : public XBarrier { class XExitApp : public XBarrier {
public: public:
XExitApp(int code); XExitApp(int code);
virtual ~XExitApp() _NOEXCEPT { } virtual ~XExitApp() noexcept { }
//! Get the exit code //! Get the exit code
int getCode() const throw(); int getCode() const noexcept;
protected: protected:
virtual std::string getWhat() const throw(); virtual std::string getWhat() const noexcept;
private: private:
int m_code; int m_code;

View File

@ -22,7 +22,7 @@
// XScreenOpenFailure // XScreenOpenFailure
// //
std::string XScreenOpenFailure::getWhat() const throw() std::string XScreenOpenFailure::getWhat() const noexcept
{ {
return format("XScreenOpenFailure", "unable to open screen"); return format("XScreenOpenFailure", "unable to open screen");
} }
@ -32,7 +32,7 @@ std::string XScreenOpenFailure::getWhat() const throw()
// XScreenXInputFailure // XScreenXInputFailure
// //
std::string XScreenXInputFailure::getWhat() const throw() std::string XScreenXInputFailure::getWhat() const noexcept
{ {
return ""; return "";
} }
@ -48,7 +48,7 @@ XScreenUnavailable::XScreenUnavailable(double timeUntilRetry) :
// do nothing // do nothing
} }
XScreenUnavailable::~XScreenUnavailable() _NOEXCEPT XScreenUnavailable::~XScreenUnavailable() noexcept
{ {
// do nothing // do nothing
} }
@ -59,7 +59,7 @@ XScreenUnavailable::getRetryTime() const
return m_timeUntilRetry; return m_timeUntilRetry;
} }
std::string XScreenUnavailable::getWhat() const throw() std::string XScreenUnavailable::getWhat() const noexcept
{ {
return format("XScreenUnavailable", "unable to open screen"); return format("XScreenUnavailable", "unable to open screen");
} }

View File

@ -47,7 +47,7 @@ public:
trying to open the screen again. trying to open the screen again.
*/ */
XScreenUnavailable(double timeUntilRetry); XScreenUnavailable(double timeUntilRetry);
virtual ~XScreenUnavailable() _NOEXCEPT; virtual ~XScreenUnavailable() noexcept;
//! @name manipulators //! @name manipulators
//@{ //@{
@ -61,7 +61,7 @@ public:
//@} //@}
protected: protected:
virtual std::string getWhat() const throw(); virtual std::string getWhat() const noexcept;
private: private:
double m_timeUntilRetry; double m_timeUntilRetry;

View File

@ -38,13 +38,13 @@ XBase::XBase(const std::string& msg) :
// do nothing // do nothing
} }
XBase::~XBase() _NOEXCEPT XBase::~XBase() noexcept
{ {
// do nothing // do nothing
} }
const char* const char*
XBase::what() const _NOEXCEPT XBase::what() const noexcept
{ {
const char* what = std::runtime_error::what(); const char* what = std::runtime_error::what();
if (strlen(what) == 0) { if (strlen(what) == 0) {
@ -54,8 +54,7 @@ XBase::what() const _NOEXCEPT
return what; return what;
} }
std::string std::string XBase::format(const char* /*id*/, const char* fmt, ...) const noexcept
XBase::format(const char* /*id*/, const char* fmt, ...) const throw()
{ {
// FIXME -- lookup message string using id as an index. set // FIXME -- lookup message string using id as an index. set
// fmt to that string if it exists. // fmt to that string if it exists.

View File

@ -18,7 +18,7 @@
#pragma once #pragma once
#include "common/stdexcept.h" #include <stdexcept>
#include <string> #include <string>
//! Exception base class //! Exception base class
@ -31,14 +31,14 @@ public:
XBase(); XBase();
//! Use \c msg as the result of what() //! Use \c msg as the result of what()
XBase(const std::string& msg); XBase(const std::string& msg);
virtual ~XBase() _NOEXCEPT; virtual ~XBase() noexcept;
//! Reason for exception //! Reason for exception
virtual const char* what() const _NOEXCEPT; virtual const char* what() const noexcept;
protected: protected:
//! Get a human readable string describing the exception //! 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 //! Format a string
/*! /*!
@ -46,7 +46,7 @@ protected:
no format can be found, then replaces positional parameters in no format can be found, then replaces positional parameters in
the format string and returns the result. 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: private:
mutable std::string m_what; mutable std::string m_what;
}; };
@ -62,7 +62,7 @@ class name_ : public super_ { \
public: \ public: \
name_() : super_() { } \ name_() : super_() { } \
name_(const std::string& msg) : super_(msg) { } \ name_(const std::string& msg) : super_(msg) { } \
virtual ~name_() _NOEXCEPT { } \ virtual ~name_() noexcept { } \
} }
/*! /*!
@ -76,10 +76,10 @@ class name_ : public super_ { \
public: \ public: \
name_() : super_() { } \ name_() : super_() { } \
name_(const std::string& msg) : super_(msg) { } \ name_(const std::string& msg) : super_(msg) { } \
virtual ~name_() _NOEXCEPT { } \ virtual ~name_() noexcept { } \
\ \
protected: \ protected: \
virtual std::string getWhat() const throw(); \ virtual std::string getWhat() const noexcept; \
} }
/*! /*!
@ -98,9 +98,9 @@ private: \
public: \ public: \
name_() : super_(), m_state(kDone) { } \ name_() : super_(), m_state(kDone) { } \
name_(const std::string& msg) : super_(msg), m_state(kFirst) { } \ 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) { \ if (m_state == kFirst) { \
m_state = kFormat; \ m_state = kFormat; \
@ -116,7 +116,7 @@ public: \
} \ } \
\ \
protected: \ protected: \
virtual std::string getWhat() const throw(); \ virtual std::string getWhat() const noexcept; \
\ \
private: \ private: \
mutable EState m_state; \ mutable EState m_state; \

View File

@ -38,11 +38,11 @@
#include "base/IEventQueue.h" #include "base/IEventQueue.h"
#include "base/TMethodEventJob.h" #include "base/TMethodEventJob.h"
#include "base/TMethodJob.h" #include "base/TMethodJob.h"
#include "common/stdexcept.h"
#include <cstring> #include <cstring>
#include <cstdlib> #include <cstdlib>
#include <sstream> #include <sstream>
#include <stdexcept>
#include <fstream> #include <fstream>
// //

View File

@ -1,23 +0,0 @@
/*
* barrier -- mouse and keyboard sharing utility
* Copyright (C) 2014-2016 Symless Ltd.
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdexcept>
// apple declares _NOEXCEPT
#ifndef _NOEXCEPT
# define _NOEXCEPT throw()
#endif

View File

@ -22,7 +22,7 @@
// XIOClosed // XIOClosed
// //
std::string XIOClosed::getWhat() const throw() std::string XIOClosed::getWhat() const noexcept
{ {
return format("XIOClosed", "already closed"); return format("XIOClosed", "already closed");
} }
@ -32,7 +32,7 @@ std::string XIOClosed::getWhat() const throw()
// XIOEndOfStream // XIOEndOfStream
// //
std::string XIOEndOfStream::getWhat() const throw() std::string XIOEndOfStream::getWhat() const noexcept
{ {
return format("XIOEndOfStream", "reached end of stream"); return format("XIOEndOfStream", "reached end of stream");
} }
@ -42,7 +42,7 @@ std::string XIOEndOfStream::getWhat() const throw()
// XIOWouldBlock // XIOWouldBlock
// //
std::string XIOWouldBlock::getWhat() const throw() std::string XIOWouldBlock::getWhat() const noexcept
{ {
return format("XIOWouldBlock", "stream operation would block"); return format("XIOWouldBlock", "stream operation would block");
} }

View File

@ -22,7 +22,7 @@
// XMTThreadUnavailable // XMTThreadUnavailable
// //
std::string XMTThreadUnavailable::getWhat() const throw() std::string XMTThreadUnavailable::getWhat() const noexcept
{ {
return format("XMTThreadUnavailable", "cannot create thread"); return format("XMTThreadUnavailable", "cannot create thread");
} }

View File

@ -23,7 +23,7 @@
// XSocketAddress // XSocketAddress
// //
XSocketAddress::XSocketAddress(EError error, const std::string& hostname, int port) _NOEXCEPT : XSocketAddress::XSocketAddress(EError error, const std::string& hostname, int port) noexcept :
m_error(error), m_error(error),
m_hostname(hostname), m_hostname(hostname),
m_port(port) m_port(port)
@ -31,25 +31,22 @@ XSocketAddress::XSocketAddress(EError error, const std::string& hostname, int po
// do nothing // do nothing
} }
XSocketAddress::EError XSocketAddress::EError XSocketAddress::getError() const noexcept
XSocketAddress::getError() const throw()
{ {
return m_error; return m_error;
} }
std::string std::string XSocketAddress::getHostname() const noexcept
XSocketAddress::getHostname() const throw()
{ {
return m_hostname; return m_hostname;
} }
int int XSocketAddress::getPort() const noexcept
XSocketAddress::getPort() const throw()
{ {
return m_port; return m_port;
} }
std::string XSocketAddress::getWhat() const throw() std::string XSocketAddress::getWhat() const noexcept
{ {
static const char* s_errorID[] = { static const char* s_errorID[] = {
"XSocketAddressUnknown", "XSocketAddressUnknown",
@ -75,7 +72,7 @@ std::string XSocketAddress::getWhat() const throw()
// XSocketIOClose // XSocketIOClose
// //
std::string XSocketIOClose::getWhat() const throw() std::string XSocketIOClose::getWhat() const noexcept
{ {
return format("XSocketIOClose", "close: %{1}", what()); return format("XSocketIOClose", "close: %{1}", what());
} }
@ -85,7 +82,7 @@ std::string XSocketIOClose::getWhat() const throw()
// XSocketBind // XSocketBind
// //
std::string XSocketBind::getWhat() const throw() std::string XSocketBind::getWhat() const noexcept
{ {
return format("XSocketBind", "cannot bind address: %{1}", what()); return format("XSocketBind", "cannot bind address: %{1}", what());
} }
@ -95,7 +92,7 @@ std::string XSocketBind::getWhat() const throw()
// XSocketConnect // XSocketConnect
// //
std::string XSocketConnect::getWhat() const throw() std::string XSocketConnect::getWhat() const noexcept
{ {
return format("XSocketConnect", "cannot connect socket: %{1}", what()); return format("XSocketConnect", "cannot connect socket: %{1}", what());
} }
@ -105,7 +102,7 @@ std::string XSocketConnect::getWhat() const throw()
// XSocketCreate // XSocketCreate
// //
std::string XSocketCreate::getWhat() const throw() std::string XSocketCreate::getWhat() const noexcept
{ {
return format("XSocketCreate", "cannot create socket: %{1}", what()); return format("XSocketCreate", "cannot create socket: %{1}", what());
} }

View File

@ -40,24 +40,24 @@ public:
kBadPort //!< The port is invalid kBadPort //!< The port is invalid
}; };
XSocketAddress(EError, const std::string& hostname, int port) _NOEXCEPT; XSocketAddress(EError, const std::string& hostname, int port) noexcept;
virtual ~XSocketAddress() _NOEXCEPT { } virtual ~XSocketAddress() noexcept { }
//! @name accessors //! @name accessors
//@{ //@{
//! Get the error code //! Get the error code
EError getError() const throw(); EError getError() const noexcept;
//! Get the hostname //! Get the hostname
std::string getHostname() const throw(); std::string getHostname() const noexcept;
//! Get the port //! Get the port
int getPort() const throw(); int getPort() const noexcept;
//@} //@}
protected: protected:
// XBase overrides // XBase overrides
virtual std::string getWhat() const throw(); virtual std::string getWhat() const noexcept;
private: private:
EError m_error; EError m_error;

View File

@ -88,5 +88,5 @@ public:
XMSWindowsWatchdogError(const std::string& msg) : XBarrier(msg) { } XMSWindowsWatchdogError(const std::string& msg) : XBarrier(msg) { }
// XBase overrides // XBase overrides
virtual std::string getWhat() const throw() { return what(); } virtual std::string getWhat() const noexcept { return what(); }
}; };

View File

@ -2271,12 +2271,12 @@ XConfigRead::XConfigRead(const ConfigReadContext& context, const char* errorFmt,
// do nothing // do nothing
} }
XConfigRead::~XConfigRead() _NOEXCEPT XConfigRead::~XConfigRead() noexcept
{ {
// do nothing // do nothing
} }
std::string XConfigRead::getWhat() const throw() std::string XConfigRead::getWhat() const noexcept
{ {
return format("XConfigRead", "read error: %{1}", m_error.c_str()); return format("XConfigRead", "read error: %{1}", m_error.c_str());
} }

View File

@ -521,11 +521,11 @@ class XConfigRead : public XBase {
public: public:
XConfigRead(const ConfigReadContext& context, const std::string&); XConfigRead(const ConfigReadContext& context, const std::string&);
XConfigRead(const ConfigReadContext& contex, const char* errorFmt, const std::string& arg); XConfigRead(const ConfigReadContext& contex, const char* errorFmt, const std::string& arg);
virtual ~XConfigRead() _NOEXCEPT; virtual ~XConfigRead() noexcept;
protected: protected:
// XBase overrides // XBase overrides
virtual std::string getWhat() const throw(); virtual std::string getWhat() const noexcept;
private: private:
std::string m_error; std::string m_error;

View File

@ -43,14 +43,13 @@
#include "base/IEventQueue.h" #include "base/IEventQueue.h"
#include "base/Log.h" #include "base/Log.h"
#include "base/TMethodEventJob.h" #include "base/TMethodEventJob.h"
#include "common/stdexcept.h"
#include <cstring> #include <cstring>
#include <cstdlib> #include <cstdlib>
#include <sstream> #include <sstream>
#include <fstream> #include <fstream>
#include <ctime> #include <ctime>
#include <stdexcept>
// //
// Server // Server
// //

View File

@ -20,7 +20,7 @@
#include "base/Log.h" #include "base/Log.h"
#include "base/TMethodEventJob.h" #include "base/TMethodEventJob.h"
#include "base/SimpleEventQueueBuffer.h" #include "base/SimpleEventQueueBuffer.h"
#include "common/stdexcept.h" #include <stdexcept>
void void
TestEventQueue::raiseQuitEvent() TestEventQueue::raiseQuitEvent()

View File

@ -38,7 +38,7 @@
#include "base/TMethodEventJob.h" #include "base/TMethodEventJob.h"
#include "base/TMethodJob.h" #include "base/TMethodJob.h"
#include "base/Log.h" #include "base/Log.h"
#include "common/stdexcept.h" #include <stdexcept>
#include "test/global/gtest.h" #include "test/global/gtest.h"
#include <sstream> #include <sstream>