Skip to content

Commit

Permalink
Revert operator abuse
Browse files Browse the repository at this point in the history
  • Loading branch information
Skylion007 committed May 3, 2022
1 parent e71d9b9 commit e9a2e6d
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions include/pybind11/pytypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "buffer_info.h"

#include <exception>
#include <stdexcept>
#include <string>
#include <type_traits>
#include <utility>
Expand Down Expand Up @@ -388,16 +387,13 @@ class PYBIND11_EXPORT_EXCEPTION error_already_set : public std::runtime_error {
}
}

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) {
Expand All @@ -411,7 +407,6 @@ class PYBIND11_EXPORT_EXCEPTION error_already_set : public std::runtime_error {
return m_lazy_what.c_str();
}
}

assert(!m_lazy_what.empty());
return m_lazy_what.c_str();
}
Expand All @@ -420,8 +415,7 @@ class PYBIND11_EXPORT_EXCEPTION error_already_set : public std::runtime_error {
/// 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().");
}
Expand Down

0 comments on commit e9a2e6d

Please sign in to comment.