/* --------------------------------
PROBLEM: name lookup failure in inheritance tree
PLATFORM: HP nx8220 Fedora Core 6
PACKAGES: gcc-4.1.2-13.fc6
PACKAGES: gcc-c++-4.1.2-13.fc6
PACKAGES: libgcc-4.1.2-13.fc6
OUTPUT: g++ -v -o a a.cc
-----------------------------------
Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-libgcj-multifile
--enable-languages=c,c++,objc,obj-c++,java,fortran,ada
--enable-java-awt=gtk --disable-dssi --enable-plugin
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre
--with-cpu=generic --host=i386-redhat-linux
Thread model: posix
gcc version 4.1.2 20070626 (Red Hat 4.1.2-13)
/usr/libexec/gcc/i386-redhat-linux/4.1.2/cc1plus -quiet -v -D_GNU_SOURCE a.cc
-quiet -dumpbase a.cc -mtune=generic -auxbase a -version -o
/tmp/ccq59QI3.s
ignoring nonexistent directory
"/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../i386-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/i386-redhat-linux
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/backward
/usr/local/include
/usr/lib/gcc/i386-redhat-linux/4.1.2/include
/usr/include
End of search list.
GNU C++ version 4.1.2 20070626 (Red Hat 4.1.2-13) (i386-redhat-linux)
compiled by GNU C version 4.1.2 20070626 (Red Hat 4.1.2-13).
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 3a456da196cbee4c75d3822886d8cc8c
----------------- the error message ------------------------------
a.cc: In function int main(int, char**):
a.cc:73: error: no matching function for call to B::f(int)
a.cc:61: note: candidates are: void B::f(int, int)
*/
// ============= the source code ================
#include <stdio.h>
// This combination of functions works fine ...
void g( int x ) { printf("::g(i)\n"); }
void g( int x, int y ) { printf("::g(i,i)\n"); }
// but ...
class A // A baseclass
{
public:
void f(int x) { printf("A::f(i)\n"); }
};
class B : public A
{
public:
void f(int x, int y) { printf("B::f(i,i)\n"); }
// This method has the same name (f) as the one inherited
// from A, but a different parameter list, so it should be
// distinct (like the global g's above).
};
int main( int argc, char * argv[] )
{
g( 1 ); // expect ::g(i) oke
g( 1, 2 ); // expect ::g(i,i) oke
B b;
b.f( 1 ); // expect A::f(i) oops
// but apparently the compiler can now
// only recognize B::f(i,i)
b.f( 1, 2 );// expect B::f(i,i) oke
return 0;
}
/* ================ expected ouput =========
If you rename B::f to B::h you'll get the expected output
::g(i)
::g(i,i)
A::f(i)
B::f(i,i)
To summarize the problem in general:
When a derived class defines a (or more) method(s)
with the same name as a method inherited from a baseclass,
all inherited methods with that name get 'shadowed', even when
they have totally different parameterlists.
*/
--
Summary: method name lookup failure in inheritance tree
Product: gcc
Version: 4.1.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: r dot a dot akkersdijk at saxion dot nl
GCC build triplet: i386-redhat-linux
GCC host triplet: i386-redhat-linux
GCC target triplet: i386-redhat-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33165