Implicit assignment operator hidden by overloaded assignement operator?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Implicit assignment operator hidden by overloaded assignement operator?

Andrzej K. Haczewski
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.

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.

Should I submit it as bugs or are these known ones?

Regards,
Andrzej
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Implicit assignment operator hidden by overloaded assignement operator?

John McCall

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.
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Implicit assignment operator hidden by overloaded assignement operator?

Andrzej K. Haczewski
2010/3/10 John McCall <[hidden email]>:

>
> On Mar 9, 2010, at 2:33 PM, Andrzej K. Haczewski wrote:
>
>>
>> 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.

Done: http://llvm.org/bugs/show_bug.cgi?id=6570

Andrzej

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev