Example of bug in functions returning bool overriden in python
diff --git a/example/example12.cpp b/example/example12.cpp
index 57a0765..7bba2c8 100644
--- a/example/example12.cpp
+++ b/example/example12.cpp
@@ -27,6 +27,7 @@
return state + value;
}
+ virtual bool run_bool() = 0;
virtual void pure_virtual() = 0;
private:
int state;
@@ -47,6 +48,14 @@
);
}
+ virtual bool run_bool() {
+ PYBIND11_OVERLOAD_PURE(
+ bool,
+ Example12,
+ run_bool
+ );
+ }
+
virtual void pure_virtual() {
PYBIND11_OVERLOAD_PURE(
void, /* Return type */
@@ -61,6 +70,10 @@
return ex->run(value);
}
+bool runExample12Bool(Example12* ex) {
+ return ex->run_bool();
+}
+
void runExample12Virtual(Example12 *ex) {
ex->pure_virtual();
}
@@ -75,8 +88,10 @@
.def(py::init<int>())
/* Reference original class in function definitions */
.def("run", &Example12::run)
+ .def("run_bool", &Example12::run_bool)
.def("pure_virtual", &Example12::pure_virtual);
m.def("runExample12", &runExample12);
+ m.def("runExample12Bool", &runExample12Bool);
m.def("runExample12Virtual", &runExample12Virtual);
}
diff --git a/example/example12.py b/example/example12.py
index 4f78575..eb17523 100644
--- a/example/example12.py
+++ b/example/example12.py
@@ -3,7 +3,7 @@
import sys
sys.path.append('.')
-from example import Example12, runExample12, runExample12Virtual
+from example import Example12, runExample12, runExample12Virtual, runExample12Bool
class ExtendedExample12(Example12):
@@ -15,6 +15,10 @@
print('ExtendedExample12::run(%i), calling parent..' % value)
return super(ExtendedExample12, self).run(value + 1)
+ def run_bool(self):
+ print('ExtendedExample12::run_bool()')
+ return False
+
def pure_virtual(self):
print('ExtendedExample12::pure_virtual(): %s' % self.data)
@@ -28,4 +32,5 @@
ex12p = ExtendedExample12(10)
print(runExample12(ex12p, 20))
+print(runExample12Bool(ex12p))
runExample12Virtual(ex12p)
diff --git a/example/example12.ref b/example/example12.ref
index be6d092..2274cdd 100644
--- a/example/example12.ref
+++ b/example/example12.ref
@@ -6,6 +6,8 @@
ExtendedExample12::run(20), calling parent..
Original implementation of Example12::run(state=11, value=21)
32
+ExtendedExample12::run_bool()
+False
ExtendedExample12::pure_virtual(): Hello world
Destructing Example12..
Destructing Example12..