Namespace bug

Carsten Leue carsten.leue@iwr.uni-heidelberg.de
Thu Dec 17 01:24:00 GMT 1998


Dear Developers.

Compiling the following file main.cpp with egcs-2.91.57 produces the
following output.
Any help or workaround will be appreciated.

Sincerely
Carsten Leue

output:
BASH.EXE-2.01$ gcc -c main.cpp
main.cpp: In function `int ** alloc<int>(int, int)':
main.cpp:65:   instantiated from here
main.cpp:37: Internal compiler error 980519.
main.cpp:37: Please submit a full bug report to `egcs-bugs@cygnus.com'.

file main.cpp
#include <assert.h>
#include <iostream.h>

namespace vector {

	/* Allokiert Speicher für einen Vektor der angegebenen Größe.
	*/
	template <class T>
	inline T* alloc(const int aWidth)
	{
		// Speicher allokieren
		return new T[aWidth];
	}

	/* Gibt den mit alloc reservierten Speicher wieder frei
	*/
	template <class T>
	inline bool free(T* aVec)
	{
		if (aVec==NULL) return false;
		// Speicher freigeben
		delete[] aVec;
		return true;
	}

};

namespace matrix {

	/* Allokiert Speicher für eine Matrix der Breite aWidth und der Höhe
aHeight (also
		eine [aHeight x aWidth] Matrix). Die Matrixindizes sind nullbasiert!
	*/
	template <class T>
	T** alloc(const int aWidth,const int aHeight)
	{
		// Speicher allokieren
		T **mat = vector::alloc<T*>(aHeight),
			*data = vector::alloc<T> (aWidth*aHeight);
		assert(mat && data);
		// Zeiger zuweisen
		for (int i=0; i<aHeight; i++)
			mat[i] = &data[aWidth*i];
		// ok
		return mat;
	}

	/* Gibt eine mit 'alloc' allokierte Matrix wieder frei
	*/
	template <class T>
	bool free(T** aMat)
	{
		if (!aMat) return false;
		// Daten löschen
		vector::free(*aMat);
		vector::free(aMat);
		// ok
		return true;
	}

};


int main()
{
	int** data = matrix::alloc<int>(5,5);
	cout<<data<<endl;
	matrix::free(data);

	return true;
}



More information about the Gcc-bugs mailing list