Commit edde08f7 authored by Stefan Behnel's avatar Stefan Behnel

Fix comparison of templates when mixing "const" with typedefs.

See #2148.
parent e9423fd9
......@@ -14,6 +14,10 @@ Bugs fixed
* ``PyFrozenSet_New()`` was accidentally used in PyPy where it is lacking
from the C-API.
* Assignment between some C++ templated types were incorrectly rejected
when the templates mix ``const`` with ``ctypedef``.
(Github issue #2148)
0.28 (2018-03-13)
=================
......
......@@ -1595,6 +1595,12 @@ class CConstType(BaseType):
self.to_py_function = self.const_base_type.to_py_function
return True
def same_as_resolved_type(self, other_type):
if other_type.is_const:
return self.const_base_type.same_as_resolved_type(other_type.const_base_type)
# Accept const LHS <- non-const RHS.
return self.const_base_type.same_as_resolved_type(other_type)
def __getattr__(self, name):
return getattr(self.const_base_type, name)
......
# distutils: extra_compile_args=-std=c++0x
# mode: run
# tag: cpp, werror
# tag: cpp, werror, cpp11
# distutils: extra_compile_args=-std=c++0x
from libcpp.memory cimport unique_ptr, shared_ptr, default_delete
from libcpp cimport nullptr
......@@ -12,6 +12,10 @@ cdef extern from "cpp_smart_ptr_helper.h":
cdef cppclass FreePtr[T]:
pass
ctypedef const CountAllocDealloc const_CountAllocDealloc
def test_unique_ptr():
"""
>>> test_unique_ptr()
......@@ -42,17 +46,18 @@ def test_unique_ptr():
x_ptr3.reset()
assert x_ptr3.get() == nullptr;
def test_shared_ptr():
def test_const_shared_ptr():
"""
>>> test_shared_ptr()
>>> test_const_shared_ptr()
"""
cdef int alloc_count = 0, dealloc_count = 0
cdef shared_ptr[CountAllocDealloc] ptr = shared_ptr[CountAllocDealloc](
cdef shared_ptr[const CountAllocDealloc] ptr = shared_ptr[const_CountAllocDealloc](
new CountAllocDealloc(&alloc_count, &dealloc_count))
assert alloc_count == 1
assert dealloc_count == 0
cdef shared_ptr[CountAllocDealloc] ptr2 = ptr
cdef shared_ptr[const CountAllocDealloc] ptr2 = ptr
assert alloc_count == 1
assert dealloc_count == 0
......
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