[Bug c++/18072] New: Function overload being selected from file scope instead of template class scope when called from base template class
dwoldrich_ebay at yahoo dot com
gcc-bugzilla@gcc.gnu.org
Wed Oct 20 09:27:00 GMT 2004
This problem evolved out of my trying to implement a context aware logger. It
appears that template classes with template parameters that themselves have
template parameters can cause gcc to be unable to select an overload from the
class correctly and incorrectly goes to the file scope for the default method.
It's very confusing and hard to explain... I will paste the code below, but
hopefully there is a attach function I can use later on to just attach the
source file.
In VC6.0, the code prints the following when run:
I'd really love to call my base class'es method ... and the base class is
indeed printing as I had hoped it would.
In GCC 3.4.1, the code prints the following (undesired/incorrect?) when run:
I'd really love to call my base class'es method... but the file scoped
function is selected! WAH! Why does GCC and/or the C++ standard hate me so!?
I believe there is something specific about the following line that the compiler
is not processing correctly:
template<class ANYTYPE2> class DERIVED : public BASETEMPLATE< DERIVED<ANYTYPE2> >
using GCC from mingw:
Reading specs from ../lib/gcc/mingw32/3.4.1/specs
Configured with: ../gcc/configure --with-gcc --with-gnu-ld --with-gnu-as
--host=mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls
--enable-languages=c,c++,f77,ada,objc,java --disable-win32-registry
--disable-shared --enable-sjlj-exceptions --enable-libgcj --disable-java-awt
--without-x --enable-java-gc=boehm --disable-libgcj-debug --enable-interpreter
--enable-hash-synchronization --enable-libstdcxx-debug
Thread model: win32
gcc version 3.4.1 (mingw special)
compiled with:
gcc -c -g -mwindows -DWIN32 -D_WINDOWS -D_DEBUG -IC:\devproject\woldie\protos
-std=gnu++98 -felide-constructors -frepo -fshort-enums -fshort-wchar
-fkeep-static-consts -ftemplate-depth-255 -mms-bitfields -march=i586
-malign-stringops -mfancy-math-387 -mhard-float -mfp-ret-in-387 -m32
-mno-mmx-mno-3dnow -mno-sse -mno-sse2 -mno-sse3
C:\devproject\woldie\protos\testforfails.cpp
linked with:
gcc -g -Wl,--force-exe-suffix -o protos protos\Debug\testforfails.o
-LC:\MinGW\lib\debug -Wl,-Bstatic -lstdc++ -Wl,-Bstatic -lsupc++ -lkernel32
-luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32
-luuid -lodbc32 -lodbccp32
here's the code:
#include <stdio.h>
class BASEOFBASE
{
public:
BASEOFBASE(void) {}
virtual ~BASEOFBASE(void) {}
};
extern BASEOFBASE& PrintSumpthin(void);
template<class ANYTYPE> class BASETEMPLATE : public BASEOFBASE
{
private:
mutable int whocaresjustignoreme;
protected:
BASETEMPLATE(void) {}
friend BASEOFBASE& ::PrintSumpthin(void);
public:
virtual const BASEOFBASE& PrintSumpthin(void) const
{
printf(" ... and the base class is indeed printing as I had hoped it
would.\n");
return(*this);
}
virtual BASEOFBASE& PrintSumpthin(void)
{
printf(" ... and the base class is indeed printing as I had hoped it
would.\n");
return(*this);
}
public:
virtual ~BASETEMPLATE(void) {}
};
template<class ANYTYPE2> class DERIVED : public BASETEMPLATE< DERIVED<ANYTYPE2> >
{
private:
ANYTYPE2 thistoodoesnotmatterawhit;
public:
DERIVED(void) {}
~DERIVED(void) {}
void ImGonnaPrint(void)
{
printf("I'd really love to call my base class'es method");
PrintSumpthin();
}
};
int main(int argc, char** argv)
{
DERIVED<char>* myDerived = new DERIVED<char>();
myDerived->ImGonnaPrint();
return(0);
}
BASEOFBASE& PrintSumpthin(void)
{
static BASETEMPLATE<int> thisisjustheretoconfuse;
printf("... but the file scoped function is selected! WAH! Why does GCC
and/or the C++ standard hate me so!?\n");
return(thisisjustheretoconfuse);
}
--
Summary: Function overload being selected from file scope instead
of template class scope when called from base template
class
Product: gcc
Version: 3.4.1
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: dwoldrich_ebay at yahoo dot com
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18072
More information about the Gcc-bugs
mailing list