public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/18072] New: Function overload being selected from file scope instead of template class scope when called from base template class
@ 2004-10-20 9:27 dwoldrich_ebay at yahoo dot com
2004-10-20 9:29 ` [Bug c++/18072] " dwoldrich_ebay at yahoo dot com
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: dwoldrich_ebay at yahoo dot com @ 2004-10-20 9:27 UTC (permalink / raw)
To: gcc-bugs
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/18072] Function overload being selected from file scope instead of template class scope when called from base template class
2004-10-20 9:27 [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
@ 2004-10-20 9:29 ` dwoldrich_ebay at yahoo dot com
2004-10-20 13:11 ` pinskia at gcc dot gnu dot org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: dwoldrich_ebay at yahoo dot com @ 2004-10-20 9:29 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From dwoldrich_ebay at yahoo dot com 2004-10-20 09:29 -------
Created an attachment (id=7384)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=7384&action=view)
Source code
This is the source code to the test I wrote.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18072
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/18072] Function overload being selected from file scope instead of template class scope when called from base template class
2004-10-20 9:27 [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
2004-10-20 9:29 ` [Bug c++/18072] " dwoldrich_ebay at yahoo dot com
@ 2004-10-20 13:11 ` pinskia at gcc dot gnu dot org
2004-11-05 19:28 ` bangerth at dealii dot org
2004-11-05 19:34 ` bangerth at dealii dot org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-10-20 13:11 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-10-20 13:11 -------
Did you read the release notes? This is documented in them and how the code should change.
Invalid by the C++ standard.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18072
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/18072] Function overload being selected from file scope instead of template class scope when called from base template class
2004-10-20 9:27 [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
2004-10-20 9:29 ` [Bug c++/18072] " dwoldrich_ebay at yahoo dot com
2004-10-20 13:11 ` pinskia at gcc dot gnu dot org
@ 2004-11-05 19:28 ` bangerth at dealii dot org
2004-11-05 19:34 ` bangerth at dealii dot org
3 siblings, 0 replies; 5+ messages in thread
From: bangerth at dealii dot org @ 2004-11-05 19:28 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bangerth at dealii dot org 2004-11-05 19:27 -------
These are all duplicates of PR 15552
--
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|INVALID |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18072
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/18072] Function overload being selected from file scope instead of template class scope when called from base template class
2004-10-20 9:27 [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
` (2 preceding siblings ...)
2004-11-05 19:28 ` bangerth at dealii dot org
@ 2004-11-05 19:34 ` bangerth at dealii dot org
3 siblings, 0 replies; 5+ messages in thread
From: bangerth at dealii dot org @ 2004-11-05 19:34 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bangerth at dealii dot org 2004-11-05 19:34 -------
Duplicate of PR 15552.
*** This bug has been marked as a duplicate of 15552 ***
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |DUPLICATE
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18072
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2004-11-05 19:34 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-20 9:27 [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
2004-10-20 9:29 ` [Bug c++/18072] " dwoldrich_ebay at yahoo dot com
2004-10-20 13:11 ` pinskia at gcc dot gnu dot org
2004-11-05 19:28 ` bangerth at dealii dot org
2004-11-05 19:34 ` bangerth at dealii dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).