This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Type problem with template functions and inheritance ?


Because Comeau's test drive compiler accepts I would fill a bug report in
Bugzilla if I were you.

VH


On Wed, 8 Sep 2004, Simon MARTIN wrote:

> Hello.
>
> I played a little with templates and template functions, and I encountered a
> problem with GCC while doing so. The code at the end of this message builds
> with Microsoft's Visual C++ Toolkit 2003, but fails with GCC. Since the code
> is quite "weird", I wonder whether there's a problem in GCC or Visual is too
> laxist.
>
> What is strange is:
>   - the "<unknown type>" in the error message
>   - the fact that if I "help" GCC a little (before the first static_cast),
> then things work fine.
>
> Thanks in advance for your help / explanation.
>
> Regards,
> Simon
>
> [simon@texel gcc_test]$ g++ -v
> Reading specs from /usr/lib/gcc-lib/i586-mandrake-linux-gnu/3.3.2/specs
> Configured with: ../configure --prefix=/usr --libdir=/usr/lib
> --with-slibdir=/lib --mandir=/usr/share/man --infodir=/usr/share/info
> --enable-shared --enable-threads=posix --disable-checking --enable-long-long
> --enable-__cxa_atexit --enable-clocale=gnu
> --enable-languages=c,c++,ada,f77,objc,java,pascal
> --host=i586-mandrake-linux-gnu --with-system-zlib
> Thread model: posix
> gcc version 3.3.2 (Mandrake Linux 10.0 3.3.2-6mdk)
>
> [simon@texel gcc_test]$ g++ -Wall -o test test.cpp
> test.cpp: In function `int main(int, char**)':
> test.cpp:18: error: invalid static_cast from type `<unknown type>' to type
> `bool (Base::*)(const char*)'
>
> ==== test.cpp
> class Base {};
> struct MyClass : public Base
> {
>   template<int key> bool Method(const char *value) { return true; }
> };
>
> int main(int argc, char *argv[])
> {
>   typedef bool (Base::*BaseMethodPtr)(const char*);
>   typedef bool (MyClass::*MethodPtr)(const char*);
>
>   MyClass aClass;
>
>   MethodPtr mp = &MyClass::Method<1>;
>   BaseMethodPtr p1 = static_cast<BaseMethodPtr>(mp);
>   (aClass.*p1)("One");
>
>   BaseMethodPtr p2 = static_cast<BaseMethodPtr>(&MyClass::Method<1>);
>   (aClass.*p2)("OneAgain");
>
>   return 0;
> }
> ==== end of test.cpp
>
> --
> Kile - an Integrated LaTeX Environment for KDE
> http://kile.sourceforge.net
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]