[cfe-dev] Implicit assignment operator hidden by overloaded assignement operator?

John McCall rjmccall at apple.com
Tue Mar 9 15:05:40 PST 2010


On Mar 9, 2010, at 2:33 PM, Andrzej K. Haczewski wrote:

> Hi,
> 
> Trying to compile Ogre3D with clang I believe I found a bug. The
> reduced test case looks like this:
> 
> class A {
> };
> 
> class B {
> public:
> 	B() {}
> 
> 	B(const A& a) {
> 		operator = (CONST);
> 		operator = (a);
> 	}
> 	
> 	B& operator = (const A& a) {
> 		return *this;
> 	}
> 	
> 	static const B CONST;
> };
> 
> The clang output is:
> 
> t3.cc:13:15: error: no viable conversion from 'class B const' to 'class A const'
>                operator = (CONST);
>                            ^~~~~
> t3.cc:1:7: note: candidate constructor (the implicit copy constructor)
> not viable: no known conversion from 'class B const' to 'class A
> const' for 1st argument
> class A {
>      ^
> 2 diagnostics generated.

This seems to be a bug;  please file it.

> If you remove the overloaded operator = then everything compiles,
> which is another strange behaviour, because there should be no
> implicit class A to class B conversion.

The parameter of the implicit copy-assignment operator is being bound to a temporary B object built with the appropriate constructor.  This is correct.

John.



More information about the cfe-dev mailing list