This is the mail archive of the gcc-bugs@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]

g++ template bug


I've encountered this error a few times in g++2.95.2, and finally
pinned it down to a small case (~60 lines after preprocessing).  The
code is below, followed by the output of g++ with "-v --save-temps" as
suggested in the bug reporting info.  A comment in the code below
points to the crux of the matter.

----------------------------------------------------------------------
// This demonstrates my compiler bug

template <class A, class B, class C, class D>
struct Help {
   typedef A First;
   typedef B Second;
   typedef D Third;
};

template <class A, class B, class C>
struct HelpSig {
   typedef A First;
   typedef B Second;
   typedef C Third;
};

struct Plus {
   template <class T, class U>
   struct Sig : public HelpSig<T,U,T> {};

   template <class T>
   T operator()( const T& x, const T& y ) const {
      return x+y;
   }
};

template <class T>
struct Ethel {
   typedef T WrappedType;
};

struct Fred {
//////////////////////////////////////////////////////////////////////
// If you "comment out" this thing below, the compiler quits
// (mis)reporting errors   (this this isn't even used!!!)
//////////////////////////////////////////////////////////////////////
   template <class Z, class LA, class LB>
   struct Fig : public Help<Z,LA,LB,
   Ethel<typename Z::Sig<typename LA::WrappedType,
                        typename LB::WrappedType>::Third> > {};
//////////////////////////////////////////////////////////////////////

   template <class Z, class A, class B>
   Ethel<typename Z::Sig<A,B>::Third>
   operator()( const Z&, const Ethel<A>&, const Ethel<B>&) const {
      return Ethel<typename Z::Sig<A,B>::Third>();
   }
};

int main() {
   Fred()( Plus(), Ethel<int>(), Ethel<int>() );
   return 0;
}

----------------------------------------------------------------------
Reading specs from /net/hp45/yannis/gcc.2.95.2-install/lib/gcc-lib/sparc-sun-solaris2.7/2.95.2/specs
gcc version 2.95.2 19991024 (release)
 /net/hp45/yannis/gcc.2.95.2-install/lib/gcc-lib/sparc-sun-solaris2.7/2.95.2/cpp -lang-c++ -v -I/net/hp45/yannis/gcc.2.95.2-install//include/g++ -D__GNUC__=2 -D__GNUG__=2 -D__GNUC_MINOR__=95 -D__cplusplus -Dsparc -Dsun -Dunix -D__svr4__ -D__SVR4 -D__sparc__ -D__sun__ -D__unix__ -D__svr4__ -D__SVR4 -D__sparc -D__sun -D__unix -Asystem(unix) -Asystem(svr4) -D__EXCEPTIONS -D__OPTIMIZE__ -W -Wall -Woverloaded-virtual -D__GCC_NEW_VARARGS__ -Acpu(sparc) -Amachine(sparc) foo.cc foo.ii
GNU CPP version 2.95.2 19991024 (release) (sparc)
#include "..." search starts here:
#include <...> search starts here:
 /net/hp45/yannis/gcc.2.95.2-install/include/g++
 /net/hp45/yannis/gcc.2.95.2-install/lib/gcc-lib/sparc-sun-solaris2.7/2.95.2/../../../../sparc-sun-solaris2.7/include
 /net/hp45/yannis/gcc.2.95.2-install/lib/gcc-lib/sparc-sun-solaris2.7/2.95.2/include
 /usr/include
End of search list.
The following default directories have been omitted from the search path:
 /net/hp45/yannis/gcc.2.95.2-install/include/g++
 /net/hp45/yannis/gcc.2.95.2-install/include/include
End of omitted list.
 /net/hp45/yannis/gcc.2.95.2-install/lib/gcc-lib/sparc-sun-solaris2.7/2.95.2/cc1plus foo.ii -quiet -dumpbase foo.cc -O -W -Wall -Woverloaded-virtual -version -o foo.s
GNU C++ version 2.95.2 19991024 (release) (sparc-sun-solaris2.7) compiled by GNU C version 2.95.2 19991024 (release).
foo.cc: In function `int main()':
foo.cc:45: `int' is not a class, struct, or union type
foo.cc:45: `int' is not a class, struct, or union type
foo.cc:45: template argument 1 is invalid
foo.cc:45: template argument 2 is invalid
foo.cc:45: template argument 1 is invalid
foo.cc:45: `Fred::operator ()<Plus, int, int>(...)' must be a nonstatic member function
foo.cc: At top level:
foo.cc: In instantiation of `Fred::operator ()<Plus, int, int>(...)':
foo.cc:51:   instantiated from here
foo.cc:45: `int' is not a class, struct, or union type
foo.cc:45: `int' is not a class, struct, or union type
foo.cc:45: template argument 1 is invalid
foo.cc:45: template argument 2 is invalid
foo.cc:45: template argument 1 is invalid
foo.cc:45: `Fred::operator ()<Plus, int, int>(...)' must be a nonstatic member function
foo.cc: In function `{error} Fred::operator ()<Plus, int, int>(...)':
foo.cc:45: return-type `{error}' is an incomplete type
foo.cc:45: confused by earlier errors, bailing out
----------------------------------------------------------------------

-- 
-Brian McNamara (lorgon@cc.gatech.edu), your friendly CS 2340 TA

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