Replies: 2 comments 2 replies
-
You will need to submit a small reproducer, otherwise I can't help you. I suspect that the cause is more complex than the snippet shown here (the default type casters don't call |
Beta Was this translation helpful? Give feedback.
0 replies
-
Thanks for your quick reply! Here is the code snapshot to reproduce the issue: #include "nanobind/nanobind.h"
#include "nanobind/stl/optional.h"
namespace nb = nanobind;
using namespace nb::literals;
struct A{};
NB_MODULE(test_nanobind_bad_cast, m) {
nb::class_<A>(m, "A")
.def("__init__", [](A *holder, std::optional<int> min, std::optional<int> max) {
new (holder) A{};
}, "minimum"_a = std::nullopt, "maximum"_a = std::nullopt);
} from test_nanobind_bad_cast import A
a = A() My environment is: macOS Ventura, Python 3.9.17, with nanobind 1.5.0. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I had a code like below:
It compiles fine, but when I import the library, it gives me a

RuntimeError: bast_cast
.After debugging with a debug build, it is because
std::nullopt
have notype_caster
defined, but somehow it still calls thecast
function and thus throw abad_cast
error:bad_cast
error?Beta Was this translation helpful? Give feedback.
All reactions