Commit 139143ee authored by Stefan Behnel's avatar Stefan Behnel

Do not issue "redefined" warnings on C++ function overrides with different...

Do not issue "redefined" warnings on C++ function overrides with different signatures (previously only applied to methods).
Closes #2013.
parent 084af98b
......@@ -146,6 +146,9 @@ Bugs fixed
* The builtin ``bytearray`` type could not be used as base type of cdef classes.
(Github issue #2106)
* Overloaded C++ functions no longer issue warnings about redeclarations.
(Github issue #2013)
Other changes
-------------
......
......@@ -26,6 +26,10 @@ class CythonScope(ModuleScope):
cname='<error>')
entry.in_cinclude = True
def is_cpp(self):
# Alow C++ utility code in C++ contexts.
return self.context.cpp
def lookup_type(self, name):
# This function should go away when types are all first-level objects.
type = parse_basic_type(name)
......
......@@ -446,9 +446,22 @@ class Scope(object):
warning(pos, "'%s' is a reserved name in C." % cname, -1)
entries = self.entries
if name and name in entries and not shadow:
old_type = entries[name].type
if self.is_cpp_class_scope and type.is_cfunction and old_type.is_cfunction and type != old_type:
# C++ method overrides are ok
old_entry = entries[name]
# Reject redeclared C++ functions only if they have the same type signature.
cpp_override_allowed = False
if type.is_cfunction and old_entry.type.is_cfunction and self.is_cpp():
for alt_entry in old_entry.all_alternatives():
if type == alt_entry.type:
if name == '<init>' and not type.args:
# Cython pre-declares the no-args constructor - allow later user definitions.
cpp_override_allowed = True
break
else:
cpp_override_allowed = True
if cpp_override_allowed:
# C++ function/method overrides with different signatures are ok.
pass
elif self.is_cpp_class_scope and entries[name].is_inherited:
# Likewise ignore inherited classes.
......
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