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]
Other format: [Raw text]

Maybe a bug in G++


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello,

I think I have found an identifier lookup bug in g++ (GCC) 3.3.3 (Debian 
20040422). Attached are two files, one which compiles and one which doesn't  
though I think that it should compile.

But since I have found a workaround (or maybe a standard conforming 
solution) ...
- --
Best Regards
Sven Gohlke

GnuPG Fingerprint: 7197 61F6 AFDE F46D 914B 65C2 2A4B 5BBF 6CC0
at hkp://wwwkeys.pgp.net

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iEYEARECAAYFAkD6s5wACgkQZcIqS1u/bMCsswCfQxYoW40o3e4Ju0c5sgYi57BD
XeQAnAuZywdEymg2MqLuuuVUm9K3S19L
=IV24
-----END PGP SIGNATURE-----
#include <iostream>

template<typename _T>
struct _TypeOf_
{
	friend class _Null_;
	private:
		template<int, typename _1>
		struct H
		{
			typedef typename _1::Type Type;
		};
		template<typename _1>
		struct H<0, _1>
		{
			typedef _1 Type;
		};

		typedef char HasType;
		typedef struct { char _[2]; }	NoType;
		template<typename _1> static NoType test (...);
		template<typename _1> static HasType test (typename _1::Type const*);
	public:
		typedef typename
			H<sizeof(test<_T>(0))==sizeof(HasType), _T>::Type Type;
};

template<typename _T1, typename _T2>
struct _IsIdentical_
{
	enum { Value = 0 };
};

template<typename _T1>
struct _IsIdentical_<_T1, _T1>
{
	enum { Value = 1 };
};

/*
 * First test type
 *
 * has an empty member type Type
*/
struct ItHas
{
	struct Type{};
};

/*
 * Second test type
 *
 * has a member type Type identical to ItHas::Type
*/
struct ItHasNot
{
	typedef ItHas::Type Type;
};

/*
 * Third test type
*/
typedef int Other;

int
main (int argc, const char **argv)
{
	/* Both test are made at compile time. No calculations are made at run
	 * time. The first calculation results to 0, the second to 1.
	*/
	std::cout << "_IsIdentical_<ItHas, ItHasNot>: " <<
		_IsIdentical_<ItHas, ItHasNot>::Value << std::endl;
	std::cout << "_IsIdentical_<ItHas, Other>: " <<
		_IsIdentical_<ItHas, Other>::Value << std::endl;
	std::cout <<
		"_IsIdentical_<_TypeOf_<ItHas>::Type, _TypeOf_<ItHasNot>::Type>: " <<
		_IsIdentical_<_TypeOf_<ItHas>::Type, _TypeOf_<ItHasNot>::Type>::Value <<
			std::endl;
	std::cout <<
		"_IsIdentical_<_TypeOf_<ItHas>::Type, _TypeOf_<Other>::Type>: " <<
		_IsIdentical_<_TypeOf_<ItHas>::Type, _TypeOf_<Other>::Type>::Value <<
			std::endl;
	return 0;
}

#include <iostream>

template<typename _T>
struct _TypeOf_
{
	friend class _Null_;
	private:
		template<int, typename _1>
		struct H
		{
			typedef typename _1::Type Type;
		};
		template<typename _1>
		struct H<0, _1>
		{
			typedef _1 Type;
		};

		typedef char HasType;
		typedef struct { char _[2]; }	NoType;
		template<typename _1> static NoType test (...);
		template<typename _1> static HasType test (typename _1::Type const*);
		typedef _TypeOf_ This;
	public:
		typedef typename
			H<sizeof(This::test<_T>(0))==sizeof(HasType), _T>::Type Type;
};

template<typename _T1, typename _T2>
struct _IsIdentical_
{
	enum { Value = 0 };
};

template<typename _T1>
struct _IsIdentical_<_T1, _T1>
{
	enum { Value = 1 };
};

/*
 * First test type
 *
 * has an empty member type Type
*/
struct ItHas
{
	struct Type{};
};

/*
 * Second test type
 *
 * has a member type Type identical to ItHas::Type
*/
struct ItHasNot
{
	typedef ItHas::Type Type;
};

/*
 * Third test type
*/
typedef int Other;

int
main (int argc, const char **argv)
{
	/* Both test are made at compile time. No calculations are made at run
	 * time. The first calculation results to 0, the second to 1.
	*/
	std::cout << "_IsIdentical_<ItHas, ItHasNot>: " <<
		_IsIdentical_<ItHas, ItHasNot>::Value << std::endl;
	std::cout << "_IsIdentical_<ItHas, Other>: " <<
		_IsIdentical_<ItHas, Other>::Value << std::endl;
	std::cout <<
		"_IsIdentical_<_TypeOf_<ItHas>::Type, _TypeOf_<ItHasNot>::Type>: " <<
		_IsIdentical_<_TypeOf_<ItHas>::Type, _TypeOf_<ItHasNot>::Type>::Value <<
			std::endl;
	std::cout <<
		"_IsIdentical_<_TypeOf_<ItHas>::Type, _TypeOf_<Other>::Type>: " <<
		_IsIdentical_<_TypeOf_<ItHas>::Type, _TypeOf_<Other>::Type>::Value <<
			std::endl;
	return 0;
}


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