This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
g++ 2.95.2 friend template function declaration within template class
- To: gcc-bugs at gcc dot gnu dot org
- Subject: g++ 2.95.2 friend template function declaration within template class
- From: David Scott Page <page at cs dot utexas dot edu>
- Date: Mon, 21 Feb 2000 12:45:36 -0600 (CST)
// This program demonstrates what I believe is a bug with
// GCC-2.95.2/SPARC (g++).
//
// If a template function is declared within a template class, and the
// template parameters are those of the class, (superfluously)
// specifying the template parameters in the function declaration,
// e.g., fu< bar >() causes an error when the template function is
// instantiated. Compile the following program using
//
// g++ -v <filename> -DBUG_1
//
#if defined( BUG_1 )
#define XXX_NO_CLASS_DECLARED_FRIEND_TEMPLATE_FUNCTION_WITH_EXPLICIT_PARAMETERS
#endif
#if ! ( defined( __GNUC__ ) && ( __GNUC__ <= 2 ) && ( __GNUC_MINOR__ <= 95 ) ) // check _G_LIB_VERSION "2.8.0" instead?
#include <iterator>
#else // patch missing std::iterator template class
#include <iterator>
namespace std
{
template <class _Category, class _Tp, class _Distance = ptrdiff_t,
class _Pointer = _Tp*, class _Reference = _Tp&>
struct iterator {
typedef _Category iterator_category;
typedef _Tp value_type;
typedef _Distance difference_type;
typedef _Pointer pointer;
typedef _Reference reference;
};
}
#endif
template< typename T , typename C >
class SliceIter ;
// out-of-class declaration of friend function - superfluous for GCC,
// needed for KCC 3.4g
template< typename T , typename C >
bool
operator==( SliceIter< T , C > const & , SliceIter< T , C > const & ) ;
// friendship granting class definition.
template< typename T , typename C >
class SliceIter
: public std::iterator< std::random_access_iterator_tag , T >
{
private :
int curr ;
#ifdef XXX_NO_CLASS_DECLARED_FRIEND_TEMPLATE_FUNCTION_WITH_EXPLICIT_PARAMETERS
friend bool
operator==< T , C >( SliceIter< T , C > const & , SliceIter< T , C > const & ) ;
#else
friend bool
operator==< >( SliceIter< T , C > const & , SliceIter< T , C > const & ) ;
#endif
} ;
template< typename T , typename C >
bool
operator==( SliceIter< T , C > const & p , SliceIter< T , C > const & q )
{
return( p.curr == q.curr ) ;
}
#include <valarray>
int
main( void )
{
SliceIter< int , std::valarray< int > > sa ;
SliceIter< int , std::valarray< int > > sb ;
return( sa == sb ) ;
}
// ---------------------------- command and results ------------------------
// g++ -v templateFriendDeclaration.C -DBUG_1
// Reading specs from /usr/local/lib/gcc-lib/sparc-sun-solaris2.7/2.95.2/specs
// gcc version 2.95.2 19991024 (release)
// /usr/local/lib/gcc-lib/sparc-sun-solaris2.7/2.95.2/cpp -lang-c++ -v -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__GCC_NEW_VARARGS__ -Acpu(sparc) -Amachine(sparc) -DBUG_1 templateFriendDeclaration.C /var/tmp/ccBTpZaf.ii
// GNU CPP version 2.95.2 19991024 (release) (sparc)
// #include "..." search starts here:
// #include <...> search starts here:
// /usr/local/lib/gcc-lib/sparc-sun-solaris2.7/2.95.2/../../../../include/g++-3
// /usr/local/include
// /usr/local/lib/gcc-lib/sparc-sun-solaris2.7/2.95.2/../../../../sparc-sun-solaris2.7/include
// /usr/local/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:
// End of omitted list.
// /usr/local/lib/gcc-lib/sparc-sun-solaris2.7/2.95.2/cc1plus /var/tmp/ccBTpZaf.ii -quiet -dumpbase templateFriendDeclaration.cc -version -o /var/tmp/ccA40E2N.s
// GNU C++ version 2.95.2 19991024 (release) (sparc-sun-solaris2.7) compiled by GNU C version 2.95.2 19991024 (release).
// templateFriendDeclaration.C: In instantiation of `SliceIter<int,valarray<int> >':
// templateFriendDeclaration.C:72: instantiated from here
// templateFriendDeclaration.C:53: template argument 2 is invalid