pybind/pybind11
Auf GitHub ansehennoexcept base class methods are not recognized in C++17 mode
Open
#2.234 geöffnet am 29. Mai 2020
enhancementhelp wanted
Repository-Metriken
- Stars
- (14.677 Stars)
- PR-Merge-Metriken
- (Durchschn. Merge 5T 2h) (10 gemergte PRs in 30 T)
Beschreibung
Issue description
Base class methods attributed with noexcept are not recognized by pybind11 overload system in C++17 mode. The example below compiles just fine in C++11/C++14 mode. Probably it's related to:
The noexcept-specification is a part of the function type and may appear as part of any function declarator. (since C++17)
https://en.cppreference.com/w/cpp/language/noexcept_spec#Explanation
Reproducible example code
#include "pybind11/pybind11.h"
#include "pybind11/embed.h"
namespace py = pybind11;
struct Base {
int size() const noexcept { return 0; }
};
struct Derived : Base {};
PYBIND11_EMBEDDED_MODULE(example, m) {
py::class_<Derived>(m, "Derived")
.def(py::init<>())
.def("size", &Derived::size);
}
int main() {
py::scoped_interpreter guard{};
py::exec(R"(
from example import Derived
d = Derived()
print(d.size())
)");
}
Output (C++17):
terminate called after throwing an instance of 'pybind11::error_already_set'
what(): TypeError: size(): incompatible function arguments. The following argument types are supported:
1. (self: Base) -> int
Invoked with: <example.Derived object at 0x7f42fb179ce0>
At:
<string>(5): <module>
(tried with g++-8 / clang-9)