From e9a2e6d013dbf8f8fc139be35f0f4e629abbde17 Mon Sep 17 00:00:00 2001 From: Aaron Gokaslan Date: Tue, 3 May 2022 10:40:48 -0400 Subject: [PATCH] Revert operator abuse --- include/pybind11/pytypes.h | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/include/pybind11/pytypes.h b/include/pybind11/pytypes.h index 8239533e9..9584443d1 100644 --- a/include/pybind11/pytypes.h +++ b/include/pybind11/pytypes.h @@ -13,7 +13,6 @@ #include "buffer_info.h" #include -#include #include #include #include @@ -388,16 +387,13 @@ public: } } - error_already_set(const error_already_set &) noexcept = default; - error_already_set(error_already_set &&) noexcept = default; + error_already_set(const error_already_set &) = default; + error_already_set(error_already_set &&) = default; inline ~error_already_set() override; const char *what() const noexcept override { - auto *sup_what = std::runtime_error::what(); - if (sup_what[0] != '\0') { - return sup_what; - } else if (m_lazy_what.empty()) { + if (m_lazy_what.empty()) { try { m_lazy_what = detail::error_string(m_type.ptr(), m_value.ptr(), m_trace.ptr()); } catch (const std::exception &e) { @@ -411,7 +407,6 @@ public: return m_lazy_what.c_str(); } } - assert(!m_lazy_what.empty()); return m_lazy_what.c_str(); } @@ -420,8 +415,7 @@ public: /// already set it is cleared first. After this call, the current object no longer stores the /// error variables (but the `.what()` string is still available). void restore() { - // Abuse assignment operator to cache what() - std::runtime_error::operator=(std::runtime_error(what())); // Force-build `.what()`. + what(); // Force-build `.what()`. if (m_lazy_what.empty()) { pybind11_fail("Critical error building lazy error_string()."); }