Commit 075e025f authored by Stefan Behnel's avatar Stefan Behnel

reimplement warning when Python objects coerce to C++ references

parent 9a0983ec
...@@ -714,7 +714,8 @@ class ExprNode(Node): ...@@ -714,7 +714,8 @@ class ExprNode(Node):
if self.check_for_coercion_error(dst_type, env): if self.check_for_coercion_error(dst_type, env):
return self return self
if dst_type.is_reference and not src_type.is_reference: used_as_reference = dst_type.is_reference
if used_as_reference and not src_type.is_reference:
dst_type = dst_type.ref_base_type dst_type = dst_type.ref_base_type
if src_type.is_const: if src_type.is_const:
...@@ -781,6 +782,11 @@ class ExprNode(Node): ...@@ -781,6 +782,11 @@ class ExprNode(Node):
if src.constant_result is not None: if src.constant_result is not None:
src = PyTypeTestNode(src, dst_type, env) src = PyTypeTestNode(src, dst_type, env)
elif src.type.is_pyobject: elif src.type.is_pyobject:
if used_as_reference:
warning(
self.pos,
"Cannot pass Python object as C++ data structure reference (%s &), will pass by copy." % dst_type,
level=1)
src = CoerceFromPyTypeNode(dst_type, src, env) src = CoerceFromPyTypeNode(dst_type, src, env)
elif (dst_type.is_complex elif (dst_type.is_complex
and src_type != dst_type and src_type != dst_type
......
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
from libcpp.set cimport set from libcpp.set cimport set
cdef extern from "foo.cpp": cdef extern from *:
void cpp_function_set1(set[int]) void cpp_function_set1(set[int] arg)
void cpp_function_set2(set[int] &) void cpp_function_set2(set[int]& arg)
def pass_py_obj_as_cpp_cont_ref(): def pass_py_obj_as_cpp_cont_ref():
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment