[cfe-dev] [cfe-commits] r169670 - in /cfe/trunk: include/clang/AST/DeclCXX.h lib/AST/DeclCXX.cpp lib/Sema/SemaDeclCXX.cpp
Kim Gräsman
kim.grasman at gmail.com
Tue Dec 11 03:08:25 PST 2012
Hi Richard,
On Tue, Dec 11, 2012 at 1:17 AM, Richard Smith <richard at metafoo.co.uk> wrote:
>
>> I think the old one (above) called 'something' for;
>>
>> T& operator=(const T& t);
>> T& operator=(T& t);
>>
>> whereas the new one should call it for any of the below that exist:
>>
>> T& operator=(const T& t);
>> T& operator=(const volatile T& t);
>> T& operator=(T& t);
>> T& operator=(volatile T& t);
>> T& operator=(T&& t);
>>
>> I think that preserves the behavior we had and makes it more correct,
>> even if I'm not entirely sure why this is done. :-/
>
> There can only be one implicit copy assignment operator, and if there
> is an implicit one, there are no explicit ones. The former code would
> call 'something' twice, passing the same function both times...
Thanks, it's getting clearer.
The former code passed true/false to get at different const-ness,
probably according to the rule described here [1] -- sometimes the
implicit assignment operator will take a const-ref arg and sometimes
it will take a non-const-ref arg.
It looks like getCopyAssignmentOperator returned NULL if we asked for
an overload that didn't exist, so I think the only reason this worked
was because the original code was really;
something(decl->getCopyAssignmentOperator(true)) || // <--- note: OR
something(decl->getCopyAssignmentOperator(false));
Since the non-const case is by far the most common, it short-circuited
out before it could attempt to run something(NULL).
Anyway, now I understand how to phrase this under the new
implementation, thanks a lot!
- Kim
[1] http://en.cppreference.com/w/cpp/language/as_operator
More information about the cfe-dev
mailing list