[Bug c++/11416] New: Nested template as arg to base class template confuses args

GccBugs at Skyler dot com gcc-bugzilla@gcc.gnu.org
Thu Jul 3 01:58:00 GMT 2003


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11416

           Summary: Nested template as arg to base class template confuses
                    args
           Product: gcc
           Version: 3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: GccBugs at Skyler dot com
                CC: gcc-bugs at gcc dot gnu dot org

#include	<iostream>
using	namespace	std;

template<class T>	struct	Base	{	static	void	f	(void)
	{	T::f	();	}	};

template<class U>
struct	Outer
{	template<class T>	struct	Inner	{	static	void	f
	(void)	{	U::f	();	}	};	};

struct	T1	{	static	void	f	(void)	{	cout	<<
	"T1";	}	};
struct	T2	{	static	void	f	(void)	{	cout	<<
	"T2";	}	};
////////////////////////////////////////////////////////////////////////////////
#if	1
////////////////////////////////////////////////////////////////////////////////
//	The bug:
////////////////////////////////////////////////////////////////////////////////
template<class T, class U>
struct	Derived	:	public	Base<Outer<U>::Inner<T> >	{	};

int	main	(void)	{	Derived<T1, T2>::f();	};
////////////////////////////////////////////////////////////////////////////////
//	What should happen:
//
//	Calling Derived<T1, T2>::f() actually calls Base<Outer<T2>::Inner<T1> 
>::f()
//	which calls T2::f()
//	which prints "T2"
//
//	Actual output: "T1"
////////////////////////////////////////////////////////////////////////////////
#else
////////////////////////////////////////////////////////////////////////////////
//	Workaround:
////////////////////////////////////////////////////////////////////////////////
template<class T, class U>
struct	Nest
{
	template<class O>	struct	Out	{	typedef	typename 
O::Inner<T>	In;	};
	typedef	typename Out<Outer<U> >::In	Nested;
};

template<class T, class U>
struct	Derived	:	public	Base<typename Nest<T, U>::Nested>	{
	};

int	main	(void)	{	Derived<T1, T2>::f();	};

//	Prints "T2"
////////////////////////////////////////////////////////////////////////////////
#endif
////////////////////////////////////////////////////////////////////////////////



More information about the Gcc-bugs mailing list