Skip to content

Commit

Permalink
Fix -Wweak-vtables warnings in exception classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbreitbart authored and jbeder committed Dec 3, 2016
1 parent d025040 commit 0f20ddc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
16 changes: 14 additions & 2 deletions include/yaml-cpp/exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

#include "yaml-cpp/mark.h"
#include "yaml-cpp/traits.h"
#include <sstream>
#include <stdexcept>
#include <string>
#include <sstream>

namespace YAML {
// error messages
Expand Down Expand Up @@ -112,7 +112,7 @@ class Exception : public std::runtime_error {
public:
Exception(const Mark& mark_, const std::string& msg_)
: std::runtime_error(build_what(mark_, msg_)), mark(mark_), msg(msg_) {}
virtual ~Exception() noexcept {}
virtual ~Exception() noexcept;

Exception(const Exception&) = default;

Expand All @@ -137,19 +137,22 @@ class ParserException : public Exception {
public:
ParserException(const Mark& mark_, const std::string& msg_)
: Exception(mark_, msg_) {}
virtual ~ParserException() noexcept;
};

class RepresentationException : public Exception {
public:
RepresentationException(const Mark& mark_, const std::string& msg_)
: Exception(mark_, msg_) {}
virtual ~RepresentationException() noexcept;
};

// representation exceptions
class InvalidScalar : public RepresentationException {
public:
InvalidScalar(const Mark& mark_)
: RepresentationException(mark_, ErrorMsg::INVALID_SCALAR) {}
virtual ~InvalidScalar() noexcept;
};

class KeyNotFound : public RepresentationException {
Expand All @@ -158,6 +161,7 @@ class KeyNotFound : public RepresentationException {
KeyNotFound(const Mark& mark_, const T& key_)
: RepresentationException(mark_, ErrorMsg::KEY_NOT_FOUND_WITH_KEY(key_)) {
}
virtual ~KeyNotFound() noexcept;
};

template <typename T>
Expand All @@ -180,12 +184,14 @@ class InvalidNode : public RepresentationException {
public:
InvalidNode()
: RepresentationException(Mark::null_mark(), ErrorMsg::INVALID_NODE) {}
virtual ~InvalidNode() noexcept;
};

class BadConversion : public RepresentationException {
public:
explicit BadConversion(const Mark& mark_)
: RepresentationException(mark_, ErrorMsg::BAD_CONVERSION) {}
virtual ~BadConversion() noexcept;
};

template <typename T>
Expand All @@ -198,35 +204,41 @@ class BadDereference : public RepresentationException {
public:
BadDereference()
: RepresentationException(Mark::null_mark(), ErrorMsg::BAD_DEREFERENCE) {}
virtual ~BadDereference() noexcept;
};

class BadSubscript : public RepresentationException {
public:
BadSubscript()
: RepresentationException(Mark::null_mark(), ErrorMsg::BAD_SUBSCRIPT) {}
virtual ~BadSubscript() noexcept;
};

class BadPushback : public RepresentationException {
public:
BadPushback()
: RepresentationException(Mark::null_mark(), ErrorMsg::BAD_PUSHBACK) {}
virtual ~BadPushback() noexcept;
};

class BadInsert : public RepresentationException {
public:
BadInsert()
: RepresentationException(Mark::null_mark(), ErrorMsg::BAD_INSERT) {}
virtual ~BadInsert() noexcept;
};

class EmitterException : public Exception {
public:
EmitterException(const std::string& msg_)
: Exception(Mark::null_mark(), msg_) {}
virtual ~EmitterException() noexcept;
};

class BadFile : public Exception {
public:
BadFile() : Exception(Mark::null_mark(), ErrorMsg::BAD_FILE) {}
virtual ~BadFile() noexcept;
};
}

Expand Down
19 changes: 19 additions & 0 deletions src/exceptions.cpp
Original file line number Diff line number Diff line change
@@ -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 {}
}

0 comments on commit 0f20ddc

Please sign in to comment.