Bug 87496 - gcc segmentation fault while compiling the source
gcc segmentation fault while compiling the source
Status: CLOSED CURRENTRELEASE
Product: Red Hat Linux
Classification: Retired
Component: gcc3 (Show other bugs)
8.0
i686 Linux
medium Severity low
: ---
: ---
Assigned To: Jakub Jelinek
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2003-03-27 14:07 EST by Sergei Kozachenko
Modified: 2007-04-18 12:52 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2004-10-03 09:15:56 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
reformatted test case (3.49 KB, text/plain)
2004-10-03 09:09 EDT, Richard Henderson
no flags Details
re-reformatted (3.49 KB, text/plain)
2004-10-03 09:13 EDT, Richard Henderson
no flags Details

  None (edit)
Description Sergei Kozachenko 2003-03-27 14:07:09 EST
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;}/*************************************/
Comment 1 Richard Henderson 2004-10-03 09:09:39 EDT
Created attachment 104677 [details]
reformatted test case
Comment 2 Richard Henderson 2004-10-03 09:13:19 EDT
Created attachment 104678 [details]
re-reformatted

Oops, missed a critical newline to uncomment a bit of code.
Comment 3 Richard Henderson 2004-10-03 09:15:56 EDT
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 `&' ?)

Note You need to log in before you can comment on or make changes to this bug.