From Bugzilla Helper:User-Agent: Mozilla/5.0 (compatible; Konqueror/3; Linux)Description of problem:When I try to compile my source it(g++) says:----------------rarray.gcc-sgFault.cc: In instantiation of `rarray<int>':rarray.gcc-sgFault.cc:146: instantiated from hererarray.gcc-sgFault.cc:105: internal error: Segmentation faultPlease submit a full bug report,with preprocessed source if appropriate.See <URL:http://bugzilla.redhat.com/bugzilla/> for instructions.-----------------Version-Release number of selected component (if applicable):gcc-c++-3.2-7How reproducible:AlwaysSteps to Reproduce:1.c++ rarray.gcc-sgFault.cc2.3. Actual Results: segmentation faultExpected Results: are you joking? ;)Additional info:this is my source:/*********************************/#include <iostream>#define RUN_DEBUG#ifdef RUN_DEBUG#define DEBUG_MSG(x) std::cout << x << std::endl#else#define DEBUG_MSG(x)#endiftemplate <class TYPE> class rarray{ template <class T> class list { friend class rarray<T>; typedef struct entry_t { int num; T content; entry_t *next; } *entry; entry cur_entry, head; int cur_num; public: list() { DEBUG_MSG("incorrect using of class list"); } list(TYPE &t) { head = new entry_t; head->next = NULL; head->content = t; } ~list() { while (head) { cur_entry = head; head = head->next; delete cur_entry; } } operator TYPE&() { if (!cur_entry->next || cur_entry->next->num != cur_num) { return head->content; } return cur_entry->next->content; } void operator=(TYPE &n) { if (n == head->content) { if(cur_entry->next && cur_entry->next->num == cur_num) { entry t = cur_entry->next; cur_entry->next = cur_entry->next->next; delete t; } } else { if(cur_entry->next && cur_entry->next->num == cur_num) { cur_entry->next->content = n; } else { entry t = new entry_t; t->content = n; t->num = cur_num; t->next = cur_entry->next; cur_entry->next = t; } } } void operator=(TYPE n) const { if (n == head->content) { if(cur_entry->next && cur_entry->next->num == cur_num) { entry t = cur_entry->next; cur_entry->next = cur_entry->next->next; delete t; } } else { if(cur_entry->next && cur_entry->next->num == cur_num) { cur_entry->next->content = n; } else { entry t = new entry_t; t->content = n; t->num = cur_num; t->next = cur_entry->next; cur_entry->next = t; } } } };// I know that correctly it shoul be// typedef class list<TYPE>& (rarray<TYPE>::*pfunc)(int);// but not this typedef class list<TYPE>& (rarray<TYPE>::pfunc)(int);// but fact is the fact - there shoud not be a segmentation fault, // isn't it?protected: list<TYPE> *p; void *head; pfunc opri; TYPE zEl; list<TYPE>& listopri(int i) { p->cur_entry = p->head; while(p->cur_entry->next && p->cur_entry->next->num < i) { p->cur_entry = p->cur_entry->next; } p->cur_num = i; return *p; } void cList() { reinterpret_cast <list<TYPE>*>(head) = new list<TYPE>(zEl); p = reinterpret_cast <list<TYPE>*> (head); opri = &rarray<TYPE>::listopri; }public: rarray(TYPE &rz) : zEl(rz) { cList(); } ~rarray() { delete reinterpret_cast <list<TYPE>*>(head); } list<TYPE>& operator[](int i) { return this->rarray<TYPE>::opri(i); } // opereator+, ++, --, etc - not implemented yet...};int main(){ int n, k, z = 0; rarray <int> rar(z); for (int i = 0; i <= 10; i++) { k = 1+(int) (100.0*rand()/(RAND_MAX+1.0)); n = 1+(int) (100.0*rand()/(RAND_MAX+1.0)); rar[k] = n; std::cout << "rar[" << k << "] = " << n << " == " << rar[k] << std::endl; } k = 99; rar[0] = 4; rar[0] = rar[1]+rar[2]; k = 0; rar[20] = k; rar[2] = k; std::cout << "----------------------" << std::endl; for (int i = 0; i <= 100; i++) if (rar[i] != z) std::cout << "rar[" << i << "] = " << rar[i] << std::endl;}/*************************************/
Created attachment 104677 [details] reformatted test case
Created attachment 104678 [details] re-reformatted Oops, missed a critical newline to uncomment a bit of code.
Fails with 3.2.3-20; fixed with gcc 3.3.2-1 z.c: In member function `void rarray<TYPE>::cList() [with TYPE = int]': z.c:138: instantiated from `rarray<TYPE>::rarray(TYPE&) [with TYPE = int]' z.c:155: instantiated from here z.c:133: error: invalid use of member (did you forget the `&' ?)