possible bug in g++

Mattia Jona-Lasinio mattia.jona@gmail.com
Wed Feb 15 17:11:00 GMT 2012


Hi list,

the following code does not link with g++ 4.3.2 but works with the
intel compiler version 11.0

#include <iostream>

template <int T = 5>
struct X
{
	static const int v = T*X<T-1>::v;
};

template <>
struct X<0>
{
	static const int v = 1;
};

template <typename T>
T *aa(int n)
{
	return (new T[n]);
}

int main()
{
	X<4> *b;

	std::cout << (b = aa< X<4> >(3))[1].v << std::endl; // relevant line

	delete[] b;

	return 0;
}

Also the following shorter version does not link with g++

int main()
{
	std::cout << aa< X<4> >(3)[1].v << std::endl; // relevant line

	return 0;
}

while the following version links with g++ though all versions must be
equivalent. Am I missing something?

int main()
{
	X<4> *b;

	b = aa< X<4> >(3); // relevant line
	std::cout << b[1].v << std::endl; // relevant line

	delete[] b;

	return 0;
}


Thanks for the help.

Best

Mattia



More information about the Gcc-help mailing list