[cfe-dev] Trying to work on "C++ Type-checking for copy assignment" project

Sebastian Redl sebastian.redl at getdesigned.at
Sat May 16 10:40:45 PDT 2009


Vyacheslav Kononenko wrote:
>> There may be a deeper issue here. Why is falling back to the built-in
>> assignment operator the wrong thing to do? Apparently it does something
>> that lets invalid cases pass. Why is that so?
>>     
> If I understand correctly in C++ assignment to a class instance can be
> done only by overloaded operator= implicit or explicit. So I think
> case with assignment operator and class instance on the left could be
> done only by overload resolution in general.
>
>   
OK, that makes sense.
>> For others,
>> especially when there are no user-defined assignment operators in the
>> target type, 'incompatible type' would be the better message.
>>     
> There is always assignment operator in a class - implicit one. So no
> viable operator= found probably is correct message even in this case.
>   
But implicit assignment operators are not user-defined. I just wonder
how hard we should try in making POD types feel like built-ins.
> Maybe it should print additional diagnostics - which assignment
> operators are available (like it does for ambiguity) but that is
> different question.
>
>   
I'm not sure, but I don't think our lookup automatically limits it to
those operators that are viable for the left-hand side, so we'd have to
filter all others out manually. We certainly don't want every possible
assignment operator in that list.
Now, with assignment only being overloadable within the class, it
probably wouldn't be that bad, but I don't want to rely on that.

>> What does it say for this:
>>
>> int i = hasNoConversionToInt();
>>
>> For this case, no viable overload would definitely be the wrong message.
>>     
> Changes that I made only for the case when class instance on the left.
> This one will work as before. I can actually put this as a test case
> there as well.
>   
Please do, and update the old test cases, and resend the patch. I'll
commit it. We can do minor improvements later.

Sebastian



More information about the cfe-dev mailing list