[comp.lang.c++] Bug in Sun C++ 2.0

rmartin@clear.com (Bob Martin) (03/21/91)

I have been having a problem with Sun C++ 2.0.  I have a class in
which I declare the following set of overloaded member functions:

	Add(int, ...);
	Add(long, ...);
	Add(double, ...);

The compiler can disambiguate calls to the first two, but not
to the third.  If I scramble the order of the declarations, it is
still the third declaration that cannot be disambiguated.

For example:  Add((int)1, 2, 2, 0); works just fine.
and also..... Add((long)1, 2, 2, 0); also works fine.
But.......... Add((double)1.2, 2, 2, 0); fails, with complaints that
the call is ambiguous between Add(int, ...) and Add(long, ...).  It
furthermore says that a double has been converted to a int.  When I
run the program the Add(int, ...) is indeed called.

If I alter the order of the declarations so that the Add(int, ...) is
the last declaration, then it can disambiguate calls to Add(long, ...)
and Add(double, ...), but not to Add(int, ...);

Has anybody else seen this problem?  Is there a workaround?


-- 
+-Robert C. Martin-----+:RRR:::CCC:M:::::M:| Nobody is responsible for |
| rmartin@clear.com    |:R::R:C::::M:M:M:M:| my words but me.  I want  |
| uunet!clrcom!rmartin |:RRR::C::::M::M::M:| all the credit, and all   |
+----------------------+:R::R::CCC:M:::::M:| the blame.  So there.     |

rmartin@clear.com (Bob Martin) (03/23/91)

			Bug in Sun CFont 2.0
			--------------------
			 Sun Ref# 696308
			 Called in by Robert Martin.

Abstract
	In a class with overloaded member function of the form:
		
		Add(type, ...);

	Only the first two declarations are recognized.  
	Subsequent declarations do not seem to work if called
	with variable arguments.

Example

	class X
	{
	public:
		X::X() {}
		void Add(int, ...) {};
		void Add(long, ...) {};
		void Add(double, ...) {};
	};

	main()
	{
		X x;

		x.Add(1, 1);
		x.Add(1L, 2);
	/*###16 [cc] error: ambiguous argument for X::Add(): 
		void X::(int ... ) and void X::(long ... )%%%*/
	/*###16 [cc] warning: double passed as int%%%*/
		x.Add(1.2, 3); // fails.

		x.Add(1);
		x.Add(1L);
		x.Add(1.2); // works.
	} 


	But if you swap the declarations around a bit.


	class X
	{
	public:
		X::X() {}
		void Add(double, ...) {}; // now double is first.
		void Add(int, ...) {};
		void Add(long, ...) {};
	};

	main()
	{
		X x;

		x.Add(1, 1);
	/*###15 [cc] error: ambiguous argument for X::Add(): 
	void X::(double ... ) and void X::(int ... )%%%*/
		x.Add(1L, 2); // now it doesn't like longs.  
		x.Add(1.2, 3); 

		x.Add(1);
		x.Add(1L); // but this it can handle.
		x.Add(1.2); 
	} 

So I conclude that the compiler is having trouble matching
the signatures of member functions if those member functions are
called with variable arguments.  

***********

Sun has acknowledged that this is indeed a bug, and that it has been
fixed in version 2.1.


+-Robert C. Martin-----+:RRR:::CCC:M:::::M:| Nobody is responsible for |
| rmartin@clear.com    |:R::R:C::::M:M:M:M:| my words but me.  I want  |
| uunet!clrcom!rmartin |:RRR::C::::M::M::M:| all the credit, and all   |
+----------------------+:R::R::CCC:M:::::M:| the blame.  So there.     |
-- 
+-Robert C. Martin-----+:RRR:::CCC:M:::::M:| Nobody is responsible for |
| rmartin@clear.com    |:R::R:C::::M:M:M:M:| my words but me.  I want  |
| uunet!clrcom!rmartin |:RRR::C::::M::M::M:| all the credit, and all   |
+----------------------+:R::R::CCC:M:::::M:| the blame.  So there.     |