Bug Report #2

Alexandrescu, Andrei AlexandrescuA@MICROMODELING.COM
Sat Nov 7 23:58:00 GMT 1998


Hello,

Please tell me if you want me to continue to submit bug reports (and to
whom). I develop some high-octane templates and I am in a zone where bugs
appear very often.

Here is another bug: while groking the following code, egcs crashes:

/////////////////////////////////////////////////////
namespace a
{
	const unsigned Flag1 = 1u << 2;
};
template <
	typename Interface, 
	unsigned long Options = 0
	>
class Test
{
	template <typename Interface, bool Flag>
	class TemplateComponent
	{
	};
	typedef TemplateComponent<
		Interface, 
		((Options & ::a::Flag1) != 0)
		> 
		Component;
};
/////////////////////////////////////////////////////

The crash is due to the expression ((Options & ::a::Flag1) != 0). If I put a
true or a false there, it works. I found a workaround by defining an
aditional bool constant:

/////////////////////////////////////////////////////
namespace a
{
	const unsigned Flag1 = 1u << 2;
};
template <
	typename Interface, 
	unsigned long Options = 0
	>
class Test
{
	template <typename Interface, bool Flag>
	class TemplateComponent
	{
	};
	static const bool Flag = (Options & ::a::Flag1) != 0;
	typedef TemplateComponent<
		Interface, 
		Flag
		> 
		Component;
};
/////////////////////////////////////////////////////

This way the compiler works correctly.

Also a minor annoyance - the following incorrect code compiles, although
I've no idea what it really means:

template <class A> template <class B>
class C
{
};

It seems like A is ignored. If you try to use the type A inside the class C,
the compiler crashes.

Yours,

Andrei



More information about the Gcc-bugs mailing list