don't try to cast 'None' into a C++ lvalue reference

This commit is contained in:
Wenzel Jakob
2016-05-01 14:42:20 +02:00
parent bdd11030c2
commit bd57eb484d
5 changed files with 24 additions and 6 deletions

View File

@@ -21,7 +21,7 @@ void init_issues(py::module &m) {
// #70 compilation issue if operator new is not public
class NonConstructible { private: void *operator new(size_t bytes) throw(); };
py::class_<NonConstructible>(m, "Foo");
m.def("getstmt", []() -> NonConstructible * { return nullptr; },
m2.def("getstmt", []() -> NonConstructible * { return nullptr; },
py::return_value_policy::reference);
#endif
@@ -101,4 +101,7 @@ void init_issues(py::module &m) {
list.append(py::cast(e));
return list;
});
};
// (no id): should not be able to pass 'None' to a reference argument
m2.def("print_element", [](ElementA &el) { std::cout << el.value() << std::endl; });
}

View File

@@ -7,7 +7,7 @@ from example.issues import print_cchar, print_char
from example.issues import DispatchIssue, dispatch_issue_go
from example.issues import Placeholder, return_vec_of_reference_wrapper
from example.issues import iterator_passthrough
from example.issues import ElementList, ElementA
from example.issues import ElementList, ElementA, print_element
import gc
print_cchar("const char *")
@@ -42,3 +42,8 @@ gc.collect()
for i, v in enumerate(el.get()):
print("%i==%i, " % (i, v.value()), end='')
print()
try:
print_element(None)
except Exception as e:
print("Failed as expected: " + str(e))

View File

@@ -5,3 +5,6 @@ Yay..
[Placeholder[1], Placeholder[2], Placeholder[3], Placeholder[4]]
[3, 5, 7, 9, 11, 13, 15]
0==0, 1==1, 2==2, 3==3, 4==4, 5==5, 6==6, 7==7, 8==8, 9==9,
Failed as expected: Incompatible function arguments. The following argument types are supported:
1. (example.issues.ElementA) -> NoneType