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]

c++/4072: g++ fails to compile template code



>Number:         4072
>Category:       c++
>Synopsis:       g++ fails to compile template code
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Aug 21 13:46:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Adrian Cornish
>Release:        3.0
>Organization:
>Environment:
System: Linux falcon 2.2.18-SMP #1 SMP Wed Jan 24 12:30:30 GMT 2001 i686 unknown
Architecture: i686

	
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: /home/adrian/gcc/gcc-3.0/configure --prefix=/usr --enable-threads
>Description:

Apoligies if this bug is the "Two stage lookup in templates is not implemented." mentioned on the gcc web site, but my c++ isn't that good.

g++ fails to compile and hangs with the following error:-
adrian@falcon:/home/adrian/code/c++/testbed> g++ -g -ansi -pedantic it.cpp -o it
In file included from it.cpp:5:
Table.h:36: syntax error before `;' token
Table.h: In constructor `Table<T>::Table()':
Table.h:14: parse error before `;' token
(hangs here)

if it helps here is the process from the process table:-
adrian   16876 16875 68 21:33 pts/7    00:02:00 /usr/lib/gcc-lib/i686-pc-linux-gnu/3.0/cc1plus -D__GNUC__=3 -D__GNUC_MINOR__=0 -D__GNUC_PATCHLEVEL__=0 -D__ELF__ -D__unix__ -D__linux__ -D__unix -D__linux -Asystem=posix -D__NO_INLINE__ -D__STDC_HOSTED__=1 -pedantic -D_GNU_SOURCE -Acpu=i386 -Amachine=i386 -D__i386 -D__i386__ -D__tune_i686__ -D__tune_pentiumpro__ it.cpp -D__GNUG__=3 -D__GXX_DEPRECATED -D__EXCEPTIONS -D__GXX_ABI_VERSION=100 -D__STRICT_ANSI__ -trigraphs -$ -quiet -dumpbase it.cpp -ansi -g -pedantic -ansi -o /tmp/ccXLye5K.s

>How-To-Repeat:
The following 2 source causes this error:-
/* Table.h */

#ifndef TABLE_H
#define TABLE_H

#include <string>
#include <vector>
#include <fstream>
#include <algorithm>

template <class T>
class Table
{
	public:
		Table(const std::string &filename);		
		Table() {};
		~Table();

		bool Insert(T &r);
		bool Delete(const T &r);
		bool Modify(const T &r);
		bool Find(const T &r);
		void GoToFirst(void);
		
		bool GetFirst(T &r);
		bool GetNext(T &r);
		void ShowMemTable(void);

	private:
		Table(const Table &t);
		Table &operator=(const Table &rhs);
		void LoadRecords(void);

		unsigned long NextRecordNo;
		std::string FileName;
		std::fstream *FilePtr;
		std::vector<T *> Records;
		std::vector<T *>::iterator MemPtr;
};


template <class T>
Table<T>::Table(const std::string &filename)
	:FileName(filename)
{
	NextRecordNo=1;
	FilePtr=new std::fstream(FileName.c_str(), std::ios_base::in | std::ios_base::out);
	
	if(!*FilePtr)
	{
		std::cout << "File does not exist. Creating " << FileName << std::endl;
		delete FilePtr;
		FilePtr=new std::fstream(FileName.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::trunc);
		*FilePtr << std::setfill('0') << std::setw(10) <<NextRecordNo << std::endl;
		if(!*FilePtr)
		{
			throw std::string("Cannot open file " + FileName);
		}
	}

	// Read next record number from file
	FilePtr->seekg(0);
	*FilePtr >> NextRecordNo;
	if(FilePtr->eof())
	{
		FilePtr->clear();
	}
	std::cout << "Next recno=" << NextRecordNo << std::endl;
	LoadRecords();
	std::cout << Records.size() << " records loaded\n";
}

template <class T>
Table<T>::~Table()
{
	std::vector<T *>::iterator i=Records.begin();
	for( ; i<Records.end(); i++)
	{
		delete *i;
	}
	
	delete FilePtr;
}

template <class T>
bool Table<T>::Insert(T &r)
{
	// Increment record number

	r.SetAutoIncrement(NextRecordNo);
	Records.push_back(new T(r));

	FilePtr->seekp(0, std::ios_base::end);
	*FilePtr << r << std::endl;
		
	FilePtr->seekp(0, std::ios_base::beg);
	NextRecordNo++;
	*FilePtr << std::setfill('0') << std::setw(10) << NextRecordNo << std::endl;

	return true;
}

template <class T>
bool Table<T>::Delete(const T &r)
{
	return false;
}

template <class T>
bool Table<T>::Modify(const T &r)
{
	bool rc=false;
	if(Find(r))
	{
		*FilePtr << r << std::endl;
		**MemPtr=r;
		if(FilePtr->good())
		{
			rc=true;
		}
	}
	return rc;
}

template <class T>
bool Table<T>::Find(const T &r)
{
	MemPtr=std::find(Records.begin(), Records.end(), r);
	if(MemPtr==Records.end())
	{
		// Dont search file if not in mem table
		return false;
	}
	std::fstream::pos_type save;
	T file_rec;

	GoToFirst();
	while(!FilePtr->eof())
	{
		save=FilePtr->tellg();
		*FilePtr >> file_rec;
		if(file_rec==r)
		{
			std::cout << "Found it\n";
			FilePtr->seekg(save, std::ios_base::beg);
			FilePtr->seekp(save, std::ios_base::beg);

			return true;
		}
		FilePtr->ignore(1000, '\n');
	}	
	FilePtr->clear();
	
	return false;
}

template <class T>
void Table<T>::GoToFirst(void)
{
	FilePtr->seekg(0);
	// Skip next rec no
	FilePtr->ignore(11, '\n');
	MemPtr=Records.begin();
}

template <class T>
bool Table<T>::GetFirst(T &r)
{
	GoToFirst();
	*FilePtr >> r;

	return FilePtr->good();
}

template <class T>
bool Table<T>::GetNext(T &r)
{
	*FilePtr >> r;
	MemPtr++;

	return FilePtr->good();
}

template <class T>
void Table<T>::LoadRecords(void)
{
	T rec;
	if(GetFirst(rec))
	{
		Records.push_back(new T(rec));
		while(GetNext(rec))
		{
			Records.push_back(new T(rec));
		}
	}
	
	if(FilePtr->eof())
	{
		FilePtr->clear();
	}
	FilePtr->seekg(0);
	FilePtr->seekp(0);
	MemPtr=Records.begin();
}

template <class T>
void Table<T>::ShowMemTable(void)
{
	std::vector<T *>::iterator i=Records.begin();
	for( ; i<Records.end(); i++)
	{
		std::cout << (**i) << std::endl;
	}
}

#endif

/* it.cpp */

#include <iostream>
#include <string>
#include <vector>

#include "Table.h"

using namespace std;

int main(int argc, char *argv[])
{
	Table<string> a;
	Table<int> b;

	return 0;
}

>Fix:
	Removing -pedantic from the compile line works


Adrian Cornish
adrian.cornish@bluedreamer.com
>Release-Note:
>Audit-Trail:
>Unformatted:


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