🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #1654

Infinite loop in cc1plus caused by simple code.

#1654
From: Gordon Joly
Date: Tue, 26 Jan 1993 02:11
103 lines
2592 bytes
On a SUN4, SunOS 4.1.1, gcc 2.3.3 (built with 2.3.1) libg++ 2.3, & SUN
libc.so.1.6.1 


#include<iostream.h>
#include<String.h>

// A very simple class consisiting of a String, int pair

class Collection
{
	String name;
	int id_number;
public:
	Collection(String& s, int p):name(s),id_number(p){}

	// constructor does nothing exciting

	operator String(){return name;}

	// conversion operator similarly dull

	ostream& print(ostream& a)
		{
			a<<"name: "<<name<<"\n"
				<<"id_number: "<<id_number<<"\n";
			return a;
		}

	// output

	String& GetName()
		{
			return name;
		}
	// .. and access
};

// a trivial example function ... but could just as well have been
// a class member function for this problem

void DoSomething(String& s)
{
	cout<<"ya boo sucks: "<<s<<"\n";
}

int main()
{
	Collection guanaco("llama", 42);

//	DoSomething(guanaco.GetName());		// This works fine

	DoSomething(guanaco);			// Compiler never exits...

	guanaco.print(cout)<<"\n";

	return 0;
}

/*

----------------------------------------------------- 


Above is an example of code that compiles without error on the
departmental compiler and causes 2.3.3 to hang.

NB 2.3.3 copes if the commented DoSomething() invocation is used
instead.

I think there may be some other bugs in the error recovery department
i.e. a parse error gets reported sometimes and the compiler hangs. But
I will try to provide a separate example of this.



D.Critchley
-------------------------------------------------------------

*/


Runs with output:

porridge:gjoly/c++/2.x[76] a.out
ya boo sucks: llama
name: llama
id_number: 42

porridge:gjoly/c++/2.x[77]


Snapshot with "error"

  PID USERNAME PRI NICE   SIZE   RES STATE   TIME   WCPU    CPU COMMAND
 9845 gjoly     82    0 32424K 14256K run     1:17 74.04% 73.83% cc1plus

Gordon.


Gordon Joly      Phone  +44 71 387 7050 ext 3703      FAX  +44 71 387 1397
Internet: G.Joly@cs.ucl.ac.uk        UUCP: ...!{uunet,uknet}!ucl-cs!G.Joly
Computer Science, University College London, Gower Street, LONDON WC1E 6BT
Technical Details
Message-ID: <9301251817.AA08369@life.ai.mit.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!cs.ucl.ac.uk!G.Joly

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!cs.ucl.ac.uk!G.Joly
From: G.Joly@cs.ucl.ac.uk (Gordon Joly)
Newsgroups: gnu.gcc.bug
Subject: Infinite loop in cc1plus caused by simple code.
Date: 25 Jan 1993 21:11:16 -0500
Organization: GNUs Not Usenet
Lines: 104
Sender: daemon@cis.ohio-state.edu
Approved: bug-gcc@prep.ai.mit.edu
Distribution: gnu
Message-ID: <9301251817.AA08369@life.ai.mit.edu>