public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: adrian.cornish@bluedreamer.com To: gcc-gnats@gcc.gnu.org Subject: c++/4072: g++ fails to compile template code Date: Tue, 21 Aug 2001 13:46:00 -0000 [thread overview] Message-ID: <200108212047.f7LKlrP16935@falcon.bluedreamer.com> (raw) >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:
next reply other threads:[~2001-08-21 13:46 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2001-08-21 13:46 adrian.cornish [this message] 2001-08-21 21:53 aoliva
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=200108212047.f7LKlrP16935@falcon.bluedreamer.com \ --to=adrian.cornish@bluedreamer.com \ --cc=gcc-gnats@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).