From 139143ee181fb6d4ef151defca10f5882ebce977 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Sun, 11 Mar 2018 09:25:15 +0100 Subject: Do not issue "redefined" warnings on C++ function overrides with different signatures (previously only applied to methods). Closes #2013. --- Cython/Compiler/Symtab.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'Cython/Compiler/Symtab.py') diff --git a/Cython/Compiler/Symtab.py b/Cython/Compiler/Symtab.py index 3d4954764..9e49acd0d 100644 --- a/Cython/Compiler/Symtab.py +++ b/Cython/Compiler/Symtab.py @@ -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 == '' 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. -- cgit v1.2.1