Skip to content

Commit 42b01fb

Browse files
oralubenXZiar
andcommitted
Set visibility of exceptions to default.
Co-authored-by: XZiar <[email protected]>
1 parent f61855b commit 42b01fb

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

include/pybind11/detail/common.h

+9-2
Original file line numberDiff line numberDiff line change
@@ -723,16 +723,23 @@ using expand_side_effects = bool[];
723723

724724
PYBIND11_NAMESPACE_END(detail)
725725

726+
#if defined(_MSC_VER)
727+
# pragma warning(push)
728+
# pragma warning(disable: 4275) // warning C4275: An exported class was derived from a class that wasn't exported. Can be ignored when derived from a STL class.
729+
#endif
726730
/// C++ bindings of builtin Python exceptions
727-
class builtin_exception : public std::runtime_error {
731+
class PYBIND11_EXPORT builtin_exception : public std::runtime_error {
728732
public:
729733
using std::runtime_error::runtime_error;
730734
/// Set the error using the Python C API
731735
virtual void set_error() const = 0;
732736
};
737+
#if defined(_MSC_VER)
738+
# pragma warning(pop)
739+
#endif
733740

734741
#define PYBIND11_RUNTIME_EXCEPTION(name, type) \
735-
class name : public builtin_exception { public: \
742+
class PYBIND11_EXPORT name : public builtin_exception { public: \
736743
using builtin_exception::builtin_exception; \
737744
name() : name("") { } \
738745
void set_error() const override { PyErr_SetString(type, what()); } \

include/pybind11/pytypes.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -319,11 +319,15 @@ PYBIND11_NAMESPACE_BEGIN(detail)
319319
inline std::string error_string();
320320
PYBIND11_NAMESPACE_END(detail)
321321

322+
#if defined(_MSC_VER)
323+
# pragma warning(push)
324+
# pragma warning(disable: 4275 4251) // warning C4275: An exported class was derived from a class that wasn't exported. Can be ignored when derived from a STL class.
325+
#endif
322326
/// Fetch and hold an error which was already set in Python. An instance of this is typically
323327
/// thrown to propagate python-side errors back through C++ which can either be caught manually or
324328
/// else falls back to the function dispatcher (which then raises the captured error back to
325329
/// python).
326-
class error_already_set : public std::runtime_error {
330+
class PYBIND11_EXPORT error_already_set : public std::runtime_error {
327331
public:
328332
/// Constructs a new exception from the current Python error indicator, if any. The current
329333
/// Python error indicator will be cleared.
@@ -371,6 +375,9 @@ class error_already_set : public std::runtime_error {
371375
private:
372376
object m_type, m_value, m_trace;
373377
};
378+
#if defined(_MSC_VER)
379+
# pragma warning(pop)
380+
#endif
374381

375382
/** \defgroup python_builtins _
376383
Unless stated otherwise, the following C++ functions behave the same

0 commit comments

Comments
 (0)