Commit c492bab6 authored by Robert Bradshaw's avatar Robert Bradshaw

Detect function template parameters through pointers and references.

Fixes #1541
parent ba006541
...@@ -545,6 +545,9 @@ class CPtrDeclaratorNode(CDeclaratorNode): ...@@ -545,6 +545,9 @@ class CPtrDeclaratorNode(CDeclaratorNode):
child_attrs = ["base"] child_attrs = ["base"]
def analyse_templates(self):
return self.base.analyse_templates()
def analyse(self, base_type, env, nonempty=0): def analyse(self, base_type, env, nonempty=0):
if base_type.is_pyobject: if base_type.is_pyobject:
error(self.pos, "Pointer base type cannot be a Python object") error(self.pos, "Pointer base type cannot be a Python object")
...@@ -557,6 +560,9 @@ class CReferenceDeclaratorNode(CDeclaratorNode): ...@@ -557,6 +560,9 @@ class CReferenceDeclaratorNode(CDeclaratorNode):
child_attrs = ["base"] child_attrs = ["base"]
def analyse_templates(self):
return self.base.analyse_templates()
def analyse(self, base_type, env, nonempty=0): def analyse(self, base_type, env, nonempty=0):
if base_type.is_pyobject: if base_type.is_pyobject:
error(self.pos, "Reference base type cannot be a Python object") error(self.pos, "Reference base type cannot be a Python object")
......
...@@ -10,6 +10,7 @@ cdef extern from "cpp_template_functions_helper.h": ...@@ -10,6 +10,7 @@ cdef extern from "cpp_template_functions_helper.h":
pair[T, U] method[U](T, U) pair[T, U] method[U](T, U)
cdef T nested_deduction[T](const T*) cdef T nested_deduction[T](const T*)
pair[T, U] pair_arg[T, U](pair[T, U] a) pair[T, U] pair_arg[T, U](pair[T, U] a)
cdef T* pointer_param[T](T*)
def test_no_arg(): def test_no_arg():
""" """
...@@ -63,3 +64,10 @@ def test_class_deductions(pair[long, double] x): ...@@ -63,3 +64,10 @@ def test_class_deductions(pair[long, double] x):
""" """
return pair_arg(x) return pair_arg(x)
def test_deduce_through_pointers(int k):
"""
>>> test_deduce_through_pointers(5)
(5, 5.0)
"""
cdef double x = k
return pointer_param(&k)[0], pointer_param(&x)[0]
...@@ -31,3 +31,8 @@ template <typename T, typename U> ...@@ -31,3 +31,8 @@ template <typename T, typename U>
std::pair<T, U> pair_arg(std::pair<T, U> a) { std::pair<T, U> pair_arg(std::pair<T, U> a) {
return a; return a;
} }
template <typename T>
T* pointer_param(T* param) {
return param;
}
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