Skip to content

Commit

Permalink
Fix const ref temporaries.
Browse files Browse the repository at this point in the history
  • Loading branch information
robertwb committed Apr 1, 2015
1 parent ebb29b0 commit b1ef20a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cython/Compiler/Code.py
Expand Up @@ -626,7 +626,7 @@ def allocate_temp(self, type, manage_ref, static=False):
A C string referring to the variable is returned.
"""
if type.is_const:
if type.is_const and not type.is_reference:
type = type.const_base_type
if not type.is_pyobject and not type.is_memoryviewslice:
# Make manage_ref canonical, so that manage_ref will always mean
Expand Down
1 change: 1 addition & 0 deletions tests/run/cpp_template_ref_args.h
Expand Up @@ -4,6 +4,7 @@
template <typename T>
struct Bar {
Bar & ref() { return *this; }
const Bar & const_ref() { return *this; }
T value;
};

Expand Down
5 changes: 3 additions & 2 deletions tests/run/cpp_template_ref_args.pyx
Expand Up @@ -8,6 +8,7 @@ cdef extern from "cpp_template_ref_args.h":
# bug: Bar[T] created before class fully defined
T value
Bar[T] & ref() except +
const Bar[T] & const_ref() except +

cdef cppclass Foo[T]:
Foo()
Expand All @@ -33,8 +34,8 @@ def test_template_ref_arg(int x):
def test_template_ref_attr(int x):
"""
>>> test_template_ref_attr(4)
4
(4, 4)
"""
cdef Bar[int] bar
bar.value = x
return bar.ref().value
return bar.ref().value, bar.const_ref().value

0 comments on commit b1ef20a

Please sign in to comment.