Skip to content

Commit e9a2e6d

Browse files
committed
Revert operator abuse
1 parent e71d9b9 commit e9a2e6d

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

include/pybind11/pytypes.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include "buffer_info.h"
1414

1515
#include <exception>
16-
#include <stdexcept>
1716
#include <string>
1817
#include <type_traits>
1918
#include <utility>
@@ -388,16 +387,13 @@ class PYBIND11_EXPORT_EXCEPTION error_already_set : public std::runtime_error {
388387
}
389388
}
390389

391-
error_already_set(const error_already_set &) noexcept = default;
392-
error_already_set(error_already_set &&) noexcept = default;
390+
error_already_set(const error_already_set &) = default;
391+
error_already_set(error_already_set &&) = default;
393392

394393
inline ~error_already_set() override;
395394

396395
const char *what() const noexcept override {
397-
auto *sup_what = std::runtime_error::what();
398-
if (sup_what[0] != '\0') {
399-
return sup_what;
400-
} else if (m_lazy_what.empty()) {
396+
if (m_lazy_what.empty()) {
401397
try {
402398
m_lazy_what = detail::error_string(m_type.ptr(), m_value.ptr(), m_trace.ptr());
403399
} catch (const std::exception &e) {
@@ -411,7 +407,6 @@ class PYBIND11_EXPORT_EXCEPTION error_already_set : public std::runtime_error {
411407
return m_lazy_what.c_str();
412408
}
413409
}
414-
415410
assert(!m_lazy_what.empty());
416411
return m_lazy_what.c_str();
417412
}
@@ -420,8 +415,7 @@ class PYBIND11_EXPORT_EXCEPTION error_already_set : public std::runtime_error {
420415
/// already set it is cleared first. After this call, the current object no longer stores the
421416
/// error variables (but the `.what()` string is still available).
422417
void restore() {
423-
// Abuse assignment operator to cache what()
424-
std::runtime_error::operator=(std::runtime_error(what())); // Force-build `.what()`.
418+
what(); // Force-build `.what()`.
425419
if (m_lazy_what.empty()) {
426420
pybind11_fail("Critical error building lazy error_string().");
427421
}

0 commit comments

Comments
 (0)