I have a strange problem working with C++ booleans using C++11 constructs. I have a small repro:
from libcpp cimport bool as cbool
from libcpp.vector cimport vector
from libcpp.memory cimport shared_ptr, make_shared
from cython.operator cimport dereference as deref
def test_vector():
cdef shared_ptr[vector[cbool]] vec
vec = make_shared[vector[cbool]]()
for i in range(3):
deref(vec).push_back(True)
cdef cbool item = deref(vec).at(1)
Cython (0.24) compiles this without any complaints using this command:
cython --cplus -3 --fast-fail test_vec.pyx
However, gcc (4.9) fails using this command:
gcc -shared -pthread -fPIC -fwrapv -O2 -Wall -fno-strict-aliasing -I/usr/include/python3.3m -std=c++11 -o test_vec.so test_vec.cpp
The error message from gcc is:
test_vec.cpp: In function ‘PyObject* __pyx_pf_8test_vec_2test_vector(PyObject*)’:
test_vec.cpp:950:15: error: no match for ‘operator=’ (operand types are ‘__Pyx_FakeReference<bool>’ and ‘std::vector<bool>::reference {aka std::_Bit_reference}’)
__pyx_t_3 = (*__pyx_v_vec).at(1);
^
test_vec.cpp:950:15: note: candidates are:
test_vec.cpp:224:7: note: __Pyx_FakeReference<bool>& __Pyx_FakeReference<bool>::operator=(const __Pyx_FakeReference<bool>&)
class __Pyx_FakeReference {
^
test_vec.cpp:224:7: note: no known conversion for argument 1 from ‘std::vector<bool>::reference {aka std::_Bit_reference}’ to ‘const __Pyx_FakeReference<bool>&’
test_vec.cpp:224:7: note: __Pyx_FakeReference<bool>& __Pyx_FakeReference<bool>::operator=(__Pyx_FakeReference<bool>&&)
test_vec.cpp:224:7: note: no known conversion for argument 1 from ‘std::vector<bool>::reference {aka std::_Bit_reference}’ to ‘__Pyx_FakeReference<bool>&&’
However, if I change all the `cbool` references to `int` in the pyx file, it compiles and runs happily. Am I misusing the bool operator?
Thanks,
Dusty