[PATCH] D18265: [clang-tidy] New: checker misc-assign-operator-return

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 30 06:21:28 PDT 2016


On Wed, Mar 30, 2016 at 8:52 AM, Gábor Horváth <xazax.hun at gmail.com> wrote:
> xazax.hun added a comment.
>
> In http://reviews.llvm.org/D18265#386717, @aaron.ballman wrote:
>
>> In http://reviews.llvm.org/D18265#386676, @alexfh wrote:
>>
>> > > What about NonIdiomaticAddignOperator or UnchainableAssignOperator?
>> >
>> >
>> > Yep, "unchainable" doesn't cover all problems the check detects. `misc-non-idiomatic-assign-operator` seems good though. I'd wait for the original author to chime in before making the change.
>>
>>
>> This doesn't check for idiomatic assignment, unfortunately. For instance, it allows `T &operator=(T)` which is a copy assignment, but not generally considered an idiomatic one. (Similar for allowing `volatile`-qualified parameters.) If we want to go with such a check, I would not be opposed to it, but we should definitely discuss what "idiomatic" means.
>
>
> IMHO `T &operator=(T)` can be idiomatic e.g. when one uses copy and swap idiom or `T &operator=(S)` where S is a type that can be copied efficiently.

For reference, between the Kona and Jacksonville WG21 meetings, I
started work on a checker for non-idiomatic copy and move assignment
operations because of confusion regarding copy assignment as the core
language sees it and the CopyAssignable library concept. "Idiomatic",
to me, means what the library cares about, not what the core language
does. A checker that tells the user "this is an idiomatic copy
assignment operator" is not very useful when you can't use that type
with the STL in well-defined ways. So if we want "idiomatic" in the
name of the check, we should probably review the patch behavior with
that in mind.

~Aaron


More information about the cfe-commits mailing list