Internal compiler error
Bruce Eckel
Bruce@EckelObjects.com
Fri Dec 11 09:57:00 GMT 1998
The following file gives me, for egcs-2.91.60 :
ForEach.cpp: In function `int main()':
ForEach.cpp:49: Internal compiler error 980715.
ForEach.cpp:49: Please submit a full bug report to `egcs-bugs@cygnus.com'.
ForEach.cpp:49: See <URL: http://egcs.cygnus.com/faq.html#bugreport > for
details
//: C21:ForEach.cpp
// Use of STL for_each() algorithm
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class Counted {
static int count;
char * id;
public:
Counted(char * ID) : id(ID) { count++; }
~Counted()
cout << id << " count = " << --count << endl;
}
};
int Counted::count = 0;
class CountedVector : public vector<Counted*> {
public:
CountedVector(char* ID) {
for(int i = 0; i < 5; i++)
push_back(new Counted(ID));
}
};
// Simple function
void Destroy(Counted* fp) { delete fp; }
// Template class w/ operator()()
template<class T>
class DestroyT {
public:
void operator()(T x) { delete x; }
};
// Template function
template <class T>
void wipe(T* x) { delete x; }
int main() {
CountedVector A("one");
for_each(A.begin(), A.end(), Destroy);
CountedVector B("two");
for_each(B.begin(), B.end(),
DestroyT<Counted*>());
CountedVector C("three");
for_each(C.begin(), C.end(), wipe<Counted*>);
// Also compiles correctly:
CountedVector D("four");
for_each(D.begin(), D.end(), wipe);
} ///:~
=============================
Bruce Eckel http://www.BruceEckel.com
Contains free electronic books: "Thinking in Java" & "Thinking in C++ 2e"
More information about the Gcc-bugs
mailing list