Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions src/bsoncxx/include/bsoncxx/v1/exception.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,10 @@ BSONCXX_PRIVATE_WARNINGS_DISABLE(MSVC(4275));
///
class exception : public std::system_error {
public:
~exception() override;

exception(exception&&) noexcept = default;
exception& operator=(exception&&) noexcept = default;
exception(exception const&) = default;
exception& operator=(exception const&) = default;

using std::system_error::system_error;

private:
BSONCXX_ABI_NO_EXPORT virtual void key_function() const;
};

BSONCXX_PRIVATE_WARNINGS_POP();
Expand Down
9 changes: 8 additions & 1 deletion src/bsoncxx/lib/bsoncxx/v1/exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,14 @@ std::error_category const& type_error_category() {
namespace bsoncxx {
namespace v1 {

exception::~exception() = default;
// Prevent vague linkage of the vtable and type_info object (-Wweak-vtables).
// - https://itanium-cxx-abi.github.io/cxx-abi/abi.html#vague-vtable
// > The key function is the first non-pure virtual function that is not inline at the point of class definition.
// - https://lld.llvm.org/missingkeyfunction:
// > It’s always advisable to ensure there is at least one eligible function that can serve as the key function.
// - https://gcc.gnu.org/onlinedocs/gcc/Vague-Linkage.html
// > For polymorphic classes (classes with virtual functions), the ‘type_info’ object is written out along with the vtable.
void exception::key_function() const {}

} // namespace v1
} // namespace bsoncxx
10 changes: 3 additions & 7 deletions src/mongocxx/include/mongocxx/v1/exception.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,10 @@ BSONCXX_PRIVATE_WARNINGS_DISABLE(MSVC(4275));
///
class exception : public std::system_error {
public:
~exception() override;

exception(exception&&) noexcept = default;
exception& operator=(exception&&) noexcept = default;
exception(exception const&) = default;
exception& operator=(exception const&) = default;

using std::system_error::system_error;

private:
MONGOCXX_ABI_NO_EXPORT virtual void key_function() const;
};

BSONCXX_PRIVATE_WARNINGS_POP();
Expand Down
9 changes: 8 additions & 1 deletion src/mongocxx/lib/mongocxx/v1/exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,14 @@ std::error_category const& type_error_category() {
return instance.value();
}

exception::~exception() = default;
// Prevent vague linkage of the vtable and type_info object (-Wweak-vtables).
// - https://itanium-cxx-abi.github.io/cxx-abi/abi.html#vague-vtable
// > The key function is the first non-pure virtual function that is not inline at the point of class definition.
// - https://lld.llvm.org/missingkeyfunction:
// > It’s always advisable to ensure there is at least one eligible function that can serve as the key function.
// - https://gcc.gnu.org/onlinedocs/gcc/Vague-Linkage.html
// > For polymorphic classes (classes with virtual functions), the ‘type_info’ object is written out along with the vtable.
void exception::key_function() const {}

} // namespace v1
} // namespace mongocxx