[comp.lang.c++] g++ bug

ronen@daisy.UUCP (daisy.ronen) (08/11/88)

I compiled the following program (taken from The Evolution of C++:1985 to 1987/
 Bjarne Stroustrup USENIX proceedings C++ Workshop 1987) to examine the 
 private/protected/public scope handling of g++.

The program was compile without any error or warning.

The g++ compiler should report errors at the statements commented with error:

Here is the program:

class X {
// private by default
	int priv;
protected:
	int prot;
public:
	int publ;
};

class Y : public X {
	void mf();
};

void Y::mf()
{
	priv = 1;		// error: priv is private
	prot = 2;		// OK: prot is protected and mf() is a member of subclass Y
	publ = 3;		// OK: publ is public
}

void f(Y* p)
{
	p->priv = 1;	// error: priv is private
	p->prot = 2;	// error: prot is protected and f() is not a friend or member of X or Y
	p->publ = 3;	// OK: publ is public
}

Ronen Arad
Daisy Systems (Mnt View, CA)
(415) 960-6884
uucp: daisy!ronen

damian@bruce.cs.monash.OZ.AU (Damian Conway) (09/06/90)

We have g++ 1.37.1 running on a Sun 350.

I _thought_ that if a class has no defined operator= the default
is copy by member.

However....

	class class1 {
		int d;
	public:
		class1() {d=1;}
		friend class1& operator=(class1&,class1);
		};

	class1& operator=(class1& c1,class1 c2) {
		c1.d=c2.d;
		return c1;
		}

	class class2 {
		int d;
	public:
		class2() {d=1;}
		};

	main() {
		class2 c1,c2;
		c1 = c2;
		}

produces:

	test.c: In function int main ():
	test.c:25: bad argument 0 for function `operator = (class class1 &, class class1)' (type was class class2 )


Questions:

	Is the defect in my understanding of g++?
	Is this a known bug?
	Is there a known fix?

damian
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  who: Damian Conway                 email:..!seismo!munnari!bruce.oz!damian
where: Dept. Computer Science        phone: +61-3-565-5779
       Monash University             quote: "A pessimist is never disappointed."
       Clayton 3168
       AUSTRALIA