[comp.lang.c++] Spurious error: two initializers for <class>

binky@bigsur.uucp (Glenn Langford) (08/03/90)

I suspect the following is a Cfront 2.0 bug.

Environment: Sun C++ 2.0, SparcStation 1, SunOS 4.0.3

I have included a sample program that illustrates
the problem below. An incorrect error message is
generated:

	error: two initializers for <class>

under certain conditions. The sample program defines
two classes A and B. B is derived from A, and has two
constructors. Both B constructors have initializers for
the parent class.  The 'two initializers' error is generated
for B's second constructor.

The error message only seems to appear when the translator
has found a legitimate error earlier in the program. In the example
code below, if the member function 'foo' is defined correctly,
the program compiles ok. If 'foo' is seeded with an error,
the 'two initializers' message appears.

Comments? Is this a Cfront bug, or strictly a Sun C++ problem?
Can someone try this with 2.1?

Glenn Langford (Bell-Northern Research)		Phone: (613) 763-8462
USENET:	...uunet!bnrgate!bigsur!binky	        binky@bnr.CA
Mail: P.O. Box 3511, Station C, Ottawa, Ontario, Canada, K1Y 4H7
Spurn dogma.


---------------snip snip---------------------------------------------

class A
{
	int a;

public:
	A(int);
	void foo(int);
};

class B : public A
{
	int b;

	B(int);
	B(int,int);
	~B();
	//
	// USING THE FOLLOWING DEFINITION OF 'FOO' WILL COMPILE OK
	//
	// void foo(int t) { b = t;}
	//
	// USE THIS DEFINITION OF 'FOO' TO INDUCE THE SPURIOUS
	// 'TWO INITIALIZERS' ERROR
	//
	void foo(int t) { b = woops; }
};

A::A(int x)
{ a = x; }

B::B(int x, int y) : A(x)
{ b = y; }

B::B(int x) : A(x)       // <---- error: two initializers for A
{ b = x; }

main()
{
}

--
Glenn Langford (Bell-Northern Research)		Phone: (613) 763-8462
USENET:	...uunet!bnrgate!bigsur!binky	        binky@bnr.CA
Mail: P.O. Box 3511, Station C, Ottawa, Ontario, Canada, K1Y 4H7
If you never say anything significant, no disclaimer is required.

mat@mole-end.UUCP (Mark A Terribile) (08/08/90)

> I suspect the following is a Cfront 2.0 bug.
> Environment: Sun C++ 2.0, SparcStation 1, SunOS 4.0.3

> I have included a sample program that illustrates the problem below.
> An incorrect error message is generated:
 
> 	error: two initializers for <class>
 
> under certain conditions. ...
 
> The error message only seems to appear when the translator
> has found a legitimate error earlier in the program. ...

Ah, yes.  I have noticed similar problems on the Sun 3.  I suggest you
chalk it up to a compiler bug, and probably an interesting one.  Well,
at least it doesn't dump core.

-- 

 (This man's opinions are his own.)
 From mole-end				Mark Terribile