Commit b352c600 authored by Robert Bradshaw's avatar Robert Bradshaw

Merge pull request #246 from dalleyg/dalleyg-lvalue1

Fixed IndexNode.is_lvalue
parents 29ff5abe bcba9251
...@@ -3204,11 +3204,22 @@ class IndexNode(ExprNode): ...@@ -3204,11 +3204,22 @@ class IndexNode(ExprNode):
return self.base.check_const_addr() and self.index.check_const() return self.base.check_const_addr() and self.index.check_const()
def is_lvalue(self): def is_lvalue(self):
base_type = self.base.type # NOTE: references currently have both is_reference and is_ptr
if self.type.is_ptr or self.type.is_array: # set. Since pointers and references have different lvalue
return not base_type.base_type.is_array # rules, we must be careful to separate the two.
else: if self.type.is_reference:
if self.type.ref_base_type.is_array:
# fixed-sized arrays aren't l-values
return False
elif self.type.is_ptr:
# non-const pointers can always be reassigned
return True return True
elif self.type.is_array:
# fixed-sized arrays aren't l-values
return False
# Just about everything else returned by the index operator
# can be an lvalue.
return True
def calculate_result_code(self): def calculate_result_code(self):
if self.is_buffer_access: if self.is_buffer_access:
......
# tag: cpp
from libcpp.vector cimport vector
__doc__ = u"""
>>> test_lvalue_ref_assignment()
"""
ctypedef double* dp
ctypedef double** dpp
cdef void foo(vector[dpp] &bar, vector[vector[dp]] &baz) nogil:
bar[0] = &baz[0][0]
def test_lvalue_ref_assignment():
cdef vector[dpp] bar
cdef vector[vector[dp]] baz
cdef vector[double] data
cdef dp bongle = &data[0]
bar.resize(1)
bar[0] = NULL
baz.resize(1)
baz[0].resize(1)
baz[0][0] = bongle
foo(bar, baz)
assert bar[0] == &baz[0][0]
assert bar[0][0] == bongle
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