[SunHELP] C++ compiler bug ?

Nicholas Dronen ndronen at frii.com
Thu Feb 28 15:34:49 CST 2002


On Thu, Feb 28, 2002 at 02:04:22PM -0500, Doherty, Kevin (Equities) wrote:
> Help,
> I have seen this ambiguity error on SunPro 5.2 and Rogue Wave has reproduced
> it
> with this case on all Forte/SunPro versions they have including 5.3
> tx
> ??
> 
> 
> class A
> {
>   public:
> 
>    void func( char c );
>    void func( int i ) const;
> };
> 
> 
> int main(void)
> {
>   A a;
>   int arg = 1; 
>   a.func(arg);
>     
>   return 0;
> }
> 
> [emma] /nfs/homes/haney 372% CC -c mytest.cpp
> "mytest.cpp", line 14: Error: Overloading ambiguity between "A::func(char)"
> and "A::func(int) const".
> 1 Error(s) detected.

I'm no C++ expert.  It would help for you to say why *you* think
this is a bug.  IMO, the compiler thinks that the overloaded prototypes
for func require a conversion for a non-const int argument.  This
seems counter-intuitive to me, as my understanding of const as a keyword
for a const member functios simply means that the invocation of that
function does not change the internal state of the object.

Using the code you supplied, I get the error with 6.1, not 5.0
or 4.2.  If I do either of the following:

	* Change the declaration of a to 'const int'
	* Cast arg to const int: a.func(static_cast<const int>(arg)); 

I do not get the error with 6.1.

Either open a bug with Sun (who might have a standards-based
justification for the behavior of the compiler) or use one
of the above work-arounds (or something similar).

Regards,

Nicholas Dronen



More information about the SunHELP mailing list