Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invalid cast of an rvalue expression of type #3754

Closed
cmpute opened this issue Jul 24, 2020 · 0 comments · Fixed by #3755
Closed

invalid cast of an rvalue expression of type #3754

cmpute opened this issue Jul 24, 2020 · 0 comments · Fixed by #3755

Comments

@cmpute
Copy link

cmpute commented Jul 24, 2020

Tested using latest cython, minimal code to reproduce:

# distutils: language = c++
from libcpp.vector cimport vector

a = {1:2, 2:3}
cdef vector[int] b = [1,2,3]
print(a[b[0]])

The compiler will report

/home/jacobz/.conda/envs/lidar/include/python3.7m/pyport.h:109:54: error: invalid cast of an rvalue expression of type ‘Py_ssize_t {aka long int}’ to type ‘int&’
 #define PY_SSIZE_T_MAX ((Py_ssize_t)(((size_t)-1)>>1))
                                                      ^
/home/jacobz/PointCloud/detection3/test.cpp:827:43: note: in definition of macro ‘likely’
   #define likely(x)   __builtin_expect(!!(x), 1)
                                           ^
/home/jacobz/PointCloud/detection3/test.cpp:668:42: note: in expansion of macro ‘PY_SSIZE_T_MAX’
           (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\
                                          ^~~~~~~~~~~~~~
/home/jacobz/PointCloud/detection3/test.cpp:978:6: note: in expansion of macro ‘__Pyx_fits_Py_ssize_t’
     (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
      ^~~~~~~~~~~~~~~~~~~~~
/home/jacobz/PointCloud/detection3/test.cpp:1644:15: note: in expansion of macro ‘__Pyx_GetItemInt’
   __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_1, __pyx_t_3, int &, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 6, __pyx_L1_error)

It seems that the type of b[0] is reduced as int&, which is not acceptable by __Pyx_GetItemInt. And if change the cython code to

c = b[0]
print(a[c])

it will work fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants