[cfe-commits] [patch] Warn on self assignment for member variables

Jordan Rose jordan_rose at apple.com
Mon Jun 25 17:10:20 PDT 2012


On Jun 25, 2012, at 16:27 , Nico Weber <thakis at chromium.org> wrote:

> On Mon, Jun 25, 2012 at 3:49 PM, Jordan Rose <jordan_rose at apple.com> wrote:
>> 
>> On Jun 25, 2012, at 14:43 , Nico Weber <thakis at chromium.org> wrote:
>> 
>>> Full build of the 'chrome' target with this warning on my MBP: real   31m41.500s
>>> Same clang binary at the same revision, without the warning: real     31m53.572s
>>> 
>>> So the compile-time impact of the warning is below noise I'd say.
>>> 
>>> Nico
>> 
>> Did you remember to add a guard around the "work" part of CheckIdentityMemvarAssignment? Or were you still doing the work and just not emitting the warning?
> 
> I uncommented the call to "CheckIdentityMemvarAssignment" (and clang
> warned me that the static function CheckIdentityMemvarAssignment
> wasn't used). With "same binary" I meant "built at the same revision"

Okay, I see. I'm a little concerned along with Ted because copying over pieces of another struct does seem like something common enough to do, but I guess it's fine.

This probably won't catch "this->_a = _a", but maybe that's okay. It is a typo you might make in a setter, though.

BTW, this would be a good warning to have in Objective-C as well (ObjCIvarRefExpr). The equivalent example there would be "self->_a = _a".

Thanks for working on this. I think over all it is a good warning to have.

Jordan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120625/9338186f/attachment.html>


More information about the cfe-commits mailing list