From 3ed206ebd0da5b33707000c3cfb0b3a96f3190ad Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 9 Jun 2005 18:38:52 +0000 Subject: [PATCH] Bug fix for when a base class has the same name as a method in a derived class. Fixes for when access changes from protected to public (-fvirtual and override/hides attributes) git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@7260 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- SWIG/Source/Modules/allocate.cxx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/SWIG/Source/Modules/allocate.cxx b/SWIG/Source/Modules/allocate.cxx index 4b83e1c3e..935920aa9 100644 --- a/SWIG/Source/Modules/allocate.cxx +++ b/SWIG/Source/Modules/allocate.cxx @@ -63,7 +63,8 @@ class Allocate : public Dispatcher { int extendmode; /* Checks if a function, n, is the same as any in the base class, ie if the method is polymorphic. - * Also checks for methods which will be hidden (ie a base has an identical non-virtual method). */ + * Also checks for methods which will be hidden (ie a base has an identical non-virtual method). + * Both methods must have public access for a match to occur. */ int function_is_defined_in_bases(Node *n, Node *bases) { if (!bases) @@ -122,13 +123,14 @@ class Allocate : public Dispatcher { return 0; } + /* Helper function for function_is_defined_in_bases */ int function_is_defined_in_bases_seek(Node *n, Node *b, Node *base, String *this_decl, String *name, String *this_type, String *resolved_decl) { String *base_decl = Getattr(base, "decl"); SwigType *base_type = Getattr(base, "type"); if (base_decl && base_type) { if (checkAttribute(base, "name", name) && !Getattr(b, "feature:ignore") /* whole class is ignored */ ) { - if (SwigType_isfunction(resolved_decl)) { + if (SwigType_isfunction(resolved_decl) && SwigType_isfunction(base_decl)) { // We have found a method that has the same name as one in a base class bool covariant_returntype = false; bool returntype_match = Strcmp(base_type, this_type) == 0 ? true : false; @@ -203,9 +205,10 @@ class Allocate : public Dispatcher { if (!most_base_covariant_type) { // Eliminate the derived virtual method. - if (virtual_elimination_mode) { - Setattr(n,"feature:ignore", "1"); - } + if (virtual_elimination_mode) + if (both_have_public_access) + if (!is_non_public_base(inclass, b)) + Setattr(n,"feature:ignore", "1"); } else { // Some languages need to know about covariant return types Setattr(n, "covariant", most_base_covariant_type); @@ -217,7 +220,8 @@ class Allocate : public Dispatcher { if (!is_non_public_base(inclass, b)) Setattr(n, "hides", base); } - return 1; + if (both_have_public_access) + return 1; } } }