Fix -Wweak-vtables warnings in exception classes.

This commit is contained in:
Jens Breitbart
2016-12-03 16:58:44 +01:00
committed by Jesse Beder
parent d025040049
commit 0f20ddcdcb
2 changed files with 33 additions and 2 deletions

View File

@@ -9,9 +9,9 @@
#include "yaml-cpp/mark.h" #include "yaml-cpp/mark.h"
#include "yaml-cpp/traits.h" #include "yaml-cpp/traits.h"
#include <sstream>
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
#include <sstream>
namespace YAML { namespace YAML {
// error messages // error messages
@@ -112,7 +112,7 @@ class Exception : public std::runtime_error {
public: public:
Exception(const Mark& mark_, const std::string& msg_) Exception(const Mark& mark_, const std::string& msg_)
: std::runtime_error(build_what(mark_, msg_)), mark(mark_), msg(msg_) {} : std::runtime_error(build_what(mark_, msg_)), mark(mark_), msg(msg_) {}
virtual ~Exception() noexcept {} virtual ~Exception() noexcept;
Exception(const Exception&) = default; Exception(const Exception&) = default;
@@ -137,12 +137,14 @@ class ParserException : public Exception {
public: public:
ParserException(const Mark& mark_, const std::string& msg_) ParserException(const Mark& mark_, const std::string& msg_)
: Exception(mark_, msg_) {} : Exception(mark_, msg_) {}
virtual ~ParserException() noexcept;
}; };
class RepresentationException : public Exception { class RepresentationException : public Exception {
public: public:
RepresentationException(const Mark& mark_, const std::string& msg_) RepresentationException(const Mark& mark_, const std::string& msg_)
: Exception(mark_, msg_) {} : Exception(mark_, msg_) {}
virtual ~RepresentationException() noexcept;
}; };
// representation exceptions // representation exceptions
@@ -150,6 +152,7 @@ class InvalidScalar : public RepresentationException {
public: public:
InvalidScalar(const Mark& mark_) InvalidScalar(const Mark& mark_)
: RepresentationException(mark_, ErrorMsg::INVALID_SCALAR) {} : RepresentationException(mark_, ErrorMsg::INVALID_SCALAR) {}
virtual ~InvalidScalar() noexcept;
}; };
class KeyNotFound : public RepresentationException { class KeyNotFound : public RepresentationException {
@@ -158,6 +161,7 @@ class KeyNotFound : public RepresentationException {
KeyNotFound(const Mark& mark_, const T& key_) KeyNotFound(const Mark& mark_, const T& key_)
: RepresentationException(mark_, ErrorMsg::KEY_NOT_FOUND_WITH_KEY(key_)) { : RepresentationException(mark_, ErrorMsg::KEY_NOT_FOUND_WITH_KEY(key_)) {
} }
virtual ~KeyNotFound() noexcept;
}; };
template <typename T> template <typename T>
@@ -180,12 +184,14 @@ class InvalidNode : public RepresentationException {
public: public:
InvalidNode() InvalidNode()
: RepresentationException(Mark::null_mark(), ErrorMsg::INVALID_NODE) {} : RepresentationException(Mark::null_mark(), ErrorMsg::INVALID_NODE) {}
virtual ~InvalidNode() noexcept;
}; };
class BadConversion : public RepresentationException { class BadConversion : public RepresentationException {
public: public:
explicit BadConversion(const Mark& mark_) explicit BadConversion(const Mark& mark_)
: RepresentationException(mark_, ErrorMsg::BAD_CONVERSION) {} : RepresentationException(mark_, ErrorMsg::BAD_CONVERSION) {}
virtual ~BadConversion() noexcept;
}; };
template <typename T> template <typename T>
@@ -198,35 +204,41 @@ class BadDereference : public RepresentationException {
public: public:
BadDereference() BadDereference()
: RepresentationException(Mark::null_mark(), ErrorMsg::BAD_DEREFERENCE) {} : RepresentationException(Mark::null_mark(), ErrorMsg::BAD_DEREFERENCE) {}
virtual ~BadDereference() noexcept;
}; };
class BadSubscript : public RepresentationException { class BadSubscript : public RepresentationException {
public: public:
BadSubscript() BadSubscript()
: RepresentationException(Mark::null_mark(), ErrorMsg::BAD_SUBSCRIPT) {} : RepresentationException(Mark::null_mark(), ErrorMsg::BAD_SUBSCRIPT) {}
virtual ~BadSubscript() noexcept;
}; };
class BadPushback : public RepresentationException { class BadPushback : public RepresentationException {
public: public:
BadPushback() BadPushback()
: RepresentationException(Mark::null_mark(), ErrorMsg::BAD_PUSHBACK) {} : RepresentationException(Mark::null_mark(), ErrorMsg::BAD_PUSHBACK) {}
virtual ~BadPushback() noexcept;
}; };
class BadInsert : public RepresentationException { class BadInsert : public RepresentationException {
public: public:
BadInsert() BadInsert()
: RepresentationException(Mark::null_mark(), ErrorMsg::BAD_INSERT) {} : RepresentationException(Mark::null_mark(), ErrorMsg::BAD_INSERT) {}
virtual ~BadInsert() noexcept;
}; };
class EmitterException : public Exception { class EmitterException : public Exception {
public: public:
EmitterException(const std::string& msg_) EmitterException(const std::string& msg_)
: Exception(Mark::null_mark(), msg_) {} : Exception(Mark::null_mark(), msg_) {}
virtual ~EmitterException() noexcept;
}; };
class BadFile : public Exception { class BadFile : public Exception {
public: public:
BadFile() : Exception(Mark::null_mark(), ErrorMsg::BAD_FILE) {} BadFile() : Exception(Mark::null_mark(), ErrorMsg::BAD_FILE) {}
virtual ~BadFile() noexcept;
}; };
} }

19
src/exceptions.cpp Normal file
View File

@@ -0,0 +1,19 @@
#include "yaml-cpp/exceptions.h"
namespace YAML {
// These destructors are defined out-of-line so the vtable is only emitted once.
Exception::~Exception() noexcept {}
ParserException::~ParserException() noexcept {}
RepresentationException::~RepresentationException() noexcept {}
InvalidScalar::~InvalidScalar() noexcept {}
KeyNotFound::~KeyNotFound() noexcept {}
InvalidNode::~InvalidNode() noexcept {}
BadConversion::~BadConversion() noexcept {}
BadDereference::~BadDereference() noexcept {}
BadSubscript::~BadSubscript() noexcept {}
BadPushback::~BadPushback() noexcept {}
BadInsert::~BadInsert() noexcept {}
EmitterException::~EmitterException() noexcept {}
BadFile::~BadFile() noexcept {}
}